From 459074237f34b316fcf0ffa31f66d9d41342fd86 Mon Sep 17 00:00:00 2001 From: sisungo Date: Mon, 6 Jul 2026 15:25:51 +0800 Subject: [PATCH] fix: remove still works after inputting n Signed-off-by: sisungo --- cli/src/print.rs | 39 +++++++++++++++++++++++++++++++++------ cli/src/remove.rs | 1 + cli/src/update.rs | 16 +++++++++++++--- src/install.rs | 25 +++++++++---------------- src/package.rs | 2 +- src/remove.rs | 20 +++++++------------- 6 files changed, 64 insertions(+), 39 deletions(-) diff --git a/cli/src/print.rs b/cli/src/print.rs index be03ede..d34daa7 100644 --- a/cli/src/print.rs +++ b/cli/src/print.rs @@ -8,12 +8,39 @@ pub struct Cli { } pub fn main(cli: Cli) -> anyhow::Result<()> { - let packie = PackieBuilder::new().readonly(true).build()?; - match &cli.key[..] { - "profile.host_arch" => { - println!("{}", packie.profile().host_arch); - Ok(()) - } + let key: Vec<&str> = cli.key.split('.').collect(); + let result = match key.get(0).copied().unwrap() { + "profile" => profile(&key[1..]), + "package" => package(&key[1..]), unknown => Err(anyhow!("unknown key {unknown} to print")), + }; + println!("{}", result?); + Ok(()) +} + +fn profile(other: &[&str]) -> anyhow::Result { + let packie = PackieBuilder::new().readonly(true).build()?; + match other { + ["host_arch"] => Ok(packie.profile().host_arch.clone()), + _ => Err(anyhow!("unsupported profile key")), + } +} + +fn package(other: &[&str]) -> anyhow::Result { + let mut packie = PackieBuilder::new().readonly(true).build()?; + match other { + ["prefix", ..] => { + let mut found = packie.search_installation(&other[1..].join(".").parse()?)?; + if found.is_empty() { + return Err(anyhow!("package not found")); + } + Ok(packie + .profile() + .pkg_dir + .join(found.remove(0).pkg_manifest.pkg_ident().to_string()) + .to_string_lossy() + .into()) + } + _ => Err(anyhow!("unsupported profile key")), } } diff --git a/cli/src/remove.rs b/cli/src/remove.rs index ccc47ec..9b92fe4 100644 --- a/cli/src/remove.rs +++ b/cli/src/remove.rs @@ -31,6 +31,7 @@ pub fn main(cli: Cli) -> anyhow::Result<()> { println!("y"); } else if !yesno(&t!("remove.confirm_removal")) { println!("{}", t!("remove.aborting")); + return Ok(()); } for i in packages { println!( diff --git a/cli/src/update.rs b/cli/src/update.rs index 4da6279..f856d27 100644 --- a/cli/src/update.rs +++ b/cli/src/update.rs @@ -15,9 +15,19 @@ pub fn main(cli: Cli) -> anyhow::Result<()> { progress_bar.set_length(progress.total_bytes); progress_bar.set_position(progress.downloaded_bytes); } - SyncEvent::Error(repo, url, err) => { - eprintln!("failed to sync repository: {err}") - } + SyncEvent::Error(repo, url, err) => match (repo, url) { + (Some(repo), Some(url)) => { + progress_bar.println(format!( + "failed to update repository \"{repo}\" from \"{url}\": {err}" + )); + } + (Some(repo), None) => { + progress_bar.println(format!("failed to update repository \"{repo}\": {err}")); + } + _ => { + progress_bar.println(format!("failed to update repositories: {err}")); + } + }, }) .run(); Ok(()) diff --git a/src/install.rs b/src/install.rs index 63cfa6d..ccf3679 100644 --- a/src/install.rs +++ b/src/install.rs @@ -90,30 +90,28 @@ impl super::Packie { ) -> Result<(), InstallError> { // Collect necessary information let pkg_manifest = package.manifest()?; + let pkg_ident = pkg_manifest.pkg_ident(); let installed_size = package.installed_size()?; let install_pkgspec = options .install_pkgspec .clone() - .unwrap_or_else(|| default_install_pkgspec(pkg_manifest.pkg_ident())); + .unwrap_or_else(|| default_install_pkgspec(pkg_ident.clone())); // Check if the package is previously installed if !self - .search_installation(&pkg_manifest.pkg_ident().into())? + .search_installation(&pkg_ident.clone().into())? .is_empty() { return Err(InstallError::AlreadyInstalled); } // Check if the package spec is valid - if !install_pkgspec.matches(&pkg_manifest.pkg_ident()) { + if !install_pkgspec.matches(&pkg_ident) { return Err(InstallError::PkgSpec); } // Copy package files - let dest_dir = self - .profile - .pkg_dir - .join(pkg_manifest.pkg_ident().to_string()); + let dest_dir = self.profile.pkg_dir.join(pkg_ident.to_string()); crate::common::copy_dir(package.bundle_dir(), dest_dir).map_err(InstallError::Copy)?; // Record installation in the database @@ -129,18 +127,13 @@ impl super::Packie { // Record abstract package provision in the database for i in installation.pkg_manifest.provides.iter() { - self.local_db - .insert_abspkg(&i, &installation.pkg_manifest.pkg_ident())?; + self.local_db.insert_abspkg(&i, &pkg_ident)?; } // Copy links file if let Some(links) = package.links() { - std::fs::copy( - &links.0, - self.local_data - .links_file(&installation.pkg_manifest.pkg_ident()), - ) - .map_err(|err| InstallError::Database(Box::new(err)))?; + std::fs::copy(&links.0, self.local_data.links_file(&pkg_ident)) + .map_err(|err| InstallError::Database(Box::new(err)))?; } // Enable default links @@ -152,7 +145,7 @@ impl super::Packie { if !linkdes.default { continue; } - _ = crate::link::activate_by_description(self, &pkg_manifest.pkg_ident(), &linkdes); + _ = crate::link::activate_by_description(self, &pkg_ident, &linkdes); } } diff --git a/src/package.rs b/src/package.rs index 3941f1a..783638a 100644 --- a/src/package.rs +++ b/src/package.rs @@ -184,7 +184,7 @@ impl FromStr for PkgSpec { if chars.peek() == Some(&'@') { chars.next(); let mut arch_str = String::new(); - while let Some(&c) = chars.peek() { + while chars.peek().is_some() { arch_str.push(chars.next().unwrap()); } arch = Some(arch_str); diff --git a/src/remove.rs b/src/remove.rs index c7a799d..998bab5 100644 --- a/src/remove.rs +++ b/src/remove.rs @@ -15,39 +15,33 @@ impl super::Packie { } assert_eq!(found.len(), 1); let found = found.remove(0); + let pkg_ident = found.pkg_manifest.pkg_ident(); // Remove all links - let links = LinksFile(self.local_data.links_file(&found.pkg_manifest.pkg_ident())); + let links = LinksFile(self.local_data.links_file(&pkg_ident)); if let Ok(links) = links.iter() { for link in links { let Ok(link) = link else { continue; }; - _ = crate::link::deactivate_by_description( - self, - &found.pkg_manifest.pkg_ident(), - &link, - ); + _ = crate::link::deactivate_by_description(self, &pkg_ident, &link); } } // Remove package files - let bundle_dir = self - .profile - .pkg_dir - .join(found.pkg_manifest.pkg_ident().to_string()); + let bundle_dir = self.profile.pkg_dir.join(pkg_ident.to_string()); std::fs::remove_dir_all(&bundle_dir).map_err(RemoveError::RemoveFiles)?; // Remove database records self.local_db - .remove_installation(&found.pkg_manifest.pkg_ident()) + .remove_installation(&pkg_ident) .map_err(RemoveError::Database)?; self.local_db - .remove_abspkg_provided_by(&found.pkg_manifest.pkg_ident()) + .remove_abspkg_provided_by(&pkg_ident) .map_err(RemoveError::Database)?; // Remove the links file - _ = std::fs::remove_file(self.local_data.links_file(&found.pkg_manifest.pkg_ident())); + _ = std::fs::remove_file(self.local_data.links_file(&pkg_ident)); Ok(()) }