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.
This commit is contained in:
Oliver Smith 2019-04-21 21:06:10 +02:00
parent fe731d7f5c
commit 8b8a73e8dd
No known key found for this signature in database
GPG Key ID: 5AE7F5513E0885CB
1 changed files with 5 additions and 1 deletions

View File

@ -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