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/Path.java b/src/main/java/com/google/devtools/build/lib/vfs/Path.java
index 532a5f0..657bb03 100644
--- a/src/main/java/com/google/devtools/build/lib/vfs/Path.java
+++ b/src/main/java/com/google/devtools/build/lib/vfs/Path.java
@@ -826,6 +826,16 @@
}
/**
+ * Create a hard link for the current path.
+ *
+ * @param link the path of the new link
+ * @throws IOException if there was an error executing {@link FileSystem#createHardLink}
+ */
+ public void createHardLink(Path link) throws IOException {
+ fileSystem.createHardLink(link, this);
+ }
+
+ /**
* Returns the canonical path for this path, by repeatedly replacing symbolic
* links with their referents. Analogous to realpath(3).
*
@@ -1135,7 +1145,8 @@
// requires us to always go up to the top-level directory and copy all segments into a new
// string array.
// This was previously showing up as a hotspot in a profile of globbing a large directory.
- Path a = this, b = o;
+ Path a = this;
+ Path b = o;
int maxDepth = Math.min(a.depth, b.depth);
while (a.depth > maxDepth) {
a = a.getParentDirectory();
@@ -1148,7 +1159,8 @@
// If a is the same as this, this.depth must be less than o.depth.
return equals(a) ? -1 : 1;
}
- Path previousa, previousb;
+ Path previousa;
+ Path previousb;
do {
previousa = a;
previousb = b;