-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
patching: Rewriter: actually delete empty patch files on rewrite #9209
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: main
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 |
|---|---|---|
|
|
@@ -375,9 +375,11 @@ | |
| parent.rewrite_patch_file(patches) | ||
| FAILED_PATCHES = [one_patch for one_patch in VALID_PATCHES if (not one_patch.applied_ok) or (one_patch.rewritten_patch is None)] | ||
| for failed_patch in FAILED_PATCHES: | ||
| log.info( | ||
| f"Consider removing {failed_patch.parent.full_file_path()}(:{failed_patch.counter}); " | ||
| f"it was not applied successfully.") | ||
| log.warning( | ||
| f"Removing {failed_patch.parent.full_file_path()}(:{failed_patch.counter}); " | ||
| f" it failed to apply/was not rewritten.") | ||
| os.remove(failed_patch.parent.full_file_path()) | ||
|
|
||
|
Comment on lines
376
to
+382
Contributor
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. Critical: File deletion logic has multiple bugs that can cause data loss and runtime errors. Several issues with this implementation:
Proposed fix: Track parents that were successfully rewritten and use unique paths+ # Get parents that were successfully rewritten
+ successful_parents = set(patch_files_by_parent.keys())
+
+ # Collect unique parent file paths that should be deleted (only if ALL patches failed)
+ parents_to_delete = set()
FAILED_PATCHES = [one_patch for one_patch in VALID_PATCHES if (not one_patch.applied_ok) or (one_patch.rewritten_patch is None)]
for failed_patch in FAILED_PATCHES:
- log.warning(
- f"Removing {failed_patch.parent.full_file_path()}(:{failed_patch.counter}); "
- f" it failed to apply/was not rewritten.")
- os.remove(failed_patch.parent.full_file_path())
-
+ # Only delete if this parent had no successfully rewritten patches
+ if failed_patch.parent not in successful_parents:
+ parents_to_delete.add(failed_patch.parent)
+
+ for parent in parents_to_delete:
+ log.warning(f"Removing {parent.full_file_path()}; all patches failed to apply/were not rewritten.")
+ os.remove(parent.full_file_path())🤖 Prompt for AI Agents |
||
|
|
||
| # Create markdown about the patches | ||
| readme_markdown: "str | None" = None | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.
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.
Critical: Duplicate file deletion attempts will crash the script.
This code will attempt to delete the same patch file multiple times if that file contains multiple patches (mbox format) that both fail to apply or weren't rewritten. The second
os.remove()call will raise aFileNotFoundError, terminating the script.Additionally, there's no error handling around
os.remove(), so any deletion failure (permissions, file locked, etc.) will also crash the script.🐛 Proposed fix: deduplicate parent files and add error handling
📝 Committable suggestion
🤖 Prompt for AI Agents
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.
@rpardini Is this concern real?
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.
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.
I don't see it like that.