I'm creating a temporary directory in python using from tempfile import TemporaryDirectory. How do I create a TemporaryDirectory in python and force its permission to be the same as the folder that it is created in?
Unfortunately, the items in TemporaryDirectory are not accessible by another program I have running. This program does have access to TemporaryDirectory's parent directory but not TemporaryDirectory.
I can't see support for it directly in
TemporaryDirectory, and indeed the mode0o700is hard-coded into the tempfile package, but you could usechmod. Example:The question only asked for permissions, but if you also require changing ownership (user or group), then look at
os.chownand thest_uidandst_gidproperties of thestat_resultobject (analogous tost_modeabove). Note that some operations may require root privileges.