Skip to content

Use TempDir for copied lockfiles #20290

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

ShoyuVanilla
Copy link
Member

@ShoyuVanilla ShoyuVanilla commented Jul 23, 2025

Fixes #20189 and closes #20244 and fixes #20113

@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jul 23, 2025
@@ -156,6 +156,7 @@ smallvec = { version = "1.15.1", features = [
"const_generics",
] }
smol_str = "0.3.2"
temp-dir = "0.1.16"
Copy link
Member Author

Choose a reason for hiding this comment

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

I chose this crate because it uses short, safe Rust codes and has no deps

Copy link
Member

Choose a reason for hiding this comment

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

TIL temp-dir (besides tempdir, which is very popular, and tempfile, which is unmaintained).

_temp_dir_guard = temp_dir::TempDir::new().ok();
let target_lockfile = _temp_dir_guard
.and_then(|tmp| tmp.path().join("Cargo.lock").try_into().ok())
.unwrap_or_else(|| {
Copy link
Member Author

@ShoyuVanilla ShoyuVanilla Jul 23, 2025

Choose a reason for hiding this comment

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

I think failures on creating TempDir or converting it to Utf8PathBuf would be quite rare, but copied disambiguation from #20244 into this fallback anyway

// The manifest is a rust file, so this means its a script manifest
if let Some(lockfile) = lockfile_path {
let target_lockfile =
target_dir.join("rust-analyzer").join("metadata").join(kind).join("Cargo.lock");
_temp_dir_guard = temp_dir::TempDir::new().ok();
Copy link
Member

Choose a reason for hiding this comment

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

Should we set a prefix here?

Copy link
Member Author

Choose a reason for hiding this comment

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

I think it's not necessary but having one would be good to some curious people who look into their /tmp/. Do you have some recommendations for prefix string?

Copy link
Member

Choose a reason for hiding this comment

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

Something with rust-analyzer or r-a? :-)

Copy link
Member

Choose a reason for hiding this comment

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

We do have one for the proc-macro server already I think on windows (where we copy the proc macro dylibs)

Copy link
Member

Choose a reason for hiding this comment

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

Ah well, doesn't matter I guess as that is proc-macro specific

to.push("rust-analyzer-proc-macros");

Copy link
Member Author

Choose a reason for hiding this comment

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

Oh, I just found that we also have a RemoveFileOnDrop for Windows there as well 😅

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-review Status: Awaiting review from the assignee but also interested parties.
Projects
None yet
4 participants