Skip to content

"rsync for cloud storage" - Google Drive, S3, Dropbox, Backblaze B2, One Drive, Swift, Hubic, Wasabi, Google Cloud Storage, Azure Blob, Azure Files, Yandex Files

sync: fix --delete-empty-src-dirs disabled by a prior error in a reused stats group - fixes #9634

ghwanycf7cdbc49f90
diff --git a/fs/sync/sync.go b/fs/sync/sync.go
index 3c8a2d8a8..50b5c16b0 100644
--- a/fs/sync/sync.go
+++ b/fs/sync/sync.go
@@ -644,7 +644,7 @@ func (s *syncCopyMove) deleteEmptyDirectories(ctx context.Context, f fs.Fs, entr
if len(entriesMap) == 0 {
return nil
}
- if accounting.Stats(ctx).Errored() && !s.ci.IgnoreErrors {
+ if s.currentError() != nil && !s.ci.IgnoreErrors {
fs.ErrorfCtx(ctx, f, "%v", fs.ErrorNotDeletingDirs)
return fs.ErrorNotDeletingDirs
}
diff --git a/fs/sync/sync_test.go b/fs/sync/sync_test.go
index ded409e3b..29eb7fb6a 100644
--- a/fs/sync/sync_test.go
+++ b/fs/sync/sync_test.go
@@ -1818,6 +1818,34 @@ func TestMoveWithoutDeleteEmptySrcDirs(t *testing.T) {
r.CheckRemoteItems(t, file1, file2)
}
+// TestMoveWithDeleteEmptySrcDirsAfterPriorError checks that --delete-empty-src-dirs
+// still removes the empty source directories when the stats group carries an error
+// from an earlier operation, as happens when a long-running rcd reuses a stats group.
+func TestMoveWithDeleteEmptySrcDirsAfterPriorError(t *testing.T) {
+ ctx := context.Background()
+ r := fstest.NewRun(t)
+ file1 := r.WriteFile("sub dir/hello world", "hello world", t1)
+ file2 := r.WriteFile("nested/sub dir/file", "nested", t1)
+ r.Mkdir(ctx, r.Fremote)
+
+ // Leave an error in the stats group, as a prior operation on a reused rcd
+ // _group would, then run an otherwise clean move.
+ ctx = predictDstFromLogger(ctx)
+ accounting.GlobalStats().ResetCounters()
+ _ = fs.CountError(ctx, errors.New("boom"))
+ err := MoveDir(ctx, r.Fremote, r.Flocal, true, false)
+ require.NoError(t, err)
+ testLoggerVsLsf(ctx, r.Fremote, r.Flocal, operations.GetLoggerOpt(ctx).JSON, t)
+ accounting.GlobalStats().ResetCounters()
+
+ r.CheckLocalListing(
+ t,
+ nil,
+ []string{},
+ )
+ r.CheckRemoteItems(t, file1, file2)
+}
+
func TestMoveWithIgnoreExisting(t *testing.T) {
ctx := context.Background()
ctx, ci := fs.AddConfig(ctx)