diff options
author | Petri Lehtinen <petri@digip.org> | 2012-06-29 12:09:12 (GMT) |
---|---|---|
committer | Petri Lehtinen <petri@digip.org> | 2012-06-29 12:10:41 (GMT) |
commit | 5b5619f717be2a712c05d6c63a0ca4184f263aee (patch) | |
tree | 4d0ae9767f7fa1160a366ceeb653f9411d132712 /Lib | |
parent | b6ee3d6b7a3eaf7af09dbe34879a821de997e215 (diff) | |
download | cpython-5b5619f717be2a712c05d6c63a0ca4184f263aee.zip cpython-5b5619f717be2a712c05d6c63a0ca4184f263aee.tar.gz cpython-5b5619f717be2a712c05d6c63a0ca4184f263aee.tar.bz2 |
#5346: Preserve permissions of mbox, MMDF and Babyl mailbox files on flush()
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/mailbox.py | 3 | ||||
-rw-r--r-- | Lib/test/test_mailbox.py | 17 |
2 files changed, 20 insertions, 0 deletions
diff --git a/Lib/mailbox.py b/Lib/mailbox.py index 73c43e2..8b00460 100644 --- a/Lib/mailbox.py +++ b/Lib/mailbox.py @@ -691,6 +691,9 @@ class _singlefileMailbox(Mailbox): _sync_close(new_file) # self._file is about to get replaced, so no need to sync. self._file.close() + # Make sure the new file's mode is the same as the old file's + mode = os.stat(self._path).st_mode + os.chmod(new_file.name, mode) try: os.rename(new_file.name, self._path) except OSError as e: diff --git a/Lib/test/test_mailbox.py b/Lib/test/test_mailbox.py index d8dca1d..9f1fdad 100644 --- a/Lib/test/test_mailbox.py +++ b/Lib/test/test_mailbox.py @@ -966,6 +966,23 @@ class _TestSingleFile(TestMailbox): self._box = self._factory(self._path) self.assertEqual(len(self._box), 1) + def test_permissions_after_flush(self): + # See issue #5346 + + # Make the mailbox world writable. It's unlikely that the new + # mailbox file would have these permissions after flush(), + # because umask usually prevents it. + mode = os.stat(self._path).st_mode | 0o666 + os.chmod(self._path, mode) + + self._box.add(self._template % 0) + i = self._box.add(self._template % 1) + # Need to remove one message to make flush() create a new file + self._box.remove(i) + self._box.flush() + + self.assertEqual(os.stat(self._path).st_mode, mode) + class _TestMboxMMDF(_TestSingleFile): |