feat: basic card setup

This commit is contained in:
2025-02-25 19:27:37 +00:00
parent 43fd622322
commit 1586f81152
12 changed files with 140 additions and 69 deletions

View File

@ -37,8 +37,8 @@ impl PackageStore {
}
}
pub fn get(&self, key: PkgKey) -> Result<&Package> {
self.store.get(&key)
pub fn get(&self, key: &PkgKey) -> Result<&Package> {
self.store.get(key)
.ok_or_else(|| anyhow!("Invalid package key"))
}
@ -49,7 +49,7 @@ impl PackageStore {
pub async fn reload_package(&mut self, key: PkgKey) {
let dir = util::pkg_dir().join(&key.0);
if let Ok(pkg) = Package::from_dir(dir).await {
self.update_package(key, pkg);
self.update_nonremote(key, pkg);
} else {
log::error!("couldn't reload {}", key);
}
@ -68,7 +68,7 @@ impl PackageStore {
while let Some(res) = futures.join_next().await {
if let Ok(Ok(pkg)) = res {
self.update_package(pkg.key(), pkg);
self.update_nonremote(pkg.key(), pkg);
}
}
@ -203,10 +203,11 @@ impl PackageStore {
}
}
fn update_package(&mut self, key: PkgKey, mut new: Package) {
if let Some(old) = self.store.get(&key) {
new.rmt = old.rmt.clone();
fn update_nonremote(&mut self, key: PkgKey, mut new: Package) {
if let Some(old) = self.store.remove(&key) {
new.rmt = old.rmt;
}
self.store.insert(key, new);
}