]> git.rkrishnan.org Git - tahoe-lafs/tahoe-lafs.git/commitdiff
Fix umask usage bit fiddling and use try finally blocks
authorDavid Stainton <dstainton415@gmail.com>
Tue, 8 Dec 2015 15:44:59 +0000 (17:44 +0200)
committerDaira Hopwood <daira@jacaranda.org>
Mon, 28 Dec 2015 15:32:37 +0000 (15:32 +0000)
src/allmydata/frontends/magic_folder.py

index a40c8c56af021fe8bbbdfc559c67915b93d06943..15ebf518aaff298210a752da4712c2a8d8c57cd3 100644 (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: