Skip to content

Commit f3b6df8

Browse files
committed
gh-117467: Add preserving of mailbox owner on flush
1 parent 7ecd55d commit f3b6df8

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

Lib/mailbox.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -750,9 +750,13 @@ def flush(self):
750750
_sync_close(new_file)
751751
# self._file is about to get replaced, so no need to sync.
752752
self._file.close()
753-
# Make sure the new file's mode is the same as the old file's
754-
mode = os.stat(self._path).st_mode
755-
os.chmod(new_file.name, mode)
753+
# Make sure the new file's mode and owner are the same as the old file's
754+
info = os.stat(self._path)
755+
os.chmod(new_file.name, info.st_mode)
756+
try:
757+
os.chown(new_file.name, info.st_uid, info.st_gid)
758+
except:
759+
pass
756760
try:
757761
os.rename(new_file.name, self._path)
758762
except FileExistsError:

0 commit comments

Comments
 (0)