From fb6e5e9ec2aec8fbff7531423137f07ff7b8359a Mon Sep 17 00:00:00 2001 From: Eric Fellheimer Date: Tue, 2 Jun 2015 20:16:57 +0000 Subject: Slight refactoring of readdir(). -- MOS_MIGRATED_REVID=95036998 --- .../google/devtools/build/lib/vfs/FileSystem.java | 28 ++++++++++++---------- .../devtools/build/lib/vfs/FileSystemTest.java | 10 ++------ 2 files changed, 17 insertions(+), 21 deletions(-) (limited to 'src') 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 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 children = getDirectoryEntries(path); List 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; diff --git a/src/test/java/com/google/devtools/build/lib/vfs/FileSystemTest.java b/src/test/java/com/google/devtools/build/lib/vfs/FileSystemTest.java index 9481b229c8..599c767984 100644 --- a/src/test/java/com/google/devtools/build/lib/vfs/FileSystemTest.java +++ b/src/test/java/com/google/devtools/build/lib/vfs/FileSystemTest.java @@ -236,12 +236,6 @@ public abstract class FileSystemTest { return (savedTime <= testTime); } - Path getTestFile() throws IOException { - Path tempPath = absolutize("test-file"); - FileSystemUtils.createEmptyFile(tempPath); - return tempPath; - } - protected Path absolutize(String relativePathName) { return workingDir.getRelative(relativePathName); } @@ -946,7 +940,7 @@ public abstract class FileSystemTest { } @Test - public void testInpuStreamThrowExceptionOnDirectory() throws Exception { + public void testOutputStreamThrowExceptionOnDirectory() throws Exception { try { xEmptyDirectory.getOutputStream(); fail("The Exception was not thrown!"); @@ -956,7 +950,7 @@ public abstract class FileSystemTest { } @Test - public void testOutputStreamThrowExceptionOnDirectory() throws Exception { + public void testInputStreamThrowExceptionOnDirectory() throws Exception { try { xEmptyDirectory.getInputStream(); fail("The Exception was not thrown!"); -- cgit v1.2.3