@Override public boolean isSymlink() { return realStatus.isSymlink(); }
@Override public boolean isSymlink() { return myFs.isSymlink(); }
/** * Is this a file? * @return true if this is a file */ public boolean isFile() { return !isDirectory() && !isSymlink(); }
/** * @return The contents of the symbolic link. */ public Path getSymlink() throws IOException { if (!isSymlink()) { throw new IOException("Path " + path + " is not a symbolic link"); } return symlink; }
private FileStatus cloneStatus() throws IOException { return new FileStatus(status.getLen(), status.isDirectory(), status.getReplication(), status.getBlockSize(), status.getModificationTime(), status.getAccessTime(), null, null, null, status.isSymlink() ? status.getSymlink() : null, status.getPath()); } }
if (stat.isDirectory() || stat.isSymlink()) { throw new IllegalArgumentException("PathHandle only available for files");
@Override public FileStatus getFileLinkStatus(final Path f) throws IOException { FileStatus status = fsImpl.getFileLinkStatus(f); // FileSystem#getFileLinkStatus qualifies the link target // AbstractFileSystem needs to return it plain since it's qualified // in FileContext, so re-get and set the plain target if (status.isSymlink()) { status.setSymlink(fsImpl.getLinkTarget(f)); } return status; }
/** * Copy constructor. * * @param other FileStatus to copy */ public FileStatus(FileStatus other) throws IOException { // It's important to call the getters here instead of directly accessing the // members. Subclasses like ViewFsFileStatus can override the getters. this(other.getLen(), other.isDirectory(), other.getReplication(), other.getBlockSize(), other.getModificationTime(), other.getAccessTime(), other.getPermission(), other.getOwner(), other.getGroup(), (other.isSymlink() ? other.getSymlink() : null), other.getPath()); }
@Override protected void processPath(PathData item) throws IOException { if (item.stat.isSymlink()) { throw new PathIOException(item.toString(), "Symlinks unsupported"); } if (item.stat.isFile()) { // Do the checking if the file is erasure coded since // replication factor for an EC file is meaningless. if (!item.stat.isErasureCoded()) { if (!item.fs.setReplication(item.path, newRep)) { throw new IOException("Could not set replication for: " + item); } out.println("Replication " + newRep + " set: " + item); if (waitOpt) { waitList.add(item); } } else { out.println("Did not set replication for: " + item + ", because it's an erasure coded file."); } } }
/** * Replace the scheme of the input {@link FileStatus} if it matches the string to replace. */ 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); } }
/** * Return a FileStatus representing the given path. If the path refers * to a symlink return a FileStatus representing the link rather than * the object the link refers to. */ @Override public FileStatus getFileLinkStatus(final Path f) throws IOException { FileStatus fi = getFileLinkStatusInternal(f, false); // getFileLinkStatus is supposed to return a symlink with a // qualified path if (fi.isSymlink()) { Path targetQual = FSLinkResolver.qualifySymlinkTarget(this.getUri(), fi.getPath(), fi.getSymlink()); fi.setSymlink(targetQual); } return fi; }
/** * Constructor * @param stat a file status * @param locations a file's block locations */ public LocatedFileStatus(FileStatus stat, BlockLocation[] locations) { this(stat.getLen(), stat.isDirectory(), stat.getReplication(), stat.getBlockSize(), stat.getModificationTime(), stat.getAccessTime(), stat.getPermission(), stat.getOwner(), stat.getGroup(), null, stat.getPath(), stat.hasAcl(), stat.isEncrypted(), stat.isErasureCoded(), locations); if (stat.isSymlink()) { try { setSymlink(stat.getSymlink()); } catch (IOException e) { throw new RuntimeException("Unexpected exception", e); } } }
@Override public FileStatus next(final AbstractFileSystem fs, final Path p) throws IOException, UnresolvedLinkException { FileStatus fi = fs.getFileLinkStatus(p); if (fi.isSymlink()) { fi.setSymlink(FSLinkResolver.qualifySymlinkTarget(fs.getUri(), p, fi.getSymlink())); } return fi; } }.resolve(this, absF);
/** * Returns the {@link FileStatus} from the {@link PathData} item. If the * current options require links to be followed then the returned file status * is that of the linked file. * * @param item * PathData * @param depth * current depth in the process directories * @return FileStatus */ protected FileStatus getFileStatus(PathData item, int depth) throws IOException { FileStatus fileStatus = item.stat; if (fileStatus.isSymlink()) { if (options.isFollowLink() || (options.isFollowArgLink() && (depth == 0))) { Path linkedFile = item.fs.resolvePath(fileStatus.getSymlink()); fileStatus = getFileSystem(item).getFileStatus(linkedFile); } } return fileStatus; }
@Override protected boolean isPathRecursable(PathData item) throws IOException { if (item.stat.isDirectory()) { return true; } if (item.stat.isSymlink()) { PathData linkedItem = new PathData(item.fs.resolvePath(item.stat.getSymlink()).toString(), getConf()); if (linkedItem.stat.isDirectory()) { if (getOptions().isFollowLink()) { return true; } if (getOptions().isFollowArgLink() && (getDepth() == 0)) { return true; } } } return false; }
setOwner(other.getOwner()); setGroup(other.getGroup()); setSymlink((other.isSymlink() ? other.getSymlink() : null)); setPath(other.getPath()); attr = attributes(other.hasAcl(), other.isEncrypted(), other.isErasureCoded(), other.isSnapshotEnabled()); assert !(isDirectory() && isSymlink()) : "A directory cannot be a symlink";
/** * Called with a source and target destination pair * @param src for the operation * @param dst for the operation * @throws IOException if anything goes wrong */ protected void processPath(PathData src, PathData dst) throws IOException { if (src.stat.isSymlink()) { // TODO: remove when FileContext is supported, this needs to either // copy the symlink or deref the symlink throw new PathOperationException(src.toString()); } else if (src.stat.isFile()) { copyFileToTarget(src, dst); } else if (src.stat.isDirectory() && !isRecursive()) { throw new PathIsDirectoryException(src.toString()); } }
@Override protected void recursePath(PathData item) throws IOException { if (isStop(item)) { // this item returned a stop result so don't recurse any further return; } if (getDepth() >= getOptions().getMaxDepth()) { // reached the maximum depth so don't got any further. return; } if (item.stat.isSymlink() && getOptions().isFollowLink()) { PathData linkedItem = new PathData(item.stat.getSymlink().toString(), getConf()); if (isAncestor(item, linkedItem)) { getOptions().getErr().println( "Infinite loop ignored: " + item.toString() + " -> " + linkedItem.toString()); return; } if (linkedItem.exists) { item = linkedItem; } } if (item.stat.isDirectory()) { super.recursePath(item); } }
public static FileStatusProto convert(FileStatus stat) throws IOException { FileStatusProto.Builder bld = FileStatusProto.newBuilder(); bld.setPath(stat.getPath().toString()); if (stat.isDirectory()) { bld.setFileType(FileStatusProto.FileType.FT_DIR); } else if (stat.isSymlink()) { bld.setFileType(FileStatusProto.FileType.FT_SYMLINK) .setSymlink(stat.getSymlink().toString()); } else { bld.setFileType(FileStatusProto.FileType.FT_FILE) .setLength(stat.getLen()) .setBlockReplication(stat.getReplication()) .setBlockSize(stat.getBlockSize()); } bld.setAccessTime(stat.getAccessTime()) .setModificationTime(stat.getModificationTime()) .setOwner(stat.getOwner()) .setGroup(stat.getGroup()) .setPermission(convert(stat.getPermission())); int flags = 0; flags |= stat.hasAcl() ? FileStatusProto.Flags.HAS_ACL_VALUE : 0; flags |= stat.isEncrypted() ? FileStatusProto.Flags.HAS_CRYPT_VALUE : 0; flags |= stat.isErasureCoded() ? FileStatusProto.Flags.HAS_EC_VALUE : 0; flags |= stat.isSnapshotEnabled() ? FileStatusProto.Flags .SNAPSHOT_ENABLED_VALUE : 0; bld.setFlags(flags); return bld.build(); }