Change the interface of SetModTime to return an error - #348
This commit is contained in:
parent
f469905d07
commit
414b35ea56
12 changed files with 39 additions and 53 deletions
|
@ -745,9 +745,9 @@ func (o *Object) ModTime() time.Time {
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetModTime sets the modification time of the local fs object
|
// 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
|
// FIXME not implemented
|
||||||
return
|
return fs.ErrorCantSetModTime
|
||||||
}
|
}
|
||||||
|
|
||||||
// Storable returns a boolean showing whether this object storable
|
// Storable returns a boolean showing whether this object storable
|
||||||
|
|
3
b2/b2.go
3
b2/b2.go
|
@ -805,8 +805,9 @@ func (o *Object) ModTime() (result time.Time) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetModTime sets the modification time of the local fs object
|
// 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
|
// Not possible with B2
|
||||||
|
return fs.ErrorCantSetModTime
|
||||||
}
|
}
|
||||||
|
|
||||||
// Storable returns if this object is storable
|
// Storable returns if this object is storable
|
||||||
|
|
|
@ -936,12 +936,10 @@ func (o *Object) ModTime() time.Time {
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetModTime sets the modification time of the drive fs object
|
// 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()
|
err := o.readMetaData()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fs.Stats.Error()
|
return err
|
||||||
fs.ErrorLog(o, "Failed to read metadata: %s", err)
|
|
||||||
return
|
|
||||||
}
|
}
|
||||||
// New metadata
|
// New metadata
|
||||||
updateInfo := &drive.File{
|
updateInfo := &drive.File{
|
||||||
|
@ -954,12 +952,11 @@ func (o *Object) SetModTime(modTime time.Time) {
|
||||||
return shouldRetry(err)
|
return shouldRetry(err)
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fs.Stats.Error()
|
return err
|
||||||
fs.ErrorLog(o, "Failed to update remote mtime: %s", err)
|
|
||||||
return
|
|
||||||
}
|
}
|
||||||
// Update info from read data
|
// Update info from read data
|
||||||
o.setMetaData(info)
|
o.setMetaData(info)
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Storable returns a boolean as to whether this object is storable
|
// Storable returns a boolean as to whether this object is storable
|
||||||
|
|
|
@ -636,9 +636,9 @@ func (o *Object) ModTime() time.Time {
|
||||||
// SetModTime sets the modification time of the local fs object
|
// SetModTime sets the modification time of the local fs object
|
||||||
//
|
//
|
||||||
// Commits the datastore
|
// Commits the datastore
|
||||||
func (o *Object) SetModTime(modTime time.Time) {
|
func (o *Object) SetModTime(modTime time.Time) error {
|
||||||
// FIXME not implemented
|
// FIXME not implemented
|
||||||
return
|
return fs.ErrorCantSetModTime
|
||||||
}
|
}
|
||||||
|
|
||||||
// Storable returns whether this object is storable
|
// Storable returns whether this object is storable
|
||||||
|
|
3
fs/fs.go
3
fs/fs.go
|
@ -31,6 +31,7 @@ var (
|
||||||
ErrorCantMove = fmt.Errorf("Can't move object - incompatible remotes")
|
ErrorCantMove = fmt.Errorf("Can't move object - incompatible remotes")
|
||||||
ErrorCantDirMove = fmt.Errorf("Can't move directory - incompatible remotes")
|
ErrorCantDirMove = fmt.Errorf("Can't move directory - incompatible remotes")
|
||||||
ErrorDirExists = fmt.Errorf("Can't copy directory - destination already exists")
|
ErrorDirExists = fmt.Errorf("Can't copy directory - destination already exists")
|
||||||
|
ErrorCantSetModTime = fmt.Errorf("Can't set modified time")
|
||||||
)
|
)
|
||||||
|
|
||||||
// RegInfo provides information about a filesystem
|
// RegInfo provides information about a filesystem
|
||||||
|
@ -142,7 +143,7 @@ type Object interface {
|
||||||
String() string
|
String() string
|
||||||
|
|
||||||
// SetModTime sets the metadata on the object to set the modification date
|
// 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 opens the file for read. Call Close() on the returned io.ReadCloser
|
||||||
Open() (io.ReadCloser, error)
|
Open() (io.ReadCloser, error)
|
||||||
|
|
|
@ -145,7 +145,11 @@ func Equal(src, dst Object) bool {
|
||||||
if !Config.CheckSum {
|
if !Config.CheckSum {
|
||||||
// Size and hash the same but mtime different so update the
|
// Size and hash the same but mtime different so update the
|
||||||
// mtime of the dst object here
|
// 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 {
|
if hash == HashNone {
|
||||||
|
|
|
@ -567,7 +567,7 @@ func metadataFromModTime(modTime time.Time) map[string]string {
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetModTime sets the modification time of the local fs object
|
// 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
|
// This only adds metadata so will perserve other metadata
|
||||||
object := storage.Object{
|
object := storage.Object{
|
||||||
Bucket: o.fs.bucket,
|
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()
|
newObject, err := o.fs.svc.Objects.Patch(o.fs.bucket, o.fs.root+o.remote, &object).Do()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fs.Stats.Error()
|
return err
|
||||||
fs.ErrorLog(o, "Failed to update remote mtime: %s", err)
|
|
||||||
}
|
}
|
||||||
o.setMetaData(newObject)
|
o.setMetaData(newObject)
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Storable returns a boolean as to whether this object is storable
|
// Storable returns a boolean as to whether this object is storable
|
||||||
|
|
|
@ -495,18 +495,13 @@ func (o *Object) ModTime() time.Time {
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetModTime sets the modification time of the local fs object
|
// 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)
|
err := os.Chtimes(o.path, modTime, modTime)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fs.Debug(o, "Failed to set mtime on file: %s", err)
|
return err
|
||||||
return
|
|
||||||
}
|
}
|
||||||
// Re-read metadata
|
// Re-read metadata
|
||||||
err = o.lstat()
|
return o.lstat()
|
||||||
if err != nil {
|
|
||||||
fs.Debug(o, "Failed to stat: %s", err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Storable returns a boolean showing if this object is storable
|
// 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()
|
o.hashes = hash.Sums()
|
||||||
|
|
||||||
// Set the mtime
|
// Set the mtime
|
||||||
o.SetModTime(src.ModTime())
|
err = o.SetModTime(src.ModTime())
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
// ReRead info now that we have finished
|
// ReRead info now that we have finished
|
||||||
return o.lstat()
|
return o.lstat()
|
||||||
|
|
|
@ -802,13 +802,13 @@ func (o *Object) setModTime(modTime time.Time) (*api.Item, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetModTime sets the modification time of the local fs object
|
// 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)
|
info, err := o.setModTime(modTime)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fs.Stats.Error()
|
return err
|
||||||
fs.ErrorLog(o, "Failed to update remote mtime: %v", err)
|
|
||||||
}
|
}
|
||||||
o.setMetaData(info)
|
o.setMetaData(info)
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Storable returns a boolean showing whether this object storable
|
// Storable returns a boolean showing whether this object storable
|
||||||
|
|
11
s3/s3.go
11
s3/s3.go
|
@ -702,12 +702,10 @@ func (o *Object) ModTime() time.Time {
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetModTime sets the modification time of the local fs object
|
// 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()
|
err := o.readMetaData()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fs.Stats.Error()
|
return err
|
||||||
fs.ErrorLog(o, "Failed to read metadata: %s", err)
|
|
||||||
return
|
|
||||||
}
|
}
|
||||||
o.meta[metaMtime] = aws.String(swift.TimeToFloatString(modTime))
|
o.meta[metaMtime] = aws.String(swift.TimeToFloatString(modTime))
|
||||||
|
|
||||||
|
@ -728,10 +726,7 @@ func (o *Object) SetModTime(modTime time.Time) {
|
||||||
MetadataDirective: &directive,
|
MetadataDirective: &directive,
|
||||||
}
|
}
|
||||||
_, err = o.fs.c.CopyObject(&req)
|
_, err = o.fs.c.CopyObject(&req)
|
||||||
if err != nil {
|
return err
|
||||||
fs.Stats.Error()
|
|
||||||
fs.ErrorLog(o, "Failed to update remote mtime: %s", err)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Storable raturns a boolean indicating if this object is storable
|
// Storable raturns a boolean indicating if this object is storable
|
||||||
|
|
|
@ -560,12 +560,10 @@ func (o *Object) ModTime() time.Time {
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetModTime sets the modification time of the local fs object
|
// 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()
|
err := o.readMetaData()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fs.Stats.Error()
|
return err
|
||||||
fs.ErrorLog(o, "Failed to read metadata: %s", err)
|
|
||||||
return
|
|
||||||
}
|
}
|
||||||
meta := o.headers.ObjectMetadata()
|
meta := o.headers.ObjectMetadata()
|
||||||
meta.SetModTime(modTime)
|
meta.SetModTime(modTime)
|
||||||
|
@ -579,11 +577,7 @@ func (o *Object) SetModTime(modTime time.Time) {
|
||||||
newHeaders[k] = v
|
newHeaders[k] = v
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
err = o.fs.c.ObjectUpdate(o.fs.container, o.fs.root+o.remote, newHeaders)
|
return 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)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Storable returns if this object is storable
|
// Storable returns if this object is storable
|
||||||
|
|
|
@ -452,14 +452,10 @@ func (o *Object) Remove() error {
|
||||||
// SetModTime sets the modification time of the local fs object
|
// SetModTime sets the modification time of the local fs object
|
||||||
//
|
//
|
||||||
// Commits the datastore
|
// Commits the datastore
|
||||||
func (o *Object) SetModTime(modTime time.Time) {
|
func (o *Object) SetModTime(modTime time.Time) error {
|
||||||
remote := o.remotePath()
|
remote := o.remotePath()
|
||||||
//set custom_property 'rclone_modified' of object to modTime
|
//set custom_property 'rclone_modified' of object to modTime
|
||||||
err := o.fs.yd.SetCustomProperty(remote, "rclone_modified", modTime.Format(time.RFC3339Nano))
|
return o.fs.yd.SetCustomProperty(remote, "rclone_modified", modTime.Format(time.RFC3339Nano))
|
||||||
if err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Storable returns whether this object is storable
|
// 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.modTime = modTime
|
||||||
o.md5sum = "" // according to unit tests after put the md5 is empty.
|
o.md5sum = "" // according to unit tests after put the md5 is empty.
|
||||||
//and set modTime of uploaded file
|
//and set modTime of uploaded file
|
||||||
o.SetModTime(modTime)
|
err = o.SetModTime(modTime)
|
||||||
}
|
}
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue