@@ -204,35 +204,40 @@ fn cross_fs() -> crate::Result {
204
204
205
205
let top_level_repo = git_testtools:: scripted_fixture_repo_writable ( "make_basic_repo.sh" ) ?;
206
206
207
- // Create an empty dmg file
208
- let dmg_location = tempfile:: tempdir ( ) ?;
209
- let dmg_file = dmg_location. path ( ) . join ( "temp.dmg" ) ;
210
- Command :: new ( "hdiutil" )
211
- . args ( & [ "create" , "-size" , "1m" ] )
212
- . arg ( & dmg_file)
213
- . status ( ) ?;
214
-
215
- // Mount dmg file into temporary location
216
- let mount_point = tempfile:: tempdir ( ) ?;
217
- Command :: new ( "hdiutil" )
218
- . args ( & [ "attach" , "-nobrowse" , "-mountpoint" ] )
219
- . arg ( mount_point. path ( ) )
220
- . arg ( & dmg_file)
221
- . status ( ) ?;
207
+ let _cleanup = {
208
+ // Create an empty dmg file
209
+ let dmg_location = tempfile:: tempdir ( ) ?;
210
+ let dmg_file = dmg_location. path ( ) . join ( "temp.dmg" ) ;
211
+ Command :: new ( "hdiutil" )
212
+ . args ( & [ "create" , "-size" , "1m" ] )
213
+ . arg ( & dmg_file)
214
+ . status ( ) ?;
222
215
223
- // Ensure that the mount point is always cleaned up
224
- let defer_detach = defer :: defer ( || {
216
+ // Mount dmg file into temporary location
217
+ let mount_point = tempfile :: tempdir ( ) ? ;
225
218
Command :: new ( "hdiutil" )
226
- . arg ( "detach" )
219
+ . args ( & [ "attach" , "-nobrowse" , "-mountpoint" ] )
227
220
. arg ( mount_point. path ( ) )
228
- . status ( )
229
- . expect ( "detach temporary test dmg filesystem successfully" ) ;
230
- } ) ;
221
+ . arg ( & dmg_file)
222
+ . status ( ) ?;
231
223
232
- // Symlink the mount point into the repo
233
- symlink ( mount_point. path ( ) , top_level_repo. path ( ) . join ( "remote" ) ) ?;
224
+ // Ensure that the mount point is always cleaned up
225
+ let cleanup = defer:: defer ( {
226
+ let arg = mount_point. path ( ) . to_owned ( ) ;
227
+ move || {
228
+ Command :: new ( "hdiutil" )
229
+ . arg ( "detach" )
230
+ . arg ( arg)
231
+ . status ( )
232
+ . expect ( "detach temporary test dmg filesystem successfully" ) ;
233
+ }
234
+ } ) ;
235
+
236
+ // Symlink the mount point into the repo
237
+ symlink ( mount_point. path ( ) , top_level_repo. path ( ) . join ( "remote" ) ) ?;
238
+ cleanup
239
+ } ;
234
240
235
- // Disovery tests
236
241
let res = git_discover:: upwards ( top_level_repo. path ( ) . join ( "remote" ) )
237
242
. expect_err ( "the cross-fs option should prevent us from discovering the repo" ) ;
238
243
assert ! ( matches!(
@@ -258,9 +263,6 @@ fn cross_fs() -> crate::Result {
258
263
top_level_repo. path( ) . file_name( )
259
264
) ;
260
265
261
- // Cleanup
262
- drop ( defer_detach) ;
263
-
264
266
Ok ( ( ) )
265
267
}
266
268
0 commit comments