Skip to content

fix: clean up tobe_clone directory on all error paths in clone()#837

Merged
kitsuyui merged 1 commit into
mainfrom
fix/audit-resource-lifecycle-clone-dir-leak-001
May 27, 2026
Merged

fix: clean up tobe_clone directory on all error paths in clone()#837
kitsuyui merged 1 commit into
mainfrom
fix/audit-resource-lifecycle-clone-dir-leak-001

Conversation

@kitsuyui

Copy link
Copy Markdown
Owner

Summary

Fix resource lifecycle leak in clone function where the pre-created tobe_clone directory was not cleaned up on error paths.

Changes

  • File changed: src/app/clone.rs

Four error paths in the clone function now remove the pre-created tobe_clone directory before returning:

  1. If git clone fails: inspect_err removes tobe_clone before propagating the error.
  2. If link_to.parent() is None: tobe_clone is explicitly removed before returning the error.
  3. If create_dir_all(link_parent) fails: map_err removes tobe_clone before wrapping and propagating the error.
  4. If unix_fs::symlink fails: tobe_clone is explicitly removed before returning the error.

Also refactored the parent binding from a borrowed let Some(parent) = tobe_clone.parent() to an owned PathBuf (.to_path_buf()) to avoid borrow conflicts with the cleanup closures that need to hold a reference to tobe_clone.

Test plan

  • cargo test passes
  • Simulate a clone failure (e.g., invalid URL) and verify no orphaned directory is left behind
  • Simulate a symlink failure and verify tobe_clone is cleaned up

@github-actions

Copy link
Copy Markdown

Code Metrics Report

main (576d783) #837 (0a9c1c4) +/-
Coverage 71.0% 70.8% -0.2%
Code to Test Ratio 1:0.0 1:0.0 0.0
Test Execution Time 12s 11s -1s
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%)

Files Coverage +/- Status
src/app/clone.rs 70.6% -8.1% modified

Reported by octocov

@kitsuyui
kitsuyui merged commit 49fbebe into main May 27, 2026
16 checks passed
@kitsuyui
kitsuyui deleted the fix/audit-resource-lifecycle-clone-dir-leak-001 branch May 27, 2026 12:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant