This commit is contained in:
+11
-9
@@ -49,7 +49,8 @@ type folder struct {
|
|||||||
fset *db.FileSet
|
fset *db.FileSet
|
||||||
ignores *ignore.Matcher
|
ignores *ignore.Matcher
|
||||||
modTimeWindow time.Duration
|
modTimeWindow time.Duration
|
||||||
ctx context.Context
|
ctx context.Context // used internally, only accessible on serve lifetime
|
||||||
|
done chan struct{} // used externally, accessible regardless of serve
|
||||||
|
|
||||||
scanInterval time.Duration
|
scanInterval time.Duration
|
||||||
scanTimer *time.Timer
|
scanTimer *time.Timer
|
||||||
@@ -103,6 +104,7 @@ func newFolder(model *model, fset *db.FileSet, ignores *ignore.Matcher, cfg conf
|
|||||||
fset: fset,
|
fset: fset,
|
||||||
ignores: ignores,
|
ignores: ignores,
|
||||||
modTimeWindow: cfg.ModTimeWindow(),
|
modTimeWindow: cfg.ModTimeWindow(),
|
||||||
|
done: make(chan struct{}),
|
||||||
|
|
||||||
scanInterval: time.Duration(cfg.RescanIntervalS) * time.Second,
|
scanInterval: time.Duration(cfg.RescanIntervalS) * time.Second,
|
||||||
scanTimer: time.NewTimer(0), // The first scan should be done immediately.
|
scanTimer: time.NewTimer(0), // The first scan should be done immediately.
|
||||||
@@ -165,6 +167,7 @@ func (f *folder) serve(ctx context.Context) {
|
|||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
case <-f.ctx.Done():
|
case <-f.ctx.Done():
|
||||||
|
close(f.done)
|
||||||
return
|
return
|
||||||
|
|
||||||
case <-f.pullScheduled:
|
case <-f.pullScheduled:
|
||||||
@@ -218,7 +221,10 @@ func (f *folder) Override() {}
|
|||||||
func (f *folder) Revert() {}
|
func (f *folder) Revert() {}
|
||||||
|
|
||||||
func (f *folder) DelayScan(next time.Duration) {
|
func (f *folder) DelayScan(next time.Duration) {
|
||||||
f.Delay(next)
|
select {
|
||||||
|
case f.scanDelay <- next:
|
||||||
|
case <-f.done:
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *folder) ignoresUpdated() {
|
func (f *folder) ignoresUpdated() {
|
||||||
@@ -258,8 +264,8 @@ func (f *folder) doInSync(fn func() error) error {
|
|||||||
select {
|
select {
|
||||||
case f.doInSyncChan <- req:
|
case f.doInSyncChan <- req:
|
||||||
return <-req.err
|
return <-req.err
|
||||||
case <-f.ctx.Done():
|
case <-f.done:
|
||||||
return f.ctx.Err()
|
return context.Canceled
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -274,10 +280,6 @@ func (f *folder) Reschedule() {
|
|||||||
f.scanTimer.Reset(interval)
|
f.scanTimer.Reset(interval)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *folder) Delay(next time.Duration) {
|
|
||||||
f.scanDelay <- next
|
|
||||||
}
|
|
||||||
|
|
||||||
func (f *folder) getHealthErrorAndLoadIgnores() error {
|
func (f *folder) getHealthErrorAndLoadIgnores() error {
|
||||||
if err := f.getHealthErrorWithoutIgnores(); err != nil {
|
if err := f.getHealthErrorWithoutIgnores(); err != nil {
|
||||||
return err
|
return err
|
||||||
@@ -925,7 +927,7 @@ func (f *folder) scanOnWatchErr() {
|
|||||||
err := f.watchErr
|
err := f.watchErr
|
||||||
f.watchMut.Unlock()
|
f.watchMut.Unlock()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
f.Delay(0)
|
f.DelayScan(0)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user