Add builder for pacman query

Signed-off-by: trivernis <trivernis@protonmail.com>
i18n
trivernis 2 years ago
parent bb6b5cc162
commit 1f5a2127e1
Signed by: Trivernis
GPG Key ID: DFFFCC2C7A02DB45

@ -12,6 +12,8 @@ WORKDIR /usr/src/amethyst
COPY Cargo.toml Cargo.lock ./
RUN cargo fetch
COPY src ./src
RUN mkdir target
COPY target/debug/build ./target/debug/build
RUN cargo build --frozen
RUN mkdir /tmp/ame
RUN cp target/debug/ame /tmp/ame/
@ -28,5 +30,5 @@ RUN rm -f $(pacdiff -o -f)
USER ame
RUN mkdir -p /home/ame/.local/share
RUN touch /home/ame/.zshrc
ENV AME_LOG=debug
ENV AME_LOG=debug,hyper=info
ENTRYPOINT ["zsh"]

@ -27,6 +27,7 @@ impl PacmanInstallBuilder {
self
}
#[allow(clippy::wrong_self_convention)]
pub fn as_deps(mut self, as_deps: bool) -> Self {
self.as_deps = as_deps;
@ -48,3 +49,46 @@ impl PacmanInstallBuilder {
command.args(self.packages).wait_success().await
}
}
#[derive(Debug, Default)]
pub struct PacmanQueryBuilder {
foreign: bool,
}
impl PacmanQueryBuilder {
/// Query for foreign packages
pub fn foreign(mut self, foreign: bool) -> Self {
self.foreign = foreign;
self
}
#[tracing::instrument(level = "debug")]
pub async fn query(self) -> AppResult<Vec<BasicPackageInfo>> {
let mut command = ShellCommand::pacman().arg("-Q").arg("--color").arg("never");
if self.foreign {
command = command.arg("-m");
}
let output = command.wait_with_output().await?;
let packages = output
.stdout
.split('\n')
.filter(|p| !p.is_empty())
.filter_map(|p| p.split_once(' '))
.map(|(name, version)| BasicPackageInfo {
name: name.to_string(),
version: version.to_string(),
})
.collect();
Ok(packages)
}
}
#[derive(Clone, Debug)]
pub struct BasicPackageInfo {
pub name: String,
pub version: String,
}

@ -1,3 +1,4 @@
use crate::builder::pacman::PacmanQueryBuilder;
use crate::internal::commands::ShellCommand;
use crate::internal::error::SilentUnwrap;
use crate::internal::exit_code::AppExitCode;
@ -42,40 +43,31 @@ pub async fn upgrade(options: Options) {
log!("Upgrading AUR packages");
}
let pacman_output = ShellCommand::pacman()
.arg("-Qm")
.args(&["--color", "never"])
.wait_with_output()
let non_native_pkgs = PacmanQueryBuilder::default()
.foreign(true)
.query()
.await
.silent_unwrap(AppExitCode::PacmanError);
let non_native_pkgs = pacman_output
.stdout
.split('\n')
.filter(|p| !p.is_empty())
.filter_map(|p| p.split_once(' '))
.collect::<Vec<(&str, &str)>>();
if verbosity >= 1 {
log!("{:?}", non_native_pkgs);
}
tracing::debug!("aur packages: {non_native_pkgs:?}");
let mut aur_upgrades = vec![];
for (pkg_name, pkg_version) in non_native_pkgs {
if verbosity >= 1 {
log!(
"remote package: name = {}, version = {}",
pkg_name,
pkg_version
);
}
let remote_package = rpcinfo(pkg_name).await.silent_unwrap(AppExitCode::RpcError);
for pkg in non_native_pkgs {
let remote_package = rpcinfo(&pkg.name)
.await
.silent_unwrap(AppExitCode::RpcError);
if let Some(remote_package) = remote_package {
if remote_package.metadata.version != pkg_version {
aur_upgrades.push(pkg_name.to_string());
if remote_package.metadata.version != pkg.version {
tracing::debug!(
"local version: {}, remote version: {}",
pkg.version,
remote_package.metadata.version
);
aur_upgrades.push(pkg.name);
}
} else {
warn!("Could not find the remote package for {}", pkg_name);
warn!("Could not find the remote package for {}", pkg.name);
}
}

Loading…
Cancel
Save