Skip to content

Commit

Permalink
use scandir for volume smoketests during up2k init;
Browse files Browse the repository at this point in the history
gives much faster startup on filesystems that are extremely slow
(TLNote: android sdcardfs)
  • Loading branch information
9001 committed Jan 9, 2024
1 parent e8a653c commit f1358db
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
5 changes: 3 additions & 2 deletions copyparty/up2k.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
absreal,
atomic_move,
db_ex_chk,
dir_is_empty,
djoin,
fsenc,
gen_filekey,
Expand Down Expand Up @@ -604,7 +605,7 @@ def init_indexes(
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)
Expand Down Expand Up @@ -991,7 +992,7 @@ def _build_file_index(self, vol: VFS, all_vols: list[VFS]) -> tuple[bool, bool]:
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
Expand Down
6 changes: 6 additions & 0 deletions copyparty/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]]:
Expand Down

0 comments on commit f1358db

Please sign in to comment.