From dc76f74d3a6f77de03c49234386bf0ca7d15bdcc Mon Sep 17 00:00:00 2001 From: Fabian Meumertzheim Date: Thu, 25 Nov 2021 10:46:58 +0100 Subject: [PATCH] Delete marker file before fetching an external repository (#14323) Fetching a repository is a long-running operation that can easily be interrupted. If it is and the marker file exists on disk, a new evaluation of the RepositoryDelegatorFunction may treat this repository as valid even though it is in an inconsistent state. Clearing the marker file before initiating the fetch and only recreating it after the fetch is complete prevents this scenario. Fixes #8993. Closes #14302. PiperOrigin-RevId: 412101756 --- .../lib/rules/repository/RepositoryDelegatorFunction.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/main/java/com/google/devtools/build/lib/rules/repository/RepositoryDelegatorFunction.java b/src/main/java/com/google/devtools/build/lib/rules/repository/RepositoryDelegatorFunction.java index cb5796f0b9a50f..774e240b2cc005 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/repository/RepositoryDelegatorFunction.java +++ b/src/main/java/com/google/devtools/build/lib/rules/repository/RepositoryDelegatorFunction.java @@ -339,6 +339,11 @@ && managedDirectoriesExist(directories.getWorkspace(), managedDirectories)) { } if (isFetch.get()) { + // Fetching a repository is a long-running operation that can easily be interrupted. If it is + // and the marker file exists on disk, a new call of this method may treat this repository as + // valid even though it is in an inconsistent state. Clear the marker file and only recreate + // it after fetching is done to prevent this scenario. + DigestWriter.clearMarkerFile(directories, repositoryName); // Fetching enabled, go ahead. RepositoryDirectoryValue.Builder builder = fetchRepository(skyKey, repoRoot, env, digestWriter.getMarkerData(), handler, rule);