]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
copy: avoid an extraneous error when reporting errors
authorPádraig Brady <P@draigBrady.com>
Tue, 7 Oct 2014 18:48:53 +0000 (19:48 +0100)
committerPádraig Brady <P@draigBrady.com>
Wed, 15 Oct 2014 01:19:48 +0000 (02:19 +0100)
* src/copy.c (copy_reg): If sparse_copy() failed, then an
erroneous error about failing to extend the file would be reported.

src/copy.c

index b8e12c2bdf11f9a37a52a45d68b4b19bba3887d0..446e72d6da948e590e8c99a0b58a2ccb87f45f47 100644 (file)
@@ -1282,13 +1282,16 @@ copy_reg (char const *src_name, char const *dst_name,
 
       off_t n_read;
       bool wrote_hole_at_eof;
-      if ( ! sparse_copy (source_desc, dest_desc, buf, buf_size,
-                          make_holes ? hole_size : 0,
-                          x->sparse_mode == SPARSE_ALWAYS, src_name, dst_name,
-                          UINTMAX_MAX, &n_read,
-                          &wrote_hole_at_eof)
-           || (wrote_hole_at_eof
-               && ftruncate (dest_desc, n_read) < 0))
+      if (! sparse_copy (source_desc, dest_desc, buf, buf_size,
+                         make_holes ? hole_size : 0,
+                         x->sparse_mode == SPARSE_ALWAYS, src_name, dst_name,
+                         UINTMAX_MAX, &n_read,
+                         &wrote_hole_at_eof))
+        {
+          return_val = false;
+          goto close_src_and_dst_desc;
+        }
+      else if (wrote_hole_at_eof && ftruncate (dest_desc, n_read) < 0)
         {
           error (0, errno, _("failed to extend %s"), quote (dst_name));
           return_val = false;