mirror of
https://github.com/python/cpython.git
synced 2025-08-11 04:19:06 +00:00
[3.12] gh-117467: Add preserving of mailbox owner on flush (GH-117510) (GH-117537)
(cherry picked from commit 3f5bcc86d0
)
Co-authored-by: Tony Mountifield <tony@mountifield.org>
Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
This commit is contained in:
parent
eca377f203
commit
14aef56ebb
3 changed files with 51 additions and 3 deletions
|
@ -9,6 +9,7 @@ import re
|
|||
import io
|
||||
import tempfile
|
||||
from test import support
|
||||
from test.support import import_helper
|
||||
from test.support import os_helper
|
||||
from test.support import socket_helper
|
||||
import unittest
|
||||
|
@ -981,6 +982,47 @@ class _TestSingleFile(TestMailbox):
|
|||
|
||||
self.assertEqual(os.stat(self._path).st_mode, mode)
|
||||
|
||||
@unittest.skipUnless(hasattr(os, 'chown'), 'requires os.chown')
|
||||
def test_ownership_after_flush(self):
|
||||
# See issue gh-117467
|
||||
|
||||
pwd = import_helper.import_module('pwd')
|
||||
grp = import_helper.import_module('grp')
|
||||
st = os.stat(self._path)
|
||||
|
||||
for e in pwd.getpwall():
|
||||
if e.pw_uid != st.st_uid:
|
||||
other_uid = e.pw_uid
|
||||
break
|
||||
else:
|
||||
self.skipTest("test needs more than one user")
|
||||
|
||||
for e in grp.getgrall():
|
||||
if e.gr_gid != st.st_gid:
|
||||
other_gid = e.gr_gid
|
||||
break
|
||||
else:
|
||||
self.skipTest("test needs more than one group")
|
||||
|
||||
try:
|
||||
os.chown(self._path, other_uid, other_gid)
|
||||
except OSError:
|
||||
self.skipTest('test needs root privilege')
|
||||
# Change permissions as in test_permissions_after_flush.
|
||||
mode = st.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()
|
||||
|
||||
st = os.stat(self._path)
|
||||
self.assertEqual(st.st_uid, other_uid)
|
||||
self.assertEqual(st.st_gid, other_gid)
|
||||
self.assertEqual(st.st_mode, mode)
|
||||
|
||||
|
||||
class _TestMboxMMDF(_TestSingleFile):
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue