X-Git-Url: http://git.annexia.org/?a=blobdiff_plain;f=daemon%2Fupload.c;h=604e705444a309d317d71c4b9f5bc9b7c1de996b;hb=54837f6d7ba83178625e2f0c3c063457d9f3f79c;hp=9a6c873129f4dd4ec8bacdb9e9200f432b5bbe52;hpb=dc706a639eec16084c0618baf7bfde00c6565f63;p=libguestfs.git diff --git a/daemon/upload.c b/daemon/upload.c index 9a6c873..604e705 100644 --- a/daemon/upload.c +++ b/daemon/upload.c @@ -20,8 +20,12 @@ #include #include +#include #include #include +#include +#include +#include #include "../src/guestfs_protocol.h" #include "daemon.h" @@ -98,6 +102,26 @@ do_download (const char *filename) return -1; } + /* Calculate the size of the file or device for notification messages. */ + uint64_t total, sent = 0; + if (!is_dev) { + struct stat statbuf; + if (fstat (fd, &statbuf) == -1) { + reply_with_perror ("%s", filename); + close (fd); + return -1; + } + total = statbuf.st_size; + } else { + int64_t size = do_blockdev_getsize64 (filename); + if (size == -1) { + /* do_blockdev_getsize64 has already sent a reply. */ + close (fd); + return -1; + } + total = (uint64_t) size; + } + /* Now we must send the reply message, before the file contents. After * this there is no opportunity in the protocol to send any error * message back. Instead we can only cancel the transfer. @@ -109,6 +133,9 @@ do_download (const char *filename) close (fd); return -1; } + + sent += r; + notify_progress (sent, total); } if (r == -1) {