@@ -155,27 +155,32 @@ impl Compose {
155
155
Ok ( true ) => {
156
156
#[ cfg( unix) ]
157
157
let mut config = ComposeConfig :: parse ( & original_path) ?;
158
+ let temp_file: NamedTempFile ;
158
159
159
- // Inject the networks block
160
- config. networks . insert (
161
- "default" . to_string ( ) ,
162
- BTreeMap :: from_iter ( [ ( "name" . to_string ( ) , network. clone ( ) ) ] ) ,
163
- ) ;
164
-
165
- // Create a named tempfile, there may be resource leakage here in case of SIGINT
166
- // Tried tempfile::tempfile() but this returns a File object without a usable path
167
- // https://docs.rs/tempfile/latest/tempfile/#resource-leaking
168
- let temp_file = Builder :: new ( )
169
- . prefix ( "compose-temp-" )
170
- . suffix ( ".yaml" )
171
- . tempfile_in ( & test_dir)
172
- . with_context ( || "Failed to create temporary compose file" ) ?;
173
-
174
- fs:: write (
175
- temp_file. path ( ) ,
176
- serde_yaml:: to_string ( & config)
177
- . with_context ( || "Failed to serialize modified compose.yml" . to_string ( ) ) ?,
178
- ) ?;
160
+ #[ cfg( unix) ]
161
+ {
162
+ // Inject the networks block
163
+ config. networks . insert (
164
+ "default" . to_string ( ) ,
165
+ BTreeMap :: from_iter ( [ ( "name" . to_string ( ) , network. clone ( ) ) ] ) ,
166
+ ) ;
167
+
168
+ // Create a named tempfile, there may be resource leakage here in case of SIGINT
169
+ // Tried tempfile::tempfile() but this returns a File object without a usable path
170
+ // https://docs.rs/tempfile/latest/tempfile/#resource-leaking
171
+ temp_file = Builder :: new ( )
172
+ . prefix ( "compose-temp-" )
173
+ . suffix ( ".yaml" )
174
+ . tempfile_in ( & test_dir)
175
+ . with_context ( || "Failed to create temporary compose file" ) ?;
176
+
177
+ fs:: write (
178
+ temp_file. path ( ) ,
179
+ serde_yaml:: to_string ( & config) . with_context ( || {
180
+ "Failed to serialize modified compose.yml" . to_string ( )
181
+ } ) ?,
182
+ ) ?;
183
+ }
179
184
180
185
Ok ( Some ( Self {
181
186
original_path,
@@ -184,6 +189,7 @@ impl Compose {
184
189
#[ cfg( unix) ]
185
190
config,
186
191
network,
192
+ #[ cfg( unix) ]
187
193
temp_file,
188
194
} ) )
189
195
}
0 commit comments