aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar Eric Fellheimer <felly@google.com>2015-06-02 20:16:57 +0000
committerGravatar Kristina Chodorow <kchodorow@google.com>2015-06-03 13:48:55 +0000
commitfb6e5e9ec2aec8fbff7531423137f07ff7b8359a (patch)
tree377289476ee5955c30fd08b60268722be06debee
parent2ffc4fe76740e4d1b45de45af1293f80eb80be6f (diff)
Slight refactoring of readdir().
-- MOS_MIGRATED_REVID=95036998
-rw-r--r--src/main/java/com/google/devtools/build/lib/vfs/FileSystem.java28
-rw-r--r--src/test/java/com/google/devtools/build/lib/vfs/FileSystemTest.java10
2 files changed, 17 insertions, 21 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;
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!");