diff options
author | 2018-01-18 10:29:11 -0800 | |
---|---|---|
committer | 2018-01-18 10:31:11 -0800 | |
commit | 4c9fafd8e7137ed117529e0a72ed4d9aefe6ec48 (patch) | |
tree | 323f9f1ba9aba622847f2da082f273b9c8e09ebf /src/main/java/com/google/devtools/build/lib/vfs/RootedPath.java | |
parent | 4dce09cdc7914d76401a6f77fd78e0176d173dd1 (diff) |
Add absolute root concept.
An absolute root accepts any absolute path fragments and simply returns it.
This concept replaces the FileSystem root directory concept.
PiperOrigin-RevId: 182400471
Diffstat (limited to 'src/main/java/com/google/devtools/build/lib/vfs/RootedPath.java')
-rw-r--r-- | src/main/java/com/google/devtools/build/lib/vfs/RootedPath.java | 15 |
1 files changed, 8 insertions, 7 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/vfs/RootedPath.java b/src/main/java/com/google/devtools/build/lib/vfs/RootedPath.java index 415e0ac80d..8deca0a95c 100644 --- a/src/main/java/com/google/devtools/build/lib/vfs/RootedPath.java +++ b/src/main/java/com/google/devtools/build/lib/vfs/RootedPath.java @@ -41,7 +41,10 @@ public class RootedPath implements Serializable { /** Constructs a {@link RootedPath} from a {@link Root} and path fragment relative to the root. */ private RootedPath(Root root, PathFragment relativePath) { - Preconditions.checkState(!relativePath.isAbsolute(), "relativePath: %s root: %s", relativePath, + Preconditions.checkState( + relativePath.isAbsolute() == root.isAbsolute(), + "relativePath: %s root: %s", + relativePath, root); this.root = root; this.relativePath = relativePath.normalize(); @@ -51,10 +54,8 @@ public class RootedPath implements Serializable { /** Returns a rooted path representing {@code relativePath} relative to {@code root}. */ public static RootedPath toRootedPath(Root root, PathFragment relativePath) { if (relativePath.isAbsolute()) { - if (root.isRootDirectory()) { - return new RootedPath( - Root.fromPath(root.getRelative(relativePath.windowsVolume())), - relativePath.toRelative()); + if (root.isAbsolute()) { + return new RootedPath(root, relativePath); } else { Preconditions.checkArgument( root.contains(relativePath), @@ -84,7 +85,7 @@ public class RootedPath implements Serializable { return toRootedPath(root, path); } } - return toRootedPath(Root.fromFileSystemRoot(path.getFileSystem()), path); + return toRootedPath(Root.absoluteRoot(path.getFileSystem()), path); } public Path asPath() { @@ -135,7 +136,7 @@ public class RootedPath implements Serializable { /** Create an instance which will deserialize RootedPaths on {@code fileSystem}. */ public RootedPathCodec(FileSystem fileSystem) { - this.rootCodec = Root.getCodec(new PathCodec(fileSystem)); + this.rootCodec = Root.getCodec(fileSystem, new PathCodec(fileSystem)); } @Override |