File tree Expand file tree Collapse file tree 2 files changed +10
-5
lines changed Expand file tree Collapse file tree 2 files changed +10
-5
lines changed Original file line number Diff line number Diff line change @@ -69,8 +69,8 @@ impl NamedTempfile {
6969 & self . path
7070 }
7171
72- pub ( super ) fn file ( & self ) -> & File {
73- self . file . as_ref ( ) . unwrap ( )
72+ pub ( super ) fn take_file ( & mut self ) -> Option < File > {
73+ self . file . take ( )
7474 }
7575}
7676
Original file line number Diff line number Diff line change @@ -122,7 +122,7 @@ impl Tool {
122122 . into ( ) ,
123123 } ) ?;
124124
125- let tmp =
125+ let mut tmp =
126126 NamedTempfile :: new ( & out_dir, "detect_compiler_family.c" ) . map_err ( |err| Error {
127127 kind : ErrorKind :: IOError ,
128128 message : format ! (
@@ -132,8 +132,13 @@ impl Tool {
132132 )
133133 . into ( ) ,
134134 } ) ?;
135- tmp. file ( )
136- . write_all ( include_bytes ! ( "detect_compiler_family.c" ) ) ?;
135+ let mut tmp_file = tmp. take_file ( ) . unwrap ( ) ;
136+ tmp_file. write_all ( include_bytes ! ( "detect_compiler_family.c" ) ) ?;
137+ // Close the file handle *now*, otherwise the compiler may fail to open it on Windows
138+ // (#1082). The file stays on disk and its path remains valid until `tmp` is dropped.
139+ tmp_file. flush ( ) ?;
140+ tmp_file. sync_data ( ) ?;
141+ drop ( tmp_file) ;
137142
138143 let stdout = run_output (
139144 Command :: new ( path) . arg ( "-E" ) . arg ( tmp. path ( ) ) ,
You can’t perform that action at this time.
0 commit comments