Bug 500195 - mkdir -p does not honour -m
mkdir -p does not honour -m
Status: CLOSED NOTABUG
Product: Fedora
Classification: Fedora
Component: coreutils (Show other bugs)
rawhide
All Linux
low Severity medium
: ---
: ---
Assigned To: Ondrej Vasik
Fedora Extras Quality Assurance
:
Depends On:
Blocks:
  Show dependency treegraph
 
Reported: 2009-05-11 11:44 EDT by Ralf Ertzinger
Modified: 2009-05-11 13:19 EDT (History)
3 users (show)

See Also:
Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Environment:
Last Closed: 2009-05-11 12:39:44 EDT
Type: ---
Regression: ---
Mount Type: ---
Documentation: ---
CRM:
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:


Attachments (Terms of Use)

  None (edit)
Description Ralf Ertzinger 2009-05-11 11:44:41 EDT
Description of problem:
When creating a directory structure with mkdir using -p, the mode set with -m is only applied to the last directory in the chain, not the intermediate directories.

Example:
[sun@lain ~ :) 1]$ umask
0077
[sun@lain ~ :) 2]$ mkdir foo
[sun@lain ~ :) 4]$ ls -ld foo
drwx------ 2 sun users 4096 2009-05-11 17:39 foo
[sun@lain ~ :) 5]$ mkdir -m 755 bar
[sun@lain ~ :) 6]$ ls -ld bar
drwxr-xr-x 2 sun users 4096 2009-05-11 17:40 bar
[sun@lain ~ :) 7]$ rm -rf foo bar
[sun@lain ~ :) 8]$ mkdir -m 755 -p foo/bar
[sun@lain ~ :) 9]$ ls -ld foo foo/bar
drwx------ 3 sun users 4096 2009-05-11 17:40 foo
drwxr-xr-x 2 sun users 4096 2009-05-11 17:40 foo/bar


Version-Release number of selected component (if applicable):
coreutils-7.2-1.fc11.i586

How reproducible:
Always

Steps to Reproduce:
1. see above
2.
3.
  
Actual results:
Mask is only applied to last directory

Expected results:
Mask applied to all created directories

Additional info:
Comment 1 Ondrej Vasik 2009-05-11 12:39:44 EDT
Thanks for report. According to POSIX (http://www.opengroup.org/onlinepubs/009695399/utilities/mkdir.html) that's exactly the way how mkdir should behave. 
POSIX states that with -p and -m option parent directory creation should behave like `mkdir -p -m $(umask -S),u+wx $(dirname dir) &&
mkdir [-m mode] dir` - and that's the way how it behaves now. If you think that my POSIX interpretation is wrong, feel free to discuss it here. 

Closing NOTABUG as the current behaviour does comply with POSIX requirements...
Comment 2 Ralf Ertzinger 2009-05-11 13:03:05 EDT
I think your interpretation of the POSIX standard is correct, it is just not what I'd expect it to do. The info page actually mentiones this behaviour, but who reads info pages?
Comment 3 Ondrej Vasik 2009-05-11 13:19:32 EDT
In the case of coreutils are info pages quite useful - as manpages of coreutils commands are only help2man-ed --help outputs of commands. But you are right - many users do ignore info pages... Maybe --help/man page improvement could be suggested on bug-coreutils@gnu.org (upstream bugreport/discussion mailing list) - to state that only final directory is affected by -m mode.

Note You need to log in before you can comment on or make changes to this bug.