From ecb863dd4fa2bd6c1c3babdad38fd6e14c31b6a8 Mon Sep 17 00:00:00 2001 From: Nick Craig-Wood Date: Wed, 2 Jan 2013 15:21:55 +0000 Subject: [PATCH] Make ModTime fall back to LastModified header Which means it no longer needs to report an error which simplifies the code --- fs.go | 22 ++++++++-------------- fs_local.go | 11 +++-------- fs_swift.go | 27 +++++++++++++-------------- notes.txt | 1 + swiftsync.go | 2 +- 5 files changed, 26 insertions(+), 37 deletions(-) diff --git a/fs.go b/fs.go index c123c2cd7..32cd03991 100644 --- a/fs.go +++ b/fs.go @@ -26,7 +26,7 @@ type Fs interface { type FsObject interface { Remote() string Md5sum() (string, error) - ModTime() (time.Time, error) + ModTime() time.Time SetModTime(time.Time) Size() int64 Open() (io.ReadCloser, error) @@ -118,24 +118,18 @@ func Equal(src, dst FsObject) bool { } // Size the same so check the mtime - srcModTime, err := src.ModTime() - if err != nil { - FsDebug(src, "Failed to read src mtime: %s", err) + srcModTime := src.ModTime() + dstModTime := dst.ModTime() + if !dstModTime.Equal(srcModTime) { + FsDebug(src, "Modification times differ") } else { - dstModTime, err := dst.ModTime() - if err != nil { - FsDebug(dst, "Failed to read dst mtime: %s", err) - } else if !dstModTime.Equal(srcModTime) { - FsDebug(src, "Modification times differ") - } else { - FsDebug(src, "Size and modification time the same") - return true - } + FsDebug(src, "Size and modification time the same") + return true } // mtime is unreadable or different but size is the same so // check the MD5SUM - same, err := CheckMd5sums(src, dst) + same, _ := CheckMd5sums(src, dst) if !same { FsDebug(src, "Md5sums differ") return false diff --git a/fs_local.go b/fs_local.go index 7d36924e9..cf33b85cc 100644 --- a/fs_local.go +++ b/fs_local.go @@ -150,12 +150,7 @@ func (f *FsLocal) Put(src FsObject) { } // Set the mtime - modTime, err := src.ModTime() - if err != nil { - FsDebug(fs, "Failed to read mtime from object: %s", err) - } else { - fs.SetModTime(modTime) - } + fs.SetModTime(src.ModTime()) } // Mkdir creates the directory if it doesn't exist @@ -200,8 +195,8 @@ func (fs *FsObjectLocal) Size() int64 { } // ModTime returns the modification time of the object -func (fs *FsObjectLocal) ModTime() (modTime time.Time, err error) { - return fs.info.ModTime(), nil +func (fs *FsObjectLocal) ModTime() time.Time { + return fs.info.ModTime() } // Sets the modification time of the local fs object diff --git a/fs_swift.go b/fs_swift.go index 91883403d..8c50e85a7 100644 --- a/fs_swift.go +++ b/fs_swift.go @@ -183,12 +183,7 @@ func (f *FsSwift) Put(src FsObject) { // Set the mtime m := swift.Metadata{} - modTime, err := src.ModTime() - if err != nil { - FsDebug(fs, "Failed to read mtime from object: %s", err) - } else { - m.SetModTime(modTime) - } + m.SetModTime(src.ModTime()) _, err = fs.swift.c.ObjectPut(fs.swift.container, fs.remote, in, true, "", "", m.ObjectHeaders()) if err != nil { @@ -246,18 +241,22 @@ func (fs *FsObjectSwift) readMetaData() (err error) { } // ModTime returns the modification time of the object -func (fs *FsObjectSwift) ModTime() (modTime time.Time, err error) { - err = fs.readMetaData() +// +// +// It attempts to read the objects mtime and if that isn't present the +// LastModified returned in the http headers +func (fs *FsObjectSwift) ModTime() time.Time { + err := fs.readMetaData() if err != nil { - FsLog(fs, "Failed to read metadata: %s", err) - return + // FsLog(fs, "Failed to read metadata: %s", err) + return fs.info.LastModified } - modTime, err = fs.meta.GetModTime() + modTime, err := fs.meta.GetModTime() if err != nil { - FsLog(fs, "Failed to read mtime from object: %s", err) - return + // FsLog(fs, "Failed to read mtime from object: %s", err) + return fs.info.LastModified } - return + return modTime } // Sets the modification time of the local fs object diff --git a/notes.txt b/notes.txt index 2e36f3ef0..342bbbfe7 100644 --- a/notes.txt +++ b/notes.txt @@ -1,5 +1,6 @@ Todo * FIXME: More -dry-run checks for object transfer + * FIXME ls is very slow also - need to run mtimes in parallel * Check logging in various parts * Make logging controllable with flags (mostly done) * progress meter would be nice! Do this by wrapping the Reader with a progress bar diff --git a/swiftsync.go b/swiftsync.go index b2acd14eb..9d8294477 100644 --- a/swiftsync.go +++ b/swiftsync.go @@ -250,7 +250,7 @@ func List(f Fs) { // fmt.Printf("%9s %19s %s\n", "Directory", "-", fs.Remote()) // } else { // FIXME ModTime is expensive? - modTime, _ := fs.ModTime() + modTime := fs.ModTime() fmt.Printf("%9d %19s %s\n", fs.Size(), modTime.Format("2006-01-02 15:04:05"), fs.Remote()) // fmt.Printf("%9d %19s %s\n", fs.Size(), object.LastModified.Format("2006-01-02 15:04:05"), fs.Remote()) // }