This change adds a separate config for the cleanup interval, and runs that cleanup from the main folder loop.
This commit is contained in:
+11
-32
@@ -12,11 +12,8 @@ import (
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
"github.com/thejerf/suture"
|
||||
|
||||
"github.com/syncthing/syncthing/lib/config"
|
||||
"github.com/syncthing/syncthing/lib/fs"
|
||||
"github.com/syncthing/syncthing/lib/util"
|
||||
)
|
||||
|
||||
func init() {
|
||||
@@ -25,7 +22,6 @@ func init() {
|
||||
}
|
||||
|
||||
type trashcan struct {
|
||||
suture.Service
|
||||
folderFs fs.Filesystem
|
||||
versionsFs fs.Filesystem
|
||||
cleanoutDays int
|
||||
@@ -42,7 +38,6 @@ func newTrashcan(cfg config.FolderConfiguration) Versioner {
|
||||
cleanoutDays: cleanoutDays,
|
||||
copyRangeMethod: cfg.CopyRangeMethod,
|
||||
}
|
||||
s.Service = util.AsService(s.serve, s.String())
|
||||
|
||||
l.Debugf("instantiated %#v", s)
|
||||
return s
|
||||
@@ -56,37 +51,16 @@ func (t *trashcan) Archive(filePath string) error {
|
||||
})
|
||||
}
|
||||
|
||||
func (t *trashcan) serve(ctx context.Context) {
|
||||
l.Debugln(t, "starting")
|
||||
defer l.Debugln(t, "stopping")
|
||||
|
||||
// Do the first cleanup one minute after startup.
|
||||
timer := time.NewTimer(time.Minute)
|
||||
defer timer.Stop()
|
||||
|
||||
for {
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
return
|
||||
|
||||
case <-timer.C:
|
||||
if t.cleanoutDays > 0 {
|
||||
if err := t.cleanoutArchive(); err != nil {
|
||||
l.Infoln("Cleaning trashcan:", err)
|
||||
}
|
||||
}
|
||||
|
||||
// Cleanups once a day should be enough.
|
||||
timer.Reset(24 * time.Hour)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (t *trashcan) String() string {
|
||||
return fmt.Sprintf("trashcan@%p", t)
|
||||
}
|
||||
|
||||
func (t *trashcan) cleanoutArchive() error {
|
||||
func (t *trashcan) Clean(ctx context.Context) error {
|
||||
if t.cleanoutDays <= 0 {
|
||||
// no cleanout requested
|
||||
return nil
|
||||
}
|
||||
|
||||
if _, err := t.versionsFs.Lstat("."); fs.IsNotExist(err) {
|
||||
return nil
|
||||
}
|
||||
@@ -98,6 +72,11 @@ func (t *trashcan) cleanoutArchive() error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
return ctx.Err()
|
||||
default:
|
||||
}
|
||||
|
||||
if info.IsDir() && !info.IsSymlink() {
|
||||
dirTracker.addDir(path)
|
||||
|
||||
Reference in New Issue
Block a user