Fix umask usage bit fiddling and use try finally blocks

This commit is contained in:
David Stainton 2015-12-08 17:44:59 +02:00 committed by Brian Warner
parent f2a7978b29
commit ae59b17e86

View File

@ -485,10 +485,12 @@ class WriteFileMixin(object):
# ensure parent directory exists
head, tail = os.path.split(abspath_u)
old_mask = os.umask(self._umask)
fileutil.make_dirs(head, ~ self._umask)
fileutil.write(replacement_path_u, file_contents)
os.umask(old_mask)
try:
old_mask = os.umask(self._umask)
fileutil.make_dirs(head, (~ self._umask) & 0777)
fileutil.write(replacement_path_u, file_contents)
finally:
os.umask(old_mask)
os.utime(replacement_path_u, (now, now - self.FUDGE_SECONDS))
if is_conflict: