aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main/java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java')
-rw-r--r--src/main/java/com/google/devtools/build/lib/vfs/AbstractFileSystem.java24
-rw-r--r--src/main/java/com/google/devtools/build/lib/vfs/AbstractFileSystemWithCustomStat.java51
-rw-r--r--src/main/java/com/google/devtools/build/lib/vfs/JavaIoFileSystem.java2
-rw-r--r--src/main/java/com/google/devtools/build/lib/vfs/ReadonlyFileSystemWithCustomStat.java88
-rw-r--r--src/main/java/com/google/devtools/build/lib/vfs/UnixFileSystem.java2
5 files changed, 141 insertions, 26 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/vfs/AbstractFileSystem.java b/src/main/java/com/google/devtools/build/lib/vfs/AbstractFileSystem.java
index 1d0b4dc070..86d90534fe 100644
--- a/src/main/java/com/google/devtools/build/lib/vfs/AbstractFileSystem.java
+++ b/src/main/java/com/google/devtools/build/lib/vfs/AbstractFileSystem.java
@@ -144,28 +144,4 @@ abstract class AbstractFileSystem extends FileSystem {
}
}
}
-
- @Override
- protected boolean isFile(Path path, boolean followSymlinks) {
- FileStatus stat = statNullable(path, followSymlinks);
- return stat != null ? stat.isFile() : false;
- }
-
- @Override
- protected boolean isSpecialFile(Path path, boolean followSymlinks) {
- FileStatus stat = statNullable(path, followSymlinks);
- return stat != null ? stat.isSpecialFile() : false;
- }
-
- @Override
- protected boolean isSymbolicLink(Path path) {
- FileStatus stat = statNullable(path, false);
- return stat != null ? stat.isSymbolicLink() : false;
- }
-
- @Override
- protected boolean isDirectory(Path path, boolean followSymlinks) {
- FileStatus stat = statNullable(path, followSymlinks);
- return stat != null ? stat.isDirectory() : false;
- }
}
diff --git a/src/main/java/com/google/devtools/build/lib/vfs/AbstractFileSystemWithCustomStat.java b/src/main/java/com/google/devtools/build/lib/vfs/AbstractFileSystemWithCustomStat.java
new file mode 100644
index 0000000000..db4fca94d5
--- /dev/null
+++ b/src/main/java/com/google/devtools/build/lib/vfs/AbstractFileSystemWithCustomStat.java
@@ -0,0 +1,51 @@
+// Copyright 2015 The Bazel Authors. All rights reserved.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+package com.google.devtools.build.lib.vfs;
+
+import java.io.IOException;
+
+/**
+ * An {@link AbstractFileSystem} that provides default implementations of {@link FileSystem#isFile}
+ * et al. in terms of {@link FileSystem#stat} (rather than the other way around, which is what
+ * {@link FileSystem} does).
+ */
+public abstract class AbstractFileSystemWithCustomStat extends AbstractFileSystem {
+ @Override
+ protected boolean isFile(Path path, boolean followSymlinks) {
+ FileStatus stat = statNullable(path, followSymlinks);
+ return stat != null ? stat.isFile() : false;
+ }
+
+ @Override
+ protected boolean isSpecialFile(Path path, boolean followSymlinks) {
+ FileStatus stat = statNullable(path, followSymlinks);
+ return stat != null ? stat.isSpecialFile() : false;
+ }
+
+ @Override
+ protected boolean isSymbolicLink(Path path) {
+ FileStatus stat = statNullable(path, false);
+ return stat != null ? stat.isSymbolicLink() : false;
+ }
+
+ @Override
+ protected boolean isDirectory(Path path, boolean followSymlinks) {
+ FileStatus stat = statNullable(path, followSymlinks);
+ return stat != null ? stat.isDirectory() : false;
+ }
+
+ @Override
+ protected abstract FileStatus stat(Path path, boolean followSymlinks) throws IOException;
+}
+
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 9d9f16e5ae..d4e69582e7 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
@@ -36,7 +36,7 @@ import java.util.Collection;
* system call - they all are associated with the VFS_STAT task.
*/
@ThreadSafe
-public class JavaIoFileSystem extends AbstractFileSystem {
+public class JavaIoFileSystem extends AbstractFileSystemWithCustomStat {
private static final LinkOption[] NO_LINK_OPTION = new LinkOption[0];
// This isn't generally safe; we rely on the file system APIs not modifying the array.
private static final LinkOption[] NOFOLLOW_LINKS_OPTION =
diff --git a/src/main/java/com/google/devtools/build/lib/vfs/ReadonlyFileSystemWithCustomStat.java b/src/main/java/com/google/devtools/build/lib/vfs/ReadonlyFileSystemWithCustomStat.java
new file mode 100644
index 0000000000..fa441250ce
--- /dev/null
+++ b/src/main/java/com/google/devtools/build/lib/vfs/ReadonlyFileSystemWithCustomStat.java
@@ -0,0 +1,88 @@
+// Copyright 2014 The Bazel Authors. All rights reserved.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+package com.google.devtools.build.lib.vfs;
+
+import java.io.IOException;
+import java.io.OutputStream;
+
+/**
+ * Functionally like a {@link ReadonlyFileSystem} and a {@link AbstractFileSystemWithCustomStat}.
+ */
+public abstract class ReadonlyFileSystemWithCustomStat extends AbstractFileSystemWithCustomStat {
+ protected ReadonlyFileSystemWithCustomStat() {
+ }
+
+ protected IOException modificationException() {
+ String longname = this.getClass().getName();
+ String shortname = longname.substring(longname.lastIndexOf('.') + 1);
+ return new IOException(
+ shortname + " does not support mutating operations");
+ }
+
+ @Override
+ protected OutputStream getOutputStream(Path path, boolean append) throws IOException {
+ throw modificationException();
+ }
+
+ @Override
+ protected void setReadable(Path path, boolean readable) throws IOException {
+ throw modificationException();
+ }
+
+ @Override
+ protected void setWritable(Path path, boolean writable) throws IOException {
+ throw modificationException();
+ }
+
+ @Override
+ protected void setExecutable(Path path, boolean executable) {
+ throw new UnsupportedOperationException("setExecutable");
+ }
+
+ @Override
+ public boolean supportsModifications() {
+ return false;
+ }
+
+ @Override
+ public boolean supportsSymbolicLinks() {
+ return false;
+ }
+
+ @Override
+ protected boolean createDirectory(Path path) throws IOException {
+ throw modificationException();
+ }
+
+ @Override
+ protected void createSymbolicLink(Path linkPath, PathFragment targetFragment) throws IOException {
+ throw modificationException();
+ }
+
+ @Override
+ protected void renameTo(Path sourcePath, Path targetPath) throws IOException {
+ throw modificationException();
+ }
+
+ @Override
+ protected boolean delete(Path path) throws IOException {
+ throw modificationException();
+ }
+
+ @Override
+ protected void setLastModifiedTime(Path path, long newTime) throws IOException {
+ throw modificationException();
+ }
+}
+
diff --git a/src/main/java/com/google/devtools/build/lib/vfs/UnixFileSystem.java b/src/main/java/com/google/devtools/build/lib/vfs/UnixFileSystem.java
index fa0c06f1f4..de7463c716 100644
--- a/src/main/java/com/google/devtools/build/lib/vfs/UnixFileSystem.java
+++ b/src/main/java/com/google/devtools/build/lib/vfs/UnixFileSystem.java
@@ -35,7 +35,7 @@ import java.util.List;
*/
// Not final only for testing.
@ThreadSafe
-public class UnixFileSystem extends AbstractFileSystem {
+public class UnixFileSystem extends AbstractFileSystemWithCustomStat {
public static final UnixFileSystem INSTANCE = new UnixFileSystem();
/**