Skip to content

Commit f3f7041

Browse files
Merge pull request #167 from pkalever/shutil-fix
rtslib: safely call shutil.copy()
2 parents 4da7a72 + 75e7377 commit f3f7041

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

rtslib/root.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -476,8 +476,8 @@ def save_to_file(self, save_file=None, so_path=None):
476476
# prevent the file from being created if it exists due to a race
477477
try:
478478
fdesc = os.open(tmp_file, os.O_WRONLY | os.O_CREAT | os.O_EXCL, mode)
479-
finally:
480-
os.umask(umask_original)
479+
except OSError:
480+
raise ExecutionError("Could not open %s" % tmp_file)
481481

482482
with os.fdopen(fdesc, 'w') as f:
483483
f.write(json.dumps(saveconf, sort_keys=True, indent=2))
@@ -488,6 +488,7 @@ def save_to_file(self, save_file=None, so_path=None):
488488

489489
# copy along with permissions
490490
shutil.copy(tmp_file, save_file)
491+
os.umask(umask_original)
491492
os.remove(tmp_file)
492493

493494
def restore_from_file(self, restore_file=None, clear_existing=True,

0 commit comments

Comments
 (0)