@@ -126,13 +126,11 @@ private void DeleteStaleIncompletePrefetchPackAndIdxs()
126126 metadata . Add ( "markerPath" , markerPath ) ;
127127 metadata . Add ( TracingConstants . MessageKey . InfoMessage , "Deleting stale temp pack and/or idx file" ) ;
128128
129- /* Conditionally delete the marker and index only after the pack has been deleted - if they stick
130- * around without the pack file it won't interfere with other pack files, and they are smaller
131- * files, but if the pack file sticks around with the index or marker it could interfere with
132- * future prefetches and takes up more space. */
133- if ( this . fileSystem . TryDeleteFile ( packPath , metadataKey : nameof ( packPath ) , metadata : metadata ) )
129+ /* Delete the index first (which makes git stop using the pack), then the pack,
130+ * last the marker. */
131+ if ( this . fileSystem . TryDeleteFile ( idxPath , metadataKey : nameof ( idxPath ) , metadata : metadata )
132+ && this . fileSystem . TryDeleteFile ( packPath , metadataKey : nameof ( packPath ) , metadata : metadata ) )
134133 {
135- this . fileSystem . TryDeleteFile ( idxPath , metadataKey : nameof ( idxPath ) , metadata : metadata ) ;
136134 this . fileSystem . TryDeleteFile ( markerPath , metadataKey : nameof ( markerPath ) , metadata : metadata ) ;
137135 }
138136
@@ -554,6 +552,10 @@ private bool TryMovePackAndIdx(string sourcePackPath, string targetPackPath, out
554552
555553 try
556554 {
555+ /* Make sure there's not an existing index first to prevent race condition where index may not
556+ * match the pack file.
557+ */
558+ this . fileSystem . DeleteFile ( targetIdxPath ) ;
557559 this . fileSystem . MoveAndOverwriteFile ( sourcePackPath , targetPackPath ) ;
558560 this . fileSystem . MoveAndOverwriteFile ( sourceIdxPath , targetIdxPath ) ;
559561 }
0 commit comments