![]() |
Set permnission with makedirs - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: Set permnission with makedirs (/thread-40119.html) |
Set permnission with makedirs - SpongeB0B - Jun-06-2023 Hi everyone, I would like to set the permission when using from os import makedirsI would like to have (for a directory) d-rwx-r-r (in other for "others") to be able to read the files inside that folder. When I do a stat on a folder that have the permission that I want I get When I transpose this in python -->makedirs('/somewhere', mode=0o0755)The created folder give me another permission than expected.. Any ideas ?
RE: Set permnission with makedirs - Gribouillis - Jun-06-2023 I try the same on my computer and it works The only difference is that I created somewhere and not /somewhere . Are you doing this as super-user?
RE: Set permnission with makedirs - SpongeB0B - Jun-06-2023 Thank you so much @Gribouillis to have tried ! Quote:Are you doing this as super-user?no, but I just tried with super-user also and it give me the same 750 instead of 755. I suppose it's linked to my umask ? RE: Set permnission with makedirs - SpongeB0B - Jun-06-2023 Yes it's linked to the umask, is there a way to not apply the umask ? RE: Set permnission with makedirs - SpongeB0B - Jun-06-2023 Meanwhile I do a chmod afterward, but it so weird ! where I do a stat after the chmod I got 0755 as expected.but when I display the Permissions trough Thunar I get ![]() ![]() RE: Set permnission with makedirs - Gribouillis - Jun-06-2023 (Jun-06-2023, 01:15 PM)SpongeB0B Wrote: Yes it's linked to the umask, is there a way to not apply the umask ?You could perhaps call os.umask() with suitable arguments? Try this to see the umask
RE: Set permnission with makedirs - SpongeB0B - Jun-15-2023 Thanks @Gribouillis ! I'm shocked the documentation about os.umask() is quite not explanatory ! So according to the documentation Set the current numeric umask and return the previous umask. print(os.umask(0))Should not only display the umask but also set it !? RE: Set permnission with makedirs - Gribouillis - Jun-15-2023 (Jun-15-2023, 07:47 AM)SpongeB0B Wrote: Should not only display the umask but also set it !?I just wanted to show the default value of the umask on my system. I chose the value 0 at random. Choose the value that you actually need for your file operation. In the linux console, the current umask can also be displayed by invoking the umask command without argument You could perhaps tryos.umask(os.umask(0) & ~(0o005))to make sure that the umask does not prevent the "others" permission 5, or even os.umask(os.umask(0) & ~(0o0755))to make sure that the umask doesn't disallow the mode 0755 |