diff options
author | 2015-06-02 20:16:57 +0000 | |
---|---|---|
committer | 2015-06-03 13:48:55 +0000 | |
commit | fb6e5e9ec2aec8fbff7531423137f07ff7b8359a (patch) | |
tree | 377289476ee5955c30fd08b60268722be06debee /src/main/java/com | |
parent | 2ffc4fe76740e4d1b45de45af1293f80eb80be6f (diff) |
Slight refactoring of readdir().
--
MOS_MIGRATED_REVID=95036998
Diffstat (limited to 'src/main/java/com')
-rw-r--r-- | src/main/java/com/google/devtools/build/lib/vfs/FileSystem.java | 28 |
1 files changed, 15 insertions, 13 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 87658ca4c1..873127f5d8 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 @@ -491,6 +491,20 @@ public abstract class FileSystem { */ protected abstract Collection<Path> getDirectoryEntries(Path path) throws IOException; + protected static Dirent.Type direntFromStat(FileStatus stat) { + if (stat == null) { + return Type.UNKNOWN; + } else if (stat.isFile()) { + return Type.FILE; + } else if (stat.isDirectory()) { + return Type.DIRECTORY; + } else if (stat.isSymbolicLink()) { + return Type.SYMLINK; + } else { + return Type.UNKNOWN; + } + } + /** * Returns a Dirents structure, listing the names of all entries within the * directory {@code path}, plus their types (file, directory, other). @@ -504,19 +518,7 @@ public abstract class FileSystem { Collection<Path> children = getDirectoryEntries(path); List<Dirent> dirents = Lists.newArrayListWithCapacity(children.size()); for (Path child : children) { - FileStatus stat = statNullable(child, followSymlinks); - Dirent.Type type; - if (stat == null) { - type = Type.UNKNOWN; - } else if (stat.isFile()) { - type = Type.FILE; - } else if (stat.isDirectory()) { - type = Type.DIRECTORY; - } else if (stat.isSymbolicLink()) { - type = Type.SYMLINK; - } else { - type = Type.UNKNOWN; - } + Dirent.Type type = direntFromStat(statNullable(child, followSymlinks)); dirents.add(new Dirent(child.getBaseName(), type)); } return dirents; |