Skip to content

Commit

Permalink
Ensure disk cache root exists
Browse files Browse the repository at this point in the history
The disk cache root directory was previously being manually created in two places before creating the disk cache client. This CL instead ensures that the disk cache root directory is created when createDiskCache() is called, and simplifies the other callsites.

This fixes an issue where the disk cache directory might not exist if using --digest_function=BLAKE3.

Closes #19202.

PiperOrigin-RevId: 555429326
Change-Id: Ifcfa8c686df30c03c9fca24be860b2db780a6374
  • Loading branch information
tylerwilliams authored and copybara-github committed Aug 10, 2023
1 parent 2f0948b commit 00dfa2e
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -142,9 +142,6 @@ private static DiskCacheClient createDiskCache(
throws IOException {
Path cacheDir =
workingDirectory.getRelative(Preconditions.checkNotNull(diskCachePath, "diskCachePath"));
if (!cacheDir.exists()) {
cacheDir.createDirectoryAndParents();
}
return new DiskCacheClient(cacheDir, verifyDownloads, digestUtil);
}

Expand All @@ -157,12 +154,6 @@ private static RemoteCacheClient createDiskAndHttpCache(
DigestUtil digestUtil,
RemoteRetrier retrier)
throws IOException {
Path cacheDir =
workingDirectory.getRelative(Preconditions.checkNotNull(diskCachePath, "diskCachePath"));
if (!cacheDir.exists()) {
cacheDir.createDirectoryAndParents();
}

RemoteCacheClient httpCache = createHttp(options, cred, authAndTlsOptions, digestUtil, retrier);
return createDiskAndRemoteClient(
workingDirectory, diskCachePath, options.remoteVerifyDownloads, digestUtil, httpCache);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ public class DiskCacheClient implements RemoteCacheClient {
* @param verifyDownloads whether verify the digest of downloaded content are the same as the
* digest used to index that file.
*/
public DiskCacheClient(Path root, boolean verifyDownloads, DigestUtil digestUtil) {
public DiskCacheClient(Path root, boolean verifyDownloads, DigestUtil digestUtil)
throws IOException {
this.verifyDownloads = verifyDownloads;
this.digestUtil = digestUtil;

Expand All @@ -66,6 +67,8 @@ public DiskCacheClient(Path root, boolean verifyDownloads, DigestUtil digestUtil
root.getChild(
Ascii.toLowerCase(digestUtil.getDigestFunction().getValueDescriptor().getName()));
}

this.root.createDirectoryAndParents();
}

/** Returns {@code true} if the provided {@code key} is stored in the CAS. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ class OnDiskBlobStoreCache extends RemoteCache {
.setSymlinkAbsolutePathStrategy(SymlinkAbsolutePathStrategy.Value.ALLOWED)
.build();

public OnDiskBlobStoreCache(RemoteOptions options, Path cacheDir, DigestUtil digestUtil) {
public OnDiskBlobStoreCache(RemoteOptions options, Path cacheDir, DigestUtil digestUtil)
throws IOException {
super(
CAPABILITIES,
new DiskCacheClient(cacheDir, /* verifyDownloads= */ true, digestUtil),
Expand Down

0 comments on commit 00dfa2e

Please sign in to comment.