aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main/java/com/google/devtools/build/lib/vfs/inmemoryfs
diff options
context:
space:
mode:
authorGravatar Nathan Harmata <nharmata@google.com>2015-10-20 21:54:34 +0000
committerGravatar Han-Wen Nienhuys <hanwen@google.com>2015-10-21 14:39:08 +0000
commitd8b6ff2dad1de2d98a407ecf67a34fe12e67d494 (patch)
tree030c5ebb89ca5835e76854ed51c0d2a75b04e4e3 /src/main/java/com/google/devtools/build/lib/vfs/inmemoryfs
parent11ef8fc44821fb593a512eb5a3423013abbe39aa (diff)
Introduce Path#isSpecialFile, FileSystem#isSpecialFile, and FileStatus#isSpecialFile to help disambiguate between a regular file and a special file, since the file size of a special file cannot be trusted.
-- MOS_MIGRATED_REVID=105903622
Diffstat (limited to 'src/main/java/com/google/devtools/build/lib/vfs/inmemoryfs')
-rw-r--r--src/main/java/com/google/devtools/build/lib/vfs/inmemoryfs/FileInfo.java5
-rw-r--r--src/main/java/com/google/devtools/build/lib/vfs/inmemoryfs/InMemoryContentInfo.java8
-rw-r--r--src/main/java/com/google/devtools/build/lib/vfs/inmemoryfs/InMemoryDirectoryInfo.java5
-rw-r--r--src/main/java/com/google/devtools/build/lib/vfs/inmemoryfs/InMemoryFileSystem.java9
-rw-r--r--src/main/java/com/google/devtools/build/lib/vfs/inmemoryfs/InMemoryLinkInfo.java5
-rw-r--r--src/main/java/com/google/devtools/build/lib/vfs/inmemoryfs/OutOfScopeFileStatus.java1
6 files changed, 32 insertions, 1 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/vfs/inmemoryfs/FileInfo.java b/src/main/java/com/google/devtools/build/lib/vfs/inmemoryfs/FileInfo.java
index 2c578d1214..3c5d55c9fe 100644
--- a/src/main/java/com/google/devtools/build/lib/vfs/inmemoryfs/FileInfo.java
+++ b/src/main/java/com/google/devtools/build/lib/vfs/inmemoryfs/FileInfo.java
@@ -43,6 +43,11 @@ public abstract class FileInfo extends InMemoryContentInfo {
return true;
}
+ @Override
+ public boolean isSpecialFile() {
+ return false;
+ }
+
protected abstract byte[] readContent() throws IOException;
protected abstract OutputStream getOutputStream(boolean append) throws IOException;
diff --git a/src/main/java/com/google/devtools/build/lib/vfs/inmemoryfs/InMemoryContentInfo.java b/src/main/java/com/google/devtools/build/lib/vfs/inmemoryfs/InMemoryContentInfo.java
index 6a721f1f94..d0044ccd28 100644
--- a/src/main/java/com/google/devtools/build/lib/vfs/inmemoryfs/InMemoryContentInfo.java
+++ b/src/main/java/com/google/devtools/build/lib/vfs/inmemoryfs/InMemoryContentInfo.java
@@ -80,12 +80,18 @@ public abstract class InMemoryContentInfo implements ScopeEscapableStatus {
public abstract boolean isSymbolicLink();
/**
- * Returns true if the current object is a regular file.
+ * Returns true if the current object is a regular or special file.
*/
@Override
public abstract boolean isFile();
/**
+ * Returns true if the current object is a special file.
+ */
+ @Override
+ public abstract boolean isSpecialFile();
+
+ /**
* Returns the size of the entity denoted by the current object. For files,
* this is the length in bytes, for directories the number of children. The
* size of links is unspecified.
diff --git a/src/main/java/com/google/devtools/build/lib/vfs/inmemoryfs/InMemoryDirectoryInfo.java b/src/main/java/com/google/devtools/build/lib/vfs/inmemoryfs/InMemoryDirectoryInfo.java
index d7a6cf5407..66d7523b16 100644
--- a/src/main/java/com/google/devtools/build/lib/vfs/inmemoryfs/InMemoryDirectoryInfo.java
+++ b/src/main/java/com/google/devtools/build/lib/vfs/inmemoryfs/InMemoryDirectoryInfo.java
@@ -96,6 +96,11 @@ class InMemoryDirectoryInfo extends InMemoryContentInfo {
return false;
}
+ @Override
+ public boolean isSpecialFile() {
+ return false;
+ }
+
/**
* In the InMemory hierarchy, the getSize on a directory always returns the
* number of children in the directory.
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 2138af1ba7..fe3731ef90 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
@@ -537,6 +537,15 @@ public class InMemoryFileSystem extends ScopeEscapableFileSystem {
}
@Override
+ protected boolean isSpecialFile(Path path, boolean followSymlinks) {
+ try {
+ return stat(path, followSymlinks).isSpecialFile();
+ } catch (IOException e) {
+ return false;
+ }
+ }
+
+ @Override
protected boolean isSymbolicLink(Path path) {
try {
return stat(path, false).isSymbolicLink();
diff --git a/src/main/java/com/google/devtools/build/lib/vfs/inmemoryfs/InMemoryLinkInfo.java b/src/main/java/com/google/devtools/build/lib/vfs/inmemoryfs/InMemoryLinkInfo.java
index 5d55fb563c..56204926e2 100644
--- a/src/main/java/com/google/devtools/build/lib/vfs/inmemoryfs/InMemoryLinkInfo.java
+++ b/src/main/java/com/google/devtools/build/lib/vfs/inmemoryfs/InMemoryLinkInfo.java
@@ -50,6 +50,11 @@ class InMemoryLinkInfo extends InMemoryContentInfo {
}
@Override
+ public boolean isSpecialFile() {
+ return false;
+ }
+
+ @Override
public long getSize() {
return linkContent.toString().length();
}
diff --git a/src/main/java/com/google/devtools/build/lib/vfs/inmemoryfs/OutOfScopeFileStatus.java b/src/main/java/com/google/devtools/build/lib/vfs/inmemoryfs/OutOfScopeFileStatus.java
index 6a71c5b203..287d97d5fe 100644
--- a/src/main/java/com/google/devtools/build/lib/vfs/inmemoryfs/OutOfScopeFileStatus.java
+++ b/src/main/java/com/google/devtools/build/lib/vfs/inmemoryfs/OutOfScopeFileStatus.java
@@ -51,6 +51,7 @@ final class OutOfScopeFileStatus extends InMemoryContentInfo {
@Override public boolean isDirectory() { throw failure(); }
@Override public boolean isSymbolicLink() { throw failure(); }
@Override public boolean isFile() { throw failure(); }
+ @Override public boolean isSpecialFile() { throw failure(); }
@Override public long getSize() { throw failure(); }
@Override protected void markModificationTime() { throw failure(); }
@Override public synchronized long getLastModifiedTime() { throw failure(); }