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

Fix warning with tempfile #11771

Merged
merged 1 commit into from
Feb 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/cargo/ops/cargo_install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ impl<'cfg, 'a> InstallablePackage<'cfg, 'a> {
let compile = ops::compile_ws(&self.ws, &self.opts, &exec).with_context(|| {
if let Some(td) = td_opt.take() {
// preserve the temporary directory, so the user can inspect it
td.into_path();
drop(td.into_path());
}

format!(
Expand Down
39 changes: 39 additions & 0 deletions tests/testsuite/install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,16 @@

use std::fs::{self, OpenOptions};
use std::io::prelude::*;
use std::path::Path;

use cargo_test_support::compare;
use cargo_test_support::cross_compile;
use cargo_test_support::git;
use cargo_test_support::registry::{self, registry_path, Package};
use cargo_test_support::{
basic_manifest, cargo_process, no_such_file_err_msg, project, project_in, symlink_supported, t,
};
use cargo_util::ProcessError;

use cargo_test_support::install::{
assert_has_installed_exe, assert_has_not_installed_exe, cargo_home,
Expand Down Expand Up @@ -2103,3 +2106,39 @@ fn no_auto_fix_note() {
.run();
assert_has_not_installed_exe(cargo_home(), "auto_fix");
}

#[cargo_test]
fn failed_install_retains_temp_directory() {
// Verifies that the temporary directory persists after a build failure.
Package::new("foo", "0.0.1")
.file("src/main.rs", "x")
.publish();
let err = cargo_process("install foo").exec_with_output().unwrap_err();
let err = err.downcast::<ProcessError>().unwrap();
let stderr = String::from_utf8(err.stderr.unwrap()).unwrap();
compare::match_contains(
"\
[UPDATING] `dummy-registry` index
[DOWNLOADING] crates ...
[DOWNLOADED] foo v0.0.1 (registry `dummy-registry`)
[INSTALLING] foo v0.0.1
[COMPILING] foo v0.0.1
",
&stderr,
None,
)
.unwrap();
compare::match_contains(
"error: failed to compile `foo v0.0.1`, intermediate artifacts can be found at `[..]`",
&stderr,
None,
)
.unwrap();

// Find the path in the output.
let start = stderr.find("found at `").unwrap() + 10;
let end = stderr[start..].find('\n').unwrap() - 1;
let path = Path::new(&stderr[start..(end + start)]);
assert!(path.exists());
assert!(path.join("release/deps").exists());
}