Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 11 additions & 10 deletions qubes-rpc/qfile-agent.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,19 @@ enum {
PROGRESS_FLAG_DONE
};

void do_notify_progress(long long total, int flag)
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",
(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 All @@ -40,7 +41,7 @@ void do_notify_progress(long long total, int flag)
}
if (!strcmp(progress_type_env, "gui") && saved_stdout_env) {
char msg[256];
snprintf(msg, sizeof(msg), "%lld\n", total);
snprintf(msg, sizeof(msg), "%lld\n", cur_total);
if (write(strtoul(saved_stdout_env, NULL, 10), msg, strlen(msg)) == -1
&& errno == EPIPE)
exit(32);
Expand All @@ -49,18 +50,18 @@ void do_notify_progress(long long total, int flag)

void notify_progress(int size, int flag)
{
static long long total = 0;
static long long cur_total = 0;
static long long prev_total = 0;
total += size;
if (total > prev_total + PROGRESS_NOTIFY_DELTA
cur_total += size;
if (cur_total > prev_total + PROGRESS_NOTIFY_DELTA
|| (flag != PROGRESS_FLAG_NORMAL)) {
// check for possible error from qfile-unpacker; if error occured,
// exit() will be called, so don't bother with current state
// (notify_progress can be called as callback from copy_file())
if (flag == PROGRESS_FLAG_NORMAL)
wait_for_result();
do_notify_progress(total, flag);
prev_total = total;
do_notify_progress(cur_total, flag);
prev_total = cur_total;
}
}

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