lib/model: Correct/unify check if item changed (#5819)
This commit is contained in:
parent
5cbc9089fd
commit
b58f6ca886
@ -577,14 +577,10 @@ func (f *sendReceiveFolder) handleDir(file protocol.FileInfo, dbUpdateChan chan<
|
||||
case err == nil && !info.IsDir():
|
||||
// Check that it is what we have in the database.
|
||||
curFile, hasCurFile := f.model.CurrentFolderFile(f.folderID, file.Name)
|
||||
if changed, err := f.itemChanged(info, curFile, hasCurFile, scanChan); err != nil {
|
||||
if err := f.scanIfItemChanged(info, curFile, hasCurFile, scanChan); err != nil {
|
||||
err = errors.Wrap(err, "handling dir")
|
||||
f.newPullError(file.Name, err)
|
||||
return
|
||||
} else if changed {
|
||||
l.Debugln("item changed on disk compared to db; not replacing with dir:", file.Name)
|
||||
scanChan <- curFile.Name
|
||||
f.newPullError(file.Name, errModified)
|
||||
return
|
||||
}
|
||||
|
||||
// Remove it to replace with the dir.
|
||||
@ -735,14 +731,10 @@ func (f *sendReceiveFolder) handleSymlink(file protocol.FileInfo, dbUpdateChan c
|
||||
if info, err := f.fs.Lstat(file.Name); err == nil {
|
||||
// Check that it is what we have in the database.
|
||||
curFile, hasCurFile := f.model.CurrentFolderFile(f.folderID, file.Name)
|
||||
if changed, err := f.itemChanged(info, curFile, hasCurFile, scanChan); err != nil {
|
||||
if err := f.scanIfItemChanged(info, curFile, hasCurFile, scanChan); err != nil {
|
||||
err = errors.Wrap(err, "handling symlink")
|
||||
f.newPullError(file.Name, err)
|
||||
return
|
||||
} else if changed {
|
||||
l.Debugln("item changed on disk compared to db; not replacing with symlink:", file.Name)
|
||||
scanChan <- curFile.Name
|
||||
f.newPullError(file.Name, errModified)
|
||||
return
|
||||
}
|
||||
// Remove it to replace with the symlink. This also handles the
|
||||
// "change symlink type" path.
|
||||
@ -1514,12 +1506,10 @@ func (f *sendReceiveFolder) performFinish(file, curFile protocol.FileInfo, hasCu
|
||||
// There is an old file or directory already in place. We need to
|
||||
// handle that.
|
||||
|
||||
if changed, err := f.itemChanged(stat, curFile, hasCurFile, scanChan); err != nil {
|
||||
if err := f.scanIfItemChanged(stat, curFile, hasCurFile, scanChan); err != nil {
|
||||
err = errors.Wrap(err, "handling file")
|
||||
f.newPullError(file.Name, err)
|
||||
return err
|
||||
} else if changed {
|
||||
l.Debugln("file changed on disk compared to db; not finishing:", file.Name)
|
||||
scanChan <- curFile.Name
|
||||
return errModified
|
||||
}
|
||||
|
||||
if !curFile.IsDirectory() && !curFile.IsSymlink() && f.inConflict(curFile.Version, file.Version) {
|
||||
@ -1903,18 +1893,19 @@ func (f *sendReceiveFolder) deleteDirOnDisk(dir string, scanChan chan<- string)
|
||||
return err
|
||||
}
|
||||
|
||||
// itemChanged returns true if the given disk file differs from the information
|
||||
// in the database and schedules that file for scanning
|
||||
func (f *sendReceiveFolder) itemChanged(stat fs.FileInfo, item protocol.FileInfo, hasItem bool, scanChan chan<- string) (changed bool, err error) {
|
||||
// scanIfItemChanged schedules the given file for scanning and returns errModified
|
||||
// if it differs from the information in the database. Returns nil if the file has
|
||||
// not changed.
|
||||
func (f *sendReceiveFolder) scanIfItemChanged(stat fs.FileInfo, item protocol.FileInfo, hasItem bool, scanChan chan<- string) (err error) {
|
||||
defer func() {
|
||||
if changed {
|
||||
if err == errModified {
|
||||
scanChan <- item.Name
|
||||
}
|
||||
}()
|
||||
|
||||
if !hasItem || item.Deleted {
|
||||
// The item appeared from nowhere
|
||||
return true, nil
|
||||
return errModified
|
||||
}
|
||||
|
||||
// Check that the item on disk is what we expect it to be according
|
||||
@ -1923,10 +1914,14 @@ func (f *sendReceiveFolder) itemChanged(stat fs.FileInfo, item protocol.FileInfo
|
||||
// touching the item.
|
||||
statItem, err := scanner.CreateFileInfo(stat, item.Name, f.fs)
|
||||
if err != nil {
|
||||
return false, errors.Wrap(err, "comparing item on disk to db")
|
||||
return errors.Wrap(err, "comparing item on disk to db")
|
||||
}
|
||||
|
||||
return !statItem.IsEquivalentOptional(item, f.IgnorePerms, true, protocol.LocalAllFlags), nil
|
||||
if !statItem.IsEquivalentOptional(item, f.IgnorePerms, true, protocol.LocalAllFlags) {
|
||||
return errModified
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// checkToBeDeleted makes sure the file on disk is compatible with what there is
|
||||
@ -1943,14 +1938,7 @@ func (f *sendReceiveFolder) checkToBeDeleted(cur protocol.FileInfo, scanChan cha
|
||||
// do not delete.
|
||||
return err
|
||||
}
|
||||
changed, err := f.itemChanged(stat, cur, true, scanChan)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if changed {
|
||||
return errModified
|
||||
}
|
||||
return nil
|
||||
return f.scanIfItemChanged(stat, cur, true, scanChan)
|
||||
}
|
||||
|
||||
func (f *sendReceiveFolder) maybeCopyOwner(path string) error {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user