feat(breaking): rename abspkg to concept
Signed-off-by: sisungo <[email protected]>
This commit is contained in:
1 parent
3ba1638f3c
commit
41bf2214ee
11 files changed
+101
-87
No files matched your search
+10
-22
@@ -1,8 +1,7 @@
|
||||
use std::{fmt::Display, path::PathBuf};
|
||||
|
||||
use chrono::{Local, TimeZone};
|
||||
use console::{Term, style};
|
||||
use indicatif::{ProgressBar, ProgressStyle};
|
||||
use dialoguer::Confirm;
|
||||
use indicatif::{HumanBytes, ProgressBar, ProgressStyle};
|
||||
use packie::{
|
||||
Packie,
|
||||
local::Installation,
|
||||
@@ -10,6 +9,7 @@ use packie::{
|
||||
repo::{DownloadPackageEvent, RepoPackage},
|
||||
};
|
||||
use rust_i18n::t;
|
||||
use std::{fmt::Display, path::PathBuf};
|
||||
use tabled::{
|
||||
Table, Tabled,
|
||||
settings::{Style, Width},
|
||||
@@ -41,19 +41,12 @@ pub fn progress_style_multidownload() -> ProgressStyle {
|
||||
}
|
||||
|
||||
pub fn yesno(prompt: &str, default: bool) -> bool {
|
||||
if default {
|
||||
eprint!("{prompt} [Y/n] ");
|
||||
} else {
|
||||
eprint!("{prompt} [y/N] ");
|
||||
}
|
||||
let line = std::io::stdin()
|
||||
.lines()
|
||||
.next()
|
||||
.transpose()
|
||||
Confirm::new()
|
||||
.with_prompt(prompt)
|
||||
.default(default)
|
||||
.wait_for_newline(true)
|
||||
.interact()
|
||||
.unwrap_or_default()
|
||||
.unwrap_or_default();
|
||||
let line = line.trim();
|
||||
["y", "Y"].contains(&line) || (line.is_empty() && default)
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
@@ -103,13 +96,8 @@ pub fn print_summary(summary: Vec<SummaryItem>) {
|
||||
println!("{}", table);
|
||||
}
|
||||
|
||||
pub fn format_size(bytes: u64) -> String {
|
||||
match bytes {
|
||||
..1000 => format!("{bytes} B"),
|
||||
..1_000_000 => format!("{} kB", bytes / 1000),
|
||||
..1_000_000_000 => format!("{:.2} MB", (bytes as f64) / 1000000.),
|
||||
_ => format!("{:.3} GB", (bytes as f64) / 1000000000.),
|
||||
}
|
||||
pub fn format_size(bytes: u64) -> impl Display {
|
||||
HumanBytes(bytes)
|
||||
}
|
||||
|
||||
pub fn format_datetime(timestamp: i64) -> String {
|
||||
|
||||
+1
-1
@@ -60,7 +60,7 @@ fn print_pkgmanifest(pkg_manifest: &PkgManifest) {
|
||||
println!(
|
||||
"{}: {}",
|
||||
t!("info.print_pkgmanifest.description"),
|
||||
pkg_manifest.arch
|
||||
pkg_manifest.description
|
||||
);
|
||||
}
|
||||
if !pkg_manifest.maintainers.is_empty() {
|
||||
|
||||
+19
-3
@@ -1,6 +1,8 @@
|
||||
use crate::common::{SummaryItem, print_summary, search_unique_package, yesno};
|
||||
use anyhow::anyhow;
|
||||
use clap::Parser;
|
||||
use console::style;
|
||||
use indicatif::ProgressBar;
|
||||
use packie::{PackieBuilder, package::PkgSpec};
|
||||
use rust_i18n::t;
|
||||
|
||||
@@ -19,6 +21,10 @@ pub fn main(cli: Cli) -> Result<(), crate::Error> {
|
||||
packages.push(search_unique_package(&mut packie, &pkgspec)?);
|
||||
}
|
||||
|
||||
if packages.is_empty() {
|
||||
Err(anyhow!("{}", t!("remove.no_packages_to_remove")))?;
|
||||
}
|
||||
|
||||
let summary = packages
|
||||
.iter()
|
||||
.map(|x| SummaryItem {
|
||||
@@ -37,14 +43,24 @@ pub fn main(cli: Cli) -> Result<(), crate::Error> {
|
||||
println!("{}", t!("remove.aborting"));
|
||||
return Ok(());
|
||||
}
|
||||
for i in packages {
|
||||
|
||||
let nr_packages = packages.len();
|
||||
let progress_bar = ProgressBar::new(nr_packages as _);
|
||||
|
||||
for (c, i) in packages.into_iter().enumerate() {
|
||||
println!(
|
||||
"{}",
|
||||
t!("remove.action_hint", package = i.pkg_manifest.pkg_ident())
|
||||
"[{}/{}] {}",
|
||||
c + 1,
|
||||
nr_packages,
|
||||
t!(
|
||||
"remove.action_hint",
|
||||
package = style(i.pkg_manifest.pkg_ident()).red()
|
||||
),
|
||||
);
|
||||
packie
|
||||
.remove(&i.pkg_manifest.pkg_ident().into())
|
||||
.map_err(|error| anyhow!("{}", t!("remove.action_failure", error = error)))?;
|
||||
progress_bar.inc(1);
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
@@ -99,7 +99,6 @@ pub fn main(cli: Cli) -> Result<(), crate::Error> {
|
||||
pkg = style(&package.install_pkgspec).green(),
|
||||
)
|
||||
));
|
||||
progress_bar.println(format!("Installing \"{}\"...", package.install_pkgspec));
|
||||
|
||||
let mut options = InstallOptions::default();
|
||||
options.auto_installed = package.auto_installed;
|
||||
|
||||
@@ -68,9 +68,9 @@ upgrade.removing_hint:
|
||||
zh-CN: "正在移除 \"%{pkg}\"..."
|
||||
ja: "「%{pkg}」を削除しています..."
|
||||
upgrade.installing_hint:
|
||||
en: "Installing \"%{pkgspec}\"..."
|
||||
zh-CN: "正在安装 \"%{pkgspec}\"..."
|
||||
ja: "「%{pkgspec}」をインストールしています..."
|
||||
en: "Installing \"%{pkg}\"..."
|
||||
zh-CN: "正在安装 \"%{pkg}\"..."
|
||||
ja: "「%{pkg}」をインストールしています..."
|
||||
info.no_package_found:
|
||||
en: "The specified package was not found."
|
||||
zh-CN: "找不到指定的包。"
|
||||
@@ -147,6 +147,10 @@ remove.action_hint:
|
||||
en: "Removing package %{package} ..."
|
||||
zh-CN: "正在移除包 %{package} ..."
|
||||
ja: "パッケージ %{package} を削除中 ..."
|
||||
remove.no_packages_to_remove:
|
||||
en: "No packages specified to remove."
|
||||
zh-CN: "未指定要移除的包。"
|
||||
ja: "削除するパッケージが指定されていません。"
|
||||
common.progress_style.speed:
|
||||
en: "Speed: "
|
||||
zh-CN: "速度:"
|
||||
|
||||
+5
-5
@@ -69,11 +69,11 @@ impl super::Packie {
|
||||
|
||||
// Check if the package spec is valid
|
||||
let real_matches = install_pkgspec.matches(&pkg_ident);
|
||||
let abstract_matches = pkg_manifest
|
||||
let concept_matches = pkg_manifest
|
||||
.provides
|
||||
.iter()
|
||||
.any(|x| install_pkgspec.abstract_matches(x));
|
||||
if !(real_matches || abstract_matches) {
|
||||
.any(|x| install_pkgspec.concept_matches(x));
|
||||
if !(real_matches || concept_matches) {
|
||||
return Err(InstallError::PkgSpec);
|
||||
}
|
||||
|
||||
@@ -115,9 +115,9 @@ impl super::Packie {
|
||||
self.local_db.insert_dependency(&pkg_ident, &pkg_ident_b)?;
|
||||
}
|
||||
|
||||
// Record abstract package provision in the database
|
||||
// Record concept provision in the database
|
||||
for i in installation.pkg_manifest.provides.iter() {
|
||||
self.local_db.insert_abspkg(&i, &pkg_ident)?;
|
||||
self.local_db.insert_concept(&i, &pkg_ident)?;
|
||||
}
|
||||
|
||||
// Copy links file
|
||||
|
||||
+23
-23
@@ -1,5 +1,5 @@
|
||||
use crate::{
|
||||
package::{AbsPkgIdent, PkgIdent, PkgManifest, PkgSpec},
|
||||
package::{ConceptIdent, PkgIdent, PkgManifest, PkgSpec},
|
||||
version::VersionFilter,
|
||||
};
|
||||
use itertools::Itertools;
|
||||
@@ -25,11 +25,11 @@ impl super::Packie {
|
||||
if !matches!(pkgspec.version, VersionFilter::Any) {
|
||||
return Ok(real);
|
||||
}
|
||||
let abspkg = AbsPkgIdent {
|
||||
let concept = ConceptIdent {
|
||||
name: pkgspec.name.clone(),
|
||||
arch: pkgspec.arch.clone(),
|
||||
};
|
||||
let abs = self.local_db.select_abspkg_by_ident(&abspkg)?;
|
||||
let abs = self.local_db.select_concept_by_ident(&concept)?;
|
||||
for (_, provider) in abs {
|
||||
real.push(self.local_db.select_installation_by_ident(&provider)?);
|
||||
}
|
||||
@@ -129,9 +129,9 @@ CREATE TABLE IF NOT EXISTS "dependency"(
|
||||
"pkg_ident_a" TEXT NOT NULL,
|
||||
"pkg_ident_b" TEXT NOT NULL
|
||||
);
|
||||
CREATE TABLE IF NOT EXISTS "abspkg"(
|
||||
CREATE TABLE IF NOT EXISTS "concept"(
|
||||
"id" INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
"abspkg_ident" TEXT NOT NULL,
|
||||
"concept_ident" TEXT NOT NULL,
|
||||
"provider" TEXT NOT NULL
|
||||
);
|
||||
"#;
|
||||
@@ -187,14 +187,14 @@ CREATE TABLE IF NOT EXISTS "abspkg"(
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn insert_abspkg(
|
||||
pub fn insert_concept(
|
||||
&mut self,
|
||||
abspkg: &AbsPkgIdent,
|
||||
concept_ident: &ConceptIdent,
|
||||
provider: &PkgIdent,
|
||||
) -> rusqlite::Result<()> {
|
||||
self.0
|
||||
.prepare_cached(r#"INSERT INTO "abspkg"("abspkg_ident", "provider") VALUES(?1, ?2)"#)?
|
||||
.execute(params![abspkg.to_string(), provider.to_string()])?;
|
||||
.prepare_cached(r#"INSERT INTO "concept"("concept_ident", "provider") VALUES(?1, ?2)"#)?
|
||||
.execute(params![concept_ident.to_string(), provider.to_string()])?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -222,19 +222,19 @@ CREATE TABLE IF NOT EXISTS "abspkg"(
|
||||
"#)?.query_one(params![pkg_ident.name, pkg_ident.version.to_string(), pkg_ident.arch], map_installation)
|
||||
}
|
||||
|
||||
pub fn select_abspkg_by_ident(
|
||||
pub fn select_concept_by_ident(
|
||||
&mut self,
|
||||
ident: &AbsPkgIdent,
|
||||
) -> rusqlite::Result<Vec<(AbsPkgIdent, PkgIdent)>> {
|
||||
ident: &ConceptIdent,
|
||||
) -> rusqlite::Result<Vec<(ConceptIdent, PkgIdent)>> {
|
||||
let mut stmt = self
|
||||
.0
|
||||
.prepare_cached(r#"SELECT * FROM "abspkg" WHERE "abspkg_ident" = ?1"#)?;
|
||||
let rows = stmt.query_map(params![ident.to_string()], map_abspkg)?;
|
||||
let mut abspkg = Vec::new();
|
||||
.prepare_cached(r#"SELECT * FROM "concept" WHERE "concept_ident" = ?1"#)?;
|
||||
let rows = stmt.query_map(params![ident.to_string()], map_concept)?;
|
||||
let mut concept = Vec::new();
|
||||
for i in rows {
|
||||
abspkg.push(i?);
|
||||
concept.push(i?);
|
||||
}
|
||||
Ok(abspkg)
|
||||
Ok(concept)
|
||||
}
|
||||
|
||||
/// Selects all package that the provided package depends on.
|
||||
@@ -292,9 +292,9 @@ CREATE TABLE IF NOT EXISTS "abspkg"(
|
||||
.map(|x| x > 0)
|
||||
}
|
||||
|
||||
pub fn remove_abspkg_provided_by(&mut self, provider: &PkgIdent) -> rusqlite::Result<bool> {
|
||||
pub fn remove_concept_provided_by(&mut self, provider: &PkgIdent) -> rusqlite::Result<bool> {
|
||||
self.0
|
||||
.prepare_cached(r#"DELETE FROM "abspkg" WHERE "provider" = ?1"#)?
|
||||
.prepare_cached(r#"DELETE FROM "concept" WHERE "provider" = ?1"#)?
|
||||
.execute(params![provider.to_string()])
|
||||
.map(|x| x > 0)
|
||||
}
|
||||
@@ -368,16 +368,16 @@ fn map_installation(row: &Row) -> rusqlite::Result<Installation> {
|
||||
})
|
||||
}
|
||||
|
||||
fn map_abspkg(row: &Row) -> rusqlite::Result<(AbsPkgIdent, PkgIdent)> {
|
||||
fn map_concept(row: &Row) -> rusqlite::Result<(ConceptIdent, PkgIdent)> {
|
||||
let provider = row
|
||||
.get::<_, String>("provider")?
|
||||
.parse()
|
||||
.map_err(from_sql_error)?;
|
||||
let abspkg_name = row
|
||||
.get::<_, String>("abspkg_ident")?
|
||||
let concept = row
|
||||
.get::<_, String>("concept_ident")?
|
||||
.parse()
|
||||
.map_err(from_sql_error)?;
|
||||
Ok((abspkg_name, provider))
|
||||
Ok((concept, provider))
|
||||
}
|
||||
|
||||
fn from_sql_error<E: std::error::Error + Send + Sync + 'static>(error: E) -> rusqlite::Error {
|
||||
|
||||
+7
-7
@@ -94,9 +94,9 @@ pub struct PkgManifest {
|
||||
#[serde(default)]
|
||||
pub recommendations: Vec<PkgSpec>,
|
||||
|
||||
/// Provided abstract packages.
|
||||
/// Provided concepts.
|
||||
#[serde(default)]
|
||||
pub provides: Vec<AbsPkgIdent>,
|
||||
pub provides: Vec<ConceptIdent>,
|
||||
}
|
||||
impl PkgManifest {
|
||||
pub const FILENAME: &str = "PkgManifest.json";
|
||||
@@ -139,7 +139,7 @@ impl PkgSpec {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn abstract_matches(&self, ident: &AbsPkgIdent) -> bool {
|
||||
pub fn concept_matches(&self, ident: &ConceptIdent) -> bool {
|
||||
self.name == ident.name && self.arch == ident.arch
|
||||
}
|
||||
}
|
||||
@@ -295,11 +295,11 @@ impl FromStr for PkgIdent {
|
||||
crate::impl_serde_str!(PkgIdent);
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||
pub struct AbsPkgIdent {
|
||||
pub struct ConceptIdent {
|
||||
pub name: String,
|
||||
pub arch: Option<String>,
|
||||
}
|
||||
impl Display for AbsPkgIdent {
|
||||
impl Display for ConceptIdent {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
match &self.arch {
|
||||
Some(arch) => write!(f, "{}@{}", self.name, arch),
|
||||
@@ -307,7 +307,7 @@ impl Display for AbsPkgIdent {
|
||||
}
|
||||
}
|
||||
}
|
||||
impl FromStr for AbsPkgIdent {
|
||||
impl FromStr for ConceptIdent {
|
||||
type Err = std::convert::Infallible;
|
||||
|
||||
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
||||
@@ -321,7 +321,7 @@ impl FromStr for AbsPkgIdent {
|
||||
})
|
||||
}
|
||||
}
|
||||
crate::impl_serde_str!(AbsPkgIdent);
|
||||
crate::impl_serde_str!(ConceptIdent);
|
||||
|
||||
#[derive(Debug, thiserror::Error)]
|
||||
pub enum ParseError {
|
||||
|
||||
+1
-1
@@ -58,7 +58,7 @@ impl super::Packie {
|
||||
.remove_installation(&pkg_ident)
|
||||
.map_err(RemoveError::Database)?;
|
||||
self.local_db
|
||||
.remove_abspkg_provided_by(&pkg_ident)
|
||||
.remove_concept_provided_by(&pkg_ident)
|
||||
.map_err(RemoveError::Database)?;
|
||||
self.local_db
|
||||
.remove_dependency_by_a(&pkg_ident)
|
||||
|
||||
+26
-19
@@ -8,7 +8,7 @@ pub use serve::RepoServeDir;
|
||||
|
||||
use crate::{
|
||||
Packie,
|
||||
package::{AbsPkgIdent, PkgIdent, PkgManifest, PkgSpec},
|
||||
package::{ConceptIdent, PkgIdent, PkgManifest, PkgSpec},
|
||||
};
|
||||
use download::Download;
|
||||
use itertools::Itertools;
|
||||
@@ -105,9 +105,9 @@ CREATE TABLE IF NOT EXISTS "package"(
|
||||
"checksum" TEXT NOT NULL,
|
||||
PRIMARY KEY ("pkg_name", "pkg_version", "pkg_arch")
|
||||
);
|
||||
CREATE TABLE IF NOT EXISTS "abspkg"(
|
||||
CREATE TABLE IF NOT EXISTS "concept"(
|
||||
"id" INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
"abspkg_ident" TEXT NOT NULL,
|
||||
"concept_ident" TEXT NOT NULL,
|
||||
"provider" TEXT NOT NULL
|
||||
);
|
||||
"#;
|
||||
@@ -164,14 +164,14 @@ CREATE TABLE IF NOT EXISTS "abspkg"(
|
||||
Ok(ret)
|
||||
}
|
||||
|
||||
pub fn select_abspkg_by_ident(
|
||||
pub fn select_concept_by_ident(
|
||||
&mut self,
|
||||
ident: &AbsPkgIdent,
|
||||
) -> rusqlite::Result<Vec<(AbsPkgIdent, PkgIdent)>> {
|
||||
ident: &ConceptIdent,
|
||||
) -> rusqlite::Result<Vec<(ConceptIdent, PkgIdent)>> {
|
||||
let mut stmt = self
|
||||
.conn
|
||||
.prepare_cached(r#"SELECT * FROM "abspkg" WHERE "abspkg_ident" = ?1"#)?;
|
||||
let rows = stmt.query_map(params![ident.to_string()], map_abspkg)?;
|
||||
.prepare_cached(r#"SELECT * FROM "concept" WHERE "concept_ident" = ?1"#)?;
|
||||
let rows = stmt.query_map(params![ident.to_string()], map_concept)?;
|
||||
let mut ret = Vec::with_capacity(16);
|
||||
for row in rows {
|
||||
ret.push(row?);
|
||||
@@ -218,10 +218,14 @@ CREATE TABLE IF NOT EXISTS "abspkg"(
|
||||
.map(|_| ())
|
||||
}
|
||||
|
||||
pub fn insert_abspkg(&mut self, abs: &AbsPkgIdent, real: &PkgIdent) -> rusqlite::Result<()> {
|
||||
pub fn insert_concept(
|
||||
&mut self,
|
||||
concept: &ConceptIdent,
|
||||
real: &PkgIdent,
|
||||
) -> rusqlite::Result<()> {
|
||||
self.conn
|
||||
.prepare_cached(r#"INSERT INTO "abspkg"("abspkg_ident", "provider") VALUES(?1, ?2)"#)?
|
||||
.execute(params![abs.to_string(), real.to_string()])?;
|
||||
.prepare_cached(r#"INSERT INTO "concept"("concept_ident", "provider") VALUES(?1, ?2)"#)?
|
||||
.execute(params![concept.to_string(), real.to_string()])?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -234,9 +238,9 @@ CREATE TABLE IF NOT EXISTS "abspkg"(
|
||||
.map(|x| x > 0)
|
||||
}
|
||||
|
||||
pub fn delete_abspkg_by_provider(&mut self, ident: &PkgIdent) -> rusqlite::Result<bool> {
|
||||
pub fn delete_concept_by_provider(&mut self, ident: &PkgIdent) -> rusqlite::Result<bool> {
|
||||
self.conn
|
||||
.prepare_cached(r#"DELETE FROM "abspkg" WHERE "provider" = ?1"#)?
|
||||
.prepare_cached(r#"DELETE FROM "concept" WHERE "provider" = ?1"#)?
|
||||
.execute(params![ident.to_string()])
|
||||
.map(|x| x > 0)
|
||||
}
|
||||
@@ -273,16 +277,16 @@ fn map_repo_package(repo_name: Option<String>, row: &Row) -> rusqlite::Result<Re
|
||||
})
|
||||
}
|
||||
|
||||
fn map_abspkg(row: &Row) -> rusqlite::Result<(AbsPkgIdent, PkgIdent)> {
|
||||
fn map_concept(row: &Row) -> rusqlite::Result<(ConceptIdent, PkgIdent)> {
|
||||
let provider = row
|
||||
.get::<_, String>("provider")?
|
||||
.parse()
|
||||
.map_err(from_sql_error)?;
|
||||
let abspkg_name = row
|
||||
.get::<_, String>("abspkg_ident")?
|
||||
let concept_ident = row
|
||||
.get::<_, String>("concept_ident")?
|
||||
.parse()
|
||||
.map_err(from_sql_error)?;
|
||||
Ok((abspkg_name, provider))
|
||||
Ok((concept_ident, provider))
|
||||
}
|
||||
|
||||
fn from_sql_error<E: std::error::Error + Send + Sync + 'static>(error: E) -> rusqlite::Error {
|
||||
@@ -451,11 +455,14 @@ impl QuerySession {
|
||||
all.push(pkg);
|
||||
}
|
||||
}
|
||||
let abspkg_ident = AbsPkgIdent {
|
||||
let concept_ident = ConceptIdent {
|
||||
name: pkgspec.name.clone(),
|
||||
arch: pkgspec.arch.clone(),
|
||||
};
|
||||
for (_, provider) in db.select_abspkg_by_ident(&abspkg_ident).unwrap_or_default() {
|
||||
for (_, provider) in db
|
||||
.select_concept_by_ident(&concept_ident)
|
||||
.unwrap_or_default()
|
||||
{
|
||||
let Ok(real) = db.select_package_by_ident(&provider) else {
|
||||
continue;
|
||||
};
|
||||
|
||||
+2
-2
@@ -88,7 +88,7 @@ impl RepoServeDir {
|
||||
self.db.insert_package(&repo_package)?;
|
||||
for abs in repo_package.pkg_manifest.provides.iter() {
|
||||
self.db
|
||||
.insert_abspkg(abs, &repo_package.pkg_manifest.pkg_ident())?;
|
||||
.insert_concept(abs, &repo_package.pkg_manifest.pkg_ident())?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
@@ -100,7 +100,7 @@ impl RepoServeDir {
|
||||
let path = self.path.join(format!("{ident}.pkg"));
|
||||
std::fs::remove_file(path)?;
|
||||
self.db.delete_package_by_ident(ident)?;
|
||||
self.db.delete_abspkg_by_provider(ident)?;
|
||||
self.db.delete_concept_by_provider(ident)?;
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user