@@ -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
0 commit comments