mirror of
https://github.com/octoleo/syncthing.git
synced 2024-11-09 23:00:58 +00:00
Add file I forgot in previous
This commit is contained in:
parent
f3057c61a7
commit
756a8a35e3
62
internal/model/scanner.go
Normal file
62
internal/model/scanner.go
Normal file
@ -0,0 +1,62 @@
|
||||
// Copyright (C) 2014 Jakob Borg and Contributors (see the CONTRIBUTORS file).
|
||||
// All rights reserved. Use of this source code is governed by an MIT-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package model
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"time"
|
||||
)
|
||||
|
||||
type Scanner struct {
|
||||
folder string
|
||||
intv time.Duration
|
||||
model *Model
|
||||
stop chan struct{}
|
||||
}
|
||||
|
||||
func (s *Scanner) Serve() {
|
||||
if debug {
|
||||
l.Debugln(s, "starting")
|
||||
defer l.Debugln(s, "exiting")
|
||||
}
|
||||
|
||||
timer := time.NewTimer(time.Millisecond)
|
||||
defer timer.Stop()
|
||||
|
||||
initialScanCompleted := false
|
||||
for {
|
||||
select {
|
||||
case <-s.stop:
|
||||
return
|
||||
|
||||
case <-timer.C:
|
||||
if debug {
|
||||
l.Debugln(s, "rescan")
|
||||
}
|
||||
|
||||
s.model.setState(s.folder, FolderScanning)
|
||||
if err := s.model.ScanFolder(s.folder); err != nil {
|
||||
invalidateFolder(s.model.cfg, s.folder, err)
|
||||
return
|
||||
}
|
||||
s.model.setState(s.folder, FolderIdle)
|
||||
|
||||
if !initialScanCompleted {
|
||||
l.Infoln("Completed initial scan (ro) of folder", s.folder)
|
||||
initialScanCompleted = true
|
||||
}
|
||||
|
||||
timer.Reset(s.intv)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (s *Scanner) Stop() {
|
||||
close(s.stop)
|
||||
}
|
||||
|
||||
func (s *Scanner) String() string {
|
||||
return fmt.Sprintf("scanner/%s@%p", s.folder, s)
|
||||
}
|
Loading…
Reference in New Issue
Block a user