Skip to content

Commit

Permalink
pythongh-117467: Add preserving of mailbox owner on flush
Browse files Browse the repository at this point in the history
  • Loading branch information
softins committed Apr 3, 2024
1 parent 985917d commit 9ca6ba1
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions Lib/mailbox.py
Expand Up @@ -750,9 +750,13 @@ def flush(self):
_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)
# Make sure the new file's mode and owner are the same as the old file's
info = os.stat(self._path)
os.chmod(new_file.name, info.st_mode)
try:
os.chown(new_file.name, info.st_uid, info.st_gid)
except:
pass
try:
os.rename(new_file.name, self._path)
except FileExistsError:
Expand Down

0 comments on commit 9ca6ba1

Please sign in to comment.