Skip to content

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).

Copy link
Contributor

Choose a reason for hiding this comment

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

(besides tempdir, which is very popular, and tempfile, which is unmaintained).

I guess you wrote them reversed? Seems tempdir is the unmaintained one, and tempfile is the popular one.

_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 😅

Copy link
Member

Choose a reason for hiding this comment

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

Note as an aside but RemoveFileOnDrop shouldn't be a thing. Windows has file creation flags to mark them as to be deleted once all OS handles are dropped which we should be using instead I think.

@Veykril Veykril added this pull request to the merge queue Jul 27, 2025
Merged via the queue into rust-lang:master with commit b770720 Jul 27, 2025
15 checks passed
@rustbot rustbot removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jul 27, 2025
@ShoyuVanilla ShoyuVanilla deleted the tmp-lockfiles branch July 27, 2025 14:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
5 participants