Subject: Re: cp --recursive --backup broken in 9.2

From: Pádraig Brady <[email-masked]>
Date: Sun, 2 Apr 2023 13:40:44 +0100

On 01/04/2023 23:40, Kristian Klausen via GNU coreutils Bug Reports wrote:
> Hi
> 
> After upgrading to coreutils 9.2-2 on Arch Linux the following:
> mkdir -p src dst
> touch {src,dst}/bar
> cp --recursive --backup src/* dst
> fails with:
> cp: cannot create regular file 'dst/foo/bar': File exists
> 
> Running strace on cp I noticed:
> renameat2(4, "foo/bar", 4, "foo/bar~", 0) = -1 ENOENT (No such file or
> directory)
> 
> In coreutils 9.1-3 the syscall succeeds:
> renameat2(4, "bar", 4, "bar~", 0)       = 0
> 
> I assume renameat2 is called with the wrong oldpath and newpath in 9.2
> and that it should just be the basename and not the full relative path.
> 
> Cheers
> Kristian Klausen

Your analysis is correct wrt the wrong paths being given to the renameat2().
This is related to https://bugs.gnu.org/55029

For completeness the correct repro is:

   mkdir -p {src,dst}/foo
   touch {src,dst}/foo/bar
   cp --recursive --backup src/* dst

thanks,
Pádraig