From 31e7a0006db2dcd3e32154e6ea9c4e4ccd8ebe64 Mon Sep 17 00:00:00 2001 From: Maxim Karasev Date: Thu, 24 Jun 2021 02:50:47 +0300 Subject: [PATCH] pmb.helpers.other.folder_size: use kilobytes (MR 2074) busybox du doesn't support bytes or custom block sizes. --- pmb/chroot/zap.py | 2 +- pmb/helpers/other.py | 5 ++--- pmb/install/_install.py | 2 +- test/test_folder_size.py | 4 ++-- 4 files changed, 6 insertions(+), 7 deletions(-) diff --git a/pmb/chroot/zap.py b/pmb/chroot/zap.py index c9a552cd..a86b3413 100644 --- a/pmb/chroot/zap.py +++ b/pmb/chroot/zap.py @@ -88,7 +88,7 @@ def zap(args, confirm=True, dry=False, pkgs_local=False, http=False, logging.info("Dry run: nothing has been deleted") else: size_new = pmb.helpers.other.folder_size(args, args.work) - mb = (size_old - size_new) / 1024 / 1024 + mb = (size_old - size_new) / 1024 logging.info(f"Cleared up ~{math.ceil(mb)} MB of space") diff --git a/pmb/helpers/other.py b/pmb/helpers/other.py index eec5f6e6..7991e821 100644 --- a/pmb/helpers/other.py +++ b/pmb/helpers/other.py @@ -17,10 +17,9 @@ def folder_size(args, path): faster than doing the same task in pure Python). This result is only approximatelly right, but good enough for pmbootstrap's use case (#760). - :returns: folder size in bytes + :returns: folder size in kilobytes """ - output = pmb.helpers.run.root(args, ["du", "--summarize", - "--block-size=1", + output = pmb.helpers.run.root(args, ["du", "-ks", path], output_return=True) # Only look at last line to filter out sudo garbage (#1766) diff --git a/pmb/install/_install.py b/pmb/install/_install.py index be8f5705..eea875ab 100644 --- a/pmb/install/_install.py +++ b/pmb/install/_install.py @@ -49,7 +49,7 @@ def get_subpartitions_size(args, suffix): # calculation is not as trivial as one may think, and depending on the # file system etc it seems to be just impossible to get it right. chroot = f"{args.work}/chroot_{suffix}" - root = pmb.helpers.other.folder_size(args, chroot) / 1024 / 1024 + root = pmb.helpers.other.folder_size(args, chroot) / 1024 root *= 1.20 root += 50 + int(args.extra_space) return (boot, root) diff --git a/test/test_folder_size.py b/test/test_folder_size.py index 029e81a9..65e06c44 100644 --- a/test/test_folder_size.py +++ b/test/test_folder_size.py @@ -31,7 +31,7 @@ def test_get_folder_size(args, tmpdir): # Check if the size is correct. Unfortunately, the `du` call # in pmb.helpers.other.folder_size is not very accurate, so we # allow 30kb of tolerance (good enough for our use case): #760 #1717 - tolerance = 30 * 1024 - size = 204800 * files + tolerance = 30 + size = 200 * files result = pmb.helpers.other.folder_size(args, tmpdir) assert (result < size + tolerance and result > size - tolerance)