]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
cp: don’t create empty file if cannot clone
authorPaul Eggert <eggert@cs.ucla.edu>
Tue, 5 Jul 2022 14:34:17 +0000 (09:34 -0500)
committerPaul Eggert <eggert@cs.ucla.edu>
Tue, 5 Jul 2022 15:02:46 +0000 (10:02 -0500)
* src/copy.c (copy_reg): With --reflink=always, if FICLONE fails
on a file we just created, clean up by removing the file (Bug#56391).

src/copy.c

index 0c368d0e4e3c22bcfdc85a42ff2670c1790d8243..eaed148b4f07124d58104c00ab2dab3cd7768dae 100644 (file)
@@ -1279,6 +1279,9 @@ copy_reg (char const *src_name, char const *dst_name,
         {
           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)
+            error (0, errno, _("cannot remove %s"), quoteaf (dst_name));
           return_val = false;
           goto close_src_and_dst_desc;
         }