Skip to content

Commit 83f03ba

Browse files
committed
Also catch same permission denied error from os.makedirs operation.
1 parent f709a3c commit 83f03ba

File tree

1 file changed

+15
-13
lines changed

1 file changed

+15
-13
lines changed

st2api/st2api/controllers/v1/actions.py

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
import os
1717
import os.path
18+
import stat
1819
import errno
1920

2021
import six
@@ -262,7 +263,18 @@ def _write_data_files_to_disk(self, pack_ref, data_files):
262263
file_path=file_path)
263264

264265
LOG.debug('Writing data file "%s" to "%s"' % (str(data_file), file_path))
265-
self._write_data_file(pack_ref=pack_ref, file_path=file_path, content=content)
266+
267+
try:
268+
self._write_data_file(pack_ref=pack_ref, file_path=file_path, content=content)
269+
except (OSError, IOError) as e:
270+
# Throw a more user-friendly exception on Permission denied error
271+
if e.errno == errno.EACCES:
272+
msg = ('Unable to write data to "%s" (permission denied). Make sure '
273+
'permissions for that pack directory are configured correctly so '
274+
'st2api can write to it.' % (file_path))
275+
raise ValueError(msg)
276+
raise e
277+
266278
written_file_paths.append(file_path)
267279

268280
return written_file_paths
@@ -302,18 +314,8 @@ def _write_data_file(self, pack_ref, file_path, content):
302314
mode = stat.S_IRWXU | stat.S_IRWXG | stat.S_IROTH | stat.S_IXOTH
303315
os.makedirs(directory, mode)
304316

305-
try:
306-
with open(file_path, 'w') as fp:
307-
fp.write(content)
308-
except IOError as e:
309-
# Throw a more user-friendly exception on Permission denied error
310-
if e.errno == errno.EACCES:
311-
msg = ('Unable to write to pack directory "%s" (permission denied). Make sure '
312-
'permissions for that directory are configured correctly so st2api can '
313-
'write to it.' % (directory))
314-
raise ValueError(msg)
315-
316-
raise e
317+
with open(file_path, 'w') as fp:
318+
fp.write(content)
317319

318320
def _dispatch_trigger_for_written_data_files(self, action_db, written_data_files):
319321
trigger = ACTION_FILE_WRITTEN_TRIGGER['name']

0 commit comments

Comments
 (0)