|
122 | 122 | import com.google.devtools.build.lib.vfs.RootedPath; |
123 | 123 | import com.google.devtools.common.options.OptionsBase; |
124 | 124 | import com.google.devtools.common.options.OptionsParsingResult; |
| 125 | +import java.io.FileNotFoundException; |
125 | 126 | import java.io.IOException; |
126 | 127 | import java.lang.reflect.InvocationTargetException; |
127 | 128 | import java.time.Instant; |
@@ -377,28 +378,40 @@ public void beforeCommand(CommandEnvironment env) throws AbruptExitException { |
377 | 378 | } |
378 | 379 | Path repoContentsCachePath = repositoryCache.getRepoContentsCache().getPath(); |
379 | 380 | if (repoContentsCachePath != null) { |
| 381 | + Path resolvedOutputBase; |
380 | 382 | 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 | | - } |
| 383 | + resolvedOutputBase = env.getOutputBase().resolveSymbolicLinks(); |
| 384 | + } catch (IOException e) { |
| 385 | + throw new AbruptExitException( |
| 386 | + detailedExitCode( |
| 387 | + "could not resolve output base: %s".formatted(e.getMessage()), |
| 388 | + Code.BAD_REPO_CONTENTS_CACHE), |
| 389 | + e); |
| 390 | + } |
| 391 | + Path resolvedRepoContentsCache = repoContentsCachePath; |
| 392 | + try { |
| 393 | + resolvedRepoContentsCache = resolvedRepoContentsCache.resolveSymbolicLinks(); |
| 394 | + } catch (FileNotFoundException e) { |
| 395 | + // Will be created later. |
395 | 396 | } catch (IOException e) { |
396 | 397 | throw new AbruptExitException( |
397 | 398 | detailedExitCode( |
398 | 399 | "could not resolve repo contents cache path: %s".formatted(e.getMessage()), |
399 | 400 | Code.BAD_REPO_CONTENTS_CACHE), |
400 | 401 | e); |
401 | 402 | } |
| 403 | + if (resolvedOutputBase.startsWith(resolvedOutputBase)) { |
| 404 | + // This is dangerous as the repo contents cache GC may delete files in the output base. |
| 405 | + throw new AbruptExitException( |
| 406 | + detailedExitCode( |
| 407 | + """ |
| 408 | + The output base [%s] is inside the repo contents cache [%s]. This can cause \ |
| 409 | + spurious failures. Disable the repo contents cache with `--repo_contents_cache=`, \ |
| 410 | + or specify `--repo_contents_cache=<path that doesn't contain the output base>`. |
| 411 | + """ |
| 412 | + .formatted(resolvedOutputBase, resolvedRepoContentsCache), |
| 413 | + Code.BAD_REPO_CONTENTS_CACHE)); |
| 414 | + } |
402 | 415 | } |
403 | 416 | if (repoContentsCachePath != null |
404 | 417 | && env.getWorkspace() != null |
|
0 commit comments