+
+ while (nread = ::read(fd_from, buf, sizeof(buf)), nread > 0) {
+ char *out_ptr = buf;
+ do {
+ ssize_t nwritten = ::write(fd_to, out_ptr, nread);
+ if (nwritten >= 0) {
+ nread -= nwritten;
+ out_ptr += nwritten;
+ } else if (errno != EINTR) {
+ goto copy_error;
+ }
+ } while (nread > 0);
+ }
+
+ if (nread == 0) {
+ if (::close(fd_to)) {
+ fd_to = -1;
+ goto copy_error;
+ }
+ ::close(fd_from);
+ return true;
+ }
+
+copy_error:
+ int saved_errno = errno;
+
+ if (fd_from >= 0) {
+ ::close(fd_from);
+ }
+ if (fd_to >= 0) {
+ ::close(fd_to);
+ }
+
+ error << string_compose (_("Unable to Copy file %1 to %2 (%3)"),
+ from_path, to_path, strerror(saved_errno))
+ << endmsg;
+ return false;