Skip to content

Commit

Permalink
qvm-copy: support --ignore-symlinks and honor "--"
Browse files Browse the repository at this point in the history
"--" was stripped from the arguments before being passed to qfile-agent,
so "qvm-copy -- --ignore-symlinks" would ignore symlinks instead of
copying a file named "--ignore-symlinks".  To fix this problem, always
pass "--" to qfile-agent, preceeded by --ignore-symlinks if necessary.
This requires qfile-agent to honor -- as indicating end of options, so
patch it to do that.
  • Loading branch information
DemiMarie committed Nov 4, 2024
1 parent 607c341 commit 1a34521
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
14 changes: 11 additions & 3 deletions qubes-rpc/qfile-agent.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include <stdlib.h>
#include <unistd.h>
#include <errno.h>
#include <stdbool.h>
#include <gui-fatal.h>
#include <libqubes-rpc-filecopy.h>

Expand Down Expand Up @@ -82,10 +83,17 @@ int main(int argc, char **argv)
invocation_cwd_fd = open(".", O_PATH | O_DIRECTORY);
if (invocation_cwd_fd < 0)
gui_fatal("open \".\"");
bool ignore_options = false;
for (i = 1; i < argc; i++) {
if (strcmp(argv[i], "--ignore-symlinks")==0) {
ignore_symlinks = 1;
continue;
if (!ignore_options) {
if (strcmp(argv[i], "--ignore-symlinks")==0) {
ignore_symlinks = 1;
continue;
}
if (strcmp(argv[i], "--") == 0) {
ignore_options = true;
continue;
}
}
if (!*argv[i])
gui_fatal("Invalid empty argument %i", i);
Expand Down
9 changes: 5 additions & 4 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_BYTES service scriptdir
unset PROGRESS_TYPE OPERATION_TYPE TARGET_TYPE MIN_ARGS FILECOPY_TOTAL_BYTES service scriptdir ignore_symlinks

# Determine the operation to be performed
case ${0##*/} in
Expand All @@ -41,9 +41,9 @@ esac

usage () {
if [ "$TARGET_TYPE" = "vm" ]; then
echo "usage: $0 [--without-progress] destination_qube_name FILE [FILE ...]"
echo "usage: $0 [--without-progress] [--ignore-symlinks] destination_qube_name FILE [FILE ...]"
else
echo "usage: $0 [--without-progress] FILE [FILE ...]"
echo "usage: $0 [--without-progress] [--ignore-symlinks] FILE [FILE ...]"
fi

echo
Expand All @@ -66,6 +66,7 @@ export PROGRESS_TYPE=console
while [ "$#" -gt 0 ]; do
case $1 in
(--without-progress) export PROGRESS_TYPE=none; shift;;
(--ignore-symlinks) ignore_symlinks=true; shift;;
(-h|--help) usage 0;;
(--) shift; break;;
(-*) usage 1;;
Expand Down Expand Up @@ -93,7 +94,7 @@ 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" "$@"
"$service" "$scriptdir/qubes/qfile-agent" ${ignore_symlinks+--ignore-symlinks} -- "$@"

if [ "$OPERATION_TYPE" = "move" ] ; then
rm -rf -- "$@"
Expand Down

0 comments on commit 1a34521

Please sign in to comment.