From 25dbe9142f9c808089e7f5e1a52b40a8ec0e3ca5 Mon Sep 17 00:00:00 2001 From: Lubos Kolouch Date: Thu, 7 Nov 2024 15:51:57 +0100 Subject: [PATCH] feat(src/os.ml,-src/strings.ml): Introduce tempkeepdays parameter to config after how many days should be temporary .unison*.tmp files deleted --- src/os.ml | 11 +++++++++-- src/strings.ml | 1 + 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/os.ml b/src/os.ml index e366fc41e..fd26ae976 100644 --- a/src/os.ml +++ b/src/os.ml @@ -120,6 +120,13 @@ let allChildrenOf fspath path = | None -> []) + +let tempkeepdays: int Prefs.t = + Prefs.createInt "tempkeepdays" 30 + ~category:(`Advanced `General) + "set the number of days to keep temporary files" + "Specifies the number of days temporary files are kept before being deleted." + (* Assumes that (fspath, path) is a directory, and returns the list of *) (* children, except for temporary files and AppleDouble files. *) let rec childrenOf fspath path = @@ -138,8 +145,8 @@ let rec childrenOf fspath path = if Util.endswith file !tempFileSuffix then begin let p = Path.child path filename in let i = Fileinfo.getBasic false fspath p in - let secondsinthirtydays = 2592000.0 in - if Props.time i.Fileinfo.desc +. secondsinthirtydays < Util.time() + let secondsInRetentionPeriod = float_of_int (Prefs.read tempkeepdays) *. 86400.0 in + if Props.time i.Fileinfo.desc +. secondsInRetentionPeriod < Util.time() then begin debug (fun()-> Util.msg "deleting old temp file %s\n" (Fspath.toDebugString (Fspath.concat fspath p))); diff --git a/src/strings.ml b/src/strings.ml index d737edb3a..a3c27235b 100644 --- a/src/strings.ml +++ b/src/strings.ml @@ -1213,6 +1213,7 @@ let docs = \032 -rootalias xxx register alias for canonical root names\n\ \032 -showarchive show 'true names' (for rootalias) of roots and archive\n\ \032 -source xxx include a file's preferences\n\ + \032 -tempkeepdays n after how many days should be temporary files deleted \032 -ui xxx select UI ('text' or 'graphic'); command-line only\n\ \032 -unicode xxx assume Unicode encoding in case insensitive mode\n\ \032 -watch when set, use a file watcher process to detect changes\n\