Example usage for org.apache.hadoop.fs FileStatus getSymlink

List of usage examples for org.apache.hadoop.fs FileStatus getSymlink

Introduction

In this page you can find the example usage for org.apache.hadoop.fs FileStatus getSymlink.

Prototype

public Path getSymlink() throws IOException 

Source Link

Usage

From source file:com.mellanox.r4h.DistributedFileSystem.java

License:Apache License

@Override
public FileStatus getFileLinkStatus(final Path f)
        throws AccessControlException, FileNotFoundException, UnsupportedFileSystemException, IOException {
    statistics.incrementReadOps(1);/*w w  w .  j  a  v  a2 s .  co m*/
    final Path absF = fixRelativePart(f);
    FileStatus status = new FileSystemLinkResolver<FileStatus>() {
        @Override
        public FileStatus doCall(final Path p) throws IOException, UnresolvedLinkException {
            HdfsFileStatus fi = dfs.getFileLinkInfo(getPathName(p));
            if (fi != null) {
                return fi.makeQualified(getUri(), p);
            } else {
                throw new FileNotFoundException("File does not exist: " + p);
            }
        }

        @Override
        public FileStatus next(final FileSystem fs, final Path p) throws IOException, UnresolvedLinkException {
            return fs.getFileLinkStatus(p);
        }
    }.resolve(this, absF);
    // Fully-qualify the symlink
    if (status.isSymlink()) {
        Path targetQual = FSLinkResolver.qualifySymlinkTarget(this.getUri(), status.getPath(),
                status.getSymlink());
        status.setSymlink(targetQual);
    }
    return status;
}

From source file:com.uber.hoodie.common.table.timeline.dto.FileStatusDTO.java

License:Apache License

public static FileStatusDTO fromFileStatus(FileStatus fileStatus) {
    if (null == fileStatus) {
        return null;
    }//from  ww  w.  j a  va  2 s  .c o  m

    FileStatusDTO dto = new FileStatusDTO();
    try {
        dto.path = FilePathDTO.fromPath(fileStatus.getPath());
        dto.length = fileStatus.getLen();
        dto.isdir = fileStatus.isDirectory();
        dto.blockReplication = fileStatus.getReplication();
        dto.blocksize = fileStatus.getBlockSize();
        dto.modificationTime = fileStatus.getModificationTime();
        dto.accessTime = fileStatus.getModificationTime();
        dto.symlink = fileStatus.isSymlink() ? FilePathDTO.fromPath(fileStatus.getSymlink()) : null;
        safeReadAndSetMetadata(dto, fileStatus);
    } catch (IOException ioe) {
        throw new HoodieException(ioe);
    }
    return dto;
}

From source file:eagle.security.hdfs.entity.FileStatusEntity.java

License:Apache License

public FileStatusEntity(FileStatus status) throws IOException {
    //this.path = status.getPath();
    this.length = status.getLen();
    this.isdir = status.isDirectory();
    this.block_replication = status.getReplication();
    this.blocksize = status.getBlockSize();
    this.modification_time = status.getModificationTime();
    this.access_time = status.getAccessTime();
    this.permission = status.getPermission();
    this.owner = status.getOwner();
    this.group = status.getGroup();
    if (status.isSymlink()) {
        this.symlink = status.getSymlink();
    }/*from w  ww .  ja va  2  s  . c o  m*/
}

From source file:fr.ens.biologie.genomique.eoulsan.data.protocols.PathDataProtocol.java

License:LGPL

@Override
public DataFileMetadata getMetadata(final DataFile src) throws IOException {

    if (!exists(src, true)) {
        throw new FileNotFoundException("File not found: " + src);
    }/* w ww  .  ja v  a  2  s  . co  m*/

    final Path path = getPath(src);
    final FileStatus status = path.getFileSystem(this.conf).getFileStatus(path);

    final SimpleDataFileMetadata result = new SimpleDataFileMetadata();
    result.setContentLength(status.getLen());
    result.setLastModified(status.getModificationTime());
    result.setDataFormat(DataFormatRegistry.getInstance().getDataFormatFromFilename(src.getName()));

    final CompressionType ct = CompressionType.getCompressionTypeByFilename(src.getSource());

    if (ct != null) {
        result.setContentEncoding(ct.getContentEncoding());
    }

    if (status.isDirectory()) {
        result.setDirectory(true);
    }

    if (status.isSymlink()) {
        result.setSymbolicLink(new DataFile(status.getSymlink().toUri()));
    }

    return result;
}

From source file:gobblin.util.filesystem.InstrumentedFileSystemUtils.java

License:Apache License

/**
 * Replace the scheme of the input {@link FileStatus} if it matches the string to replace.
 *//*from  w  w w.j ava 2 s . com*/
