From: Ian Jackson Date: Sat, 15 May 2021 22:39:47 +0000 (+0100) Subject: library listing: Provide for listing libs on the server side X-Git-Tag: otter-0.6.0~250 X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=commitdiff_plain;h=70235a30e6b65340929e3a9e208cc15121bad67a;p=otter.git library listing: Provide for listing libs on the server side Signed-off-by: Ian Jackson --- diff --git a/daemon/cmdlistener.rs b/daemon/cmdlistener.rs index a6036493..9f29763a 100644 --- a/daemon/cmdlistener.rs +++ b/daemon/cmdlistener.rs @@ -349,6 +349,25 @@ fn execute_and_respond(cs: &mut CommandStreamData, cmd: MgmtCommand, Fine } + MC::LibraryListLibraries { game } => { + let (ag, gref) = start_access_game(&game)?; + let (libs, _auth) = + access_bundles( + cs,&ag,&gref, &[TP::UploadBundles], + &mut |ig, _| Ok( + ig.all_shapelibs() + .iter() + .map(|reg| reg.iter()) + .flatten() + .map(|ll| ll.iter()) + .flatten() + .map(|l| l.enquiry()) + .collect::>() + ) + )?; + MR::Libraries(libs) + } + MC::LibraryListByGlob { game, glob: spec } => { let (ag, gref) = start_access_game(&game)?; let (results, _auth) = diff --git a/src/commands.rs b/src/commands.rs index 166b5d9f..6c02d48c 100644 --- a/src/commands.rs +++ b/src/commands.rs @@ -54,6 +54,9 @@ pub enum MgmtCommand { id: bundles::Id, }, + LibraryListLibraries { + game: InstanceName, + }, LibraryListByGlob { game: InstanceName, glob: shapelib::ItemSpec, @@ -90,6 +93,7 @@ pub enum MgmtResponse { AlterGame { error: Option, responses: Vec }, AccountsList(Vec>), GamesList(Vec>), + Libraries(Vec), LibraryItems(Vec), Bundles { bundles: MgmtBundleList }, } diff --git a/src/mgmtchannel.rs b/src/mgmtchannel.rs index ef41428d..0edb7470 100644 --- a/src/mgmtchannel.rs +++ b/src/mgmtchannel.rs @@ -91,7 +91,7 @@ impl MgmtChannel { match &resp { Progress(_) => panic!(), Fine | AccountsList{..} | GamesList{..} | - LibraryItems(_) | Bundles{..} => { }, + Libraries(_) | LibraryItems(_) | Bundles{..} => { }, AlterGame { error: None, .. } => { }, Error { error } => { Err(error.clone()).context( diff --git a/src/shapelib.rs b/src/shapelib.rs index b0ef0898..c68cee13 100644 --- a/src/shapelib.rs +++ b/src/shapelib.rs @@ -236,6 +236,23 @@ impl Display for ItemEnquiryData { } } +#[derive(Debug,Clone,Serialize,Deserialize,Eq,PartialEq,Ord,PartialOrd)] +pub struct LibraryEnquiryData { + pub libname: String, +} +impl Display for LibraryEnquiryData { + #[throws(fmt::Error)] + fn fmt(&self, f: &mut Formatter) { + if self.libname.chars().all(|c| { + c.is_alphanumeric() || c=='-' || c=='_' || c=='.' + }) { + Display::fmt(&self.libname, f)?; + } else { + Debug::fmt(&self.libname, f)?; + } + } +} + #[dyn_upcast] impl OutlineTrait for Item { delegate! { to self.outline { fn outline_path(&self, scale: f64) -> Result; @@ -354,6 +371,10 @@ impl Registry { pub fn clear(&mut self) { self.libs.clear() } + + pub fn iter(&self) -> impl Iterator { + self.libs.values().map(|v| v.as_slice()) + } } pub struct AllRegistries<'ig> { @@ -405,6 +426,11 @@ pub fn lib_name_list(ig: &Instance) -> Vec { } impl<'ig> AllRegistries<'ig> { + pub fn all_libs(&self) -> impl Iterator { + self.iter().map(|reg| ®.libs).flatten().map( + |(_libname, lib)| lib.as_slice() + ) + } pub fn lib_name_lookup(&self, libname: &str) -> Result<&[Contents], SpE> { for reg in self.iter() { if let Some(r) = reg.libs.get(libname) { return Ok(r) } @@ -551,6 +577,12 @@ impl Contents { (Box::new(it), occultable) } + pub fn enquiry(&self) -> LibraryEnquiryData { + LibraryEnquiryData { + libname: self.libname.clone(), + } + } + #[throws(MgmtError)] pub fn list_glob(&self, pat: &str) -> Vec { let pat = glob::Pattern::new(pat).map_err(|pe| ME::BadGlob {