cpython: 69f654f718f4 (original) (raw)
Mercurial > cpython
changeset 77850:69f654f718f4 2.7
#5346: Preserve permissions of mbox, MMDF and Babyl mailbox files on flush() [#5346]
Petri Lehtinen petri@digip.org | |
---|---|
date | Fri, 29 Jun 2012 15:09:12 +0300 |
parents | 3d7a75e945ee |
children | ee51e3aef302 bb4b184e5b33 |
files | Lib/mailbox.py Lib/test/test_mailbox.py Misc/NEWS |
diffstat | 3 files changed, 23 insertions(+), 0 deletions(-)[+] [-] Lib/mailbox.py 3 Lib/test/test_mailbox.py 17 Misc/NEWS 3 |
line wrap: on
line diff
--- a/Lib/mailbox.py +++ b/Lib/mailbox.py @@ -665,6 +665,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[](#l1.7)
mode = os.stat(self._path).st_mode[](#l1.8)
os.chmod(new_file.name, mode)[](#l1.9) try:[](#l1.10) os.rename(new_file.name, self._path)[](#l1.11) except OSError, e:[](#l1.12)
--- a/Lib/test/test_mailbox.py +++ b/Lib/test/test_mailbox.py @@ -848,6 +848,23 @@ class _TestSingleFile(TestMailbox): self._box = self._factory(self._path) self.assertEqual(len(self._box), 1)
# Make the mailbox world writable. It's unlikely that the new[](#l2.10)
# mailbox file would have these permissions after flush(),[](#l2.11)
# because umask usually prevents it.[](#l2.12)
mode = os.stat(self._path).st_mode | 0o666[](#l2.13)
os.chmod(self._path, mode)[](#l2.14)
self._box.add(self._template % 0)[](#l2.16)
i = self._box.add(self._template % 1)[](#l2.17)
# Need to remove one message to make flush() create a new file[](#l2.18)
self._box.remove(i)[](#l2.19)
self._box.flush()[](#l2.20)
self.assertEqual(os.stat(self._path).st_mode, mode)[](#l2.22)
+ class _TestMboxMMDF(_TestSingleFile):
--- a/Misc/NEWS +++ b/Misc/NEWS @@ -75,6 +75,9 @@ Core and Builtins Library ------- +- Issue #5346: Preserve permissions of mbox, MMDF and Babyl mailbox