Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ RUA is a build tool for ArchLinux, AUR. Its features:

`rua install pinta` # install or upgrade a package

`rua upgrade` # upgrade all AUR packages. You can selectively ignore packages by using `--ignore` or adding them to `IgnorePkg` in `pacman.conf` (same as with non-AUR packages and `pacman`). You can upgrade only specific packages with `rua install A B C`.
`rua upgrade` # upgrade AUR packages. By default, all packages are upgraded, unless specific packages are given as arguments. You can selectively ignore packages by using `--ignore` or adding them to `IgnorePkg` in `pacman.conf` (same as with non-AUR packages and `pacman`).

`rua shellcheck path/to/my/PKGBUILD` # run `shellcheck` on a PKGBUILD, discovering potential problems with the build instruction. Takes care of PKGBUILD-specific variables.

Expand Down
34 changes: 28 additions & 6 deletions src/action_upgrade.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,13 @@ fn pkg_is_devel(name: &str) -> bool {
RE.is_match(name)
}

pub fn upgrade_printonly(devel: bool, ignored: &HashSet<&str>) {
pub fn upgrade_printonly(
devel: bool,
ignored: &HashSet<&str>,
only_packages: &HashSet<&str>,
) -> Result<()> {
let alpm = new_alpm_wrapper();
let (outdated, nonexistent) =
calculate_upgrade(&*alpm, devel, ignored).expect("Calculating upgrade failed");
let (outdated, nonexistent) = calculate_upgrade(&*alpm, devel, ignored, only_packages)?;

if outdated.is_empty() && nonexistent.is_empty() {
eprintln!(
Expand All @@ -43,12 +46,17 @@ pub fn upgrade_printonly(devel: bool, ignored: &HashSet<&str>) {
println!("{}", pkg);
}
}
Ok(())
}

pub fn upgrade_real(devel: bool, rua_paths: &RuaPaths, ignored: &HashSet<&str>) {
pub fn upgrade_real(
devel: bool,
rua_paths: &RuaPaths,
ignored: &HashSet<&str>,
only_packages: &HashSet<&str>,
) -> Result<()> {
let alpm = new_alpm_wrapper();
let (outdated, nonexistent) =
calculate_upgrade(&*alpm, devel, ignored).expect("calculating upgrade failed");
let (outdated, nonexistent) = calculate_upgrade(&*alpm, devel, ignored, only_packages)?;

if outdated.is_empty() && nonexistent.is_empty() {
eprintln!(
Expand Down Expand Up @@ -77,6 +85,7 @@ pub fn upgrade_real(devel: bool, rua_paths: &RuaPaths, ignored: &HashSet<&str>)
}
}
}
Ok(())
}

type OutdatedPkgs = Vec<(String, String, String)>;
Expand All @@ -86,6 +95,7 @@ fn calculate_upgrade(
alpm: &dyn AlpmWrapper,
devel: bool,
locally_ignored_packages: &HashSet<&str>,
only_packages: &HashSet<&str>,
) -> Result<(OutdatedPkgs, ForeignPkgs)> {
let system_ignored_packages = pacman::get_ignored_packages().unwrap_or_else(|err| {
warn!("Could not get ignored packages, {}", err);
Expand All @@ -94,6 +104,15 @@ fn calculate_upgrade(

let aur_pkgs = alpm.get_non_pacman_packages()?;

if !only_packages.is_empty() {
let installed: HashSet<&str> = aur_pkgs.iter().map(|(n, _)| n.as_str()).collect();
for pkg in only_packages {
if !installed.contains(pkg) {
anyhow::bail!("Package {} is not installed", pkg);
}
}
}

let aur_pkgs_string = aur_pkgs
.iter()
.map(|(name, _version)| name.to_string())
Expand All @@ -111,6 +130,9 @@ fn calculate_upgrade(
let info_map = info_map.unwrap_or_else(|err| panic!("Failed to get AUR information: {}", err));

for (pkg, local_ver) in aur_pkgs {
if !only_packages.is_empty() && !only_packages.contains(pkg.as_str()) {
continue;
}
let raur_ver: Option<String> = info_map.get(&pkg).map(|p| p.version.to_string());

if let Some(raur_ver) = raur_ver {
Expand Down
7 changes: 6 additions & 1 deletion src/cli_args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ Sources are downloaded using .SRCINFO only"
target: PathBuf,
},
#[structopt(
about = "Upgrade AUR packages. To ignore packages, add them to IgnorePkg in /etc/pacman.conf"
about = "Upgrade AUR packages by name, or all packages if package names are not provide"
)]
Upgrade {
#[structopt(
Expand All @@ -121,6 +121,11 @@ Supports: git, hg, bzr, svn, cvs, darcs. Currently by suffix only."
help = "Don't upgrade the specified package(s). Accepts multiple arguments separated by `,`."
)]
ignored: Option<String>,
#[structopt(
help = "Package names to upgrade. If no packages are given, all AUR packages will be upgraded",
multiple = true
)]
packages: Vec<String>,
},
}

Expand Down
12 changes: 9 additions & 3 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,16 +70,22 @@ fn main() {
devel,
printonly,
ignored,
packages,
} => {
let ignored_set = ignored
.iter()
.flat_map(|i| i.split(','))
.collect::<HashSet<&str>>();
if *printonly {
action_upgrade::upgrade_printonly(*devel, &ignored_set);
let only_packages: HashSet<&str> = packages.iter().map(String::as_str).collect();
let result = if *printonly {
action_upgrade::upgrade_printonly(*devel, &ignored_set, &only_packages)
} else {
let paths = rua_paths::RuaPaths::initialize_paths();
action_upgrade::upgrade_real(*devel, &paths, &ignored_set);
action_upgrade::upgrade_real(*devel, &paths, &ignored_set, &only_packages)
};
if let Err(e) = result {
eprintln!("{}", e);
exit(1);
}
}
};
Expand Down