Skip to content

fix: rename temp downloaded file to given cache path#332

Open
2bndy5 wants to merge 2 commits into
mainfrom
no-atomic-rename
Open

fix: rename temp downloaded file to given cache path#332
2bndy5 wants to merge 2 commits into
mainfrom
no-atomic-rename

Conversation

@2bndy5
Copy link
Copy Markdown
Collaborator

@2bndy5 2bndy5 commented Jun 6, 2026

resolves #330

This simply keeps the downloaded temp file in the same directory as the destination of the downloaded file. When download is done, the file is renamed to the specified file name.

This also removes the tempfile dependency from production code. It is still used heavily in tests.

Summary by CodeRabbit

  • Bug Fixes

    • Improved error handling for download operations with clearer, contextual messages when temporary file or filesystem operations fail.
  • Breaking Changes

    • The shape of download error reporting was changed; integrations that inspect specific download error variants may need updates.
  • Chores

    • Test/dev setup updated (added a dev dependency for temporary-file utilities) and CI triggers expanded to include installer-related files and manifests.

resolves #330

This simply keeps the downloaded temp file in the same directory as the destination of the downloaded file.
When download is done, the file is renamed to the specified file name.

This also removes the `tempfile` dependency from production code. It is still used heavily in tests.
@2bndy5 2bndy5 added the bug Something isn't working label Jun 6, 2026
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Jun 6, 2026

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: e5bb8a87-375b-4eb5-b9be-bc2641bf9636

📥 Commits

Reviewing files that changed from the base of the PR and between 636682e and 94a806c.

📒 Files selected for processing (2)
  • .github/workflows/run-dev-tests.yml
  • clang-installer/src/downloader/mod.rs
🚧 Files skipped from review as they are similar to previous changes (1)
  • clang-installer/src/downloader/mod.rs

Walkthrough

Refactors clang-installer download flow to write to a deterministic temp path and atomically persist via fs::rename while mapping IO errors to a new DownloadError::TempFile variant; adds tempfile to dev-dependencies and expands CI workflow path filters to include clang-installer/** and manifest files.

Changes

Temporary file handling refactor

Layer / File(s) Summary
Error type contract
clang-installer/src/downloader/mod.rs
DownloadError replaces TempFilePersistence(#[from] tempfile::PersistError) with TempFile(&'static str, #[source] std::io::Error).
Download file creation and finalization
clang-installer/src/downloader/mod.rs
Switches from tempfile::NamedTempFile to opening cache_path.with_extension("tmp") with fs::OpenOptions, writing chunks, setting modified time, dropping the handle, and persisting via fs::rename, mapping failures to the new error variant.
Development dependency for tests
clang-installer/Cargo.toml
Adds tempfile to [dev-dependencies] for test fixtures that require temporary files.

CI workflow trigger update

Layer / File(s) Summary
Workflow path filters
.github/workflows/run-dev-tests.yml
on.push.paths and on.pull_request.paths now include clang-installer/**, Cargo.toml, Cargo.lock, and the workflow file.

🎯 3 (Moderate) | ⏱️ ~20 minutes

  • Possibly related PRs:

Suggested labels: rust

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: refactoring temp file handling to rename temp files to the cache path instead of using cross-device atomic rename.
Linked Issues check ✅ Passed The code changes successfully implement the solution from issue #330: temp file is now created in the same directory as cache path and renamed after download, avoiding cross-device rename failures.
Out of Scope Changes check ✅ Passed All changes are directly related to issue #330: removing tempfile from production code, implementing deterministic temp path in cache directory, and updating CI workflow to test the installer crate.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch no-atomic-rename

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@clang-installer/src/downloader/mod.rs`:
- Line 61: The temp path creation uses cache_path.with_extension("tmp") which
replaces the last dot-segment and drops version info; instead construct
tmp_file_path by appending ".tmp" to the full file name (use
cache_path.file_name() to get the complete name and
cache_path.with_file_name(...) to build a new PathBuf), so the versioned
filenames like "clang-format-18.1.8" become "clang-format-18.1.8.tmp" and avoid
collisions; update the code that sets tmp_file_path accordingly (reference
tmp_file_path, cache_path.with_extension, cache_path.file_name,
cache_path.with_file_name).
- Around line 89-92: The temp file is not closed before fs::rename and is never
cleaned up on errors; modify the download flow around
tmp_file/tmp_file_path/cache_path so you drop/close tmp_file (e.g.,
drop(tmp_file) or let tmp_file go out of scope) before calling
fs::rename(cache_path) to avoid Windows share issues, and ensure the
tmp_file_path is removed on any error/early return (or replace the manual tmp
logic with tempfile::NamedTempFile and use its persist method to atomically move
into cache_path, mapping persist errors into DownloadError::TempFile); update
error handling paths to remove the *.tmp placeholder when failures occur.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 1aba07b3-51a5-4b15-a150-6c731e2ad05a

📥 Commits

Reviewing files that changed from the base of the PR and between 8e2fcad and 636682e.

📒 Files selected for processing (2)
  • clang-installer/Cargo.toml
  • clang-installer/src/downloader/mod.rs

Comment thread clang-installer/src/downloader/mod.rs
Comment thread clang-installer/src/downloader/mod.rs
run CI tests on installer crate too
@codecov
Copy link
Copy Markdown

codecov Bot commented Jun 6, 2026

Codecov Report

❌ Patch coverage is 84.61538% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 90.91%. Comparing base (8e2fcad) to head (94a806c).

Files with missing lines Patch % Lines
clang-installer/src/downloader/mod.rs 84.61% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #332      +/-   ##
==========================================
- Coverage   90.94%   90.91%   -0.04%     
==========================================
  Files          22       22              
  Lines        3368     3378      +10     
==========================================
+ Hits         3063     3071       +8     
- Misses        305      307       +2     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Error when installing clang tool on Linux (from PyPI)

1 participant