8000 gh-117467: Add preserving of mailbox owner on flush by softins · Pull Request #117510 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

gh-117467: Add preserving of mailbox owner on flush #117510

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Apr 4, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
gh-117467: Add preserving of mailbox owner on flush
  • Loading branch information
softins committed Apr 3, 2024
commit 9ca6ba11994687997492c78b967b1ec70fea6d22
10 changes: 7 additions & 3 deletions Lib/mailbox.py
Original file line number Diff line number Diff line change
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:
Copy link
Member
@serhiy-storchaka serhiy-storchaka Apr 3, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Silently ignoring arbitrary exceptions is never a good idea. KeyboardInterrupt, MemoryError and RecursionError can be raised by virtually any code.

It is better to make the exception check more specific, for example: (PermissionError, AttributeError).

pass
try:
os.rename(new_file.name, self._path)
except FileExistsError:
Expand Down
0