sync: fix deadlock with --track-renames-strategy modtime - fixes #4427

Before this change we could exit the popRenameMap function with the
lock held.

This fixes the problem by defer-ring the unlock.

See: https://forum.rclone.org/t/track-renames-strategy-modtime-doesnt-work/16992
This commit is contained in:
Nick Craig-Wood 2020-07-15 15:05:44 +01:00
parent bcd362fcd5
commit 811b30d116
1 changed files with 1 additions and 1 deletions

View File

@ -658,6 +658,7 @@ func (s *syncCopyMove) pushRenameMap(hash string, obj fs.Object) {
// renameMap or returns nil if not found.
func (s *syncCopyMove) popRenameMap(hash string, src fs.Object) (dst fs.Object) {
s.renameMapMu.Lock()
defer s.renameMapMu.Unlock()
dsts, ok := s.renameMap[hash]
if ok && len(dsts) > 0 {
// Element to remove
@ -690,7 +691,6 @@ func (s *syncCopyMove) popRenameMap(hash string, src fs.Object) (dst fs.Object)
delete(s.renameMap, hash)
}
}
s.renameMapMu.Unlock()
return dst
}