Make all new directories have 777 permissions

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-10 14:42:10

问题


I have a script that, when run, creates a directory inside /home/test/ and then writes some files in it. When I run this script, it works fine. However, when I call it from a perl script with

$ret = `/home/..../testscript.py`

it doesn't have permissions so it can't create the folder, or can't write inside it after it is created. It looks like when Python does open("/home/test/abcde/file1.txt", "w"), that file has permissions -rw-r--r--

What can I do to get around this? Is there a way to set /home/test to recursively make all subdirectories have global write-access? Or a better solution maybe?


回答1:


Put:

os.umask(0000)

in the Python script before it creates the directory. If you can't change the Python script, put:

umask(0000)

in the Perl script before it calls the Python script.

When a new file or directory is created, the permissions are determined by taking the permissions specified in the call to creat() or mkdir(), and then masking off the bits that are specified in the umask.

Typically, applications specify 0666 or 0777 permissions when they call the function (depending on whether they're creating something that should be executable or not). A common value for umask is 022, which turns off group and world write permissions. If you don't want them turned off, use the above umask value to keep the permissions specified in the call.



来源:https://stackoverflow.com/questions/17756585/make-all-new-directories-have-777-permissions

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!