parent
30056cd1ae
commit
b7234785f8
|
@ -37,6 +37,7 @@ type folder struct {
|
||||||
scanNow chan rescanRequest
|
scanNow chan rescanRequest
|
||||||
scanDelay chan time.Duration
|
scanDelay chan time.Duration
|
||||||
initialScanFinished chan struct{}
|
initialScanFinished chan struct{}
|
||||||
|
stopped chan struct{}
|
||||||
|
|
||||||
pullScheduled chan struct{}
|
pullScheduled chan struct{}
|
||||||
|
|
||||||
|
@ -81,6 +82,7 @@ func newFolder(model *Model, cfg config.FolderConfiguration) folder {
|
||||||
watchCancel: func() {},
|
watchCancel: func() {},
|
||||||
watchErr: errWatchNotStarted,
|
watchErr: errWatchNotStarted,
|
||||||
watchErrMut: sync.NewMutex(),
|
watchErrMut: sync.NewMutex(),
|
||||||
|
stopped: make(chan struct{}),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -91,6 +93,7 @@ func (f *folder) Serve() {
|
||||||
defer func() {
|
defer func() {
|
||||||
f.scanTimer.Stop()
|
f.scanTimer.Stop()
|
||||||
f.setState(FolderIdle)
|
f.setState(FolderIdle)
|
||||||
|
close(f.stopped)
|
||||||
}()
|
}()
|
||||||
|
|
||||||
pause := f.basePause()
|
pause := f.basePause()
|
||||||
|
@ -223,6 +226,7 @@ func (f *folder) Delay(next time.Duration) {
|
||||||
|
|
||||||
func (f *folder) Stop() {
|
func (f *folder) Stop() {
|
||||||
f.cancel()
|
f.cancel()
|
||||||
|
<-f.stopped
|
||||||
}
|
}
|
||||||
|
|
||||||
// CheckHealth checks the folder for common errors, updates the folder state
|
// CheckHealth checks the folder for common errors, updates the folder state
|
||||||
|
|
|
@ -344,10 +344,14 @@ func (m *Model) RemoveFolder(cfg config.FolderConfiguration) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *Model) tearDownFolderLocked(cfg config.FolderConfiguration) {
|
func (m *Model) tearDownFolderLocked(cfg config.FolderConfiguration) {
|
||||||
// Stop the services running for this folder
|
// Stop the services running for this folder and wait for them to finish
|
||||||
for _, id := range m.folderRunnerTokens[cfg.ID] {
|
// stopping to prevent races on restart.
|
||||||
m.Remove(id)
|
tokens := m.folderRunnerTokens[cfg.ID]
|
||||||
|
m.fmut.Unlock()
|
||||||
|
for _, id := range tokens {
|
||||||
|
m.RemoveAndWait(id, 0)
|
||||||
}
|
}
|
||||||
|
m.fmut.Lock()
|
||||||
|
|
||||||
// Close connections to affected devices
|
// Close connections to affected devices
|
||||||
for _, dev := range cfg.Devices {
|
for _, dev := range cfg.Devices {
|
||||||
|
|
Loading…
Reference in New Issue