Skip to content

Commit 00dfa2e

Browse files
tylerwilliamscopybara-github
authored andcommitted
Ensure disk cache root exists
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 bazelbuild#19202. PiperOrigin-RevId: 555429326 Change-Id: Ifcfa8c686df30c03c9fca24be860b2db780a6374
1 parent 2f0948b commit 00dfa2e

File tree

3 files changed

+6
-11
lines changed

3 files changed

+6
-11
lines changed

src/main/java/com/google/devtools/build/lib/remote/RemoteCacheClientFactory.java

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -142,9 +142,6 @@ private static DiskCacheClient createDiskCache(
142142
throws IOException {
143143
Path cacheDir =
144144
workingDirectory.getRelative(Preconditions.checkNotNull(diskCachePath, "diskCachePath"));
145-
if (!cacheDir.exists()) {
146-
cacheDir.createDirectoryAndParents();
147-
}
148145
return new DiskCacheClient(cacheDir, verifyDownloads, digestUtil);
149146
}
150147

@@ -157,12 +154,6 @@ private static RemoteCacheClient createDiskAndHttpCache(
157154
DigestUtil digestUtil,
158155
RemoteRetrier retrier)
159156
throws IOException {
160-
Path cacheDir =
161-
workingDirectory.getRelative(Preconditions.checkNotNull(diskCachePath, "diskCachePath"));
162-
if (!cacheDir.exists()) {
163-
cacheDir.createDirectoryAndParents();
164-
}
165-
166157
RemoteCacheClient httpCache = createHttp(options, cred, authAndTlsOptions, digestUtil, retrier);
167158
return createDiskAndRemoteClient(
168159
workingDirectory, diskCachePath, options.remoteVerifyDownloads, digestUtil, httpCache);

src/main/java/com/google/devtools/build/lib/remote/disk/DiskCacheClient.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,8 @@ public class DiskCacheClient implements RemoteCacheClient {
5555
* @param verifyDownloads whether verify the digest of downloaded content are the same as the
5656
* digest used to index that file.
5757
*/
58-
public DiskCacheClient(Path root, boolean verifyDownloads, DigestUtil digestUtil) {
58+
public DiskCacheClient(Path root, boolean verifyDownloads, DigestUtil digestUtil)
59+
throws IOException {
5960
this.verifyDownloads = verifyDownloads;
6061
this.digestUtil = digestUtil;
6162

@@ -66,6 +67,8 @@ public DiskCacheClient(Path root, boolean verifyDownloads, DigestUtil digestUtil
6667
root.getChild(
6768
Ascii.toLowerCase(digestUtil.getDigestFunction().getValueDescriptor().getName()));
6869
}
70+
71+
this.root.createDirectoryAndParents();
6972
}
7073

7174
/** Returns {@code true} if the provided {@code key} is stored in the CAS. */

src/tools/remote/src/main/java/com/google/devtools/build/remote/worker/OnDiskBlobStoreCache.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@ class OnDiskBlobStoreCache extends RemoteCache {
4343
.setSymlinkAbsolutePathStrategy(SymlinkAbsolutePathStrategy.Value.ALLOWED)
4444
.build();
4545

46-
public OnDiskBlobStoreCache(RemoteOptions options, Path cacheDir, DigestUtil digestUtil) {
46+
public OnDiskBlobStoreCache(RemoteOptions options, Path cacheDir, DigestUtil digestUtil)
47+
throws IOException {
4748
super(
4849
CAPABILITIES,
4950
new DiskCacheClient(cacheDir, /* verifyDownloads= */ true, digestUtil),

0 commit comments

Comments
 (0)