lib: Add util.Service as suture.Service template (fixes #5801) (#5806)

This commit is contained in:
Simon Frei
2019-07-09 11:40:30 +02:00
committed by GitHub
parent d0ab65a178
commit ba056578ec
21 changed files with 340 additions and 420 deletions

View File

@@ -11,7 +11,10 @@ import (
"strconv"
"time"
"github.com/thejerf/suture"
"github.com/syncthing/syncthing/lib/fs"
"github.com/syncthing/syncthing/lib/util"
)
func init() {
@@ -20,10 +23,10 @@ func init() {
}
type Trashcan struct {
suture.Service
folderFs fs.Filesystem
versionsFs fs.Filesystem
cleanoutDays int
stop chan struct{}
}
func NewTrashcan(folderID string, folderFs fs.Filesystem, params map[string]string) Versioner {
@@ -34,8 +37,8 @@ func NewTrashcan(folderID string, folderFs fs.Filesystem, params map[string]stri
folderFs: folderFs,
versionsFs: fsFromParams(folderFs, params),
cleanoutDays: cleanoutDays,
stop: make(chan struct{}),
}
s.Service = util.AsService(s.serve)
l.Debugf("instantiated %#v", s)
return s
@@ -49,7 +52,7 @@ func (t *Trashcan) Archive(filePath string) error {
})
}
func (t *Trashcan) Serve() {
func (t *Trashcan) serve(stop chan struct{}) {
l.Debugln(t, "starting")
defer l.Debugln(t, "stopping")
@@ -59,7 +62,7 @@ func (t *Trashcan) Serve() {
for {
select {
case <-t.stop:
case <-stop:
return
case <-timer.C:
@@ -75,10 +78,6 @@ func (t *Trashcan) Serve() {
}
}
func (t *Trashcan) Stop() {
close(t.stop)
}
func (t *Trashcan) String() string {
return fmt.Sprintf("trashcan@%p", t)
}