coreutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH] cp: do not create empty dst file if failed to make reflink


From: Guangyu Sun
Subject: [PATCH] cp: do not create empty dst file if failed to make reflink
Date: Mon, 11 Mar 2013 12:05:52 -0700
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130106 Thunderbird/17.0.2

If making reflink across devices or if the filesystem does not support
reflink, we want it to return an error and do nothing else. However,
now it will create a new empty file to the dst. Fix it.

test case in an ext4 filesystem:
$ ls
foo
$ cp --reflink foo bar
cp: failed to clone `bar': Inappropriate ioctl for device
$ ls
foo     bar
$

Signed-off-by: Guangyu Sun <address@hidden>
---
 src/copy.c |    3 +++
 1 file changed, 3 insertions(+)

diff --git a/src/copy.c b/src/copy.c
index 5c0ee1e..b323876 100644
--- a/src/copy.c
+++ b/src/copy.c
@@ -1176,6 +1176,9 @@ close_src_and_dst_desc:
       error (0, errno, _("failed to close %s"), quote (dst_name));
       return_val = false;
     }
+  if (! return_val && *new_dst)
+    if (unlink (dst_name))
+      error (0, errno, _("cannot remove %s"), quote (dst_name));
 close_src_desc:
   if (close (source_desc) < 0)
     {
--
1.7.9.5



reply via email to

[Prev in Thread] Current Thread [Next in Thread]