Skip to content

Commit 6dd48af

Browse files
committed
Add complete db dir cleanup for done/partly done
1 parent cd111c3 commit 6dd48af

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

pbm/restore/physical.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ func (r *PhysRestore) close(noerr, cleanup bool) {
248248
}
249249
} else { // cluster status is done or partlyDone
250250
r.log.Debug("clean-up dbpath")
251-
err := removeAll(r.dbpath, r.log)
251+
err := removeAll(r.dbpath, nil, r.log)
252252
if err != nil {
253253
r.log.Error("flush dbpath %s: %v", r.dbpath, err)
254254
}
@@ -392,7 +392,7 @@ func (r *PhysRestore) migrateDbDirToFallbackDir() error {
392392
// moves all content from fallback path.
393393
func (r *PhysRestore) migrateFromFallbackDirToDbDir() error {
394394
r.log.Debug("clean-up dbpath")
395-
err := removeAll(r.dbpath, r.log)
395+
err := removeAll(r.dbpath, []string{fallbackDir}, r.log)
396396
if err != nil {
397397
r.log.Error("flush dbpath %s: %v", r.dbpath, err)
398398
}
@@ -2524,7 +2524,7 @@ func moveAll(fromDir, toDir string, toIgnore []string, l log.LogEvent) error {
25242524
return nil
25252525
}
25262526

2527-
func removeAll(dir string, l log.LogEvent) error {
2527+
func removeAll(dir string, toIgnore []string, l log.LogEvent) error {
25282528
d, err := os.Open(dir)
25292529
if err != nil {
25302530
return errors.Wrap(err, "open dir")
@@ -2536,7 +2536,7 @@ func removeAll(dir string, l log.LogEvent) error {
25362536
return errors.Wrap(err, "read file names")
25372537
}
25382538
for _, n := range names {
2539-
if n == internalMongodLog || n == fallbackDir {
2539+
if n == internalMongodLog || slices.Contains(toIgnore, n) {
25402540
continue
25412541
}
25422542
err = os.RemoveAll(filepath.Join(dir, n))

0 commit comments

Comments
 (0)