/** * Creates results for a file or for a symlink that points to one. * * <p>A symlink may be direct (points to a file) or transitive (points at a direct or transitive * symlink). */ private static RecursiveFilesystemTraversalValue resultForFileRoot( RootedPath path, FileInfo info) { Preconditions.checkState( info.type.isFile() && info.type.exists(), "{%s} {%s}", path, info.type); if (info.type.isSymlink()) { return RecursiveFilesystemTraversalValue.of( ResolvedFile.symlinkToFile( info.realPath, path, info.unresolvedSymlinkTarget, info.metadata)); } else { return RecursiveFilesystemTraversalValue.of(ResolvedFile.regularFile(path, info.metadata)); } }
/** * Creates result for a dangling symlink. * * @param linkName path to the symbolic link * @param info the {@link FileInfo} associated with the link file */ private static RecursiveFilesystemTraversalValue resultForDanglingSymlink( RootedPath linkName, FileInfo info) { Preconditions.checkState( info.type.isSymlink() && !info.type.exists(), "{%s} {%s}", linkName, info.type); return RecursiveFilesystemTraversalValue.of( ResolvedFile.danglingSymlink(linkName, info.unresolvedSymlinkTarget, info.metadata)); }
private static RecursiveFilesystemTraversalValue resultForDirectory( TraversalRequest traversal, FileInfo rootInfo, Collection<RecursiveFilesystemTraversalValue> subdirTraversals) { // Collect transitive closure of files in subdirectories. NestedSetBuilder<ResolvedFile> paths = NestedSetBuilder.stableOrder(); for (RecursiveFilesystemTraversalValue child : subdirTraversals) { paths.addTransitive(child.getTransitiveFiles()); } ResolvedFile root; if (rootInfo.type.isSymlink()) { root = ResolvedFile.symlinkToDirectory( rootInfo.realPath, traversal.path, rootInfo.unresolvedSymlinkTarget, rootInfo.metadata); paths.add(root); } else { root = ResolvedFile.directory(rootInfo.realPath); } return RecursiveFilesystemTraversalValue.of(root, paths.build()); }