Reputation: 1096
I'm creating a directory using the makedirs
function:
makedirs(self.output_dir, exist_ok=True)
I'm then copying some files from a temporary directory (temp_dir
) inside this new directory.
In the end, and according to the Python documentation, I expect the permission of output_dir
to be rwxrwxrwx
.
os.makedirs(path[, mode])
Recursive directory creation function. Like mkdir(), but makes all intermediate-level directories needed to contain the leaf directory. Raises an error exception if the leaf directory already exists or cannot be created. The default mode is 0777 (octal).
However, the permission of output_dir
turns out to be rwx------
. I don't understand this result because I'm not doing any manipulation of the permission of output_dir
anywhere in my code. I'm not using os.chmod
for example.
Assuming I run my Python script as root, what factors could have changed the permission of the directory?
EDIT
I noticed that the temporary directory temp_dir
has the same unexpected permission (rwxrwxrwx
). I create it by using the following function:
temp_dir = tempfile.TemporaryDirectory()
Is this expected behavior? I couldn't find anything on this subject.
Upvotes: 0
Views: 39
Reputation: 193
If you already have a umask present before running the python then the directory creation honours the umask.
E.g
umask -S u=rwx,g=,o=
Then
import os
os.makedirs(...
Upvotes: 2