Permalink
Browse files

- simplified and improved copyfile function

  • Loading branch information...
aschnell committed Feb 22, 2013
1 parent 479c9a2 commit f8be7ccba9675d7ef87db58c5be2d83eaa6f0ebe
Showing with 10 additions and 14 deletions.
  1. +10 −14 snapper/AppUtil.cc
View
@@ -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;
}

0 comments on commit f8be7cc

Please sign in to comment.