diff options
author | Googler <noreply@google.com> | 2016-09-07 14:33:29 +0000 |
---|---|---|
committer | Yun Peng <pcloudy@google.com> | 2016-09-08 08:43:41 +0000 |
commit | e1cd9509862aef684b4dbbdfd15d0b877fb8fad3 (patch) | |
tree | abc9f51fa1ecdb86854b0c39ae56dd6844cc0eb6 /src/main/java/com/google/devtools/build/lib/vfs/inmemoryfs | |
parent | 0d3e8ae7c2bd6937bc0ffd32963d6635bfe825f5 (diff) |
Fixed the issue that hard links are handled improperly when bazel decompresses tarballs.
Issue link: https://github.com/bazelbuild/bazel/issues/574
--
MOS_MIGRATED_REVID=132434278
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/InMemoryFileSystem.java | 34 |
1 files changed, 34 insertions, 0 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 dd974e55e4..e763ebe4e8 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 @@ -655,6 +655,11 @@ public class InMemoryFileSystem extends ScopeEscapableFileSystem { } @Override + public boolean supportsHardLinksNatively() { + return true; + } + + @Override public boolean isFilePathCaseSensitive() { return true; } @@ -931,4 +936,33 @@ public class InMemoryFileSystem extends ScopeEscapableFileSystem { throw Error.EACCES.exception(targetPath); } } + + @Override + protected void createFSDependentHardLink(Path linkPath, Path originalPath) + throws IOException { + + // Same check used when creating a symbolic link + if (originalPath.equals(rootPath)) { + throw Error.EACCES.exception(originalPath); + } + + InMemoryDirectoryInfo linkParent; + synchronized (this) { + linkParent = getDirectory(linkPath.getParentDirectory()); + // Same check used when creating a symbolic link + if (!linkParent.outOfScope()) { + if (linkParent.getChild(linkPath.getBaseName()) != null) { + throw Error.EEXIST.exception(linkPath); + } + insert( + linkParent, + linkPath.getBaseName(), + getDirectory(originalPath.getParentDirectory()).getChild(originalPath.getBaseName()), + linkPath); + return; + } + } + // If we get here, we're out of scope. + getDelegatedPath(linkParent.getEscapingPath(), originalPath).createHardLink(linkPath); + } } |