Skip to content

Commit fbeb118

Browse files
authored
All files created in the staging directory should be world-readable. (#2)
1 parent 4f7c3b4 commit fbeb118

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

src/pygobbler/_utils.py

+7
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,13 @@ def dump_request(staging: str, url: str, action: str, payload: Optional[Dict]) -
2727
with os.fdopen(fd, "w") as handle:
2828
handle.write(as_str)
2929

30+
# Making sure that the gobbler's service account can read this request file.
31+
old_umask = os.umask(22)
32+
try:
33+
os.chmod(os.path.join(staging, holding_name), 0o644)
34+
finally:
35+
os.umask(old_umask)
36+
3037
res = requests.post(url + "/new/" + os.path.basename(holding_name))
3138
if res.status_code >= 300:
3239
raise format_error(res)

src/pygobbler/upload_directory.py

+23
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,29 @@ def upload_directory(project: str, asset: str, version: str, directory: str, sta
5858

5959
directory = newdir
6060

61+
# Ensuring that everything is world-readable in this directory.
62+
old_umask = os.umask(22)
63+
try:
64+
import stat
65+
extra_file_args = stat.S_IROTH | stat.S_IRGRP | stat.S_IRUSR
66+
extra_dir_args = extra_file_args | stat.S_IXOTH | stat.S_IXGRP | stat.S_IXUSR
67+
st = os.stat(directory)
68+
if st.st_mode & extra_dir_args != extra_dir_args:
69+
os.chmod(directory, st.st_mode | extra_dir_args)
70+
for root, dirs, files in os.walk(directory):
71+
for name in dirs:
72+
path = os.path.join(root, name)
73+
st = os.stat(path)
74+
if st.st_mode & extra_dir_args != extra_dir_args:
75+
os.chmod(path, st.st_mode | extra_dir_args)
76+
for name in files:
77+
path = os.path.join(root, name)
78+
st = os.stat(path)
79+
if st.st_mode & extra_file_args != extra_file_args:
80+
os.chmod(path, st.st_mode | extra_file_args)
81+
finally:
82+
os.umask(old_umask)
83+
6184
req = {
6285
"source": os.path.basename(directory),
6386
"project": project,

0 commit comments

Comments
 (0)