nginx不会创建具有组写权限的文件

时间:2014-01-13 04:57:52

标签: python nginx uwsgi

我正在使用此代码跟踪此处(LINK)所见的python教程:

# !/usr/bin/python

import os
import stat

filename = '/tmp/tmpfile'
mode = 0600|stat.S_IRUSR

# filesystem node specified with different modes
os.mknod(filename, mode)

效果很好。但我想用组写权限编写该文件。但是当我将模式改为“按组写”模式时:

mode = 0600|stat.S_IWGRP

(来自LINK2)文件运行时没有抛出错误,但该文件没有组写权限。除了组写和其他写操作之外,所有“模式”权限都有效。

如何让我的python / uwsgi / nginx应用程序创建具有组写权限的文件?

1 个答案:

答案 0 :(得分:0)

试试这个:

mode = stat.S_IFREG | stat.S_IWGRP | stat.S_IRUSR

来自帮助文档字符串:

mknod(filename [, mode=0600, device])

Create a filesystem node (file, device special file or named pipe)
named filename. mode specifies both the permissions to use and the
type of node to be created, being combined (bitwise OR) with one of
S_IFREG, S_IFCHR, S_IFBLK, and S_IFIFO. For S_IFCHR and S_IFBLK,
device defines the newly created device special file (probably using
os.makedev()), otherwise it is ignored.

P.S。尝试在bash中运行umask。如果它返回0000以外的其他内容,则会从您指定的内容(man 2 umask)中自动减去该值。尝试运行umask 0000然后再次运行python脚本!