From 1edda5009b1118ee28faa1b30154f5d9011780ba Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Tue, 5 Jul 2022 09:34:17 -0500 Subject: [PATCH] =?utf8?q?cp:=20don=E2=80=99t=20create=20empty=20file=20if?= =?utf8?q?=20cannot=20clone?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit * 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 | 3 +++ 1 file changed, 3 insertions(+) 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; } -- 2.47.2