MKDIR未正确设置权限
我正在尝试制作一个具有“执行中设置组ID”的目录 Python中
在Shell中的
$ mkdir --mode 2775 mail
$ ls -ld mail
drwxrwsr-x 1 john john 0 May 3 08:34 mail
^
:在Python中,我正在使用 pathlib.path.mkdir
,似乎没有考虑到一些模式的位,
即使清除了 umask
:
from pathlib import Path
import os
os.umask(0)
md = Path('mail')
md.mkdir(mode=0o2775)
drwxrwxr-x 1 john john 0 May 3 08:35 mail
^
在九个位时是否有一些截止,不是documented
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
最终,在非Windows Systems,
path.mkdir
呼叫os.mkdir
又调用C系统调用mkdirat
。该呼叫的行为是根据模式请注意,在
0777的上方,权限明确掩盖了所有位
;这就是mkdir
系统调用在某些OS上的行为。事实之后,您只需要chmod
即可。Ultimately, on non-Windows systems,
Path.mkdir
callsos.mkdir
which in turn invokes the C system callmkdirat
. That call's behavior is defined in terms ofmkdir
, which, on Linux, documents themode
with:Note that the permissions explicitly mask off all bits above
0777
; this is just howmkdir
system calls behave on some OSes. You'll just have tochmod
it after the fact.pathlib
'smkdir
基本上只调用os.mkdir()
。那里的文档包括:因此,仅保证使用最后9位。
您必须执行(无需设置Umask):
如果
Pathlib
不会默默地忽略额外的位,而是实际上抛出了一个值,那就更好了。pathlib
'smkdir
essentially just callsos.mkdir()
. The documentation there includes the section:So only the last 9 bits are guaranteed to be used.
You'll have to do (no need to set umask):
It would be better if
pathlib
would not silently ignore extra bits, but actually threw a ValueError.