Skip to content

Commit

Permalink
lib/model: Trigger pulls instead of pulling periodically
Browse files Browse the repository at this point in the history
GitHub-Pull-Request: #4340
  • Loading branch information
imsodin authored and calmh committed Nov 7, 2017
1 parent c5f90d6 commit f6ea2a7
Show file tree
Hide file tree
Showing 5 changed files with 139 additions and 126 deletions.
1 change: 0 additions & 1 deletion lib/config/folderconfiguration.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ type FolderConfiguration struct {
Order PullOrder `xml:"order" json:"order"`
IgnoreDelete bool `xml:"ignoreDelete" json:"ignoreDelete"`
ScanProgressIntervalS int `xml:"scanProgressIntervalS" json:"scanProgressIntervalS"` // Set to a negative value to disable. Value of 0 will get replaced with value of 2 (default value)
PullerSleepS int `xml:"pullerSleepS" json:"pullerSleepS"`
PullerPauseS int `xml:"pullerPauseS" json:"pullerPauseS"`
MaxConflicts int `xml:"maxConflicts" json:"maxConflicts"`
DisableSparseFiles bool `xml:"disableSparseFiles" json:"disableSparseFiles"`
Expand Down
5 changes: 3 additions & 2 deletions lib/model/folder.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,16 @@ func (f *folder) DelayScan(next time.Duration) {
f.scan.Delay(next)
}

func (f *folder) IndexUpdated() {
}
func (f *folder) IndexUpdated() {}

func (f *folder) IgnoresUpdated() {
if f.FSWatcherEnabled {
f.scheduleWatchRestart()
}
}

func (f *folder) SchedulePull() {}

func (f *folder) Jobs() ([]string, []string) {
return nil, nil
}
Expand Down
14 changes: 8 additions & 6 deletions lib/model/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,9 @@ const (
type service interface {
BringToFront(string)
DelayScan(d time.Duration)
IndexUpdated() // Remote index was updated notification
IgnoresUpdated() // ignore matcher was updated notification
IndexUpdated() // Remote index was updated notification
IgnoresUpdated() // ignore matcher was updated notification
SchedulePull()
Jobs() ([]string, []string) // In progress, Queued
Scan(subs []string) error
Serve()
Expand Down Expand Up @@ -813,7 +814,7 @@ func (m *Model) Index(deviceID protocol.DeviceID, folder string, fs []protocol.F
if runner != nil {
// Runner may legitimately not be set if this is the "cleanup" Index
// message at startup.
defer runner.IndexUpdated()
defer runner.SchedulePull()
}

m.pmut.RLock()
Expand Down Expand Up @@ -862,7 +863,7 @@ func (m *Model) IndexUpdate(deviceID protocol.DeviceID, folder string, fs []prot
"version": files.Sequence(deviceID),
})

runner.IndexUpdated()
runner.SchedulePull()
}

func (m *Model) folderSharedWith(folder string, deviceID protocol.DeviceID) bool {
Expand Down Expand Up @@ -1002,7 +1003,7 @@ func (m *Model) ClusterConfig(deviceID protocol.DeviceID, cm protocol.ClusterCon
// that we need to pull so let the folder runner know
// that it should recheck the index data.
if runner := m.folderRunners[folder.ID]; runner != nil {
defer runner.IndexUpdated()
defer runner.SchedulePull()
}
}
}
Expand Down Expand Up @@ -1853,7 +1854,6 @@ func (m *Model) internalScanFolderSubdirs(ctx context.Context, folder string, su
// Check if the ignore patterns changed as part of scanning this folder.
// If they did we should schedule a pull of the folder so that we
// request things we might have suddenly become unignored and so on.

oldHash := ignores.Hash()
defer func() {
if ignores.Hash() != oldHash {
Expand All @@ -1879,6 +1879,8 @@ func (m *Model) internalScanFolderSubdirs(ctx context.Context, folder string, su
return err
}

defer runner.SchedulePull()

// Clean the list of subitems to ensure that we start at a known
// directory, and don't scan subdirectories of things we've already
// scanned.
Expand Down
2 changes: 0 additions & 2 deletions lib/model/requests_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,6 @@ func TestRequestVersioningSymlinkAttack(t *testing.T) {

cfg := defaultConfig.RawCopy()
cfg.Folders[0] = config.NewFolderConfiguration("default", fs.FilesystemTypeBasic, "_tmpfolder")
cfg.Folders[0].PullerSleepS = 1
cfg.Folders[0].Devices = []config.FolderDeviceConfiguration{
{DeviceID: device1},
{DeviceID: device2},
Expand Down Expand Up @@ -289,7 +288,6 @@ func TestRequestVersioningSymlinkAttack(t *testing.T) {
func setupModelWithConnection() (*Model, *fakeConnection) {
cfg := defaultConfig.RawCopy()
cfg.Folders[0] = config.NewFolderConfiguration("default", fs.FilesystemTypeBasic, "_tmpfolder")
cfg.Folders[0].PullerSleepS = 1
cfg.Folders[0].Devices = []config.FolderDeviceConfiguration{
{DeviceID: device1},
{DeviceID: device2},
Expand Down

0 comments on commit f6ea2a7

Please sign in to comment.