Skip to content
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
4 changes: 2 additions & 2 deletions src/tempfile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ impl NamedTempfile {
&self.path
}

pub(super) fn file(&self) -> &File {
self.file.as_ref().unwrap()
pub(super) fn take_file(&mut self) -> Option<File> {
self.file.take()
}
}

Expand Down
11 changes: 8 additions & 3 deletions src/tool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ impl Tool {
.into(),
})?;

let tmp =
let mut tmp =
NamedTempfile::new(&out_dir, "detect_compiler_family.c").map_err(|err| Error {
kind: ErrorKind::IOError,
message: format!(
Expand All @@ -132,8 +132,13 @@ impl Tool {
)
.into(),
})?;
tmp.file()
.write_all(include_bytes!("detect_compiler_family.c"))?;
let mut tmp_file = tmp.take_file().unwrap();
tmp_file.write_all(include_bytes!("detect_compiler_family.c"))?;
// Close the file handle *now*, otherwise the compiler may fail to open it on Windows
// (#1082). The file stays on disk and its path remains valid until `tmp` is dropped.
tmp_file.flush()?;
tmp_file.sync_data()?;
drop(tmp_file);

let stdout = run_output(
Command::new(path).arg("-E").arg(tmp.path()),
Expand Down