@@ -248,7 +248,7 @@ func (r *PhysRestore) close(noerr, cleanup bool) {
248
248
}
249
249
} else if cleanup { // clean-up dbpath on err if needed (cluster is done or partlyDone)
250
250
r .log .Debug ("clean-up dbpath" )
251
- err := removeAll (r .dbpath , nil , r .log )
251
+ err := removeAll (r .dbpath , r .log , getInternlLogFileSkipRule () )
252
252
if err != nil {
253
253
r .log .Error ("flush dbpath %s: %v" , r .dbpath , err )
254
254
}
@@ -398,7 +398,7 @@ func (r *PhysRestore) migrateDBDirToFallbackDir() error {
398
398
// moves all content from fallback path.
399
399
func (r * PhysRestore ) migrateFromFallbackDirToDBDir () error {
400
400
r .log .Debug ("clean-up dbpath" )
401
- err := removeAll (r .dbpath , [] string { fallbackDir }, r .log )
401
+ err := removeAll (r .dbpath , r .log , getFallbackSyncFileSkipRule (), getInternlLogFileSkipRule () )
402
402
if err != nil {
403
403
r .log .Error ("flush dbpath %s: %v" , r .dbpath , err )
404
404
return errors .Wrap (err , "remove all from dbpath" )
@@ -2588,7 +2588,7 @@ func moveAll(fromDir, toDir string, toIgnore []string, l log.LogEvent) error {
2588
2588
return nil
2589
2589
}
2590
2590
2591
- func removeAll (dir string , toIgnore [] string , l log.LogEvent ) error {
2591
+ func removeAll (dir string , l log.LogEvent , fileSkipRules ... fileSkipRule ) error {
2592
2592
d , err := os .Open (dir )
2593
2593
if err != nil {
2594
2594
return errors .Wrap (err , "open dir" )
@@ -2600,7 +2600,7 @@ func removeAll(dir string, toIgnore []string, l log.LogEvent) error {
2600
2600
return errors .Wrap (err , "read file names" )
2601
2601
}
2602
2602
for _ , n := range names {
2603
- if isInternalMongoLog ( n ) || slices . Contains ( toIgnore , n ) {
2603
+ if isFileToSkip ( n , fileSkipRules ... ) {
2604
2604
continue
2605
2605
}
2606
2606
err = os .RemoveAll (filepath .Join (dir , n ))
@@ -2618,6 +2618,32 @@ func isInternalMongoLog(f string) bool {
2618
2618
return strings .HasPrefix (f , internalMongodLog )
2619
2619
}
2620
2620
2621
+ type fileSkipRule func (string ) bool
2622
+
2623
+ // isFileToSkip for the given file name f and the given set of skip rules: skipRules,
2624
+ // function returns true if at least one rule is satisfied. In case when all rules
2625
+ // are false it returns false, which means that file shouldn't be skipped.
2626
+ func isFileToSkip (f string , skipRules ... fileSkipRule ) bool {
2627
+ for _ , rule := range skipRules {
2628
+ if rule (f ) {
2629
+ return true
2630
+ }
2631
+ }
2632
+ return false
2633
+ }
2634
+
2635
+ func getInternlLogFileSkipRule () fileSkipRule {
2636
+ return func (f string ) bool {
2637
+ return isInternalMongoLog (f )
2638
+ }
2639
+ }
2640
+
2641
+ func getFallbackSyncFileSkipRule () fileSkipRule {
2642
+ return func (f string ) bool {
2643
+ return f == fallbackDir
2644
+ }
2645
+ }
2646
+
2621
2647
func majmin (v string ) string {
2622
2648
if len (v ) == 0 {
2623
2649
return v
0 commit comments