aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main/java/com/google/devtools/build/lib/vfs/ZipFileSystem.java
diff options
context:
space:
mode:
authorGravatar Laszlo Csomor <laszlocsomor@google.com>2016-10-17 14:56:30 +0000
committerGravatar Philipp Wollermann <philwo@google.com>2016-10-18 10:55:49 +0000
commite0d7a540e3c615c628f63fcaaaba0c47fca2cb25 (patch)
treea1e5db9dcc26fdaa8524531d318bca49e1daffbf /src/main/java/com/google/devtools/build/lib/vfs/ZipFileSystem.java
parent50b4e8f62b57f2d13acc9b3538525a231dba704e (diff)
VFS: implement a Windows-specific Path subclass
The new subclass WindowsFileSystem.WindowsPath is aware of Windows drives. This change: - introduces a new factory for Path objects so FileSystems can return a custom implementation that instantiates filesystem-specific Paths - implements the WindowsPath subclass of Path that is aware of Windows drives - introduces the bazel.windows_unix_root JVM argument that defines the MSYS root, which defines the absolute Windows path that is the root of all Unix paths that Bazel creates (e.g. "/usr/lib" -> "C:/tools/msys64/usr/lib") except if the path is of the form "/c/foo" which is treated as "C:/foo" - removes all Windows-specific logic from Path PathFragment is still aware of drive letters and it has to remain so because it is unaware of file systems. WindowsPath restricts the allowed path strings to absolute Unix paths where the first segment, if any, is a volume specifier. From now on if Bazel attempts to create a WindowsPath from an absolute Unix path, Bazel will make it relative to WindowsPath.UNIX_ROOT, unless the first component is a single-letter name (e.g. "/c/foo" which is "C:/foo"). Subclassing Path is necessary because a Unix-style absolute path doesn't sufficiently define a full Windows path, as it may be relative to any drive. Fixes https://github.com/bazelbuild/bazel/issues/1463 -- MOS_MIGRATED_REVID=136350304
Diffstat (limited to 'src/main/java/com/google/devtools/build/lib/vfs/ZipFileSystem.java')
-rw-r--r--src/main/java/com/google/devtools/build/lib/vfs/ZipFileSystem.java32
1 files changed, 22 insertions, 10 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/vfs/ZipFileSystem.java b/src/main/java/com/google/devtools/build/lib/vfs/ZipFileSystem.java
index 4830d8fe19..892fecb10b 100644
--- a/src/main/java/com/google/devtools/build/lib/vfs/ZipFileSystem.java
+++ b/src/main/java/com/google/devtools/build/lib/vfs/ZipFileSystem.java
@@ -16,7 +16,7 @@ package com.google.devtools.build.lib.vfs;
import com.google.common.base.Predicate;
import com.google.devtools.build.lib.concurrent.ThreadSafety.ThreadSafe;
import com.google.devtools.build.lib.util.Preconditions;
-
+import com.google.devtools.build.lib.vfs.Path.PathFactory;
import java.io.Closeable;
import java.io.File;
import java.io.FileNotFoundException;
@@ -96,6 +96,23 @@ public class ZipFileSystem extends ReadonlyFileSystem implements Closeable {
// #getDirectoryEntries}. Then this field becomes redundant.
@ThreadSafe
private static class ZipPath extends Path {
+
+ private enum Factory implements PathFactory {
+ INSTANCE {
+ @Override
+ public Path createRootPath(FileSystem filesystem) {
+ Preconditions.checkArgument(filesystem instanceof ZipFileSystem);
+ return new ZipPath((ZipFileSystem) filesystem);
+ }
+
+ @Override
+ public Path createChildPath(Path parent, String childName) {
+ Preconditions.checkState(parent instanceof ZipPath);
+ return new ZipPath((ZipFileSystem) parent.getFileSystem(), childName, (ZipPath) parent);
+ }
+ };
+ }
+
/**
* Non-null iff this file/directory exists. Set by setZipEntry for files
* explicitly mentioned in the zipfile's table of contents, or implicitly
@@ -104,12 +121,12 @@ public class ZipFileSystem extends ReadonlyFileSystem implements Closeable {
ZipEntry entry = null;
// Root path.
- ZipPath(ZipFileSystem fileSystem) {
+ private ZipPath(ZipFileSystem fileSystem) {
super(fileSystem);
}
// Non-root paths.
- ZipPath(ZipFileSystem fileSystem, String name, ZipPath parent) {
+ private ZipPath(ZipFileSystem fileSystem, String name, ZipPath parent) {
super(fileSystem, name, parent);
}
@@ -128,11 +145,6 @@ public class ZipFileSystem extends ReadonlyFileSystem implements Closeable {
path.setZipEntry(new ZipEntry(path + "/")); // trailing "/" => isDir
}
}
-
- @Override
- protected ZipPath createChildPath(String childName) {
- return new ZipPath((ZipFileSystem) getFileSystem(), childName, this);
- }
}
/**
@@ -157,8 +169,8 @@ public class ZipFileSystem extends ReadonlyFileSystem implements Closeable {
}
@Override
- protected Path createRootPath() {
- return new ZipPath(this);
+ protected PathFactory getPathFactory() {
+ return ZipPath.Factory.INSTANCE;
}
/** Returns the ZipEntry associated with a given path name, if any. */