From 8b066ba77cc129472f8f8f7d334982bdf1c51978 Mon Sep 17 00:00:00 2001 From: Nick Craig-Wood Date: Thu, 10 Jan 2013 22:14:23 +0000 Subject: [PATCH] Don't delete files if errors in copy phase of sync Make check return errors on differences --- notes.txt | 1 - swiftsync.go | 10 +++++++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/notes.txt b/notes.txt index fa54b0f9d..8c3d67522 100644 --- a/notes.txt +++ b/notes.txt @@ -2,7 +2,6 @@ Todo * Factor fses into own packages * FIXME: ls without an argument for buckets/containers? * FIXME: More -dry-run checks for object transfer - * FIXME: don't delete in sync if errors * Might be quicker to check md5sums first? for swift <-> swift certainly, and maybe for small files * Ignoring the pseudo directories * if object.PseudoDirectory { diff --git a/swiftsync.go b/swiftsync.go index c4db9d340..3e6bd3d30 100644 --- a/swiftsync.go +++ b/swiftsync.go @@ -173,7 +173,10 @@ func Sync(fdst, fsrc Fs) { log.Printf("Waiting for transfers to finish") copierWg.Wait() - // FIXME don't delete if IO errors + if stats.errors != 0 { + log.Printf("Not deleting files as there were IO errors") + return + } // Delete the spare files toDelete := make(FsObjectsChan, *transfers) @@ -213,11 +216,13 @@ func Check(fdst, fsrc Fs) { log.Printf("Files in %s but not in %s", fdst, fsrc) for remote := range dstFiles { + stats.Error() log.Printf(remote) } log.Printf("Files in %s but not in %s", fsrc, fdst) for remote := range srcFiles { + stats.Error() log.Printf(remote) } @@ -239,6 +244,7 @@ func Check(fdst, fsrc Fs) { stats.Checking(src) if src.Size() != dst.Size() { stats.DoneChecking(src) + stats.Error() FsLog(src, "Sizes differ") continue } @@ -248,6 +254,7 @@ func Check(fdst, fsrc Fs) { continue } if !same { + stats.Error() FsLog(src, "Md5sums differ") } FsDebug(src, "OK") @@ -257,6 +264,7 @@ func Check(fdst, fsrc Fs) { log.Printf("Waiting for checks to finish") checkerWg.Wait() + log.Printf("%d differences found", stats.errors) } // List the Fs to stdout