Modify interface for accounting to take a string not an fs.Object

This commit is contained in:
Nick Craig-Wood 2016-07-02 16:58:50 +01:00
parent 9aae143833
commit 0a43ff9c13
2 changed files with 26 additions and 22 deletions

View file

@ -202,17 +202,17 @@ func (s *StatsInfo) Error() {
} }
// Checking adds a check into the stats // Checking adds a check into the stats
func (s *StatsInfo) Checking(o Object) { func (s *StatsInfo) Checking(remote string) {
s.lock.Lock() s.lock.Lock()
defer s.lock.Unlock() defer s.lock.Unlock()
s.checking[o.Remote()] = struct{}{} s.checking[remote] = struct{}{}
} }
// DoneChecking removes a check from the stats // DoneChecking removes a check from the stats
func (s *StatsInfo) DoneChecking(o Object) { func (s *StatsInfo) DoneChecking(remote string) {
s.lock.Lock() s.lock.Lock()
defer s.lock.Unlock() defer s.lock.Unlock()
delete(s.checking, o.Remote()) delete(s.checking, remote)
s.checks++ s.checks++
} }
@ -224,17 +224,17 @@ func (s *StatsInfo) GetTransfers() int64 {
} }
// Transferring adds a transfer into the stats // Transferring adds a transfer into the stats
func (s *StatsInfo) Transferring(o Object) { func (s *StatsInfo) Transferring(remote string) {
s.lock.Lock() s.lock.Lock()
defer s.lock.Unlock() defer s.lock.Unlock()
s.transferring[o.Remote()] = struct{}{} s.transferring[remote] = struct{}{}
} }
// DoneTransferring removes a transfer from the stats // DoneTransferring removes a transfer from the stats
func (s *StatsInfo) DoneTransferring(o Object) { func (s *StatsInfo) DoneTransferring(remote string) {
s.lock.Lock() s.lock.Lock()
defer s.lock.Unlock() defer s.lock.Unlock()
delete(s.transferring, o.Remote()) delete(s.transferring, remote)
s.transfers++ s.transfers++
} }

View file

@ -374,9 +374,9 @@ func PairChecker(in ObjectPairChan, out ObjectPairChan, wg *sync.WaitGroup) {
defer wg.Done() defer wg.Done()
for pair := range in { for pair := range in {
src := pair.src src := pair.src
Stats.Checking(src) Stats.Checking(src.Remote())
checkOne(pair, out) checkOne(pair, out)
Stats.DoneChecking(src) Stats.DoneChecking(src.Remote())
} }
} }
@ -385,13 +385,13 @@ func PairCopier(in ObjectPairChan, fdst Fs, wg *sync.WaitGroup) {
defer wg.Done() defer wg.Done()
for pair := range in { for pair := range in {
src := pair.src src := pair.src
Stats.Transferring(src) Stats.Transferring(src.Remote())
if Config.DryRun { if Config.DryRun {
Log(src, "Not copying as --dry-run") Log(src, "Not copying as --dry-run")
} else { } else {
Copy(fdst, pair.dst, src) Copy(fdst, pair.dst, src)
} }
Stats.DoneTransferring(src) Stats.DoneTransferring(src.Remote())
} }
} }
@ -404,7 +404,7 @@ func PairMover(in ObjectPairChan, fdst Fs, wg *sync.WaitGroup) {
for pair := range in { for pair := range in {
src := pair.src src := pair.src
dst := pair.dst dst := pair.dst
Stats.Transferring(src) Stats.Transferring(src.Remote())
if Config.DryRun { if Config.DryRun {
Log(src, "Not moving as --dry-run") Log(src, "Not moving as --dry-run")
} else if haveMover && src.Fs().Name() == fdst.Name() { } else if haveMover && src.Fs().Name() == fdst.Name() {
@ -426,7 +426,7 @@ func PairMover(in ObjectPairChan, fdst Fs, wg *sync.WaitGroup) {
} else { } else {
Copy(fdst, pair.dst, src) Copy(fdst, pair.dst, src)
} }
Stats.DoneTransferring(src) Stats.DoneTransferring(src.Remote())
} }
} }
@ -435,9 +435,9 @@ func DeleteFile(dst Object) (err error) {
if Config.DryRun { if Config.DryRun {
Log(dst, "Not deleting as --dry-run") Log(dst, "Not deleting as --dry-run")
} else { } else {
Stats.Checking(dst) Stats.Checking(dst.Remote())
err = dst.Remove() err = dst.Remove()
Stats.DoneChecking(dst) Stats.DoneChecking(dst.Remote())
if err != nil { if err != nil {
Stats.Error() Stats.Error()
ErrorLog(dst, "Couldn't delete: %v", err) ErrorLog(dst, "Couldn't delete: %v", err)
@ -872,8 +872,8 @@ func MoveDir(fdst, fsrc Fs) error {
// //
// it returns true if differences were found // it returns true if differences were found
func checkIdentical(dst, src Object) bool { func checkIdentical(dst, src Object) bool {
Stats.Checking(src) Stats.Checking(src.Remote())
defer Stats.DoneChecking(src) defer Stats.DoneChecking(src.Remote())
if src.Size() != dst.Size() { if src.Size() != dst.Size() {
Stats.Error() Stats.Error()
ErrorLog(src, "Sizes differ") ErrorLog(src, "Sizes differ")
@ -1020,9 +1020,9 @@ func List(f Fs, w io.Writer) error {
// Lists in parallel which may get them out of order // Lists in parallel which may get them out of order
func ListLong(f Fs, w io.Writer) error { func ListLong(f Fs, w io.Writer) error {
return ListFn(f, func(o Object) { return ListFn(f, func(o Object) {
Stats.Checking(o) Stats.Checking(o.Remote())
modTime := o.ModTime() modTime := o.ModTime()
Stats.DoneChecking(o) Stats.DoneChecking(o.Remote())
syncFprintf(w, "%9d %s %s\n", o.Size(), modTime.Local().Format("2006-01-02 15:04:05.000000000"), o.Remote()) syncFprintf(w, "%9d %s %s\n", o.Size(), modTime.Local().Format("2006-01-02 15:04:05.000000000"), o.Remote())
}) })
} }
@ -1048,9 +1048,9 @@ func Sha1sum(f Fs, w io.Writer) error {
func hashLister(ht HashType, f Fs, w io.Writer) error { func hashLister(ht HashType, f Fs, w io.Writer) error {
return ListFn(f, func(o Object) { return ListFn(f, func(o Object) {
Stats.Checking(o) Stats.Checking(o.Remote())
sum, err := o.Hash(ht) sum, err := o.Hash(ht)
Stats.DoneChecking(o) Stats.DoneChecking(o.Remote())
if err == ErrHashUnsupported { if err == ErrHashUnsupported {
sum = "UNSUPPORTED" sum = "UNSUPPORTED"
} else if err != nil { } else if err != nil {
@ -1386,5 +1386,9 @@ func CleanUp(f Fs) error {
if !ok { if !ok {
return errors.Errorf("%v doesn't support cleanup", f) return errors.Errorf("%v doesn't support cleanup", f)
} }
if Config.DryRun {
Log(f, "Not running cleanup as --dry-run set")
return nil
}
return fc.CleanUp() return fc.CleanUp()
} }