lib/model: Refactor override implementation into sendOnlyFolder
I'm trying to slowly clean this up a bit, and moving functionality out into the folder types and having those methods not reach into model is part of it. That can mean takign some odd arguments in the meantime, some of those should probably become interfaces or properties on folder in the long term.
This commit is contained in:
@@ -56,6 +56,7 @@ const (
|
||||
|
||||
type service interface {
|
||||
BringToFront(string)
|
||||
Override(*db.FileSet, func([]protocol.FileInfo))
|
||||
DelayScan(d time.Duration)
|
||||
IgnoresUpdated() // ignore matcher was updated notification
|
||||
SchedulePull() // something relevant changed, we should try a pull
|
||||
@@ -2300,50 +2301,21 @@ func (m *Model) WatchError(folder string) error {
|
||||
}
|
||||
|
||||
func (m *Model) Override(folder string) {
|
||||
// Grab the runner and the file set.
|
||||
|
||||
m.fmut.RLock()
|
||||
fs, ok := m.folderFiles[folder]
|
||||
runner := m.folderRunners[folder]
|
||||
fs, fsOK := m.folderFiles[folder]
|
||||
runner, runnerOK := m.folderRunners[folder]
|
||||
m.fmut.RUnlock()
|
||||
if !ok {
|
||||
if !fsOK || !runnerOK {
|
||||
return
|
||||
}
|
||||
|
||||
runner.setState(FolderScanning)
|
||||
batch := make([]protocol.FileInfo, 0, maxBatchSizeFiles)
|
||||
batchSizeBytes := 0
|
||||
fs.WithNeed(protocol.LocalDeviceID, func(fi db.FileIntf) bool {
|
||||
need := fi.(protocol.FileInfo)
|
||||
if len(batch) == maxBatchSizeFiles || batchSizeBytes > maxBatchSizeBytes {
|
||||
m.updateLocalsFromScanning(folder, batch)
|
||||
batch = batch[:0]
|
||||
batchSizeBytes = 0
|
||||
}
|
||||
// Run the override, taking updates as if they came from scanning.
|
||||
|
||||
have, ok := fs.Get(protocol.LocalDeviceID, need.Name)
|
||||
// Don't override invalid (e.g. ignored) files
|
||||
if ok && have.Invalid {
|
||||
return true
|
||||
}
|
||||
if !ok || have.Name != need.Name {
|
||||
// We are missing the file
|
||||
need.Deleted = true
|
||||
need.Blocks = nil
|
||||
need.Version = need.Version.Update(m.shortID)
|
||||
need.Size = 0
|
||||
} else {
|
||||
// We have the file, replace with our version
|
||||
have.Version = have.Version.Merge(need.Version).Update(m.shortID)
|
||||
need = have
|
||||
}
|
||||
need.Sequence = 0
|
||||
batch = append(batch, need)
|
||||
batchSizeBytes += need.ProtoSize()
|
||||
return true
|
||||
runner.Override(fs, func(files []protocol.FileInfo) {
|
||||
m.updateLocalsFromScanning(folder, files)
|
||||
})
|
||||
if len(batch) > 0 {
|
||||
m.updateLocalsFromScanning(folder, batch)
|
||||
}
|
||||
runner.setState(FolderIdle)
|
||||
}
|
||||
|
||||
// CurrentSequence returns the change version for the given folder.
|
||||
|
||||
Reference in New Issue
Block a user