Bug 500195

Summary: mkdir -p does not honour -m
Product: [Fedora] Fedora Reporter: Ralf Ertzinger <redhat-bugzilla>
Component: coreutilsAssignee: Ondrej Vasik <ovasik>
Status: CLOSED NOTABUG QA Contact: Fedora Extras Quality Assurance <extras-qa>
Severity: medium Docs Contact:
Priority: low    
Version: rawhideCC: kdudka, ovasik, twaugh
Target Milestone: ---   
Target Release: ---   
Hardware: All   
OS: Linux   
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:
Cloudforms Team: ---

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.

[sun@lain ~ :) 1]$ umask
[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):

How reproducible:

Steps to Reproduce:
1. see above
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.