aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main/java
diff options
context:
space:
mode:
authorGravatar tomlu <tomlu@google.com>2018-01-11 17:21:55 -0800
committerGravatar Copybara-Service <copybara-piper@google.com>2018-01-11 17:23:20 -0800
commit88131ba135e743c2237bf62a3bc17a2a7a1c24f8 (patch)
tree090f73ef799e20182dc393d6c1ab87156dcca45e /src/main/java
parent3864a45afa368473a4a6a90d69edb48cb67d367a (diff)
Factor out InMemoryFileSystem's use of root directory.
When there is no root directory this minimises the size of the change required to keep InMemoryFileSystem working. PiperOrigin-RevId: 181685159
Diffstat (limited to 'src/main/java')
-rw-r--r--src/main/java/com/google/devtools/build/lib/vfs/inmemoryfs/InMemoryFileSystem.java25
1 files changed, 14 insertions, 11 deletions
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 0008423cc9..e63d03f817 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
@@ -349,8 +349,7 @@ public class InMemoryFileSystem extends FileSystem {
// and it may only appear as part of a contiguous prefix sequence.
Stack<String> stack = new Stack<>();
- PathFragment rootPathFragment = getRootDirectory().asFragment();
- for (Path p = path; !p.asFragment().equals(rootPathFragment); p = p.getParentDirectory()) {
+ for (Path p = path; !isRootDirectory(p); p = p.getParentDirectory()) {
stack.push(p.getBaseName());
}
@@ -425,7 +424,7 @@ public class InMemoryFileSystem extends FileSystem {
if (followSymlinks) {
return scopeLimitedStat(path, true);
} else {
- if (path.equals(getRootDirectory())) {
+ if (isRootDirectory(path)) {
return rootInode;
} else {
return getNoFollowStatOrOutOfScopeParent(path);
@@ -458,7 +457,7 @@ public class InMemoryFileSystem extends FileSystem {
if (followSymlinks) {
return pathWalk(path, false);
} else {
- if (path.equals(getRootDirectory())) {
+ if (isRootDirectory(path)) {
return rootInode;
} else {
return getNoFollowStatOrOutOfScopeParent(path);
@@ -599,7 +598,7 @@ public class InMemoryFileSystem extends FileSystem {
@Override
public boolean createDirectory(Path path) throws IOException {
- if (path.equals(getRootDirectory())) {
+ if (isRootDirectory(path)) {
throw Error.EACCES.exception(path);
}
@@ -627,7 +626,7 @@ public class InMemoryFileSystem extends FileSystem {
@Override
public synchronized void createDirectoryAndParents(Path path) throws IOException {
List<Path> subdirs = new ArrayList<>();
- for (; !path.isRootDirectory(); path = path.getParentDirectory()) {
+ for (; !isRootDirectory(path); path = path.getParentDirectory()) {
if (path.isDirectory()) {
break;
} else if (path.exists()) {
@@ -643,7 +642,7 @@ public class InMemoryFileSystem extends FileSystem {
@Override
protected void createSymbolicLink(Path path, PathFragment targetFragment)
throws IOException {
- if (path.equals(getRootDirectory())) {
+ if (isRootDirectory(path)) {
throw Error.EACCES.exception(path);
}
@@ -696,7 +695,7 @@ public class InMemoryFileSystem extends FileSystem {
@Override
public boolean delete(Path path) throws IOException {
- if (path.equals(getRootDirectory())) {
+ if (isRootDirectory(path)) {
throw Error.EBUSY.exception(path);
}
if (!exists(path, false)) { return false; }
@@ -770,10 +769,10 @@ public class InMemoryFileSystem extends FileSystem {
@Override
public void renameTo(Path sourcePath, Path targetPath)
throws IOException {
- if (sourcePath.equals(getRootDirectory())) {
+ if (isRootDirectory(sourcePath)) {
throw Error.EACCES.exception(sourcePath);
}
- if (targetPath.equals(getRootDirectory())) {
+ if (isRootDirectory(targetPath)) {
throw Error.EACCES.exception(targetPath);
}
synchronized (this) {
@@ -821,7 +820,7 @@ public class InMemoryFileSystem extends FileSystem {
throws IOException {
// Same check used when creating a symbolic link
- if (originalPath.equals(getRootDirectory())) {
+ if (isRootDirectory(originalPath)) {
throw Error.EACCES.exception(originalPath);
}
@@ -838,4 +837,8 @@ public class InMemoryFileSystem extends FileSystem {
linkPath);
}
}
+
+ private boolean isRootDirectory(Path path) {
+ return path.isRootDirectory();
+ }
}