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 {
69
69
& self . path
70
70
}
71
71
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 ( )
74
74
}
75
75
}
76
76
Original file line number Diff line number Diff line change @@ -122,7 +122,7 @@ impl Tool {
122
122
. into ( ) ,
123
123
} ) ?;
124
124
125
- let tmp =
125
+ let mut tmp =
126
126
NamedTempfile :: new ( & out_dir, "detect_compiler_family.c" ) . map_err ( |err| Error {
127
127
kind : ErrorKind :: IOError ,
128
128
message : format ! (
@@ -132,8 +132,13 @@ impl Tool {
132
132
)
133
133
. into ( ) ,
134
134
} ) ?;
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) ;
137
142
138
143
let stdout = run_output (
139
144
Command :: new ( path) . arg ( "-E" ) . arg ( tmp. path ( ) ) ,
You can’t perform that action at this time.
0 commit comments