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 <[email protected]> --- 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
