** Changes in behavior
+ 'cp --reflink=always A B' no longer leaves behind a newly created
+ empty file B merely because copy-on-write clones are not supported.
+
'ls -v' and 'sort -V' go back to sorting ".0" before ".A",
reverting to the behavior in coreutils-9.0 and earlier.
This behavior is now documented.
{
error (0, errno, _("failed to clone %s from %s"),
quoteaf_n (0, dst_name), quoteaf_n (1, src_name));
- if (*new_dst && unlinkat (dst_dirfd, dst_relname, 0) != 0
- && errno != ENOENT)
+
+ /* Remove the destination if cp --reflink=always created it
+ but cloned no data. If clone_file failed with
+ EOPNOTSUPP, EXDEV or EINVAL no data were copied so do not
+ go to the expense of lseeking. */
+ if (*new_dst
+ && (is_ENOTSUP (errno) || errno == EXDEV || errno == EINVAL
+ || lseek (dest_desc, 0, SEEK_END) == 0)
+ && unlinkat (dst_dirfd, dst_relname, 0) != 0 && errno != ENOENT)
error (0, errno, _("cannot remove %s"), quoteaf (dst_name));
+
return_val = false;
goto close_src_and_dst_desc;
}