Skip to content

Commit eca2631

Browse files
committed
Address review comments
1 parent b5eea3e commit eca2631

File tree

2 files changed

+36
-15
lines changed

2 files changed

+36
-15
lines changed

src/main/java/com/google/devtools/build/lib/bazel/BazelRepositoryModule.java

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -376,17 +376,29 @@ public void beforeCommand(CommandEnvironment env) throws AbruptExitException {
376376
repositoryCache.getRepoContentsCache().setPath(toPath(repoOptions.repoContentsCache, env));
377377
}
378378
Path repoContentsCachePath = repositoryCache.getRepoContentsCache().getPath();
379-
if (repoContentsCachePath != null && env.getOutputBase().startsWith(repoContentsCachePath)) {
380-
// This is dangerous as the repo contents cache GC may delete files in the output base.
381-
throw new AbruptExitException(
382-
detailedExitCode(
383-
"""
384-
The repo contents cache [%s] is inside the output base [%s]. This can cause \
385-
spurious failures. Disable the repo contents cache with `--repo_contents_cache=`, \
386-
or specify `--repo_contents_cache=<path outside the output base>`.
387-
"""
388-
.formatted(repoContentsCachePath, env.getOutputBase()),
389-
Code.BAD_REPO_CONTENTS_CACHE));
379+
if (repoContentsCachePath != null) {
380+
try {
381+
Path resolvedRepoContentsCache = repoContentsCachePath.resolveSymbolicLinks();
382+
Path resolvedOutputBase = env.getOutputBase().resolveSymbolicLinks();
383+
if (resolvedOutputBase.startsWith(resolvedOutputBase)) {
384+
// This is dangerous as the repo contents cache GC may delete files in the output base.
385+
throw new AbruptExitException(
386+
detailedExitCode(
387+
"""
388+
The output base [%s] is inside the repo contents cache [%s]. This can cause \
389+
spurious failures. Disable the repo contents cache with `--repo_contents_cache=`, \
390+
or specify `--repo_contents_cache=<path that doesn't contain the output base>`.
391+
"""
392+
.formatted(resolvedOutputBase, resolvedRepoContentsCache),
393+
Code.BAD_REPO_CONTENTS_CACHE));
394+
}
395+
} catch (IOException e) {
396+
throw new AbruptExitException(
397+
detailedExitCode(
398+
"could not resolve repo contents cache path: %s".formatted(e.getMessage()),
399+
Code.BAD_REPO_CONTENTS_CACHE),
400+
e);
401+
}
390402
}
391403
if (repoContentsCachePath != null
392404
&& env.getWorkspace() != null

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

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -344,10 +344,20 @@ public void beforeCommand(CommandEnvironment env) throws AbruptExitException {
344344
boolean enableRemoteDownloader = shouldEnableRemoteDownloader(remoteOptions);
345345

346346
if (enableDiskCache) {
347-
if (env.getOutputBase().startsWith(remoteOptions.diskCache)) {
348-
// This is dangerous as the disk cache GC may delete files in the output base.
347+
try {
348+
Path resolvedOutputBase = env.getOutputBase().resolveSymbolicLinks();
349+
Path resolvedDiskCache =
350+
env.getWorkingDirectory().getRelative(remoteOptions.diskCache).resolveSymbolicLinks();
351+
if (resolvedOutputBase.startsWith(resolvedDiskCache)) {
352+
// This is dangerous as the disk cache GC may delete files in the output base.
353+
throw createOptionsExitException(
354+
"The output base [%s] cannot be a subdirectory of the --disk_cache directory [%s]"
355+
.formatted(resolvedOutputBase, resolvedDiskCache),
356+
FailureDetails.RemoteOptions.Code.EXECUTION_WITH_INVALID_CACHE);
357+
}
358+
} catch (IOException e) {
349359
throw createOptionsExitException(
350-
"The --disk_cache directory cannot be a subdirectory of the output base",
360+
"Failed to resolve disk cache directory: %s".formatted(e.getMessage()),
351361
FailureDetails.RemoteOptions.Code.EXECUTION_WITH_INVALID_CACHE);
352362
}
353363
var gcIdleTask =
@@ -1229,5 +1239,4 @@ static Credentials createCredentials(
12291239
Downloader getRemoteDownloader() {
12301240
return remoteDownloader;
12311241
}
1232-
12331242
}

0 commit comments

Comments
 (0)