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
diff --git a/src/main/java/com/google/devtools/build/lib/vfs/UnionFileSystem.java b/src/main/java/com/google/devtools/build/lib/vfs/UnionFileSystem.java
index cf67d1e..a0a0955 100644
--- a/src/main/java/com/google/devtools/build/lib/vfs/UnionFileSystem.java
+++ b/src/main/java/com/google/devtools/build/lib/vfs/UnionFileSystem.java
@@ -173,6 +173,11 @@
}
@Override
+ public boolean supportsHardLinksNatively() {
+ return true;
+ }
+
+ @Override
public boolean isFilePathCaseSensitive() {
return this.isCaseSensitive;
}
@@ -435,4 +440,20 @@
sourceDelegate.delete(sourcePath);
}
}
+
+ @Override
+ protected void createFSDependentHardLink(Path linkPath, Path originalPath)
+ throws IOException {
+ checkModifiable();
+
+ FileSystem originalDelegate = getDelegate(originalPath);
+ FileSystem linkDelegate = getDelegate(linkPath);
+
+ if (!originalDelegate.equals(linkDelegate) || !linkDelegate.supportsHardLinksNatively()) {
+ throw new UnsupportedOperationException(
+ "Attempted to create a hard link, but hard link support is disabled.");
+ }
+ linkDelegate.createFSDependentHardLink(
+ adjustPath(linkPath, linkDelegate), adjustPath(originalPath, originalDelegate));
+ }
}