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 3bcec69
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 @@ -214,10 +216,25 @@ 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) {
Path rootDir = root;
if (!isOldStyleDigestFunction(digestUtil.getDigestFunction())) {
rootDir =
rootDir.getChild(
Ascii.toLowerCase(digestUtil.getDigestFunction().getValueDescriptor().getName()));
}

String cacheFolder = actionResult ? AC_DIRECTORY : CAS_DIRECTORY;
// Create the file in a subfolder to bypass possible folder file count limits
return root.getChild(cacheFolder).getChild(key.substring(0, 2)).getChild(key);
return rootDir.getChild(cacheFolder).getChild(key.substring(0, 2)).getChild(key);
}

private void saveFile(String key, InputStream in, boolean actionResult) throws IOException {
Expand Down

0 comments on commit 3bcec69

Please sign in to comment.