Skip to content

Commit

Permalink
qfile-agent: fix CLI progress display unit mismatch
Browse files Browse the repository at this point in the history
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
  • Loading branch information
rustybird committed Jun 27, 2024
1 parent 2b7b10a commit ca6e96d
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
7 changes: 4 additions & 3 deletions qubes-rpc/qfile-agent.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
6 changes: 3 additions & 3 deletions qubes-rpc/qvm-copy
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

set -e -o pipefail

unset PROGRESS_TYPE OPERATION_TYPE TARGET_TYPE MIN_ARGS FILECOPY_TOTAL_SIZE service scriptdir
unset PROGRESS_TYPE OPERATION_TYPE TARGET_TYPE MIN_ARGS FILECOPY_TOTAL_BYTES service scriptdir

# Determine the operation to be performed
case ${0##*/} in
Expand Down Expand Up @@ -82,15 +82,15 @@ else
VM="@default"
fi

if FILECOPY_TOTAL_SIZE=$("$scriptdir/qubes/qubes-fs-tree-check" \
if FILECOPY_TOTAL_BYTES=$("$scriptdir/qubes/qubes-fs-tree-check" \
--allow-symlinks --allow-directories --machine -- "$@"); then
service=qubes.Filecopy
else
status=$?
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

"$scriptdir/qubes/qrexec-client-vm" --filter-escape-chars-stderr -- "$VM" \
"$service" "$scriptdir/qubes/qfile-agent" "$@"
Expand Down

0 comments on commit ca6e96d

Please sign in to comment.