Introduce Path#readSymbolicLinkUnchecked, intended to only be used when the caller already knows the path is a symlink, and use this new method throughout the codebase.
--
MOS_MIGRATED_REVID=103229983
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 38a29ac..88e8d3b 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
@@ -758,7 +758,7 @@
public void createSymbolicLink(PathFragment target) throws IOException {
fileSystem.createSymbolicLink(this, target);
}
-
+
/**
* Returns the target of the current path, which must be a symbolic link. The
* link contents are returned exactly, and may contain an absolute or relative
@@ -773,6 +773,18 @@
}
/**
+ * If the current path is a symbolic link, returns the target of this symbolic link. The
+ * semantics are intentionally left underspecified otherwise to permit efficient implementations.
+ *
+ * @return the content (i.e. target) of the symbolic link
+ * @throws IOException if the current path is not a symbolic link, or the
+ * contents of the link could not be read for any reason
+ */
+ public PathFragment readSymbolicLinkUnchecked() throws IOException {
+ return fileSystem.readSymbolicLinkUnchecked(this);
+ }
+
+ /**
* Returns the canonical path for this path, by repeatedly replacing symbolic
* links with their referents. Analogous to realpath(3).
*