From 041a825edd1a4f8ec5e868a77afd0b004af7ebc4 Mon Sep 17 00:00:00 2001 From: Yuri Chiucconi Date: Mon, 26 Aug 2024 14:45:43 +0200 Subject: [PATCH] less lines for folder_files and size --- fractal_server/zip_tools.py | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/fractal_server/zip_tools.py b/fractal_server/zip_tools.py index 33c1d3e130..47d2e5a748 100644 --- a/fractal_server/zip_tools.py +++ b/fractal_server/zip_tools.py @@ -52,18 +52,14 @@ def iterfile(): def _zipping_worked(*, folder: str) -> bool: zip_file = f"{folder}_tmp.zip" + folder = Path(folder) # CHECK 1: zip file exists if not os.path.exists(zip_file): return False - folder_size = 0 - folder_files = set() - for dirpath, dirnames, filenames in os.walk(folder): - for f in filenames: - fp = os.path.join(dirpath, f) - folder_files.add(os.path.relpath(fp, folder)) - folder_size += os.path.getsize(fp) + folder_files = [f for f in folder.glob("**/*") if f.is_file()] + folder_size = sum(f.stat().st_size for f in folder_files) with ZipFile(zip_file, "r") as zip_ref: zip_files = set(