From f1358dbaba5efb43ccf3b9c0c1f3e26b4ead8698 Mon Sep 17 00:00:00 2001 From: ed Date: Tue, 9 Jan 2024 21:47:02 +0100 Subject: [PATCH] use scandir for volume smoketests during up2k init; gives much faster startup on filesystems that are extremely slow (TLNote: android sdcardfs) --- copyparty/up2k.py | 5 +++-- copyparty/util.py | 6 ++++++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/copyparty/up2k.py b/copyparty/up2k.py index eb1c1357..0a9c9723 100644 --- a/copyparty/up2k.py +++ b/copyparty/up2k.py @@ -37,6 +37,7 @@ from .util import ( absreal, atomic_move, db_ex_chk, + dir_is_empty, djoin, fsenc, gen_filekey, @@ -604,7 +605,7 @@ class Up2k(object): for vol in vols: try: bos.makedirs(vol.realpath) # gonna happen at snap anyways - bos.listdir(vol.realpath) + dir_is_empty(self.log_func, not self.args.no_scandir, vol.realpath) except: self.volstate[vol.vpath] = "OFFLINE (cannot access folder)" self.log("cannot access " + vol.realpath, c=1) @@ -991,7 +992,7 @@ class Up2k(object): rtop = absreal(top) n_add = n_rm = 0 try: - if not bos.listdir(rtop): + if dir_is_empty(self.log_func, not self.args.no_scandir, rtop): t = "volume /%s at [%s] is empty; will not be indexed as this could be due to an offline filesystem" self.log(t % (vol.vpath, rtop), 6) return True, False diff --git a/copyparty/util.py b/copyparty/util.py index 8a7e5beb..9de08a72 100644 --- a/copyparty/util.py +++ b/copyparty/util.py @@ -2363,6 +2363,12 @@ def statdir( print(t) +def dir_is_empty(logger: "RootLogger", scandir: bool, top: str): + for _ in statdir(logger, scandir, False, top): + return False + return True + + def rmdirs( logger: "RootLogger", scandir: bool, lstat: bool, top: str, depth: int ) -> tuple[list[str], list[str]]: