@@ -928,6 +928,55 @@ fn snapshot_restore_records_its_source_and_starts_a_restore_of_it() {
928928 assert ! ( !state. exists( ) ) ;
929929}
930930
931+ /// `snapshot restore` refuses a share that reaches its snapshot store, whose files the view of
932+ /// each restore links, as every start of its sandbox would refuse it: before it records the
933+ /// sandbox, so that no provisioned sandbox stays behind, which a corrected restore into the same
934+ /// state directory would find provisioned.
935+ #[ test]
936+ fn snapshot_restore_refuses_a_share_of_its_snapshot_store_before_it_provisions ( ) {
937+ let fixture = Fixture :: new ( false ) ;
938+ let root = artifact_root ( & fixture. state ( "checkout" ) ) ;
939+ let layer = fixture. state ( "distro.erofs" ) ;
940+ fs:: write ( & layer, "distro" ) . unwrap ( ) ;
941+ let store = fixture. root . path ( ) . join ( "store" ) ;
942+ let state = fixture. state ( "command" ) ;
943+ // The store itself, and a directory inside it.
944+ for shared in [ store. clone ( ) , store. join ( "snapshots" ) ] {
945+ let arguments = [
946+ "restore" ,
947+ "source" ,
948+ "--store-dir" ,
949+ store. to_str ( ) . unwrap ( ) ,
950+ "--state-dir" ,
951+ state. to_str ( ) . unwrap ( ) ,
952+ "--layer" ,
953+ & format ! (
954+ "distro,{},11111111-1111-1111-1111-111111111111" ,
955+ layer. display( )
956+ ) ,
957+ "--upper" ,
958+ "ram" ,
959+ "--hypervisor" ,
960+ if cfg ! ( windows) { "whp" } else { "kvm" } ,
961+ "--mount" ,
962+ & format ! ( "/data,{},ro" , shared. display( ) ) ,
963+ ]
964+ . map ( str:: to_owned) ;
965+ let ( command, unrecognized) = snapshots:: parse ( & arguments) . unwrap ( ) ;
966+ assert ! ( unrecognized. is_empty( ) , "{unrecognized:?}" ) ;
967+ let error = snapshots:: run ( Some ( & root) , command) . unwrap_err ( ) ;
968+ assert_eq ! ( error. code( ) , Some ( ErrorCode :: Unsupported ) , "{error:?}" ) ;
969+ let message = error. message ( ) . unwrap_or_default ( ) ;
970+ assert ! (
971+ message. contains( "overlaps the sandbox's snapshot store" ) ,
972+ "{message}"
973+ ) ;
974+ assert ! ( !state. exists( ) , "{}" , shared. display( ) ) ;
975+ }
976+ assert ! ( fixture. snapshot_free( ) ) ;
977+ assert ! ( fixture. spawned( ) . is_empty( ) ) ;
978+ }
979+
931980/// `snapshot restore` refuses a hypervisor that this host's operating system cannot run, which
932981/// every start of its sandbox would fail on, before it opens the store or locks the snapshot, so
933982/// that it reports that refusal and leaves the store as it was, whatever the snapshot.
0 commit comments