fix: clean up tobe_clone directory on all error paths in clone()#837
Merged
Merged
Conversation
Code Metrics Report
Details | | main (576d783) | #837 (0a9c1c4) | +/- |
|---------------------|----------------|----------------|-------|
- | Coverage | 71.0% | 70.8% | -0.2% |
| Files | 18 | 18 | 0 |
| Lines | 1919 | 1930 | +11 |
+ | Covered | 1364 | 1368 | +4 |
| Code to Test Ratio | 1:0.0 | 1:0.0 | 0.0 |
| Code | 2493 | 2504 | +11 |
| Test | 0 | 0 | 0 |
+ | Test Execution Time | 12s | 11s | -1s |Code coverage of files in pull request scope (78.7% → 70.6%)
Reported by octocov |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fix resource lifecycle leak in
clonefunction where the pre-createdtobe_clonedirectory was not cleaned up on error paths.Changes
src/app/clone.rsFour error paths in the
clonefunction now remove the pre-createdtobe_clonedirectory before returning:git clonefails:inspect_errremovestobe_clonebefore propagating the error.link_to.parent()isNone:tobe_cloneis explicitly removed before returning the error.create_dir_all(link_parent)fails:map_errremovestobe_clonebefore wrapping and propagating the error.unix_fs::symlinkfails:tobe_cloneis explicitly removed before returning the error.Also refactored the
parentbinding from a borrowedlet Some(parent) = tobe_clone.parent()to an ownedPathBuf(.to_path_buf()) to avoid borrow conflicts with the cleanup closures that need to hold a reference totobe_clone.Test plan
cargo testpassestobe_cloneis cleaned up