From d1810f2ff24cb2c36f1d441e694ed213ab9d1444 Mon Sep 17 00:00:00 2001 From: Rusty Bird Date: Thu, 27 Jun 2024 12:59:19 +0000 Subject: [PATCH] qfile-agent: fix CLI progress display unit mismatch qubes-fs-tree-check outputs the total estimated size in bytes, not KB. Fix the display bug by renaming the env variable that's used to pass this number (in the qvm-copy wrapper script) to $FILECOPY_TOTAL_BYTES, and then making qfile-agent convert from bytes to KB display units. $ truncate -s 10K foo $ qvm-copy foo # before: sent 10/10240 KB $ qvm-copy foo # after: sent 10/10 KB (cherry picked from commit ca6e96d31b8b8c7b62266c9724d4b5a21920b4b8) --- qubes-rpc/qfile-agent.c | 7 ++++--- qubes-rpc/qvm-copy | 6 +++--- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/qubes-rpc/qfile-agent.c b/qubes-rpc/qfile-agent.c index e759ecfc..c4d789e5 100644 --- a/qubes-rpc/qfile-agent.c +++ b/qubes-rpc/qfile-agent.c @@ -21,16 +21,17 @@ enum { void do_notify_progress(long long cur_total, int flag) { - const char *du_size_env = getenv("FILECOPY_TOTAL_SIZE"); + const char *total_bytes_env = getenv("FILECOPY_TOTAL_BYTES"); const char *progress_type_env = getenv("PROGRESS_TYPE"); const char *saved_stdout_env = getenv("SAVED_FD_1"); int ignore; if (!progress_type_env) return; - if (!strcmp(progress_type_env, "console") && du_size_env) { + if (!strcmp(progress_type_env, "console") && total_bytes_env) { char msg[256]; snprintf(msg, sizeof(msg), "sent %lld/%lld KB\r", - (cur_total + 1023) / 1024, strtoull(du_size_env, NULL, 10)); + (cur_total + 1023) / 1024, + (strtoull(total_bytes_env, NULL, 10) + 1023) / 1024); ignore = write(2, msg, strlen(msg)); if (flag == PROGRESS_FLAG_DONE) ignore = write(2, "\n", 1); diff --git a/qubes-rpc/qvm-copy b/qubes-rpc/qvm-copy index 0bc5d2f3..3726a341 100755 --- a/qubes-rpc/qvm-copy +++ b/qubes-rpc/qvm-copy @@ -21,7 +21,7 @@ set -e -o pipefail -unset PROGRESS_TYPE OPERATION_TYPE TARGET_TYPE MIN_ARGS FILECOPY_TOTAL_SIZE service +unset PROGRESS_TYPE OPERATION_TYPE TARGET_TYPE MIN_ARGS FILECOPY_TOTAL_BYTES service case ${0##*/} in (qvm-move) OPERATION_TYPE=move TARGET_TYPE=default MIN_ARGS=1;; @@ -74,7 +74,7 @@ else VM="@default" fi -if FILECOPY_TOTAL_SIZE=$(/usr/lib/qubes/qubes-fs-tree-check \ +if FILECOPY_TOTAL_BYTES=$(/usr/lib/qubes/qubes-fs-tree-check \ --allow-symlinks --allow-directories --machine -- "$@"); then service=qubes.Filecopy else @@ -82,7 +82,7 @@ else if [[ "$status" -ne 2 ]]; then exit "$status"; fi service=qubes.Filecopy+allow-all-names fi -if [[ "$PROGRESS_TYPE" = 'console' ]]; then export FILECOPY_TOTAL_SIZE; fi +if [[ "$PROGRESS_TYPE" = 'console' ]]; then export FILECOPY_TOTAL_BYTES; fi /usr/lib/qubes/qrexec-client-vm --filter-escape-chars-stderr -- "$VM" \ "$service" /usr/lib/qubes/qfile-agent "$@"