mirror of
https://github.com/tahoe-lafs/tahoe-lafs.git
synced 2025-04-08 03:14:21 +00:00
Use chmod instead of changing umask
Conflicts: src/allmydata/frontends/magic_folder.py
This commit is contained in:
parent
3d909682a4
commit
51ccec7a33
@ -573,7 +573,7 @@ class WriteFileMixin(object):
|
||||
def _get_conflicted_filename(self, abspath_u):
|
||||
return abspath_u + u".conflict"
|
||||
|
||||
def _write_downloaded_file(self, abspath_u, file_contents, is_conflict=False, now=None):
|
||||
def _write_downloaded_file(self, local_path_u, abspath_u, file_contents, is_conflict=False, now=None):
|
||||
self._log("_write_downloaded_file(%r, <%d bytes>, is_conflict=%r, now=%r)"
|
||||
% (abspath_u, len(file_contents), is_conflict, now))
|
||||
|
||||
@ -596,12 +596,17 @@ class WriteFileMixin(object):
|
||||
# ensure parent directory exists
|
||||
head, tail = os.path.split(abspath_u)
|
||||
|
||||
old_mask = os.umask(self._umask)
|
||||
try:
|
||||
fileutil.make_dirs(head, (~ self._umask) & 0777)
|
||||
fileutil.write(replacement_path_u, file_contents)
|
||||
finally:
|
||||
os.umask(old_mask)
|
||||
fileutil.make_dirs(head)
|
||||
os.chmod(head, (~ self._umask) & 0777)
|
||||
while head and head != os.path.abspath(local_path_u):
|
||||
head, tail = os.path.split(head)
|
||||
if head == os.path.abspath(local_path_u):
|
||||
break
|
||||
else:
|
||||
os.chmod(head, (~ self._umask) & 0777)
|
||||
|
||||
fileutil.write(replacement_path_u, file_contents)
|
||||
os.chmod(replacement_path_u, (~ self._umask) & 0777)
|
||||
|
||||
# FUDGE_SECONDS is used to determine if another process
|
||||
# has written to the same file concurrently. This is described
|
||||
@ -888,7 +893,7 @@ class Downloader(QueueMixin, WriteFileMixin):
|
||||
d.addCallback(lambda ign: self._rename_deleted_file(abspath_u))
|
||||
else:
|
||||
d.addCallback(lambda ign: item.file_node.download_best_version(progress=item.progress))
|
||||
d.addCallback(lambda contents: self._write_downloaded_file(abspath_u, contents,
|
||||
d.addCallback(lambda contents: self._write_downloaded_file(self._local_path_u, abspath_u, contents,
|
||||
is_conflict=is_conflict))
|
||||
|
||||
d.addCallbacks(do_update_db, failed)
|
||||
|
@ -1254,7 +1254,7 @@ class MockTest(MagicFolderTestMixin, unittest.TestCase):
|
||||
fileutil.write(local_file, "foo")
|
||||
|
||||
# if is_conflict is False, then the .conflict file shouldn't exist.
|
||||
writefile._write_downloaded_file(local_file, "bar", False, None)
|
||||
writefile._write_downloaded_file(workdir, local_file, "bar", False, None)
|
||||
conflicted_path = local_file + u".conflict"
|
||||
self.failIf(os.path.exists(conflicted_path))
|
||||
|
||||
@ -1270,7 +1270,7 @@ class MockTest(MagicFolderTestMixin, unittest.TestCase):
|
||||
self.failUnlessEqual(fileutil.read(local_file), "bar")
|
||||
|
||||
# now a test for conflicted case
|
||||
writefile._write_downloaded_file(local_file, "bar", True, None)
|
||||
writefile._write_downloaded_file(workdir, local_file, "bar", True, None)
|
||||
self.failUnless(os.path.exists(conflicted_path))
|
||||
|
||||
# .tmp file shouldn't exist
|
||||
|
Loading…
x
Reference in New Issue
Block a user