@@ -101,6 +101,7 @@ struct ContainerDeployment {
101101 address : engine:: Address ,
102102}
103103
104+ #[ derive( Clone ) ]
104105struct LeftoverDatabase {
105106 root : PathBuf ,
106107 /// Sorted, exactly as offered: the only set a confirmation may remove.
@@ -1248,7 +1249,7 @@ fn reset_leftover_database_with(
12481249 containers : & [ String ] ,
12491250 confirmed : bool ,
12501251 read_secrets : impl FnOnce ( ) -> Result < stack:: Secrets , Problem > ,
1251- reset : impl FnOnce ( & engine :: Address , & stack:: Secrets ) -> Result < ( ) , Problem > ,
1252+ reset : impl FnOnce ( & LeftoverDatabase , & stack:: Secrets ) -> Result < ( ) , Problem > ,
12521253) -> Result < ( ) , Problem > {
12531254 if !confirmed {
12541255 return Err ( Problem :: plain (
@@ -1278,20 +1279,21 @@ fn reset_leftover_database_with(
12781279 names
12791280 } ;
12801281 let ( volumes, containers) = ( sorted ( volumes) , sorted ( containers) ) ;
1281- let address = shell. leftover_database . lock ( ) . unwrap ( ) . as_ref ( )
1282+ // The removal receives the offer itself, so it can only remove the set this check matched.
1283+ let offer = shell. leftover_database . lock ( ) . unwrap ( ) . as_ref ( )
12821284 . filter ( |offer| {
12831285 offer. root == root
12841286 && !volumes. is_empty ( )
12851287 && offer. volumes == volumes
12861288 && offer. containers == containers
12871289 } )
1288- . map ( |offer| offer . address . clone ( ) )
1290+ . cloned ( )
12891291 . ok_or_else ( || Problem :: plain ( "The leftover data reset offer is no longer current. Try Start again before confirming a reset." ) ) ?;
12901292 let secrets = read_secrets ( ) ?;
12911293 if !fresh_root_without_encryption_key ( root, & secrets) ? {
12921294 return Err ( Problem :: plain ( "This installation is already configured or has its original encryption key. Its data cannot be reset here." ) ) ;
12931295 }
1294- reset ( & address , & secrets) ?;
1296+ reset ( & offer , & secrets) ?;
12951297 * shell. leftover_database . lock ( ) . unwrap ( ) = None ;
12961298 Ok ( ( ) )
12971299}
@@ -1310,7 +1312,7 @@ async fn reset_leftover_database<R: tauri::Runtime>(
13101312 & shell,
13111313 & root,
13121314 & volumes,
1313- & [ ] ,
1315+ & containers ,
13141316 confirmed,
13151317 || {
13161318 openbot_desktop_lib:: vault:: already_given_no_ui (
@@ -1319,8 +1321,14 @@ async fn reset_leftover_database<R: tauri::Runtime>(
13191321 & openbot_env:: MINTED [ ..] ,
13201322 )
13211323 } ,
1322- |address, secrets| {
1323- stack:: reset_leftover_volumes ( address, & root, secrets, & volumes, & containers)
1324+ |offer, secrets| {
1325+ stack:: reset_leftover_volumes (
1326+ & offer. address ,
1327+ & root,
1328+ secrets,
1329+ & offer. volumes ,
1330+ & offer. containers ,
1331+ )
13241332 } ,
13251333 )
13261334}
@@ -5425,7 +5433,11 @@ mod tests {
54255433 & containers,
54265434 true ,
54275435 || Ok ( stack:: Secrets :: new ( ) ) ,
5428- |_, _| Ok ( ( ) ) ,
5436+ |offer, _| {
5437+ assert_eq ! ( offer. volumes, offered, "removal gets the confirmed volumes" ) ;
5438+ assert_eq ! ( offer. containers, containers, "and the confirmed containers" ) ;
5439+ Ok ( ( ) )
5440+ } ,
54295441 )
54305442 . unwrap ( ) ;
54315443 assert ! ( shell. leftover_database. lock( ) . unwrap( ) . is_none( ) ) ;
@@ -5639,8 +5651,8 @@ mod tests {
56395651 & [ ] ,
56405652 true ,
56415653 || Ok ( stack:: Secrets :: new( ) ) ,
5642- |address , _| {
5643- assert_eq!( address, & original) ;
5654+ |offer , _| {
5655+ assert_eq!( offer . address, original) ;
56445656 Err ( unavailable. clone( ) )
56455657 }
56465658 ) ,
@@ -5653,9 +5665,9 @@ mod tests {
56535665 & [ ] ,
56545666 true ,
56555667 || Ok ( stack:: Secrets :: new ( ) ) ,
5656- |address , _| {
5657- assert_eq ! ( address, & original) ;
5658- let command = address. command ( ) ;
5668+ |offer , _| {
5669+ assert_eq ! ( offer . address, original) ;
5670+ let command = offer . address . command ( ) ;
56595671 let arguments: Vec < _ > = command. get_args ( ) . collect ( ) ;
56605672 assert_eq ! ( arguments, [ "--connection" , "original-machine" ] ) ;
56615673 Ok ( ( ) )
@@ -5744,12 +5756,12 @@ mod tests {
57445756 & [ ] ,
57455757 false ,
57465758 || Ok ( secrets. clone( ) ) ,
5747- |address , secrets| stack:: reset_leftover_volumes(
5748- address,
5759+ |offer , secrets| stack:: reset_leftover_volumes(
5760+ & offer . address,
57495761 & root,
57505762 secrets,
5751- & volumes,
5752- & [ ]
5763+ & offer . volumes,
5764+ & offer . containers
57535765 )
57545766 )
57555767 . is_err( ) ) ;
@@ -5763,8 +5775,14 @@ mod tests {
57635775 & [ ] ,
57645776 true ,
57655777 || Ok ( secrets. clone ( ) ) ,
5766- |address, secrets| {
5767- stack:: reset_leftover_volumes ( address, & root, secrets, & volumes, & [ ] )
5778+ |offer, secrets| {
5779+ stack:: reset_leftover_volumes (
5780+ & offer. address ,
5781+ & root,
5782+ secrets,
5783+ & offer. volumes ,
5784+ & offer. containers ,
5785+ )
57685786 } ,
57695787 )
57705788 . unwrap ( ) ;
0 commit comments