[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
bug#14249: mkdir --parents --mode XXX incorrect mode for parents
From: |
Eric Blake |
Subject: |
bug#14249: mkdir --parents --mode XXX incorrect mode for parents |
Date: |
Tue, 23 Apr 2013 11:43:02 -0600 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130402 Thunderbird/17.0.5 |
tag 14249 notabug
thanks
On 04/23/2013 07:22 AM, Richard Russon wrote:
> Description of problem:
> mkdir doesn't honour the mode option when the parents option is used.
> The leaf directories have their permissions set correctly, but the
> parent directory has the permissions according to your umask.
Thanks for the report. However, this is the behavior required by POSIX,
so it is correct:
http://pubs.opengroup.org/onlinepubs/9699919799/utilities/mkdir.html
... the mkdir utility shall create any pathname components of the path
prefix of dir that do not name an existing directory by performing
actions equivalent to first calling the mkdir() function with the
following arguments:
A pathname naming the missing pathname component, ending with a
trailing <slash> character, as the path argument
The value zero as the mode argument
and then calling the chmod() function with the following arguments:
The same path argument as in the mkdir() call
The value (S_IWUSR|S_IXUSR| Ěfilemask)&0777[1] as the mode argument,
where filemask is the file mode creation mask of the process (see XSH
umask).
...For intermediate pathname components created by mkdir, the mode is
the default modified by u+ wx so that the subdirectories can always be
created regardless of the file mode creation mask; if different ultimate
permissions are desired for the intermediate directories, they can be
changed afterwards with chmod.
[1]Shoot - there's a bug in the html rendition of the POSIX 2013
document, just released this month. The pdf version has the correct
text; I'll chase down getting the omitted portion of the html version fixed.
> Steps to Reproduce:
> 1. umask 077
> 2. mkdir --parents --mode 755 project/subproject
> 3. ls -ld project project/subproject
>
> Actual results:
> drwx------. 3 flatcap flatcap 60 Apr 23 14:17 project
> drwxr-xr-x. 2 flatcap flatcap 40 Apr 23 14:17 project/subproject
This behavior is what POSIX mandates.
>
> Expected results:
> drwxr-xr-x. 3 flatcap flatcap 60 Apr 23 14:17 project
> drwxr-xr-x. 2 flatcap flatcap 40 Apr 23 14:17 project/subproject
If you want that, then you have to either (temporarily) clear your
umask, or call multiple mkdir invocations yourself, instead of letting
-p do it for you.
I'm closing out this bug report, although you may continue to comment if
you have further questions.
--
Eric Blake eblake redhat com +1-919-301-3266
Libvirt virtualization library http://libvirt.org
signature.asc
Description: OpenPGP digital signature