Sometimes we run commands as the invoking user and these commands
should be able to access the resources. If the resources are unpacked
to a temporary directory, this directory will have mode 0700 so we
need to relax the permissions to make sure it can be accessed by the
invoking user.
t = importlib.resources.files(mod)
with as_file(t) as p:
+ # Make sure any temporary directory that the resources are unpacked in is accessible to the invoking user so
+ # that any commands executed as the invoking user can access files within it.
+ if (
+ p.parent.parent == Path(os.getenv("TMPDIR", "/tmp")) and
+ stat.S_IMODE(p.parent.stat().st_mode) == 0o700
+ ):
+ p.parent.chmod(0o755)
+
yield p