mirror of
https://github.com/octoleo/syncthing.git
synced 2025-02-08 23:08:27 +00:00
Ensure progress when delete-by-rename fails (fixes #1373)
This commit is contained in:
parent
c25107eff3
commit
44d0da02d0
@ -614,22 +614,31 @@ func (p *Puller) renameFile(source, target protocol.FileInfo) {
|
|||||||
err = osutil.TryRename(from, to)
|
err = osutil.TryRename(from, to)
|
||||||
}
|
}
|
||||||
|
|
||||||
if err != nil {
|
if err == nil {
|
||||||
l.Infof("Puller (folder %q, file %q): rename from %q: %v", p.folder, target.Name, source.Name, err)
|
// The file was renamed, so we have handled both the necessary delete
|
||||||
return
|
// of the source and the creation of the target. Fix-up the metadata,
|
||||||
}
|
// and update the local index of the target file.
|
||||||
|
|
||||||
// Fix-up the metadata, and update the local index of the target file
|
p.model.updateLocal(p.folder, source)
|
||||||
err = p.shortcutFile(target)
|
|
||||||
if err != nil {
|
|
||||||
l.Infof("Puller (folder %q, file %q): rename from %q metadata: %v", p.folder, target.Name, source.Name, err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// Source file already has the delete bit set.
|
err = p.shortcutFile(target)
|
||||||
// Because we got rid of the file (by renaming it), we just need to update
|
if err != nil {
|
||||||
// the index, and we're done with it.
|
l.Infof("Puller (folder %q, file %q): rename from %q metadata: %v", p.folder, target.Name, source.Name, err)
|
||||||
p.model.updateLocal(p.folder, source)
|
return
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// We failed the rename so we have a source file that we still need to
|
||||||
|
// get rid of. Attempt to delete it instead so that we make *some*
|
||||||
|
// progress. The target is unhandled.
|
||||||
|
|
||||||
|
err = osutil.InWritableDir(os.Remove, from)
|
||||||
|
if err != nil {
|
||||||
|
l.Infof("Puller (folder %q, file %q): delete %q after failed rename: %v", p.folder, target.Name, source.Name, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
p.model.updateLocal(p.folder, source)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// handleFile queues the copies and pulls as necessary for a single new or
|
// handleFile queues the copies and pulls as necessary for a single new or
|
||||||
|
Loading…
x
Reference in New Issue
Block a user