diff --git a/fs/operations/operations.go b/fs/operations/operations.go index d0a2a2f77..a6d61de28 100644 --- a/fs/operations/operations.go +++ b/fs/operations/operations.go @@ -249,6 +249,10 @@ var _ fs.MimeTyper = (*overrideRemoteObject)(nil) // It returns the destination object if possible. Note that this may // be nil. func Copy(f fs.Fs, dst fs.Object, remote string, src fs.Object) (newDst fs.Object, err error) { + accounting.Stats.Transferring(src.Remote()) + defer func() { + accounting.Stats.DoneTransferring(src.Remote(), err == nil) + }() newDst = dst if fs.Config.DryRun { fs.Logf(src, "Not copying as --dry-run") @@ -391,6 +395,10 @@ func Copy(f fs.Fs, dst fs.Object, remote string, src fs.Object) (newDst fs.Objec // It returns the destination object if possible. Note that this may // be nil. func Move(fdst fs.Fs, dst fs.Object, remote string, src fs.Object) (newDst fs.Object, err error) { + accounting.Stats.Checking(src.Remote()) + defer func() { + accounting.Stats.DoneChecking(src.Remote()) + }() newDst = dst if fs.Config.DryRun { fs.Logf(src, "Not moving as --dry-run") @@ -1451,9 +1459,7 @@ func moveOrCopyFile(fdst fs.Fs, fsrc fs.Fs, dstFileName string, srcFileName stri } if NeedTransfer(dstObj, srcObj) { - accounting.Stats.Transferring(srcFileName) _, err = Op(fdst, dstObj, dstFileName, srcObj) - accounting.Stats.DoneTransferring(srcFileName, err == nil) } else { accounting.Stats.Checking(srcFileName) if !cp { diff --git a/fs/sync/sync.go b/fs/sync/sync.go index cd8fc910e..122a03335 100644 --- a/fs/sync/sync.go +++ b/fs/sync/sync.go @@ -288,14 +288,12 @@ func (s *syncCopyMove) pairCopyOrMove(in *pipe, fdst fs.Fs, wg *sync.WaitGroup) return } src := pair.Src - accounting.Stats.Transferring(src.Remote()) if s.DoMove { _, err = operations.Move(fdst, pair.Dst, src.Remote(), src) } else { _, err = operations.Copy(fdst, pair.Dst, src.Remote(), src) } s.processError(err) - accounting.Stats.DoneTransferring(src.Remote(), err == nil) } } @@ -604,9 +602,6 @@ func (s *syncCopyMove) makeRenameMap() { // tryRename renames a src object when doing track renames if // possible, it returns true if the object was renamed. func (s *syncCopyMove) tryRename(src fs.Object) bool { - accounting.Stats.Checking(src.Remote()) - defer accounting.Stats.DoneChecking(src.Remote()) - // Calculate the hash of the src object hash := s.renameHash(src) if hash == "" { diff --git a/fs/sync/sync_test.go b/fs/sync/sync_test.go index ed4c8ee7b..e77719dff 100644 --- a/fs/sync/sync_test.go +++ b/fs/sync/sync_test.go @@ -995,9 +995,9 @@ func TestSyncWithTrackRenames(t *testing.T) { fstest.CheckItems(t, r.Fremote, f1, f2) if canTrackRenames { - assert.Equal(t, accounting.Stats.GetTransfers(), int64(0)) + assert.Equal(t, int64(0), accounting.Stats.GetTransfers()) } else { - assert.Equal(t, accounting.Stats.GetTransfers(), int64(1)) + assert.Equal(t, int64(1), accounting.Stats.GetTransfers()) } }