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:
parent
0655738da6
commit
2eb31a4f1d
3 changed files with 10 additions and 9 deletions
|
@ -249,6 +249,10 @@ var _ fs.MimeTyper = (*overrideRemoteObject)(nil)
|
||||||
// It returns the destination object if possible. Note that this may
|
// It returns the destination object if possible. Note that this may
|
||||||
// be nil.
|
// be nil.
|
||||||
func Copy(f fs.Fs, dst fs.Object, remote string, src fs.Object) (newDst fs.Object, err error) {
|
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
|
newDst = dst
|
||||||
if fs.Config.DryRun {
|
if fs.Config.DryRun {
|
||||||
fs.Logf(src, "Not copying as --dry-run")
|
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
|
// It returns the destination object if possible. Note that this may
|
||||||
// be nil.
|
// be nil.
|
||||||
func Move(fdst fs.Fs, dst fs.Object, remote string, src fs.Object) (newDst fs.Object, err error) {
|
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
|
newDst = dst
|
||||||
if fs.Config.DryRun {
|
if fs.Config.DryRun {
|
||||||
fs.Logf(src, "Not moving as --dry-run")
|
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) {
|
if NeedTransfer(dstObj, srcObj) {
|
||||||
accounting.Stats.Transferring(srcFileName)
|
|
||||||
_, err = Op(fdst, dstObj, dstFileName, srcObj)
|
_, err = Op(fdst, dstObj, dstFileName, srcObj)
|
||||||
accounting.Stats.DoneTransferring(srcFileName, err == nil)
|
|
||||||
} else {
|
} else {
|
||||||
accounting.Stats.Checking(srcFileName)
|
accounting.Stats.Checking(srcFileName)
|
||||||
if !cp {
|
if !cp {
|
||||||
|
|
|
@ -288,14 +288,12 @@ func (s *syncCopyMove) pairCopyOrMove(in *pipe, fdst fs.Fs, wg *sync.WaitGroup)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
src := pair.Src
|
src := pair.Src
|
||||||
accounting.Stats.Transferring(src.Remote())
|
|
||||||
if s.DoMove {
|
if s.DoMove {
|
||||||
_, err = operations.Move(fdst, pair.Dst, src.Remote(), src)
|
_, err = operations.Move(fdst, pair.Dst, src.Remote(), src)
|
||||||
} else {
|
} else {
|
||||||
_, err = operations.Copy(fdst, pair.Dst, src.Remote(), src)
|
_, err = operations.Copy(fdst, pair.Dst, src.Remote(), src)
|
||||||
}
|
}
|
||||||
s.processError(err)
|
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
|
// tryRename renames a src object when doing track renames if
|
||||||
// possible, it returns true if the object was renamed.
|
// possible, it returns true if the object was renamed.
|
||||||
func (s *syncCopyMove) tryRename(src fs.Object) bool {
|
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
|
// Calculate the hash of the src object
|
||||||
hash := s.renameHash(src)
|
hash := s.renameHash(src)
|
||||||
if hash == "" {
|
if hash == "" {
|
||||||
|
|
|
@ -995,9 +995,9 @@ func TestSyncWithTrackRenames(t *testing.T) {
|
||||||
fstest.CheckItems(t, r.Fremote, f1, f2)
|
fstest.CheckItems(t, r.Fremote, f1, f2)
|
||||||
|
|
||||||
if canTrackRenames {
|
if canTrackRenames {
|
||||||
assert.Equal(t, accounting.Stats.GetTransfers(), int64(0))
|
assert.Equal(t, int64(0), accounting.Stats.GetTransfers())
|
||||||
} else {
|
} else {
|
||||||
assert.Equal(t, accounting.Stats.GetTransfers(), int64(1))
|
assert.Equal(t, int64(1), accounting.Stats.GetTransfers())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue