Change the interface of SetModTime to return an error - #348

This commit is contained in:
Nick Craig-Wood 2016-03-22 15:07:10 +00:00
parent f469905d07
commit 414b35ea56
12 changed files with 39 additions and 53 deletions

View File

@ -745,9 +745,9 @@ func (o *Object) ModTime() time.Time {
}
// SetModTime sets the modification time of the local fs object
func (o *Object) SetModTime(modTime time.Time) {
func (o *Object) SetModTime(modTime time.Time) error {
// FIXME not implemented
return
return fs.ErrorCantSetModTime
}
// Storable returns a boolean showing whether this object storable

View File

@ -805,8 +805,9 @@ func (o *Object) ModTime() (result time.Time) {
}
// SetModTime sets the modification time of the local fs object
func (o *Object) SetModTime(modTime time.Time) {
func (o *Object) SetModTime(modTime time.Time) error {
// Not possible with B2
return fs.ErrorCantSetModTime
}
// Storable returns if this object is storable

View File

@ -936,12 +936,10 @@ func (o *Object) ModTime() time.Time {
}
// SetModTime sets the modification time of the drive fs object
func (o *Object) SetModTime(modTime time.Time) {
func (o *Object) SetModTime(modTime time.Time) error {
err := o.readMetaData()
if err != nil {
fs.Stats.Error()
fs.ErrorLog(o, "Failed to read metadata: %s", err)
return
return err
}
// New metadata
updateInfo := &drive.File{
@ -954,12 +952,11 @@ func (o *Object) SetModTime(modTime time.Time) {
return shouldRetry(err)
})
if err != nil {
fs.Stats.Error()
fs.ErrorLog(o, "Failed to update remote mtime: %s", err)
return
return err
}
// Update info from read data
o.setMetaData(info)
return nil
}
// Storable returns a boolean as to whether this object is storable

View File

@ -636,9 +636,9 @@ func (o *Object) ModTime() time.Time {
// SetModTime sets the modification time of the local fs object
//
// Commits the datastore
func (o *Object) SetModTime(modTime time.Time) {
func (o *Object) SetModTime(modTime time.Time) error {
// FIXME not implemented
return
return fs.ErrorCantSetModTime
}
// Storable returns whether this object is storable

View File

@ -31,6 +31,7 @@ var (
ErrorCantMove = fmt.Errorf("Can't move object - incompatible remotes")
ErrorCantDirMove = fmt.Errorf("Can't move directory - incompatible remotes")
ErrorDirExists = fmt.Errorf("Can't copy directory - destination already exists")
ErrorCantSetModTime = fmt.Errorf("Can't set modified time")
)
// RegInfo provides information about a filesystem
@ -142,7 +143,7 @@ type Object interface {
String() string
// SetModTime sets the metadata on the object to set the modification date
SetModTime(time.Time)
SetModTime(time.Time) error
// Open opens the file for read. Call Close() on the returned io.ReadCloser
Open() (io.ReadCloser, error)

View File

@ -145,7 +145,11 @@ func Equal(src, dst Object) bool {
if !Config.CheckSum {
// Size and hash the same but mtime different so update the
// mtime of the dst object here
dst.SetModTime(srcModTime)
err := dst.SetModTime(srcModTime)
if err != nil {
Stats.Error()
ErrorLog(dst, "Failed to read set modification time: %s", err)
}
}
if hash == HashNone {

View File

@ -567,7 +567,7 @@ func metadataFromModTime(modTime time.Time) map[string]string {
}
// SetModTime sets the modification time of the local fs object
func (o *Object) SetModTime(modTime time.Time) {
func (o *Object) SetModTime(modTime time.Time) error {
// This only adds metadata so will perserve other metadata
object := storage.Object{
Bucket: o.fs.bucket,
@ -576,10 +576,10 @@ func (o *Object) SetModTime(modTime time.Time) {
}
newObject, err := o.fs.svc.Objects.Patch(o.fs.bucket, o.fs.root+o.remote, &object).Do()
if err != nil {
fs.Stats.Error()
fs.ErrorLog(o, "Failed to update remote mtime: %s", err)
return err
}
o.setMetaData(newObject)
return nil
}
// Storable returns a boolean as to whether this object is storable

View File

@ -495,18 +495,13 @@ func (o *Object) ModTime() time.Time {
}
// SetModTime sets the modification time of the local fs object
func (o *Object) SetModTime(modTime time.Time) {
func (o *Object) SetModTime(modTime time.Time) error {
err := os.Chtimes(o.path, modTime, modTime)
if err != nil {
fs.Debug(o, "Failed to set mtime on file: %s", err)
return
return err
}
// Re-read metadata
err = o.lstat()
if err != nil {
fs.Debug(o, "Failed to stat: %s", err)
return
}
return o.lstat()
}
// Storable returns a boolean showing if this object is storable
@ -601,7 +596,10 @@ func (o *Object) Update(in io.Reader, src fs.ObjectInfo) error {
o.hashes = hash.Sums()
// Set the mtime
o.SetModTime(src.ModTime())
err = o.SetModTime(src.ModTime())
if err != nil {
return err
}
// ReRead info now that we have finished
return o.lstat()

View File

@ -802,13 +802,13 @@ func (o *Object) setModTime(modTime time.Time) (*api.Item, error) {
}
// SetModTime sets the modification time of the local fs object
func (o *Object) SetModTime(modTime time.Time) {
func (o *Object) SetModTime(modTime time.Time) error {
info, err := o.setModTime(modTime)
if err != nil {
fs.Stats.Error()
fs.ErrorLog(o, "Failed to update remote mtime: %v", err)
return err
}
o.setMetaData(info)
return nil
}
// Storable returns a boolean showing whether this object storable

View File

@ -702,12 +702,10 @@ func (o *Object) ModTime() time.Time {
}
// SetModTime sets the modification time of the local fs object
func (o *Object) SetModTime(modTime time.Time) {
func (o *Object) SetModTime(modTime time.Time) error {
err := o.readMetaData()
if err != nil {
fs.Stats.Error()
fs.ErrorLog(o, "Failed to read metadata: %s", err)
return
return err
}
o.meta[metaMtime] = aws.String(swift.TimeToFloatString(modTime))
@ -728,10 +726,7 @@ func (o *Object) SetModTime(modTime time.Time) {
MetadataDirective: &directive,
}
_, err = o.fs.c.CopyObject(&req)
if err != nil {
fs.Stats.Error()
fs.ErrorLog(o, "Failed to update remote mtime: %s", err)
}
return err
}
// Storable raturns a boolean indicating if this object is storable

View File

@ -560,12 +560,10 @@ func (o *Object) ModTime() time.Time {
}
// SetModTime sets the modification time of the local fs object
func (o *Object) SetModTime(modTime time.Time) {
func (o *Object) SetModTime(modTime time.Time) error {
err := o.readMetaData()
if err != nil {
fs.Stats.Error()
fs.ErrorLog(o, "Failed to read metadata: %s", err)
return
return err
}
meta := o.headers.ObjectMetadata()
meta.SetModTime(modTime)
@ -579,11 +577,7 @@ func (o *Object) SetModTime(modTime time.Time) {
newHeaders[k] = v
}
}
err = o.fs.c.ObjectUpdate(o.fs.container, o.fs.root+o.remote, newHeaders)
if err != nil {
fs.Stats.Error()
fs.ErrorLog(o, "Failed to update remote mtime: %s", err)
}
return o.fs.c.ObjectUpdate(o.fs.container, o.fs.root+o.remote, newHeaders)
}
// Storable returns if this object is storable

View File

@ -452,14 +452,10 @@ func (o *Object) Remove() error {
// SetModTime sets the modification time of the local fs object
//
// Commits the datastore
func (o *Object) SetModTime(modTime time.Time) {
func (o *Object) SetModTime(modTime time.Time) error {
remote := o.remotePath()
//set custom_property 'rclone_modified' of object to modTime
err := o.fs.yd.SetCustomProperty(remote, "rclone_modified", modTime.Format(time.RFC3339Nano))
if err != nil {
return
}
return
return o.fs.yd.SetCustomProperty(remote, "rclone_modified", modTime.Format(time.RFC3339Nano))
}
// Storable returns whether this object is storable
@ -496,7 +492,7 @@ func (o *Object) Update(in io.Reader, src fs.ObjectInfo) error {
o.modTime = modTime
o.md5sum = "" // according to unit tests after put the md5 is empty.
//and set modTime of uploaded file
o.SetModTime(modTime)
err = o.SetModTime(modTime)
}
return err
}