Make ModTime fall back to LastModified header

Which means it no longer needs to report an error which simplifies the code
This commit is contained in:
Nick Craig-Wood 2013-01-02 15:21:55 +00:00
parent 90a2c86eb3
commit ecb863dd4f
5 changed files with 26 additions and 37 deletions

22
fs.go
View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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())
// }