Skip to content

fix(upgrade): clean temporary directories on failure - #104

Open
Kewe63 wants to merge 1 commit into
Polymarket:mainfrom
Kewe63:fix/issue-93-upgrade-temp-cleanup
Open

Kewe63 wants to merge 1 commit into
Polymarket:mainfrom
Kewe63:fix/issue-93-upgrade-temp-cleanup

Conversation

@Kewe63

@Kewe63 Kewe63 commented Oct 25, 2026 •

Copy link
Copy Markdown

Summary

  • manage upgrade temporary directories with an RAII cleanup guard
  • remove temporary artifacts on success and every early failure path
  • add an offline regression for download failure cleanup

Problem

After mktemp succeeded, download, checksum, extraction, or replacement failures returned before the final cleanup call. Repeated failed upgrades could leave archives and extracted files behind.

Approach

A narrow TemporaryDirectory guard owns the created path and removes it in Drop. Cleanup therefore no longer depends on reaching the final installation step.

Tests

  • RED proof on the original implementation: forced download failure left the directory behind
  • GREEN offline integration regression using fake curl and mktemp
  • upgrade unit tests passed
  • cargo +1.91.1 fmt --check
  • cargo +1.91.1 clippy --locked -- -D warnings
  • git diff --check

Risk

Low. The change only centralizes cleanup ownership; download, verification, extraction, and replacement behavior remain unchanged.

Fixes #93


Note

Low Risk
Scope is limited to temp-dir lifecycle; download, checksum verification, extraction, and binary replacement logic are unchanged.

Overview
Fixes a leak where failed upgrade runs could leave mktemp directories and downloaded/extracted files on disk because cleanup only ran at the end of a successful install.

Upgrade now wraps the temp path in a TemporaryDirectory RAII guard whose Drop removes the directory, so cleanup happens on success and on any early exit (download, checksum, extract, or install errors). The explicit end-of-flow remove_dir_all is removed in favor of that guard.

Adds a Unix-only integration test that stubs curl and mktemp on PATH, forces a tarball download failure, and asserts the upgrade temp directory no longer exists.

Reviewed by Cursor Bugbot for commit d01a849. Bugbot is set up for automated code reviews on this repo. Configure here.

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.

[Bug]: Upgrade failures leave temporary directories behind

1 participant