Subject: bug#76702: coreutils 9.1 cp --parents --preserve /dir/file fstat relative dir

From: "Alan J. Goalby" <[email-masked]>
Date: Sun, 2 Mar 2025 15:18:17 +0000

When "cp --parents --preserve /dir/file /target/" needs to create
/target/dir/, it appears to try to Fstat information from relative
path "dir", not the actual parent path "/dir".

E.g., "cd /tmp && mkdir NewDir && cp -a --parents /etc/passwd NewDir"
will fail, as (1) below - unless (2) /tmp/etc exists, or (3) use "cd
/", or (4) omit "--preserve".

My enclosed cp-par-pres-demo.sh shows that:

(1) Cp  --parents --preserve /dir/file /target/" will

 * log ENOENT for relative "dir" for a missing /target/dir;

 * create that missing parent /target/dir with mode 700;

 * create a missing non-parent output correctly; and

 * return error status 1.

(2) If ./dir exists, Cp takes /target/dir mode from it, not /dir.

(3) With "cd /", this works normally, since "dir" is /dir.

(4) Without --preserve, there is no error.

This happens for Debian 12.9 coreutils 9.1-1, under linux 6.1.115
amd64, on an ext4 partition, for root and other users, e.g. nobody.
And for an ext3 copy Chroot under linux 5.10.226.

(md5sum --check verifies coreutils.md5sums lib*.msd5sums et al.)

This does not happen for Debian 11.11 coreutils 8.32-4+b1, under linux
5.10.226 amd64 on ext4, nor for earlier versions on i386 ext3.

I enclose logs from those good Debian 11 and wrong Debian 12 runs.

My other tests show this not happening for relative input paths.

Hope this helps.

Alan J. Goalby