]> git.ipfire.org Git - thirdparty/snapper.git/commitdiff
- simplified and improved copyfile function
authorArvin Schnell <aschnell@suse.de>
Fri, 22 Feb 2013 13:27:44 +0000 (14:27 +0100)
committerArvin Schnell <aschnell@suse.de>
Fri, 22 Feb 2013 13:27:44 +0000 (14:27 +0100)
snapper/AppUtil.cc

index b81036778afb6d501aedc616c51100e3cffc8b23..cc504088006ad7e77a6562ae619d433f5c5d85b8 100644 (file)
@@ -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;
     }