From c939cc049ecda348dfcfcb14e7c0f03106ef06b1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Marczykowski-G=C3=B3recki?= Date: Wed, 14 Aug 2013 22:13:44 +0200 Subject: [PATCH] qvm-copy-to-vm: show last processed filename on error --- qubes-rpc/qfile-agent.c | 29 +++++++++++++++++++++++++---- 1 file changed, 25 insertions(+), 4 deletions(-) diff --git a/qubes-rpc/qfile-agent.c b/qubes-rpc/qfile-agent.c index c3c8178..22712c7 100644 --- a/qubes-rpc/qfile-agent.c +++ b/qubes-rpc/qfile-agent.c @@ -53,6 +53,9 @@ void do_notify_progress(long long total, int flag) void wait_for_result() { struct result_header hdr; + struct result_header_ext hdr_ext; + char last_filename[MAX_PATH_LENGTH + 1]; + char last_filename_prefix[] = "; Last file: "; if (!read_all(0, &hdr, sizeof(hdr))) { if (errno == EAGAIN) { @@ -63,17 +66,35 @@ void wait_for_result() exit(1); // hopefully remote has produced error message } } + if (!read_all(0, &hdr_ext, sizeof(hdr_ext))) { + // remote used old result_header struct + hdr_ext.last_namelen = 0; + } + if (hdr_ext.last_namelen > MAX_PATH_LENGTH) { + // read only at most MAX_PATH_LENGTH chars + hdr_ext.last_namelen = MAX_PATH_LENGTH; + } + if (!read_all(0, last_filename, hdr_ext.last_namelen)) { + fprintf(stderr, "Failed to get last filename\n"); + hdr_ext.last_namelen = 0; + } + last_filename[hdr_ext.last_namelen] = '\0'; + if (!hdr_ext.last_namelen) + /* set prefix to empty string */ + last_filename_prefix[0] = '\0'; + + errno = hdr.error_code; if (hdr.error_code != 0) { switch (hdr.error_code) { case EEXIST: - gui_fatal("File copy: not overwriting existing file. Clean QubesIncoming dir, and retry copy"); + gui_fatal("File copy: not overwriting existing file. Clean QubesIncoming dir, and retry copy%s%s", last_filename_prefix, last_filename); break; case EINVAL: - gui_fatal("File copy: Corrupted data from packer"); + gui_fatal("File copy: Corrupted data from packer%s%s", last_filename_prefix, last_filename); break; default: - gui_fatal("File copy: %s", - strerror(hdr.error_code)); + gui_fatal("File copy: %s%s%s", + strerror(hdr.error_code), last_filename_prefix, last_filename); } } if (hdr.crc32 != crc32_sum) {