Skip to content

Commit

Permalink
Separate new-style-hash content in DiskCache
Browse files Browse the repository at this point in the history
  • Loading branch information
tylerwilliams committed Jul 25, 2023
1 parent f48c0f6 commit f7e460d
Showing 1 changed file with 18 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@

import build.bazel.remote.execution.v2.ActionResult;
import build.bazel.remote.execution.v2.Digest;
import build.bazel.remote.execution.v2.DigestFunction;
import build.bazel.remote.execution.v2.Directory;
import build.bazel.remote.execution.v2.Tree;
import com.google.common.base.Ascii;
import com.google.common.collect.ImmutableSet;
import com.google.common.io.ByteStreams;
import com.google.common.util.concurrent.Futures;
Expand Down Expand Up @@ -53,9 +55,16 @@ public class DiskCacheClient implements RemoteCacheClient {
* digest used to index that file.
*/
public DiskCacheClient(Path root, boolean verifyDownloads, DigestUtil digestUtil) {
this.root = root;
this.verifyDownloads = verifyDownloads;
this.digestUtil = digestUtil;

if (isOldStyleDigestFunction(digestUtil.getDigestFunction())) {
this.root = root;
} else {
this.root =
root.getChild(
Ascii.toLowerCase(digestUtil.getDigestFunction().getValueDescriptor().getName()));
}
}

/** Returns {@code true} if the provided {@code key} is stored in the CAS. */
Expand Down Expand Up @@ -214,6 +223,14 @@ protected Path toPathNoSplit(String key) {
return root.getChild(key);
}

private static boolean isOldStyleDigestFunction(DigestFunction.Value digestFunction) {
// Old-style digest functions (SHA256, etc) are distinguishable by the length
// of their hash alone and do not require extra specification, but newer
// digest functions (which may have the same length hashes as the older
// functions!) must be explicitly specified in the upload resource name.
return digestFunction.getNumber() <= 7;
}

protected Path toPath(String key, boolean actionResult) {
String cacheFolder = actionResult ? AC_DIRECTORY : CAS_DIRECTORY;
// Create the file in a subfolder to bypass possible folder file count limits
Expand Down

0 comments on commit f7e460d

Please sign in to comment.