From: Ian Jackson Date: Mon, 3 May 2021 16:15:46 +0000 (+0100) Subject: bundles: Save the bundle list in the ig for ready access X-Git-Tag: otter-0.6.0~435 X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=commitdiff_plain;h=391332dd5b751ea93879d01dcef8fd701188b159;p=otter.git bundles: Save the bundle list in the ig for ready access Signed-off-by: Ian Jackson --- diff --git a/daemon/cmdlistener.rs b/daemon/cmdlistener.rs index 9fdb5166..3a80418a 100644 --- a/daemon/cmdlistener.rs +++ b/daemon/cmdlistener.rs @@ -243,12 +243,10 @@ fn execute_and_respond(cs: &mut CommandStreamData, cmd: MgmtCommand, MC::ListBundles { game } => { let ag = AccountsGuard::lock(); let gref = Instance::lookup_by_name_unauth(&game)?; - let bundles = gref.lock_bundles(); let mut igu = gref.lock()?; - let (_ig, auth) = cs.check_acl(&ag, &mut igu, PCH::Instance, - TP_ACCESS_BUNDLES)?; - let bundles = bundles.by(auth); - let bundles = bundles.list(); + let (ig, _) = cs.check_acl(&ag, &mut igu, PCH::Instance, + TP_ACCESS_BUNDLES)?; + let bundles = ig.bundle_list.clone(); MR::Bundles { bundles } } MC::DownloadBundle { game, id } => { diff --git a/src/bundles.rs b/src/bundles.rs index e131d7a5..703a25fd 100644 --- a/src/bundles.rs +++ b/src/bundles.rs @@ -182,7 +182,8 @@ fn load_bundle(ib: &mut InstanceBundles, ig: &mut Instance, Err(LoadError::IE(ie)) => throw!(ie), }; - *slot = Some(Note { kind: id.kind, state }) + *slot = Some(Note { kind: id.kind, state }); + ib.update_mgmt_list(ig); } #[throws(IncorporateError)] @@ -211,8 +212,8 @@ impl InstanceBundles { }) } - pub fn list(&self) -> MgmtBundleList { - self.iter().map(|(id, state)| { + fn update_mgmt_list(&self, ig: &mut Instance) { + ig.bundle_list = self.iter().map(|(id, state)| { (id, state.clone()) }).collect() } @@ -241,6 +242,7 @@ impl InstanceBundles { } } debug!("loaded bundles {} {:?}", &ig.name, ib); + ib.update_mgmt_list(ig); ib } @@ -274,6 +276,7 @@ impl InstanceBundles { let file = BufWriter::new(file); let file = DigestWrite::new(file); let instance = ig.name.clone(); + self.update_mgmt_list(ig); Uploading { file, instance, id } } } diff --git a/src/global.rs b/src/global.rs index 0d4e2bd4..c35a7d5c 100644 --- a/src/global.rs +++ b/src/global.rs @@ -56,6 +56,7 @@ pub struct Instance { pub tokens_clients: TokenRegistry, pub acl: LoadedAcl, pub links: Arc, + pub bundle_list: MgmtBundleList, // copy for easy access } pub struct PlayerRecord { @@ -343,6 +344,7 @@ impl Instance { tokens_players: default(), tokens_clients: default(), links: default(), + bundle_list: default(), }; let c = InstanceContainer { @@ -1155,6 +1157,7 @@ impl InstanceGuard<'_> { clients: default(), tokens_clients: default(), tokens_players: default(), + bundle_list: default(), // set by load_game_bundles }; let b = InstanceBundles::load_game_bundles(&mut g)?;