forked from semios/packie
fix: remove still works after inputting n
Signed-off-by: sisungo <[email protected]>
This commit is contained in:
+33
-6
@@ -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<String> {
|
||||
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<String> {
|
||||
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")),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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!(
|
||||
|
||||
+13
-3
@@ -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(())
|
||||
|
||||
+9
-16
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -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);
|
||||
|
||||
+7
-13
@@ -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(())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user