Refactor GetMtime for early return

This commit is contained in:
Jakob Borg 2015-05-14 08:26:21 +02:00
parent 65be18cc93
commit 9d150bef9f

View File

@ -47,33 +47,31 @@ func (r *VirtualMtimeRepo) UpdateMtime(path string, diskMtime, actualMtime time.
} }
func (r *VirtualMtimeRepo) GetMtime(path string, diskMtime time.Time) time.Time { func (r *VirtualMtimeRepo) GetMtime(path string, diskMtime time.Time) time.Time {
var debugResult string data, exists := r.ns.Bytes(path)
if !exists {
// Absense of debug print is significant enough in itself here
return diskMtime
}
if data, exists := r.ns.Bytes(path); exists { var mtime time.Time
var mtime time.Time if err := mtime.UnmarshalBinary(data[:len(data)/2]); err != nil {
panic(fmt.Sprintf("Can't unmarshal stored mtime at path %s: %v", path, err))
}
if err := mtime.UnmarshalBinary(data[:len(data)/2]); err != nil { if mtime.Equal(diskMtime) {
panic(fmt.Sprintf("Can't unmarshal stored mtime at path %v: %v", path, err)) if err := mtime.UnmarshalBinary(data[len(data)/2:]); err != nil {
panic(fmt.Sprintf("Can't unmarshal stored mtime at path %s: %v", path, err))
} }
if mtime.Equal(diskMtime) { if debug {
if err := mtime.UnmarshalBinary(data[len(data)/2:]); err != nil { l.Debugf("virtual mtime: return %v instead of %v for path: %s", mtime, diskMtime, path)
panic(fmt.Sprintf("Can't unmarshal stored mtime at path %v: %v", path, err))
}
debugResult = "got it"
diskMtime = mtime
} else if debug {
debugResult = fmt.Sprintf("record exists, but mismatch inDisk:%v dbDisk:%v", diskMtime, mtime)
} }
} else { return mtime
debugResult = "record does not exist"
} }
if debug { if debug {
l.Debugf("virtual mtime: value get result:%v path:%s", debugResult, path) l.Debugf("virtual mtime: record exists, but mismatch inDisk: %v dbDisk: %v for path: %s", diskMtime, mtime, path)
} }
return diskMtime return diskMtime
} }