}
MC::LibraryListByGlob { glob: spec } => {
- let lib = shapelib::libs_lookup(&spec.lib)?;
- let results = lib.list_glob(&spec.item)?;
+ let libs = shapelib::lib_name_lookup(&spec.lib)?;
+ let mut results: Vec<shapelib::ItemEnquiryData> = default();
+ for lib in &*libs {
+ results.extend(lib.list_glob(&spec.item)?);
+ }
MR::LibraryItems(results)
}
load(&vec![tlibs.clone()])?;
}
let mut items: Vec<ItemForOutput> = default();
- for lib in libs_list() {
- let contents = libs_lookup(&lib)?;
- for pat in opts.items.split(SPLIT) {
- for item in contents.list_glob(pat)? {
- items.push((lib.clone(), item))
+ for lib in lib_name_list() {
+ for contents in &*lib_name_lookup(&lib)? {
+ for pat in opts.items.split(SPLIT) {
+ for item in contents.list_glob(pat)? {
+ items.push((lib.clone(), item))
+ }
}
}
}
#[derive(Default)]
pub struct Registry {
- libs: HashMap<String, shapelib::Contents>,
+ libs: HashMap<String, Vec<shapelib::Contents>>,
}
#[derive(Debug)]
static SHAPELIBS: RwLock<Option<Registry>> = const_rwlock(None);
-pub fn libs_list() -> Vec<String> {
+pub fn lib_name_list() -> Vec<String> {
let reg = SHAPELIBS.read();
reg.as_ref().map(
|reg| reg.libs.keys().cloned().collect()
}
#[throws(SpecError)]
-pub fn libs_lookup(libname: &str)
- -> MappedRwLockReadGuard<'static, Contents> {
+pub fn lib_name_lookup(libname: &str)
+ -> MappedRwLockReadGuard<'static, [Contents]> {
let reg = SHAPELIBS.read();
RwLockReadGuard::try_map( reg, |reg: &Option<Registry>| -> Option<_> {
(|| Some({
reg.as_ref()?.libs.get(libname)?
+ .as_slice()
}))()
})
.map_err(|_| SpE::LibraryNotFound)
impl ItemSpec {
#[throws(SpecError)]
pub fn find_load(&self, pcaliases: &PieceAliases) -> ItemSpecLoaded {
- let lib = libs_lookup(&self.lib)?;
- let idata = lib.items.get(&self.item)
+ let libs = lib_name_lookup(&self.lib)?;
+ let (lib, idata) = libs.iter().rev().find_map(
+ |lib| Some((lib, lib.items.get(&self.item)?))
+ )
.ok_or(SpE::LibraryItemNotFound(self.clone()))?;
lib.load1(idata, &self.lib, &self.item, pcaliases)?
}
SHAPELIBS.write()
.get_or_insert_with(default)
.libs
- .insert(l.name.clone(), data);
+ .entry(l.name.clone()).or_default()
+ .push(data);
info!("loaded {} shapes in library {:?} from {:?} and {:?}",
count, &l.name, &l.catalogue, &l.dirname);
}