all: Reorder sequences for better rename detection (#6574)

This commit is contained in:
Audrius Butkevicius
2020-05-11 20:15:11 +02:00
committed by GitHub
parent aac3750298
commit decb967969
9 changed files with 409 additions and 42 deletions
+49
View File
@@ -464,6 +464,13 @@ func (f *folder) scanSubdirs(subDirs []string) error {
batch.append(res.File)
changes++
if f.localFlags&protocol.FlagLocalReceiveOnly == 0 {
if nf, ok := f.findRename(snap, mtimefs, res.File); ok {
batch.append(nf)
changes++
}
}
}
if err := batch.flush(); err != nil {
@@ -615,6 +622,48 @@ 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) {
found := false
nf := protocol.FileInfo{}
snap.WithBlocksHash(file.BlocksHash, func(ifi db.FileIntf) bool {
fi := ifi.(protocol.FileInfo)
select {
case <-f.ctx.Done():
return false
default:
}
if fi.ShouldConflict() {
return true
}
if f.ignores.Match(fi.Name).IsIgnored() {
return true
}
// Only check the size.
// No point checking block equality, as that uses BlocksHash comparison if that is set (which it will be).
// No point checking BlocksHash comparison as WithBlocksHash already does that.
if file.Size != fi.Size {
return true
}
if !osutil.IsDeleted(mtimefs, fi.Name) {
return true
}
nf = fi
nf.SetDeleted(f.shortID)
nf.LocalFlags = f.localFlags
found = true
return false
})
return nf, found
}
func (f *folder) scanTimerFired() {
err := f.scanSubdirs(nil)