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 32e49f3d934900..37f467b2cc72de 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 @@ -271,6 +271,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);