pmb.helpers.other.folder_size: use kilobytes (MR 2074)
busybox du doesn't support bytes or custom block sizes.
This commit is contained in:
parent
5c1da79634
commit
31e7a0006d
|
@ -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")
|
||||
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue