mirror of
https://github.com/rclone/rclone.git
synced 2025-06-30 20:40:57 +02:00
vfs: fix duplicates on rename - fixes #5469
Before this change, if there was an existing file being uploaded when a file was renamed on top of it, then both would be uploaded. This causes a duplicate in Google Drive as both files get uploaded at the same time. This was triggered reliably by LibreOffice saving doc files. This fix removes any duplicates in the upload queue on rename.
This commit is contained in:
@ -276,13 +276,12 @@ func (wb *WriteBack) Add(id Handle, name string, modified bool, putFn PutFn) Han
|
||||
return wbItem.id
|
||||
}
|
||||
|
||||
// Remove should be called when a file should be removed from the
|
||||
// _remove should be called when a file should be removed from the
|
||||
// writeback queue. This cancels a writeback if there is one and
|
||||
// doesn't return the item to the queue.
|
||||
func (wb *WriteBack) Remove(id Handle) (found bool) {
|
||||
wb.mu.Lock()
|
||||
defer wb.mu.Unlock()
|
||||
|
||||
//
|
||||
// This should be called with the lock held
|
||||
func (wb *WriteBack) _remove(id Handle) (found bool) {
|
||||
wbItem, found := wb.lookup[id]
|
||||
if found {
|
||||
fs.Debugf(wbItem.name, "vfs cache: cancelling writeback (uploading %v) %p item %d", wbItem.uploading, wbItem, wbItem.id)
|
||||
@ -299,6 +298,16 @@ func (wb *WriteBack) Remove(id Handle) (found bool) {
|
||||
return found
|
||||
}
|
||||
|
||||
// Remove should be called when a file should be removed from the
|
||||
// writeback queue. This cancels a writeback if there is one and
|
||||
// doesn't return the item to the queue.
|
||||
func (wb *WriteBack) Remove(id Handle) (found bool) {
|
||||
wb.mu.Lock()
|
||||
defer wb.mu.Unlock()
|
||||
|
||||
return wb._remove(id)
|
||||
}
|
||||
|
||||
// Rename should be called when a file might be uploading and it gains
|
||||
// a new name. This will cancel the upload and put it back in the
|
||||
// queue.
|
||||
@ -314,6 +323,15 @@ func (wb *WriteBack) Rename(id Handle, name string) {
|
||||
// We are uploading already so cancel the upload
|
||||
wb._cancelUpload(wbItem)
|
||||
}
|
||||
|
||||
// Check to see if there are any uploads with the existing
|
||||
// name and remove them
|
||||
for existingID, existingItem := range wb.lookup {
|
||||
if existingID != id && existingItem.name == name {
|
||||
wb._remove(existingID)
|
||||
}
|
||||
}
|
||||
|
||||
wbItem.name = name
|
||||
// Kick the timer on
|
||||
wb.items._update(wbItem, wb._newExpiry())
|
||||
|
Reference in New Issue
Block a user