@@ -105,16 +105,22 @@ def _resolve_callback(body_cb: Optional[CallbackIn], request: Request) -> dict:
105105 }
106106
107107
108- def _archive_subtrees (emulator , memory_card_synced : bool ) -> tuple [str , ...]:
109- """The save subtrees this session ships in its archive.
108+ def _archive_subtrees (
109+ emulator , memory_card_synced : bool
110+ ) -> tuple [tuple [str , ...], tuple [str , ...]]:
111+ """The save subtrees this session ships, and the ones it leaves alone.
110112
111113 With the whole card synced, leaving it in the archive too would have the
112114 restore and the card hydrate writing over each other, and a stale card
113115 inside an older archive would land on top of the one RomM just laid down.
116+ The excluded set is returned rather than simply dropped because archives
117+ RomM took before the card was synced still carry it, and a restore has to
118+ pass those members over instead of refusing the whole archive.
114119 """
115120 if not memory_card_synced or emulator .memory_card_subtree is None :
116- return emulator .save_subtrees
117- return tuple (s for s in emulator .save_subtrees if s != emulator .memory_card_subtree )
121+ return emulator .save_subtrees , ()
122+ card = emulator .memory_card_subtree
123+ return tuple (s for s in emulator .save_subtrees if s != card ), (card ,)
118124
119125
120126@router .get ("/api/health" )
@@ -174,7 +180,9 @@ async def activate(
174180 await anyio .to_thread .run_sync (emulator .clear_working_slot )
175181 restore_report = None
176182 save = body .save
177- subtrees = _archive_subtrees (emulator , bool (save and save .memory_card_synced ))
183+ subtrees , excluded = _archive_subtrees (
184+ emulator , bool (save and save .memory_card_synced )
185+ )
178186 if save and save .archive and subtrees :
179187 archive_path = Path (save .archive )
180188 if not archive_path .is_file ():
@@ -184,7 +192,11 @@ async def activate(
184192 content = await anyio .to_thread .run_sync (archive_path .read_bytes )
185193 await anyio .to_thread .run_sync (emulator .prepare_restore )
186194 restore_report = await anyio .to_thread .run_sync (
187- saves .extract_save_archive , content , emulator .save_root , subtrees
195+ saves .extract_save_archive ,
196+ content ,
197+ emulator .save_root ,
198+ subtrees ,
199+ excluded ,
188200 )
189201 if restore_report ["error" ]:
190202 raise HTTPException (
@@ -252,12 +264,13 @@ async def _do_exit(save_slot: int) -> dict:
252264 emulator = sess ["emulator_obj" ]
253265 exit_report = await anyio .to_thread .run_sync (emulator .save_and_exit , save_slot )
254266
267+ dump_subtrees , _ = _archive_subtrees (
268+ emulator , bool ((sess .get ("save" ) or {}).get ("memory_card_synced" ))
269+ )
255270 dump = await anyio .to_thread .run_sync (
256271 saves .build_save_archive ,
257272 emulator .save_root ,
258- _archive_subtrees (
259- emulator , bool ((sess .get ("save" ) or {}).get ("memory_card_synced" ))
260- ),
273+ dump_subtrees ,
261274 sess ["save_baseline" ],
262275 )
263276 cb = sess .get ("callback" )
0 commit comments