Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/pr/524'
Browse files Browse the repository at this point in the history
* origin/pr/524:
  qvm-copy-to-vm.gnome: port +allow-all-names logic from qvm-copy
  qvm-copy-to-vm.gnome: lowercase $size and $description
  • Loading branch information
marmarek committed Oct 19, 2024
2 parents 0972c1f + 254312c commit 76833a7
Showing 1 changed file with 18 additions and 24 deletions.
42 changes: 18 additions & 24 deletions qubes-rpc/qvm-copy-to-vm.gnome
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,9 @@ set_qdbus() {
}

copy() {
PROGRESS_TYPE=gui /usr/lib/qubes/qrexec-client-vm @default \
qubes.Filecopy /usr/lib/qubes/qfile-agent "$@"
PROGRESS_TYPE=gui /usr/lib/qubes/qrexec-client-vm \
--filter-escape-chars-stderr -- @default \
"$service" /usr/lib/qubes/qfile-agent "$@"
}

progress_kdialog() {
Expand All @@ -43,11 +44,11 @@ progress_kdialog() {
(while read -r pos; do
if [[ $pos == 0 ]]; then
# shellcheck disable=SC2207
ref=( $(kdialog --progressbar "$DESCRIPTION") )
ref=( $(kdialog --progressbar "$description") )
trap '"$qdbus" "${ref[@]}" close' EXIT # for this subshell
fi

"$qdbus" "${ref[@]}" value $((100 * pos / SIZE))
"$qdbus" "${ref[@]}" value $((100 * pos / size))
done) >/dev/null # hide qdbus's empty output lines
}

Expand All @@ -57,38 +58,31 @@ progress_zenity() {
(while read -r pos; do
if [[ $pos == 0 ]]; then
trap 'kill -- $!' EXIT # for this subshell
exec {fd}> >(exec zenity --progress --text="$DESCRIPTION")
exec {fd}> >(exec zenity --progress --text="$description")
fi

echo $((100 * pos / SIZE)) >&$fd
echo $((100 * pos / size)) >&$fd
done)
}


find_paths=( )
for path; do
case "$path" in
(-*) find_paths+=( ./"$path" ) ;;
(*) find_paths+=( "$path" ) ;;
esac
done

SIZE=$(
find "${find_paths[@]}" -type f -print0 2>/dev/null |
du --files0-from - -c --apparent-size -b |
tail -n 1 |
cut -f 1 |
grep -xE '[0-9]+'
) || SIZE=0
if size=$(/usr/lib/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 [[ ${0##*/} == qvm-move-to-vm.* ]]; then
DESCRIPTION="Moving files..."
description="Moving files..."
trap '[[ $? == 0 ]] && rm -rf -- "$@"' EXIT
else
DESCRIPTION="Copying files..."
description="Copying files..."
fi

if [[ $SIZE == 0 ]]; then
if [[ $size == 0 ]]; then
copy "$@" >/dev/null
elif [[ $0 == *.kde ]] && type kdialog >/dev/null && set_qdbus; then
copy "$@" | progress_kdialog
Expand Down

0 comments on commit 76833a7

Please sign in to comment.