public static FileStatus replaceScheme(FileStatus st, String replace, String replacement) {
    if (replace != null && replace.equals(replacement)) {
        return st;
    }
    try {
        return new FileStatus(st.getLen(), st.isDir(), st.getReplication(), st.getBlockSize(),
                st.getModificationTime(), st.getAccessTime(), st.getPermission(), st.getOwner(), st.getGroup(),
                st.isSymlink() ? st.getSymlink() : null, replaceScheme(st.getPath(), replace, replacement));
    } catch (IOException ioe) {
        throw new RuntimeException(ioe);
    }
}

From source file:net.sf.jfilesync.plugins.net.items.THdfs_plugin.java

License:Apache License

protected TFileProperties extractFileProperties(FileStatus file, FileStatus[] filesInDir) throws IOException {
    TFileProperties prop = new TFileProperties();
    String filename = file.getPath().getName();
    prop.setFileName(filename);/*from  ww w.  ja v  a 2  s.co m*/

    final String cwd = fs.getWorkingDirectory().toUri().getPath();
    String fname = null;
    if (cwd.endsWith("/")) {
        fname = cwd + filename;
    } else {
        fname = cwd + "/" + filename;
    }
    prop.setAbsoluteFileName(fname);

    if (filename.startsWith(".")) {
        prop.setHiddenFlag(true);
    }

    // There is a little problem with ftp.getSize(), because it's sometimes
    // 0
    prop.setFileSize(new BigInteger(Long.toString(file.getLen())));
    // System.out.println(file.getName() + " , " + file.getTimestamp());
    prop.setFileModTime(file.getModificationTime());
    // System.out.println("file: " + fname);
    // System.out.println("isDirectory: " + file.isDirectory());
    prop.setDirectoryFlag(file.isDirectory());
    prop.setLinkFlag(file.isSymlink());

    int permissions = 0;

    permissions |= file.isDirectory() ? FilePermissions.S_IFDIR : 0;
    permissions |= file.isSymlink() ? FilePermissions.S_IFLNK : 0;
    permissions |= file.getPermission().toShort();

    final TFileAttributes attr = new TFileAttributes();
    attr.setPermissions(permissions);
    prop.setAttributes(attr);

    /*
     * what needs to be done is implement caching of directories which have
     * to be listed for link detection implement recursive link detection
     * for links to links SaHu July 2006
     */

    /*
     * if( file.isSymbolicLink() ) { System.out.println("link target : " +
     * file.getLink()); }
     */

    // if( file.isSymbolicLink() ) {
    // // check if link points to dir
    // final String linkTarget = file.getLink();
    // final String linkTargetBaseName =
    // getPathControl().basename(linkTarget);
    // //System.out.println("link target basename: " + linkTargetBaseName);
    // if( linkTarget != null ) {
    // String linkContaingPath =
    // getPathControl().getPathLevelUp(linkTarget);
    // FTPFile[] targetFiles = null;
    // if( linkContaingPath.equals("") || linkContaingPath.equals(cwd) ) {
    // targetFiles = filesInDir;
    // } else {
    // //System.out.println("check dir : " + linkContaingPath);
    // targetFiles = ftpClient.listFiles(linkContaingPath);
    // }
    //
    //
    // if( targetFiles != null ) {
    // for(int i=0; i<targetFiles.length; i++) {
    // //System.out.println("> " + targetFiles[i].getName());
    // if( targetFiles[i].getName().equals(linkTargetBaseName) ) {
    // if( targetFiles[i].isDirectory() ) {
    // prop.setDirectoryFlag(true);
    // }
    // break;
    // }
    // }
    // }
    // }
    // }

    if (file.isSymlink()) {
        Path path = file.getSymlink();
        if (fs.isDirectory(path))
            prop.setDirectoryFlag(true);
    }

    return prop;
}

From source file:org.datacleaner.windows.HdfsUrlChooser.java

License:Open Source License

private void selectOrBrowsePath(final boolean selectDirectory) {
    // Double-click detected
    final FileStatus element = _fileList.getModel().getElementAt(_fileList.getSelectedIndex());
    if (element.isSymlink()) {
        try {//from ww  w . j  av  a  2  s .  c  om
            _currentDirectory = element.getSymlink();
        } catch (final IOException e) {
            logger.warn("Could not get the symlink value for element {}", element, e);
        }
    } else if (element.isFile() || (element.isDirectory() && selectDirectory)) {
        _selectedFile = element.getPath();
        logger.info("Selected: " + _selectedFile);
        _dialog.dispose();
    } else if (element.isDirectory()) {
        _currentDirectory = element.getPath();
        _directoryComboBoxModel.updateDirectories();
    }
    ((HdfsDirectoryModel) _fileList.getModel()).updateFileList();
}