From 9e4265b62071b26bb77d4c2f72455f4e6b7eb0c9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20Wilczy=C5=84ski?= Date: Fri, 21 Jul 2023 13:08:06 +0200 Subject: [PATCH] gui, lib/model: Disable periodic cleanup when versions are kept forever (fixes #8350) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Currently, the cleanup is set to run on a periodic timer regardless of the days to keep versions. Because of this, even if versions are set to be kept forever, the cleanup still runs on the timer. Furthermore, the cleanup also runs even when using external versioning in spite of it doing nothing for that versioning type. This changes the behaviour as follows. 1. Cleanup is disabled when using external versioning. 2. Cleanup only runs when the days to keep versions are set to a value higher than "0". 3. When using Trash Can, Simple or Staggered versioning with the value above set to "0", the cleanup being "Disabled" is displayed in the folder information in the GUI even if the cleanup value is at its default. 4. In addition to the above, the cleanup input field is automatically disabled with a warning message informing the user about it being disabled when the number of days is set to "0". Signed-off-by: Tomasz WilczyƄski --- gui/default/index.html | 4 ++-- .../syncthing/folder/editFolderModalView.html | 6 +++++- lib/model/folder.go | 12 +++++++++++- 3 files changed, 18 insertions(+), 4 deletions(-) diff --git a/gui/default/index.html b/gui/default/index.html index 57cd558a794..f5a41caa1f0 100644 --- a/gui/default/index.html +++ b/gui/default/index.html @@ -542,8 +542,8 @@

 Forever{{folder.versioning.params.maxAge | duration}} - -   Disabled{{folder.versioning.cleanupIntervalS | duration}} + +   Disabled{{folder.versioning.cleanupIntervalS | duration}} diff --git a/gui/default/syncthing/folder/editFolderModalView.html b/gui/default/syncthing/folder/editFolderModalView.html index 4a616626952..75328e9a3c9 100644 --- a/gui/default/syncthing/folder/editFolderModalView.html +++ b/gui/default/syncthing/folder/editFolderModalView.html @@ -146,13 +146,17 @@
- +
seconds

The interval, in seconds, for running cleanup in the versions directory. Zero to disable periodic cleaning. The cleanup interval cannot be blank. The interval must be a positive number of seconds. + + + Cleanup is disabled when versions are kept forever. +

diff --git a/lib/model/folder.go b/lib/model/folder.go index d71fbd508e3..25c26bdc08d 100644 --- a/lib/model/folder.go +++ b/lib/model/folder.go @@ -13,6 +13,7 @@ import ( "math/rand" "path/filepath" "sort" + "strconv" "time" "github.com/syncthing/syncthing/lib/config" @@ -57,8 +58,11 @@ type folder struct { scanDelay chan time.Duration initialScanFinished chan struct{} scanScheduled chan struct{} + versionType string versionCleanupInterval time.Duration versionCleanupTimer *time.Timer + versionCleanoutDays int + versionMaxAge int pullScheduled chan struct{} pullPause time.Duration @@ -96,6 +100,9 @@ type puller interface { } func newFolder(model *model, fset *db.FileSet, ignores *ignore.Matcher, cfg config.FolderConfiguration, evLogger events.Logger, ioLimiter *util.Semaphore, ver versioner.Versioner) folder { + cleanoutDays, _ := strconv.Atoi(cfg.Versioning.Params["cleanoutDays"]) + maxAge, _ := strconv.Atoi(cfg.Versioning.Params["maxAge"]) + f := folder{ stateTracker: newStateTracker(cfg.ID, evLogger), FolderConfiguration: cfg, @@ -115,8 +122,11 @@ func newFolder(model *model, fset *db.FileSet, ignores *ignore.Matcher, cfg conf scanDelay: make(chan time.Duration), initialScanFinished: make(chan struct{}), scanScheduled: make(chan struct{}, 1), + versionType: cfg.Versioning.Type, versionCleanupInterval: time.Duration(cfg.Versioning.CleanupIntervalS) * time.Second, versionCleanupTimer: time.NewTimer(time.Duration(cfg.Versioning.CleanupIntervalS) * time.Second), + versionCleanoutDays: cleanoutDays, + versionMaxAge: maxAge, pullScheduled: make(chan struct{}, 1), // This needs to be 1-buffered so that we queue a pull if we're busy when it comes. @@ -161,7 +171,7 @@ func (f *folder) Serve(ctx context.Context) error { // If we're configured to not do version cleanup, or we don't have a // versioner, cancel and drain that timer now. - if f.versionCleanupInterval == 0 || f.versioner == nil { + if f.versionCleanupInterval == 0 || ((f.versionType == "trashcan" || f.versionType == "simple") && f.versionCleanoutDays == 0) || (f.versionType == "staggered" && f.versionMaxAge == 0) || f.versionType == "external" || f.versioner == nil { if !f.versionCleanupTimer.Stop() { <-f.versionCleanupTimer.C }