sync: move Transferring into operations.Copy

This makes the code more consistent with the operations code setting
the transfer statistics up.
This commit is contained in:
Nick Craig-Wood 2019-04-23 16:19:12 +01:00
parent 0655738da6
commit 2eb31a4f1d
3 changed files with 10 additions and 9 deletions

View File

@ -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 {

View File

@ -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 == "" {

View File

@ -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())
}
}