mirror of
https://github.com/rclone/rclone.git
synced 2024-11-22 09:11:11 +08:00
vfs: vfscache: Fix renaming of items while they are being uploaded
Previous to the fix, if an item was being uploaded and it was renamed, the upload would fail with missing checksum errors. This change cancels any uploads in progress if the file is renamed.
This commit is contained in:
parent
df5dbaf49b
commit
c65ed26a7e
|
@ -1018,36 +1018,35 @@ func (item *Item) Sync() (err error) {
|
|||
|
||||
// rename the item
|
||||
func (item *Item) rename(name string, newName string, newObj fs.Object) (err error) {
|
||||
var downloaders *downloaders.Downloaders
|
||||
// close downloader with mutex unlocked
|
||||
defer func() {
|
||||
if downloaders != nil {
|
||||
_ = downloaders.Close(nil)
|
||||
}
|
||||
}()
|
||||
|
||||
item.mu.Lock()
|
||||
defer item.mu.Unlock()
|
||||
|
||||
// stop downloader
|
||||
downloaders = item.downloaders
|
||||
downloaders := item.downloaders
|
||||
item.downloaders = nil
|
||||
|
||||
// id for writeback cancel
|
||||
id := item.writeBackID
|
||||
|
||||
// Set internal state
|
||||
item.name = newName
|
||||
item.o = newObj
|
||||
|
||||
// Rename cache file if it exists
|
||||
err = rename(item.c.toOSPath(name), item.c.toOSPath(newName)) // No locking in Cache
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// Rename meta file if it exists
|
||||
err = rename(item.c.toOSPathMeta(name), item.c.toOSPathMeta(newName)) // No locking in Cache
|
||||
if err != nil {
|
||||
return err
|
||||
err2 := rename(item.c.toOSPathMeta(name), item.c.toOSPathMeta(newName)) // No locking in Cache
|
||||
if err2 != nil {
|
||||
err = err2
|
||||
}
|
||||
|
||||
return nil
|
||||
item.mu.Unlock()
|
||||
|
||||
// close downloader and cancel writebacks with mutex unlocked
|
||||
if downloaders != nil {
|
||||
_ = downloaders.Close(nil)
|
||||
}
|
||||
item.c.writeback.Rename(id, newName)
|
||||
|
||||
return err
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user