mirror of
https://github.com/python/cpython.git
synced 2025-09-18 14:40:43 +00:00
#5346: Preserve permissions of mbox, MMDF and Babyl mailbox files on flush()
This commit is contained in:
parent
4e6e5a06bb
commit
d07de40490
3 changed files with 23 additions and 0 deletions
|
@ -665,6 +665,9 @@ class _singlefileMailbox(Mailbox):
|
||||||
_sync_close(new_file)
|
_sync_close(new_file)
|
||||||
# self._file is about to get replaced, so no need to sync.
|
# self._file is about to get replaced, so no need to sync.
|
||||||
self._file.close()
|
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:
|
try:
|
||||||
os.rename(new_file.name, self._path)
|
os.rename(new_file.name, self._path)
|
||||||
except OSError, e:
|
except OSError, e:
|
||||||
|
|
|
@ -848,6 +848,23 @@ class _TestSingleFile(TestMailbox):
|
||||||
self._box = self._factory(self._path)
|
self._box = self._factory(self._path)
|
||||||
self.assertEqual(len(self._box), 1)
|
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):
|
class _TestMboxMMDF(_TestSingleFile):
|
||||||
|
|
||||||
|
|
|
@ -75,6 +75,9 @@ Core and Builtins
|
||||||
Library
|
Library
|
||||||
-------
|
-------
|
||||||
|
|
||||||
|
- Issue #5346: Preserve permissions of mbox, MMDF and Babyl mailbox
|
||||||
|
files on flush().
|
||||||
|
|
||||||
- Issue #15219: Fix a reference leak when hashlib.new() is called with
|
- Issue #15219: Fix a reference leak when hashlib.new() is called with
|
||||||
invalid parameters.
|
invalid parameters.
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue