-
-
Notifications
You must be signed in to change notification settings - Fork 967
Fix atomic writes replacing destinations after command failures #1918
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -416,7 +416,13 @@ def close(self, delete: bool = False) -> None: | |||||||||||||
| if self.closed: | ||||||||||||||
| return # pragma: no cover | ||||||||||||||
| self._f.close() | ||||||||||||||
| os.replace(self._tmp_filename, self._real_filename) | ||||||||||||||
| if delete: | ||||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should fix · reliability · What: The Suggestion:
Suggested change
Callers that may care:
|
||||||||||||||
| try: | ||||||||||||||
| os.unlink(self._tmp_filename) | ||||||||||||||
| except OSError: # pragma: no cover | ||||||||||||||
| pass | ||||||||||||||
| else: | ||||||||||||||
| os.replace(self._tmp_filename, self._real_filename) | ||||||||||||||
| self.closed = True | ||||||||||||||
|
|
||||||||||||||
| def __getattr__(self, name: str) -> Any: | ||||||||||||||
|
|
||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -539,7 +539,10 @@ def convert( | |
| ) | ||
|
|
||
| if ctx is not None: | ||
| ctx.call_on_close(lf.close_intelligently) | ||
| if self.atomic: | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Worth a look · design · What: No behavior risk: api_signature Why it matters: The changes to Do this: Either fix it in this PR, or reply here explaining why the current behavior is intentional. Evidence: Callers that may care:
|
||
| ctx.with_resource(lf) | ||
| else: | ||
| ctx.call_on_close(lf.close_intelligently) | ||
|
|
||
| return cast("IO[Any]", lf) | ||
|
|
||
|
|
@@ -554,7 +557,10 @@ def convert( | |
| # type is used with prompts. | ||
| if ctx is not None: | ||
| if should_close: | ||
| ctx.call_on_close(safecall(f.close)) | ||
| if self.atomic: | ||
| ctx.with_resource(f) | ||
| else: | ||
| ctx.call_on_close(safecall(f.close)) | ||
| else: | ||
| ctx.call_on_close(safecall(f.flush)) | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Worth a look · consistency ·
tests/test_atomic_file.py:6· PR title/diff inconsistencyWhat: PR title emphasizes topics that do not appear in changed paths or added code (destinations, failures, replacing, writes).
Why it matters: Align the message or the diff. (scanner:commit_consistency)
Do this: Either fix it in this PR, or reply here explaining why the current behavior is intentional.
Evidence:
title='Fix atomic writes replacing destinations after command failures'; missing_in_diff=['destinations', 'failures', 'replacing', 'writes']