@@ -544,44 +544,48 @@ public void CanExcludeStatusOfFilesInSubmodule()
544
544
public void CanConcurrentlyDeleteFilesWhileStatusIsBeingCalculated ( )
545
545
{
546
546
string repoPath = InitNewRepository ( ) ;
547
-
548
547
using ( var repo = new Repository ( repoPath ) )
549
548
{
550
- var paths = new List < string > ( ) ;
549
+ var files = new List < string > ( ) ;
550
+ var dirs = new List < string > ( ) ;
551
551
const int numberOfFiles = 3000 ;
552
-
552
+ string dirFormat = "D" + Math . Ceiling ( Math . Log10 ( numberOfFiles ) ) ;
553
553
for ( var i = 0 ; i < numberOfFiles ; i ++ )
554
554
{
555
- string s = i . ToString ( CultureInfo . InvariantCulture ) ;
556
- string path = Path . Combine ( repo . Info . WorkingDirectory , s + ".txt" ) ;
557
- File . AppendAllText ( path , s ) ;
558
- repo . Index . Stage ( path ) ;
559
- paths . Add ( path ) ;
555
+ string s = i . ToString ( dirFormat , CultureInfo . InvariantCulture ) ;
556
+ string dirPath = Path . Combine ( repo . Info . WorkingDirectory , s ) ;
557
+ Directory . CreateDirectory ( dirPath ) ;
558
+ string filePath = Path . Combine ( dirPath , s + ".txt" ) ;
559
+ File . AppendAllText ( filePath , s ) ;
560
+ files . Add ( filePath ) ;
561
+ dirs . Add ( dirPath ) ;
560
562
}
561
-
562
563
bool deletionDone = false ;
563
- Assert . Equal ( 0 , repo . Index . RetrieveStatus ( ) . Missing . Count ( ) ) ;
564
-
565
- Task . Factory . StartNew ( ( ) =>
564
+ var loops = 0 ;
565
+ Assert . Equal ( numberOfFiles , repo . Index . RetrieveStatus ( ) . Untracked . Count ( ) ) ;
566
+ Task task = Task . Factory . StartNew ( ( ) =>
566
567
{
567
- foreach ( var path in paths )
568
+ while ( ! deletionDone )
568
569
{
569
- File . Delete ( path ) ;
570
+ var filePaths = repo . Index . RetrieveStatus ( ) . Where ( entry => entry . State != FileStatus . Ignored ) . ToArray ( ) ;
571
+ Assert . NotNull ( filePaths ) ;
572
+ loops ++ ;
570
573
}
571
-
572
- deletionDone = true ;
573
574
} ) ;
574
575
575
- var loops = 0 ;
576
- while ( ! deletionDone )
576
+ dirs . Reverse ( ) ;
577
+
578
+ foreach ( var path in dirs )
577
579
{
578
- var filePaths = repo . Index . RetrieveStatus ( ) . Where ( entry => entry . State != FileStatus . Ignored ) . ToArray ( ) ;
579
- Assert . NotNull ( filePaths ) ;
580
- loops ++ ;
580
+ Directory . Delete ( path , true ) ;
581
+ System . Threading . Thread . Sleep ( 3 ) ;
581
582
}
583
+ deletionDone = true ;
584
+
585
+ task . Wait ( ) ;
582
586
583
587
Assert . True ( loops > 0 ) ;
584
- Assert . Equal ( numberOfFiles , repo . Index . RetrieveStatus ( ) . Missing . Count ( ) ) ;
588
+ Assert . Equal ( 0 , repo . Index . RetrieveStatus ( ) . Untracked . Count ( ) ) ;
585
589
}
586
590
}
587
591
}
0 commit comments