chiark / gitweb /
bundles: Save the bundle list in the ig for ready access
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Mon, 3 May 2021 16:15:46 +0000 (17:15 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Mon, 3 May 2021 16:15:46 +0000 (17:15 +0100)
Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
daemon/cmdlistener.rs
src/bundles.rs
src/global.rs

index 9fdb5166d2259370273408618494eeb59235a594..3a80418abb922b5c4ad620baad936090a461cb93 100644 (file)
@@ -243,12 +243,10 @@ fn execute_and_respond<R,W>(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 } => {
index e131d7a529c22045b892cbdd61c2b40fe7e7dc00..703a25fddf48ee5a1ab2eb266ec456d43760ae4f 100644 (file)
@@ -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 }
   }
 }
index 0d4e2bd468405363eebda6d0b2f7eb2e159d989e..c35a7d5c1770a2b3c207fed852a3fe45ecd52e25 100644 (file)
@@ -56,6 +56,7 @@ pub struct Instance {
   pub tokens_clients: TokenRegistry<ClientId>,
   pub acl: LoadedAcl<TablePermission>,
   pub links: Arc<LinksTable>,
+  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)?;