chore: slightly optimise rename detection (ref #10777) (#10819)

Only run rename detection for new files. This skips an expensive check
for all updates to existing files. The tradeoff is that we no longer
immediately detect renames on top of another file as a rename -- this
may instead become a copy+delete operation on the destination.

---------

Signed-off-by: Jakob Borg <jakob@kastelo.net>
This commit is contained in:
Jakob Borg
2026-07-25 07:46:56 +00:00
committed by GitHub
parent b15ff42d52
commit ec35a95318
4 changed files with 33 additions and 14 deletions
+13 -6
View File
@@ -745,12 +745,19 @@ func (f *folder) scanSubdirsChangedAndNew(ctx context.Context, subDirs []string,
switch f.Type {
case config.FolderTypeReceiveOnly, config.FolderTypeReceiveEncrypted:
default:
if nf, ok := f.findRename(ctx, res.File, batch); ok {
if ok, err := batch.Update(nf); err != nil {
return 0, err
} else if ok {
changes++
batch.markDeleted(nf.Name)
// Rename detection is comparatively expensive, so only attempt
// it for files that appeared as new on disk during this scan. A
// rename that overwrites an existing file (the destination path
// already had an entry, so it scans as an update rather than a
// new file) is not optimised as a rename.
if res.File.New && res.File.Size > 0 {
if nf, ok := f.findRename(ctx, res.File, batch); ok {
if ok, err := batch.Update(nf); err != nil {
return 0, err
} else if ok {
changes++
batch.markDeleted(nf.Name)
}
}
}
}