diff --git a/src/main/java/com/google/devtools/build/lib/remote/UploadManifest.java b/src/main/java/com/google/devtools/build/lib/remote/UploadManifest.java index 5210e773d4555c..1652ec0deba1bd 100644 --- a/src/main/java/com/google/devtools/build/lib/remote/UploadManifest.java +++ b/src/main/java/com/google/devtools/build/lib/remote/UploadManifest.java @@ -240,7 +240,7 @@ void addFiles(Collection files) throws ExecException, IOException, Interru continue; } if (statNoFollow.isFile() && !statNoFollow.isSpecialFile()) { - Digest digest = digestUtil.compute(file, statNoFollow.getSize()); + Digest digest = digestUtil.compute(file, statNoFollow); addFile(digest, file); continue; } @@ -264,7 +264,7 @@ void addFiles(Collection files) throws ExecException, IOException, Interru if (statFollow.isFile() && !statFollow.isSpecialFile()) { if (followSymlinks || target.isAbsolute()) { // Symlink to file uploaded as a file. - addFile(digestUtil.compute(file), file); + addFile(digestUtil.compute(file, statFollow), file); } else { // Symlink to file uploaded as a symlink. if (target.isAbsolute()) { diff --git a/src/main/java/com/google/devtools/build/lib/remote/util/DigestUtil.java b/src/main/java/com/google/devtools/build/lib/remote/util/DigestUtil.java index 781adf4abb0a42..a3332f8e5e73b2 100644 --- a/src/main/java/com/google/devtools/build/lib/remote/util/DigestUtil.java +++ b/src/main/java/com/google/devtools/build/lib/remote/util/DigestUtil.java @@ -26,6 +26,7 @@ import com.google.devtools.build.lib.remote.common.RemoteCacheClient.ActionKey; import com.google.devtools.build.lib.vfs.DigestHashFunction; import com.google.devtools.build.lib.vfs.DigestUtils; +import com.google.devtools.build.lib.vfs.FileStatus; import com.google.devtools.build.lib.vfs.Path; import com.google.devtools.build.lib.vfs.XattrProvider; import com.google.protobuf.Message; @@ -67,12 +68,27 @@ public Digest compute(byte[] blob) { return buildDigest(hashFn.getHashFunction().hashBytes(blob).toString(), blob.length); } - public Digest compute(Path file) throws IOException { - return compute(file, file.getFileSize()); + /** + * Computes a digest for a file. + * + *

Prefer calling {@link #compute(Path, FileStatus)} when a recently obtained {@link + * FileStatus} is available. + * + * @param path the file path + */ + public Digest compute(Path path) throws IOException { + return compute(path, path.stat()); } - public Digest compute(Path file, long fileSize) throws IOException { - return buildDigest(DigestUtils.getDigestWithManualFallback(file, xattrProvider), fileSize); + /** + * Computes a digest for a file. + * + * @param path the file path + * @param status a recently obtained file status, if available + */ + public Digest compute(Path path, FileStatus status) throws IOException { + return buildDigest( + DigestUtils.getDigestWithManualFallback(path, xattrProvider, status), status.getSize()); } public Digest compute(VirtualActionInput input) throws IOException {