From: Paul Eggert Date: Tue, 5 Jul 2022 14:34:17 +0000 (-0500) Subject: cp: don’t create empty file if cannot clone X-Git-Tag: v9.2~177 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=1edda5009b1118ee28faa1b30154f5d9011780ba;p=thirdparty%2Fcoreutils.git cp: don’t create empty file if cannot clone * 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). --- diff --git a/src/copy.c b/src/copy.c index 0c368d0e4e..eaed148b4f 100644 --- a/src/copy.c +++ b/src/copy.c @@ -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; }