Skip to content
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

Avoid deleting temporary files on error #75315

Merged
merged 1 commit into from
Aug 11, 2020

Conversation

Mark-Simulacrum
Copy link
Member

Previously if the compiler error'd, fatally, then temporary directories which
should be preserved by -Csave-temps would be deleted due to fatal compiler
errors being implemented as panics.

cc @infinity0

(Hopefully) fixes #75275, but I haven't tested

@rust-highfive
Copy link
Collaborator

r? @ecstatic-morse

(rust_highfive has picked a reviewer for you, use r? to override)

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Aug 9, 2020
@Mark-Simulacrum
Copy link
Member Author

@bors try

This'll generate linux artifacts which hopefully @infinity0 can test with

@bors
Copy link
Contributor

bors commented Aug 9, 2020

⌛ Trying commit 74427e8870e6d11c9d726dae8f4aeb336a58e32a with merge 7d10458b44a5240ee001ce5e62ba6bc1460022fb...

@bors
Copy link
Contributor

bors commented Aug 9, 2020

☀️ Try build successful - checks-actions, checks-azure
Build commit: 7d10458b44a5240ee001ce5e62ba6bc1460022fb (7d10458b44a5240ee001ce5e62ba6bc1460022fb)

Copy link
Contributor

@ecstatic-morse ecstatic-morse left a comment

Choose a reason for hiding this comment

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

r=me with nits fixed or alternatives suggested (an extension trait for TempDir with a cleanup(bool) method would be cool). It seems the other places where save_temps is checked don't use RAII to manage the temporary build artifacts.

// This is `None` if the directory should not be deleted; used for
// -Csave-temps. We don't just pass around a PathBuf to keep type safety
// (only creating files in temporary locations).
dir: Option<TempDirReal>,
Copy link
Contributor

Choose a reason for hiding this comment

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

This is a tad convoluted. Why not ManuallyDrop<TempDirReal> alongside a boolean flag?

.prefix("rustc")
.tempdir()
.unwrap_or_else(|err| sess.fatal(&format!("couldn't create a temp dir: {}", err)));
let path = TempDir::new(tmpdir, sess.opts.cg.save_temps);
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we use a different name for this? MaybeTempDir or something? The boolean argument to new is surprising if you're used to tempfile::TempDir.

Previously if the compiler error'd, fatally, then temporary directories which
should be preserved by -Csave-temps would be deleted due to fatal compiler
errors being implemented as panics.
@Mark-Simulacrum
Copy link
Member Author

Yes, I also checked the other places where we use save_temps for potential problems with RAII. I would've liked a way to ensure that we don't add more, but I think that'll be hard.

Fixed both comments; I also filed an issue upstream asking if we can get this implemented in the tempfile crate itself.

@bors r=ecstatic-morse

@bors
Copy link
Contributor

bors commented Aug 9, 2020

📌 Commit 2627eed has been approved by ecstatic-morse

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Aug 9, 2020
fn drop(&mut self) {
// Safety: We are in the destructor, and no further access will
// occur.
let dir = unsafe { ManuallyDrop::take(&mut self.dir) };
Copy link
Contributor

Choose a reason for hiding this comment

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

No need for unsafe. Just drop(self.dir.into_inner()) if keep is false.

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh NVM, we can't move out of it in the destructor. I would probably have done this with ManuallyDrop::drop, but that's also unsafe.

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 considered that, but then we need to have two unsafe blocks I think - one for the into_path case, with take, the other with drop. Seems more complicated.

Copy link
Contributor

Choose a reason for hiding this comment

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

...otherwise we leak the PathBuf inside TempDir. Whoops. I'm all caught up now.

bors added a commit to rust-lang-ci/rust that referenced this pull request Aug 11, 2020
Rollup of 10 pull requests

Successful merges:

 - rust-lang#75098 (Clippy pointer cast lint experiment)
 - rust-lang#75249 (Only add a border for the rust logo)
 - rust-lang#75315 (Avoid deleting temporary files on error)
 - rust-lang#75316 (Don't try to use wasm intrinsics on vectors)
 - rust-lang#75337 (instance: only polymorphize upvar substs)
 - rust-lang#75339 (evaluate required_consts when pushing stack frame in Miri engine)
 - rust-lang#75363 (Use existing `infcx` when emitting trait impl diagnostic)
 - rust-lang#75366 (Add help button)
 - rust-lang#75369 (Move to intra-doc links in /library/core/src/borrow.rs)
 - rust-lang#75379 (Use intra-doc links in /library/core/src/cmp.rs)

Failed merges:

r? @ghost
@bors bors merged commit 992988b into rust-lang:master Aug 11, 2020
@cuviper cuviper added this to the 1.47.0 milestone May 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

-Csave-temps=on doesn't actually save anything
5 participants