@@ -359,8 +359,7 @@ impl<'a> GitCheckout<'a> {
359359 ///
360360 /// [`.cargo-ok`]: CHECKOUT_READY_LOCK
361361 fn reset ( & self , gctx : & GlobalContext ) -> CargoResult < ( ) > {
362- let ok_file = self . path . join ( CHECKOUT_READY_LOCK ) ;
363- let _ = paths:: remove_file ( & ok_file) ;
362+ let guard = CheckoutGuard :: guard ( & self . path ) ;
364363 info ! ( "reset {} to {}" , self . repo. path( ) . display( ) , self . revision) ;
365364
366365 // Ensure libgit2 won't mess with newlines when we vendor.
@@ -370,7 +369,8 @@ impl<'a> GitCheckout<'a> {
370369
371370 let object = self . repo . find_object ( self . revision , None ) ?;
372371 reset ( & self . repo , & object, gctx) ?;
373- paths:: create ( ok_file) ?;
372+
373+ guard. mark_ok ( ) ?;
374374 Ok ( ( ) )
375375 }
376376
@@ -479,6 +479,25 @@ impl<'a> GitCheckout<'a> {
479479 }
480480}
481481
482+ /// See [`GitCheckout::reset`] for rationale on this type.
483+ #[ must_use]
484+ struct CheckoutGuard {
485+ ok_file : PathBuf ,
486+ }
487+
488+ impl CheckoutGuard {
489+ fn guard ( path : & Path ) -> Self {
490+ let ok_file = path. join ( CHECKOUT_READY_LOCK ) ;
491+ let _ = paths:: remove_file ( & ok_file) ;
492+ Self { ok_file }
493+ }
494+
495+ fn mark_ok ( self ) -> CargoResult < ( ) > {
496+ let _ = paths:: create ( self . ok_file ) ?;
497+ Ok ( ( ) )
498+ }
499+ }
500+
482501/// Constructs an absolute URL for a child submodule URL with its parent base URL.
483502///
484503/// Git only assumes a submodule URL is a relative path if it starts with `./`
0 commit comments