lib/model: Fix rename handling (ref #6650) (#6652)

This commit is contained in:
Audrius Butkevicius
2020-05-16 14:40:20 +02:00
committed by Jakob Borg
parent f5ca213682
commit 258341f8bf
5 changed files with 153 additions and 12 deletions
+18 -5
View File
@@ -453,20 +453,27 @@ func (f *folder) scanSubdirs(subDirs []string) error {
}()
f.clearScanErrors(subDirs)
alreadyUsed := make(map[string]struct{})
for res := range fchan {
if res.Err != nil {
f.newScanError(res.Path, res.Err)
continue
}
if err := batch.flushIfFull(); err != nil {
return err
if batch.full() {
if err := batch.flush(); err != nil {
return err
}
snap.Release()
snap = f.fset.Snapshot()
alreadyUsed = make(map[string]struct{})
}
batch.append(res.File)
changes++
if f.localFlags&protocol.FlagLocalReceiveOnly == 0 {
if nf, ok := f.findRename(snap, mtimefs, res.File); ok {
if nf, ok := f.findRename(snap, mtimefs, res.File, alreadyUsed); ok {
batch.append(nf)
changes++
}
@@ -622,8 +629,8 @@ func (f *folder) scanSubdirs(subDirs []string) error {
return nil
}
func (f *folder) findRename(snap *db.Snapshot, mtimefs fs.Filesystem, file protocol.FileInfo) (protocol.FileInfo, bool) {
if len(file.Blocks) == 0 {
func (f *folder) findRename(snap *db.Snapshot, mtimefs fs.Filesystem, file protocol.FileInfo, alreadyUsed map[string]struct{}) (protocol.FileInfo, bool) {
if len(file.Blocks) == 0 || file.Size == 0 {
return protocol.FileInfo{}, false
}
@@ -639,6 +646,10 @@ func (f *folder) findRename(snap *db.Snapshot, mtimefs fs.Filesystem, file proto
default:
}
if _, ok := alreadyUsed[fi.Name]; ok {
return true
}
if fi.ShouldConflict() {
return true
}
@@ -658,6 +669,8 @@ func (f *folder) findRename(snap *db.Snapshot, mtimefs fs.Filesystem, file proto
return true
}
alreadyUsed[fi.Name] = struct{}{}
nf = fi
nf.SetDeleted(f.shortID)
nf.LocalFlags = f.localFlags