Skip to content

Commit

Permalink
Do aur + devel upgrade concurrently
Browse files Browse the repository at this point in the history
  • Loading branch information
Morganamilo committed Nov 16, 2020
1 parent f8ce25b commit 836bba8
Show file tree
Hide file tree
Showing 5 changed files with 113 additions and 68 deletions.
43 changes: 23 additions & 20 deletions src/devel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,12 @@ pub fn save_devel_info(config: &Config, devel_info: &DevelInfo) -> Result<()> {
Ok(())
}

async fn ls_remote(git: &str, flags: &[String], remote: String, branch: Option<&str>) -> Result<String> {
async fn ls_remote(
git: &str,
flags: &[String],
remote: String,
branch: Option<&str>,
) -> Result<String> {
let mut command = AsyncCommand::new(git);
command
.args(flags)
Expand Down Expand Up @@ -241,9 +246,8 @@ fn parse_url(source: &str) -> Option<(String, &'_ str, Option<&'_ str>)> {
Some((remote, protocol, branch))
}

pub async fn devel_updates(config: &Config, cache: &mut Cache) -> Result<Vec<String>> {
let mut devel_info = load_devel_info(config)?.unwrap_or_default();
let db = config.alpm.localdb();
pub async fn possible_devel_updates(config: &Config) -> Result<Vec<String>> {
let devel_info = load_devel_info(config)?.unwrap_or_default();

let mut futures = Vec::new();

Expand All @@ -252,44 +256,43 @@ pub async fn devel_updates(config: &Config, cache: &mut Cache) -> Result<Vec<Str
}

let updates = join_all(futures).await;
let mut updates = updates.into_iter().flatten().collect::<Vec<_>>();
let mut updates = updates
.into_iter()
.flatten()
.map(|s| s.to_string())
.collect::<Vec<_>>();

updates.sort_unstable();
updates.dedup();
Ok(updates)
}

pub async fn filter_devel_updates(
config: &Config,
cache: &mut Cache,
updates: &[String],
) -> Result<Vec<String>> {
let mut pkgbases: HashMap<&str, Vec<alpm::Package>> = HashMap::new();
let db = config.alpm.localdb();

for pkg in db.pkgs().iter() {
let name = pkg.base().unwrap_or(pkg.name());
pkgbases.entry(name).or_default().push(pkg);
}

let info = config.raur.cache_info(cache, &updates).await?;
config.raur.cache_info(cache, &updates).await?;
let updates = updates
.into_iter()
.map(|u| pkgbases.remove(u).unwrap())
.map(|u| pkgbases.remove(u.as_str()).unwrap())
.collect::<Vec<_>>();

for update in &updates {
if !update
.iter()
.any(|pkg| info.iter().any(|i| i.name == pkg.name()))
{
devel_info
.info
.remove(update[0].base().unwrap_or(update[0].name()));
}
}

let updates = updates
.iter()
.flatten()
.map(|p| p.name().to_string())
.filter(|p| cache.contains(p.as_str()))
.collect();

//save_devel_info(config, &devel_info)?;

Ok(updates)
}

Expand Down
6 changes: 4 additions & 2 deletions src/download.rs
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,8 @@ pub async fn show_comments(config: &mut Config) -> Result<i32> {

let response = client
.get(url.clone())
.send().await
.send()
.await
.with_context(|| format!("{}: {}", base, url))?;
if !response.status().is_success() {
bail!("{}: {}: {}", base, url, response.status());
Expand Down Expand Up @@ -500,7 +501,8 @@ pub async fn show_pkgbuilds(config: &mut Config) -> Result<i32> {

let response = client
.get(url.clone())
.send().await
.send()
.await
.with_context(|| format!("{}: {}", base, url))?;
if !response.status().is_success() {
bail!("{}: {}: {}", base, url, response.status());
Expand Down
25 changes: 2 additions & 23 deletions src/install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ use alpm::Alpm;
use alpm_utils::{DbListExt, Targ};
use ansi_term::Style;
use anyhow::{bail, ensure, Context, Result};
use aur_depends::{Actions, AurUpdates, Conflict, Flags, RepoPackage, Resolver};
use aur_depends::{Actions, Conflict, Flags, RepoPackage, Resolver};
use raur::Cache;
use srcinfo::Srcinfo;

Expand Down Expand Up @@ -99,28 +99,7 @@ pub async fn install(config: &mut Config, targets_str: &[String]) -> Result<i32>
let mut resolver = resolver(&config, &config.alpm, &config.raur, &mut cache, flags);

let upgrades = if config.args.has_arg("u", "sysupgrade") {
let aur_upgrades = if config.mode != "repo" {
println!(
"{} {}",
c.action.paint("::"),
c.bold.paint("Looking for AUR upgrades")
);
resolver.aur_updates().await?
} else {
AurUpdates::default()
};

for pkg in aur_upgrades.ignored {
eprintln!(
"{} {}: ignoring package upgrade ({} => {})",
c.warning.paint("warning:"),
pkg.local.name(),
pkg.local.version(),
pkg.remote.version
);
}

let upgrades = get_upgrades(config, resolver.cache(), aur_upgrades.updates).await?;
let upgrades = get_upgrades(config, &mut resolver).await?;
for pkg in &upgrades.repo_skip {
let arg = Arg {
key: "ignore".to_string(),
Expand Down
27 changes: 19 additions & 8 deletions src/query.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
use std::collections::HashSet;

use crate::config::Config;
use crate::devel::devel_updates;
use crate::devel::{possible_devel_updates};
use crate::exec;
use crate::util::{split_repo_aur_mode, split_repo_aur_pkgs};

use anyhow::Result;
use raur::Raur;
use futures::try_join;
use raur::{Raur, Cache};

pub async fn print_upgrade_list(config: &mut Config) -> Result<i32> {
let mut cache = HashSet::new();
Expand Down Expand Up @@ -47,11 +48,6 @@ pub async fn print_upgrade_list(config: &mut Config) -> Result<i32> {
let error = config.color.error;
let upgrade = config.color.upgrade;

let mut devel = Vec::new();
if config.devel {
devel.extend(devel_updates(config, &mut cache).await?);
}

for &pkg in &aur {
if db.pkg(pkg).is_err() {
eprintln!("{} package '{}' was not found", error.paint("error:"), pkg);
Expand All @@ -63,9 +59,24 @@ pub async fn print_upgrade_list(config: &mut Config) -> Result<i32> {
args.targets = aur.into_iter().collect();
let output = exec::pacman_output(config, &args)?;
let aur = String::from_utf8(output.stdout)?;

let aur = aur.trim().lines().collect::<Vec<_>>();

config.raur.cache_info(&mut cache, &aur).await?;
async fn devel_up(config: &Config) -> Result<Vec<String>>{
if config.devel {
let updates = possible_devel_updates(config).await?;
Ok(updates)
} else {
Ok(Vec::new())
}
}

async fn aur_up(config: &Config, cache: &mut Cache, pkgs: &[&str]) -> Result<()> {
config.raur.cache_info(cache, pkgs).await?;
Ok(())
}

let (_, devel) = try_join!(aur_up(config, &mut cache, &aur), devel_up(config))?;

for target in aur {
if let Some(pkg) = cache.get(target) {
Expand Down
80 changes: 65 additions & 15 deletions src/upgrade.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
use crate::config::Config;
use crate::devel::devel_updates;
use crate::devel::{filter_devel_updates, possible_devel_updates};
use crate::fmt::color_repo;
use crate::util::{input, NumberMenu};

use alpm_utils::DbListExt;
use anyhow::Result;
use raur::Cache;
use aur_depends::{AurUpdates, Resolver};
use futures::try_join;

#[derive(Default, Debug)]
pub struct Upgrades {
Expand Down Expand Up @@ -101,24 +102,73 @@ fn print_upgrade(
);
}

pub async fn get_upgrades<'a>(
async fn get_aur_only_upgrades<'a, 'b>(
config: &Config,
cache: &mut Cache,
mut aur_upgrades: Vec<aur_depends::AurUpdate<'a>>,
resolver: &mut Resolver<'a, 'b>,
print: bool,
) -> Result<AurUpdates<'a>> {
if config.mode != "repo" {
if print {
let c = config.color;
println!(
"{} {}",
c.action.paint("::"),
c.bold.paint("Looking for AUR upgrades")
);
}
Ok(resolver.aur_updates().await?)
} else {
Ok(AurUpdates::default())
}
}

async fn get_devel_upgrades(config: &Config, print: bool) -> Result<Vec<String>> {
if config.devel && config.mode != "repo" {
let c = config.color;
if print {
println!(
"{} {}",
c.action.paint("::"),
c.bold.paint("Looking for devel upgrades")
);
}

possible_devel_updates(config).await
} else {
Ok(Vec::new())
}
}

pub async fn aur_upgrades<'a>(
config: &Config,
resolver: &mut Resolver<'a, '_>,
print: bool,
) -> Result<(AurUpdates<'a>, Vec<String>)> {
try_join!(
get_aur_only_upgrades(config, resolver, print),
get_devel_upgrades(config, print)
)
}

pub async fn get_upgrades<'a, 'b>(
config: &Config,
resolver: &mut Resolver<'a, 'b>,
) -> Result<Upgrades> {
let c = config.color;
let (aur_upgrades, devel_upgrades) = aur_upgrades(config, resolver, true).await?;

let mut devel_upgrades = if config.devel && config.mode != "repo" {
println!(
"{} {}",
c.action.paint("::"),
c.bold.paint("Looking for devel upgrades")
for pkg in aur_upgrades.ignored {
eprintln!(
"{} {}: ignoring package upgrade ({} => {})",
config.color.warning.paint("warning:"),
pkg.local.name(),
pkg.local.version(),
pkg.remote.version
);
}

devel_updates(config, cache).await?
} else {
Vec::new()
};
let mut aur_upgrades = aur_upgrades.updates;
let mut devel_upgrades =
filter_devel_updates(config, resolver.cache(), &devel_upgrades).await?;

let repo_upgrades = if config.mode != "aur" && config.combined_upgrade {
repo_upgrades(config)?
Expand Down

0 comments on commit 836bba8

Please sign in to comment.