coreutils
coreutils copied to clipboard
mkdir: permissions when using -m differ from GNU
When using -m option to mkdir, the permissions of the created directory differ from those of GNU mkdir. I think this may have something to do with the umask.
GNU mkdir:
$ mkdir -m + d
$ ls -ld d
drwxrwxr-x 2 jeffrey jeffrey 4096 Jun 16 22:12 d
uutils mkdir
$ mkdir -m + d
$ ls -ld d
drwxr-xr-x 2 jeffrey jeffrey 4096 Jun 16 22:12 d
umask on my machine:
$ umask
0002
Same issue here with 022 mask.
https://github.com/uutils/coreutils/blob/fa51f8b986ece9182a7e834c34bc3b9a3dcbf68e/src/uu/mkdir/src/mkdir.rs#L56-L62
It seems the plus case doesn't result in the same mode being parsed hmmm
EDIT GOTCHA : https://github.com/uutils/coreutils/blob/fa51f8b986ece9182a7e834c34bc3b9a3dcbf68e/src/uucore/src/lib/features/mode.rs#L58
Seems that using + in mkdir -m option has some strange behavior in GNU:
$ umask
0027
$ mkdir -m + d
$ ls -l
drwxr-x--- 2 niyaz niyaz 4096 Jun 22 23:06 d
$ rmdir d
$ mkdir -m a+ d
$ ls -l
drwxr-x--- 2 niyaz niyaz 4096 Jun 22 23:07 d
$ rmdir d
$ mkdir -m +r d
$ ls -l
drwxr-x--- 2 niyaz niyaz 4096 Jun 22 23:07 d
$ rmdir d
$ mkdir -m a+r d
$ ls -l
drwxrwxrwx 2 niyaz niyaz 4096 Jun 22 23:07 d
https://github.com/coreutils/coreutils/blob/6c03e8fbb25d52b5fda62a95090568f0ba5fca70/src/mkdir.c#L283-L298 where S_IRWXUGO = (S_IRWXU|S_IRWXG|S_IRWXO) (from linux stat.h)
Could I work on this issue?
sure, please submit a PR
I'm working on this issue, but it's too difficult for me to understand how to work permissions mechanism. I can't judge which result is correct.
@wan-nyan-wan Feel free to open an incomplete draft PR to discuss or ask questions if necessary!
During Examing GNU mkdir and GNU file permissions, I noticed that mkdir has odd behavior such as the below example. When umask & perm == 0, it execute as intended, but when 0 < umask & perm, does not.
$ umask 033
# default case, umask
$ mkdir d1
# umask(033) & a+r(444) == 0
$ mkdir -m a+r d2
# 0 < umask(033) & a+w(222)
$ mkdir -m a+w d3
# umask(033) & o+r(040) == 0
$ mkdir -m o+r d4
# 0 < umask(033) & o+w(020)
$ mkdir -m o+w d5
# show result
$ ls -ld d1 d2 d3 d4 d5
drwxr--r-- - user 31 Jul 2:07 d1
drwxr--r-- - user 31 Jul 2:07 d2
drwxrwxrwx - user 31 Jul 2:07 d3
drwxr--r-- - user 31 Jul 2:07 d4
drwxrwxrwx - user 31 Jul 2:07 d5
Seems that this issue can be closed or needs more information.
MacOS:
umask && rmdir d e; \
coreutils mkdir -m + d && \
mkdir -m + e && \
ls -ld *; \
coreutils --help | grep multi
0022
drwxrwxrwx 2 tosha wheel 64 Mar 29 01:55 d
drwxrwxrwx 2 tosha wheel 64 Mar 29 01:55 e
coreutils 0.0.25 (multi-call binary)
Linux (debian):
$ umask && rmdir d e; \
coreutils mkdir -m + d && \
mkdir -m + e && \
ls -ld *; \
coreutils --help | grep multi
0002
drwxrwxrwx 2 app app 4096 Mar 28 21:27 d
drwxrwxrwx 2 app app 4096 Mar 28 21:27 e
coreutils 0.0.25 (multi-call binary)
I just tested this again.
On Ubuntu 20.04.6, uutils main branch commit uutils/coreutils@393feaf89086143216da322bfb0fcfaa5c7cea19, uutils mkdir produces this:
$ ./target/debug/mkdir -m + d && ls -ld d
drwxrwxrwx 2 jeffrey jeffrey 4096 Mar 30 15:45 d
On Ubuntu 20.04.6, GNU mkdir v8.30 produces this:
$ mkdir -m + d && ls -ld d
drwxrwxr-x 2 jeffrey jeffrey 4096 Mar 30 15:46 d
But using the main branch commit coreutils/coreutils@d2df669c9c8fb42e310f27024b8ae3e4511f257f mkdir built from source (which reports version 9.4.188-d2df6)
$ ./src/mkdir -m + d && ls -ld d
drwxrwxrwx 2 jeffrey jeffrey 4096 Mar 30 15:48 d
So the behavior of uutils is now in line with the most recent GNU. I'll close this as completed, thanks for double checking.