Make failed uploads not count as "Transferred" - fixes #708

This commit is contained in:
Nick Craig-Wood 2016-09-12 18:15:58 +01:00
parent 20a429c048
commit 83ba59749f
4 changed files with 20 additions and 9 deletions

View File

@ -799,9 +799,9 @@ func (f *Fs) purge(oldOnly bool) error {
go func() {
defer wg.Done()
for object := range toBeDeleted {
fs.Stats.Transferring(object.Name)
fs.Stats.Checking(object.Name)
checkErr(f.deleteByID(object.ID, object.Name))
fs.Stats.DoneTransferring(object.Name)
fs.Stats.DoneChecking(object.Name)
}
}()
}

View File

@ -231,11 +231,15 @@ func (s *StatsInfo) Transferring(remote string) {
}
// DoneTransferring removes a transfer from the stats
func (s *StatsInfo) DoneTransferring(remote string) {
//
// if ok is true then it increments the transfers count
func (s *StatsInfo) DoneTransferring(remote string, ok bool) {
s.lock.Lock()
defer s.lock.Unlock()
delete(s.transferring, remote)
s.transfers++
if ok {
s.transfers++
}
}
// Account limits and accounts for one transfer

View File

@ -1017,8 +1017,11 @@ func CleanUp(f Fs) error {
func Cat(f Fs, w io.Writer) error {
var mu sync.Mutex
return ListFn(f, func(o Object) {
var err error
Stats.Transferring(o.Remote())
defer Stats.DoneTransferring(o.Remote())
defer func() {
Stats.DoneTransferring(o.Remote(), err == nil)
}()
mu.Lock()
defer mu.Unlock()
in, err := o.Open()
@ -1041,5 +1044,4 @@ func Cat(f Fs, w io.Writer) error {
ErrorLog(o, "Failed to send to output: %v", err)
}
})
}

View File

@ -232,12 +232,14 @@ func (s *syncCopyMove) pairCopier(in ObjectPairChan, fdst Fs, wg *sync.WaitGroup
}
src := pair.src
Stats.Transferring(src.Remote())
var err error
if Config.DryRun {
Log(src, "Not copying as --dry-run")
} else {
s.processError(Copy(fdst, pair.dst, src))
err = Copy(fdst, pair.dst, src)
s.processError(err)
}
Stats.DoneTransferring(src.Remote())
Stats.DoneTransferring(src.Remote(), err == nil)
case <-s.abort:
return
}
@ -259,6 +261,7 @@ func (s *syncCopyMove) pairMover(in ObjectPairChan, fdst Fs, wg *sync.WaitGroup)
if !ok {
return
}
transferredOK := true
src := pair.src
dst := pair.dst
Stats.Transferring(src.Remote())
@ -267,6 +270,7 @@ func (s *syncCopyMove) pairMover(in ObjectPairChan, fdst Fs, wg *sync.WaitGroup)
err := Copy(fdst, dst, src)
s.processError(err)
if err != nil {
transferredOK = false
ErrorLog(src, "Not deleting as copy failed: %v", err)
} else {
// Delete src if no error on copy
@ -293,6 +297,7 @@ func (s *syncCopyMove) pairMover(in ObjectPairChan, fdst Fs, wg *sync.WaitGroup)
Stats.Error()
ErrorLog(dst, "Couldn't move: %v", err)
s.processError(err)
transferredOK = false
}
} else {
Debug(src, "Moved")
@ -300,7 +305,7 @@ func (s *syncCopyMove) pairMover(in ObjectPairChan, fdst Fs, wg *sync.WaitGroup)
} else {
doCopy()
}
Stats.DoneTransferring(src.Remote())
Stats.DoneTransferring(src.Remote(), transferredOK)
case <-s.abort:
return
}