From 8d755d41e0c899880d6a0dc69274b36616756192 Mon Sep 17 00:00:00 2001 From: ed Date: Mon, 9 Aug 2021 01:31:20 +0200 Subject: [PATCH] per-volume rescan interval --- copyparty/__main__.py | 3 ++- copyparty/authsrv.py | 5 +++++ copyparty/up2k.py | 17 +++++++++-------- tests/test_httpcli.py | 1 + tests/test_vfs.py | 1 + 5 files changed, 18 insertions(+), 9 deletions(-) diff --git a/copyparty/__main__.py b/copyparty/__main__.py index 6c772ed7..f1064433 100644 --- a/copyparty/__main__.py +++ b/copyparty/__main__.py @@ -271,6 +271,7 @@ def run_argparse(argv, formatter): \033[36md2d\033[35m disables all database stuff, overrides -e2* \033[36mdhash\033[35m disables file hashing on initial scans, also ehash \033[36mhist=/tmp/cdb\033[35m puts thumbnails and indexes at that location + \033[36mscan=60\033[35m scan for new files every 60sec, same as --re-maxage \033[0mdatabase, audio tags: "mte", "mth", "mtp", "mtm" all work the same as -mte, -mth, ... @@ -391,7 +392,7 @@ def run_argparse(argv, formatter): ap2.add_argument("--hist", metavar="PATH", type=u, help="where to store volume data (db, thumbs)") ap2.add_argument("--no-hash", action="store_true", help="disable hashing during e2ds folder scans") ap2.add_argument("--re-int", metavar="SEC", type=int, default=30, help="disk rescan check interval") - ap2.add_argument("--re-maxage", metavar="SEC", type=int, default=0, help="disk rescan volume interval (0=off)") + ap2.add_argument("--re-maxage", metavar="SEC", type=int, default=0, help="disk rescan volume interval, 0=off, can be set per-volume with the 'scan' cflag") ap2.add_argument("--srch-time", metavar="SEC", type=int, default=30, help="search deadline") ap2 = ap.add_argument_group('metadata db options') diff --git a/copyparty/authsrv.py b/copyparty/authsrv.py index 29447959..de5b3290 100644 --- a/copyparty/authsrv.py +++ b/copyparty/authsrv.py @@ -807,6 +807,11 @@ class AuthSrv(object): if "pk" in vol.flags and "gz" not in vol.flags and "xz" not in vol.flags: vol.flags["gz"] = False # def.pk + if "scan" in vol.flags: + vol.flags["scan"] = int(vol.flags["scan"]) + elif self.args.re_maxage: + vol.flags["scan"] = self.args.re_maxage + all_mte = {} errors = False for vol in vfs.all_vols.values(): diff --git a/copyparty/up2k.py b/copyparty/up2k.py index 45afcaa1..734d3129 100644 --- a/copyparty/up2k.py +++ b/copyparty/up2k.py @@ -176,20 +176,21 @@ class Up2k(object): return None def _sched_rescan(self): - maxage = self.args.re_maxage volage = {} while True: time.sleep(self.args.re_int) now = time.time() - vpaths = list(sorted(self.asrv.vfs.all_vols.keys())) with self.mutex: - if maxage: - for vp in vpaths: - if vp not in volage: - volage[vp] = now + for vp, vol in sorted(self.asrv.vfs.all_vols.items()): + maxage = vol.flags.get("scan") + if not maxage: + continue - if now - volage[vp] >= maxage: - self.need_rescan[vp] = 1 + if vp not in volage: + volage[vp] = now + + if now - volage[vp] >= maxage: + self.need_rescan[vp] = 1 if not self.need_rescan: continue diff --git a/tests/test_httpcli.py b/tests/test_httpcli.py index e468730a..e6cdd843 100644 --- a/tests/test_httpcli.py +++ b/tests/test_httpcli.py @@ -39,6 +39,7 @@ class Cfg(Namespace): no_scandir=False, no_sendfile=True, no_rescan=True, + re_maxage=0, ihead=False, nih=True, mtp=[], diff --git a/tests/test_vfs.py b/tests/test_vfs.py index 4eecb735..ce7d404a 100644 --- a/tests/test_vfs.py +++ b/tests/test_vfs.py @@ -26,6 +26,7 @@ class Cfg(Namespace): "no_hash": False, "css_browser": None, "no_voldump": True, + "re_maxage": 0, "rproxy": 0, } ex.update(ex2)