From 8b8a73e8dd6698044de8bc1a4cf0a1e2bf24b7f2 Mon Sep 17 00:00:00 2001 From: Oliver Smith Date: Sun, 21 Apr 2019 21:06:10 +0200 Subject: [PATCH] Fix crash from mixing 'sudo' with 'du' output (!1777) Do not crash during "pmbootstrap zap" and other actions when the user needs to type in the sudo password before running "du" to calculate the work folder size. We're trying to parse the "du" output as integer, but of course the 'Sorry, try again' message from sudo is not a valid integer. $ pmbootstrap --details-to-stdout zap (008707) [14:00:57] Shutdown complete (008707) [14:00:57] Calculate work folder size (008707) [14:00:57] % sudo du --summarize --block-size=1 /home/luca/.local/var/pmbootstrap [sudo] password for luca: [sudo] password for luca: Sorry, try again. 12966293504 /home/luca/.local/var/pmbootstrap (008707) [14:01:03] ERROR: invalid literal for int() with base 10: 'Sorry, try again.\n12966293504' It would be a good idea to separate the sudo output from the process output in general, see #1677 for a related proposal. --- pmb/helpers/other.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/pmb/helpers/other.py b/pmb/helpers/other.py index 31956f6b..c13a08eb 100644 --- a/pmb/helpers/other.py +++ b/pmb/helpers/other.py @@ -36,7 +36,11 @@ def folder_size(args, path): output = pmb.helpers.run.root(args, ["du", "--summarize", "--block-size=1", path], output_return=True) - ret = int(output.split("\t")[0]) + + # Only look at last line to filter out sudo garbage (#1766) + last_line = output.split("\n")[-2] + + ret = int(last_line.split("\t")[0]) return ret