1
0
mirror of https://github.com/rclone/rclone.git synced 2025-02-14 21:23:01 +02:00

dropbox: make setting mod time on existing files work properly

This is a fix left over from the v2 conversion.  Dropbox ignores the
client modification on an incoming file if it was identical to the
existing file.  This change deletes the existing file first before
re-uploading the new one.
This commit is contained in:
Nick Craig-Wood 2017-06-13 13:58:39 +01:00
parent 740b3f6ae2
commit 68333d34a1
5 changed files with 30 additions and 22 deletions

View File

@ -125,7 +125,7 @@ func (f *File) applyPendingModTime() error {
switch err { switch err {
case nil: case nil:
fs.Debugf(f.o, "File.applyPendingModTime OK") fs.Debugf(f.o, "File.applyPendingModTime OK")
case fs.ErrorCantSetModTime: case fs.ErrorCantSetModTime, fs.ErrorCantSetModTimeWithoutDelete:
// do nothing, in order to not break "touch somefile" if it exists already // do nothing, in order to not break "touch somefile" if it exists already
default: default:
fs.Errorf(f.o, "File.applyPendingModTime error: %v", err) fs.Errorf(f.o, "File.applyPendingModTime error: %v", err)

View File

@ -810,9 +810,9 @@ func (o *Object) ModTime() time.Time {
// Commits the datastore // Commits the datastore
func (o *Object) SetModTime(modTime time.Time) error { func (o *Object) SetModTime(modTime time.Time) error {
// Dropbox doesn't have a way of doing this so returning this // Dropbox doesn't have a way of doing this so returning this
// error will cause the file to be re-uploaded to set the // error will cause the file to be deleted first then
// time. // re-uploaded to set the time.
return fs.ErrorCantSetModTime return fs.ErrorCantSetModTimeWithoutDelete
} }
// Storable returns whether this object is storable // Storable returns whether this object is storable

View File

@ -29,22 +29,23 @@ var (
// Filesystem registry // Filesystem registry
fsRegistry []*RegInfo fsRegistry []*RegInfo
// ErrorNotFoundInConfigFile is returned by NewFs if not found in config file // ErrorNotFoundInConfigFile is returned by NewFs if not found in config file
ErrorNotFoundInConfigFile = errors.New("didn't find section in config file") ErrorNotFoundInConfigFile = errors.New("didn't find section in config file")
ErrorCantPurge = errors.New("can't purge directory") ErrorCantPurge = errors.New("can't purge directory")
ErrorCantCopy = errors.New("can't copy object - incompatible remotes") ErrorCantCopy = errors.New("can't copy object - incompatible remotes")
ErrorCantMove = errors.New("can't move object - incompatible remotes") ErrorCantMove = errors.New("can't move object - incompatible remotes")
ErrorCantDirMove = errors.New("can't move directory - incompatible remotes") ErrorCantDirMove = errors.New("can't move directory - incompatible remotes")
ErrorDirExists = errors.New("can't copy directory - destination already exists") ErrorDirExists = errors.New("can't copy directory - destination already exists")
ErrorCantSetModTime = errors.New("can't set modified time") ErrorCantSetModTime = errors.New("can't set modified time")
ErrorDirNotFound = errors.New("directory not found") ErrorCantSetModTimeWithoutDelete = errors.New("can't set modified time without deleting existing object")
ErrorObjectNotFound = errors.New("object not found") ErrorDirNotFound = errors.New("directory not found")
ErrorLevelNotSupported = errors.New("level value not supported") ErrorObjectNotFound = errors.New("object not found")
ErrorListAborted = errors.New("list aborted") ErrorLevelNotSupported = errors.New("level value not supported")
ErrorListOnlyRoot = errors.New("can only list from root") ErrorListAborted = errors.New("list aborted")
ErrorIsFile = errors.New("is a file not a directory") ErrorListOnlyRoot = errors.New("can only list from root")
ErrorNotAFile = errors.New("is a not a regular file") ErrorIsFile = errors.New("is a file not a directory")
ErrorNotDeleting = errors.New("not deleting files as there were IO errors") ErrorNotAFile = errors.New("is a not a regular file")
ErrorCantMoveOverlapping = errors.New("can't move files on overlapping remotes") ErrorNotDeleting = errors.New("not deleting files as there were IO errors")
ErrorCantMoveOverlapping = errors.New("can't move files on overlapping remotes")
) )
// RegInfo provides information about a filesystem // RegInfo provides information about a filesystem

View File

@ -183,7 +183,14 @@ func equal(src, dst Object, sizeOnly, checkSum bool) bool {
// mtime of the dst object here // mtime of the dst object here
err := dst.SetModTime(srcModTime) err := dst.SetModTime(srcModTime)
if err == ErrorCantSetModTime { if err == ErrorCantSetModTime {
Debugf(src, "src and dst identical but can't set mod time without re-uploading") Debugf(dst, "src and dst identical but can't set mod time without re-uploading")
return false
} else if err == ErrorCantSetModTimeWithoutDelete {
Debugf(dst, "src and dst identical but can't set mod time without deleting and re-uploading")
err = dst.Remove()
if err != nil {
Errorf(dst, "failed to delete before re-upload: %v", err)
}
return false return false
} else if err != nil { } else if err != nil {
Stats.Error() Stats.Error()

View File

@ -672,7 +672,7 @@ func TestObjectSetModTime(t *testing.T) {
newModTime := fstest.Time("2011-12-13T14:15:16.999999999Z") newModTime := fstest.Time("2011-12-13T14:15:16.999999999Z")
obj := findObject(t, file1.Path) obj := findObject(t, file1.Path)
err := obj.SetModTime(newModTime) err := obj.SetModTime(newModTime)
if err == fs.ErrorCantSetModTime { if err == fs.ErrorCantSetModTime || err == fs.ErrorCantSetModTimeWithoutDelete {
t.Log(err) t.Log(err)
return return
} }