Message 215034 - Python tracker (original) (raw)

I think the behaviour that an error is raised if the permissions are not the same is a nuisance that does not correspond to actual use cases (*).

I was also surprised that makedirs() checks for the exact permission.

We can probably document that makedirs(exists_ok=True) leaves the directory permission unchanged if the directory already exist, and that an explicit chmod() may be needed to ensure that permissions are the expected permissions.

If the check on permissions is removed, an enhancement would be to return a flag to indicate if at least one directory of the path already existed. So the caller can avoid calling chmod() if all directories of the path had to be created.

Something like:

if makedirs("a/b", mod=0o755, exists_ok=True): os.chmod("a", 0o755) os.chmod("a/b", 0o755)

else a and b were created with the permission 0o755