Hi,

I'm writing to report a potential bug with cp.  I don't think the mode bits
always get properly set on directories created when using the --parents
option combined with --no-preserve=mode option.  I'm not sure what the
expected behaviour is supposed to be, but my assumption is that the created
directories would match process's ~umask (like mkdir -p).

I've attached a simple script and its output to demonstrate the behaviour.
I've tested this on the most recent master branch of the coreutils git
repository (output of git describe is 'v8.25-55-gff2178b').

Thanks for your efforts on these utilities, it is much appreciated :-).

-Mark
Original source directories and files
ls -la
total 20
drwxrwxr-x 3 mark mark 4096 Aug 17 11:38 .
drwxr-xr-x 4 mark mark 4096 Aug 17 03:44 ..
drwx------ 3 mark mark 4096 Aug 17 11:38 a
-rwxrwxr-x 1 mark mark 1060 Aug 17 11:37 test-cp-parents-umask.sh
-rw-r--r-- 1 mark mark   45 Aug 17 11:38 test-output.txt
total 8
drwxr-xr-x 2 mark mark 4096 Aug 17 11:38 .
drwx------ 3 mark mark 4096 Aug 17 11:38 ..
-rwxrwxr-x 1 mark mark    0 Aug 17 11:38 c_file
Copying with --parents with normal mode preservation (and umask=0002)
cp --parents a/b/c_file test_preserved/
normal case, permissions on directory match their originals
ls -la test_preserved/
total 12
drwxr-xr-x 3 mark mark 4096 Aug 17 11:38 .
drwxrwxr-x 4 mark mark 4096 Aug 17 11:38 ..
drwx------ 3 mark mark 4096 Aug 17 11:38 a
total 8
drwxr-xr-x 2 mark mark 4096 Aug 17 11:38 .
drwx------ 3 mark mark 4096 Aug 17 11:38 ..
-rwxrwxr-x 1 mark mark    0 Aug 17 11:38 c_file
Copying with --parents and --no-preserve=mode
cp --parents --no-preserve=mode a/b/c_file test_umask/
failure case - directory a retains its original permissions even though 
--no-preserve=mode was used
ls -la test_umask/
total 12
drwxrwxr-x 3 mark mark 4096 Aug 17 11:38 .
drwxrwxr-x 5 mark mark 4096 Aug 17 11:38 ..
drwx------ 3 mark mark 4096 Aug 17 11:38 a
note though that mode bits for c_file are set correctly according to umask
ls -la test_umask/a/b/
total 8
drwxr-xr-x 2 mark mark 4096 Aug 17 11:38 .
drwx------ 3 mark mark 4096 Aug 17 11:38 ..
-rw-rw-r-- 1 mark mark    0 Aug 17 11:38 c_file

Attachment: test-cp-parents-umask.sh
Description: Bourne shell script

Reply via email to