From: Arvin Schnell Date: Fri, 22 Feb 2013 13:27:44 +0000 (+0100) Subject: - simplified and improved copyfile function X-Git-Tag: v0.1.3~22 X-Git-Url: http://git.ipfire.org/gitweb/index.cgi?a=commitdiff_plain;h=f8be7ccba9675d7ef87db58c5be2d83eaa6f0ebe;p=thirdparty%2Fsnapper.git - simplified and improved copyfile function --- diff --git a/snapper/AppUtil.cc b/snapper/AppUtil.cc index b8103677..cc504088 100644 --- a/snapper/AppUtil.cc +++ b/snapper/AppUtil.cc @@ -91,23 +91,19 @@ namespace snapper bool copyfile(int src_fd, int dest_fd) { - struct stat src_stat; - int r1 = fstat(src_fd, &src_stat); - if (r1 != 0) + while (true) { - y2err("fstat failed errno:" << errno << " (" << stringerror(errno) << ")"); - return false; - } - - size_t count = src_stat.st_size; + // use small value for count to make function better interruptible + ssize_t r1 = sendfile(dest_fd, src_fd, NULL, 0xffff); + if (r1 == 0) + return true; - ssize_t r2 = sendfile(dest_fd, src_fd, NULL, count); - if (r2 < 0) - { - y2err("sendfile failed errno:" << errno << " (" << stringerror(errno) << ")"); + if (r1 < 0) + { + y2err("sendfile failed errno:" << errno << " (" << stringerror(errno) << ")"); + return false; + } } - - return r2 >= 0; }