fix: assign proper permissions to temporary drawings

This commit is contained in:
Umut
2021-09-17 15:08:34 +03:00
parent 14d7c505d8
commit b950bb4459

View File

@@ -1,5 +1,6 @@
"""functions to draw the different graphs we can generate in the package, eg to debug."""
import os
import tempfile
from pathlib import Path
from typing import Optional
@@ -90,6 +91,23 @@ def draw_graph(
if save_to is None:
with tempfile.NamedTemporaryFile(suffix=".png", delete=False) as tmp:
# we need to change the permissions of the temporary file
# so that it can be read by all users
# (https://stackoverflow.com/a/44130605)
# get the old umask and replace it with 0o666
old_umask = os.umask(0o666)
# restore the old umask back
os.umask(old_umask)
# combine the old umask with the wanted permissions
permissions = 0o666 & ~old_umask
# set new permissions
os.chmod(tmp.name, permissions)
save_to_str = str(tmp.name)
else:
save_to_str = str(save_to)