diff options
author | 2017-10-23 18:16:44 +0200 | |
---|---|---|
committer | 2017-10-23 18:42:42 +0200 | |
commit | 0a82e703427bad76884396c171a4517e88474d69 (patch) | |
tree | 5a5a4c87dcbf6426dd0ee620f07405500b4e831d /src/main/java/com/google/devtools/build/lib/vfs | |
parent | b80c21a3eee246a1e9c7b9b2b1e19f769f93430a (diff) |
Change FileSystem#getDirectoryEntries to return strings of the file/directory names instead of paths.
This is a small isolated change that can be done ahead of the big refactoring.
PiperOrigin-RevId: 173124518
Diffstat (limited to 'src/main/java/com/google/devtools/build/lib/vfs')
5 files changed, 24 insertions, 18 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/vfs/FileSystem.java b/src/main/java/com/google/devtools/build/lib/vfs/FileSystem.java index 75851faa91..fe707ea6c3 100644 --- a/src/main/java/com/google/devtools/build/lib/vfs/FileSystem.java +++ b/src/main/java/com/google/devtools/build/lib/vfs/FileSystem.java @@ -619,12 +619,12 @@ public abstract class FileSystem { protected abstract boolean exists(Path path, boolean followSymlinks); /** - * Returns a collection containing the names of all entities within the - * directory denoted by the {@code path}. + * Returns a collection containing the names of all entities within the directory denoted by the + * {@code path}. * * @throws IOException if there was an error reading the directory entries */ - protected abstract Collection<Path> getDirectoryEntries(Path path) throws IOException; + protected abstract Collection<String> getDirectoryEntries(Path path) throws IOException; protected static Dirent.Type direntFromStat(FileStatus stat) { if (stat == null) { @@ -652,11 +652,12 @@ public abstract class FileSystem { * @throws IOException if there was an error reading the directory entries */ protected Collection<Dirent> readdir(Path path, boolean followSymlinks) throws IOException { - Collection<Path> children = getDirectoryEntries(path); + Collection<String> children = getDirectoryEntries(path); List<Dirent> dirents = Lists.newArrayListWithCapacity(children.size()); - for (Path child : children) { - Dirent.Type type = direntFromStat(statNullable(child, followSymlinks)); - dirents.add(new Dirent(child.getBaseName(), type)); + for (String child : children) { + Path childPath = path.getChild(child); + Dirent.Type type = direntFromStat(statNullable(childPath, followSymlinks)); + dirents.add(new Dirent(child, type)); } return dirents; } diff --git a/src/main/java/com/google/devtools/build/lib/vfs/JavaIoFileSystem.java b/src/main/java/com/google/devtools/build/lib/vfs/JavaIoFileSystem.java index 9ce2922584..aa3b6c3741 100644 --- a/src/main/java/com/google/devtools/build/lib/vfs/JavaIoFileSystem.java +++ b/src/main/java/com/google/devtools/build/lib/vfs/JavaIoFileSystem.java @@ -69,7 +69,7 @@ public class JavaIoFileSystem extends AbstractFileSystemWithCustomStat { } @Override - protected Collection<Path> getDirectoryEntries(Path path) throws IOException { + protected Collection<String> getDirectoryEntries(Path path) throws IOException { File file = getIoFile(path); String[] entries = null; long startTime = Profiler.nanoTimeMaybe(); @@ -85,10 +85,10 @@ public class JavaIoFileSystem extends AbstractFileSystemWithCustomStat { } finally { profiler.logSimpleTask(startTime, ProfilerTask.VFS_DIR, file.getPath()); } - Collection<Path> result = new ArrayList<>(entries.length); + Collection<String> result = new ArrayList<>(entries.length); for (String entry : entries) { if (!entry.equals(".") && !entry.equals("..")) { - result.add(path.getChild(entry)); + result.add(entry); } } return result; diff --git a/src/main/java/com/google/devtools/build/lib/vfs/Path.java b/src/main/java/com/google/devtools/build/lib/vfs/Path.java index b5eabcf1bf..81b7ac083f 100644 --- a/src/main/java/com/google/devtools/build/lib/vfs/Path.java +++ b/src/main/java/com/google/devtools/build/lib/vfs/Path.java @@ -33,6 +33,7 @@ import java.lang.ref.ReferenceQueue; import java.lang.ref.WeakReference; import java.net.URI; import java.net.URISyntaxException; +import java.util.ArrayList; import java.util.Collection; import java.util.IdentityHashMap; import java.util.Objects; @@ -514,7 +515,12 @@ public class Path implements Comparable<Path>, Serializable { * @throws IOException If the path does not denote a directory */ public Collection<Path> getDirectoryEntries() throws IOException, FileNotFoundException { - return fileSystem.getDirectoryEntries(this); + Collection<String> entries = fileSystem.getDirectoryEntries(this); + Collection<Path> result = new ArrayList<>(entries.size()); + for (String entry : entries) { + result.add(getChild(entry)); + } + return result; } /** diff --git a/src/main/java/com/google/devtools/build/lib/vfs/UnionFileSystem.java b/src/main/java/com/google/devtools/build/lib/vfs/UnionFileSystem.java index 8ef2760bb5..e444a591ee 100644 --- a/src/main/java/com/google/devtools/build/lib/vfs/UnionFileSystem.java +++ b/src/main/java/com/google/devtools/build/lib/vfs/UnionFileSystem.java @@ -333,15 +333,14 @@ public class UnionFileSystem extends FileSystem { * @param path the {@link Path} whose children are to be retrieved */ @Override - protected Collection<Path> getDirectoryEntries(Path path) throws IOException { - Path origPath = path; + protected Collection<String> getDirectoryEntries(Path path) throws IOException { path = internalResolveSymlink(path); FileSystem delegate = getDelegate(path); Path resolvedPath = adjustPath(path, delegate); Collection<Path> entries = resolvedPath.getDirectoryEntries(); - Collection<Path> result = Lists.newArrayListWithCapacity(entries.size()); + Collection<String> result = Lists.newArrayListWithCapacity(entries.size()); for (Path entry : entries) { - result.add(origPath.getChild(entry.getBaseName())); + result.add(entry.getBaseName()); } return result; } diff --git a/src/main/java/com/google/devtools/build/lib/vfs/inmemoryfs/InMemoryFileSystem.java b/src/main/java/com/google/devtools/build/lib/vfs/inmemoryfs/InMemoryFileSystem.java index 7a91db7eed..6bb578037d 100644 --- a/src/main/java/com/google/devtools/build/lib/vfs/inmemoryfs/InMemoryFileSystem.java +++ b/src/main/java/com/google/devtools/build/lib/vfs/inmemoryfs/InMemoryFileSystem.java @@ -641,7 +641,7 @@ public class InMemoryFileSystem extends FileSystem { } @Override - protected Collection<Path> getDirectoryEntries(Path path) throws IOException { + protected Collection<String> getDirectoryEntries(Path path) throws IOException { synchronized (this) { InMemoryDirectoryInfo dirInfo = getDirectory(path); FileStatus status = stat(path, false); @@ -651,10 +651,10 @@ public class InMemoryFileSystem extends FileSystem { } Collection<String> allChildren = dirInfo.getAllChildren(); - List<Path> result = new ArrayList<>(allChildren.size()); + List<String> result = new ArrayList<>(allChildren.size()); for (String child : allChildren) { if (!(child.equals(".") || child.equals(".."))) { - result.add(path.getChild(child)); + result.add(child); } } return result; |