From 849c00f1352bfb95e14b5530c3f7fe072fb87fb9 Mon Sep 17 00:00:00 2001 From: Hunter Wittenborn Date: Wed, 24 Aug 2022 10:46:33 -0500 Subject: [PATCH] More change --- Cargo.lock | 38 ++++----- makedeb/PKGBUILD | 2 +- man/mist.1.adoc | 2 +- rustfmt.toml | 1 + src/cache.rs | 201 ++++++-------------------------------------- src/clone.rs | 4 +- src/install.rs | 4 +- src/install_util.rs | 111 +++++++++++++----------- src/main.rs | 1 + src/remove.rs | 23 ++--- src/style.rs | 3 +- src/util.rs | 25 +++--- 12 files changed, 144 insertions(+), 271 deletions(-) create mode 100644 rustfmt.toml diff --git a/Cargo.lock b/Cargo.lock index 91094cd..6a7e538 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -922,9 +922,9 @@ dependencies = [ [[package]] name = "link-cplusplus" -version = "1.0.6" +version = "1.0.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f8cae2cd7ba2f3f63938b9c724475dfb7b9861b545a90324476324ed21dbc8c8" +checksum = "9272ab7b96c9046fbc5bc56c06c117cb639fe2d509df0c421cad82d2915cf369" dependencies = [ "cc", ] @@ -1255,9 +1255,9 @@ dependencies = [ [[package]] name = "pyo3" -version = "0.16.5" +version = "0.16.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e6302e85060011447471887705bb7838f14aba43fcb06957d823739a496b3dc" +checksum = "0220c44442c9b239dd4357aa856ac468a4f5e1f0df19ddb89b2522952eb4c6ca" dependencies = [ "cfg-if", "indoc", @@ -1271,9 +1271,9 @@ dependencies = [ [[package]] name = "pyo3-build-config" -version = "0.16.5" +version = "0.16.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b5b65b546c35d8a3b1b2f0ddbac7c6a569d759f357f2b9df884f5d6b719152c8" +checksum = "9c819d397859445928609d0ec5afc2da5204e0d0f73d6bf9e153b04e83c9cdc2" dependencies = [ "once_cell", "target-lexicon", @@ -1281,9 +1281,9 @@ dependencies = [ [[package]] name = "pyo3-ffi" -version = "0.16.5" +version = "0.16.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c275a07127c1aca33031a563e384ffdd485aee34ef131116fcd58e3430d1742b" +checksum = "ca882703ab55f54702d7bfe1189b41b0af10272389f04cae38fe4cd56c65f75f" dependencies = [ "libc", "pyo3-build-config", @@ -1291,9 +1291,9 @@ dependencies = [ [[package]] name = "pyo3-macros" -version = "0.16.5" +version = "0.16.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "284fc4485bfbcc9850a6d661d627783f18d19c2ab55880b021671c4ba83e90f7" +checksum = "568749402955ad7be7bad9a09b8593851cd36e549ac90bfd44079cea500f3f21" dependencies = [ "proc-macro2", "pyo3-macros-backend", @@ -1303,9 +1303,9 @@ dependencies = [ [[package]] name = "pyo3-macros-backend" -version = "0.16.5" +version = "0.16.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "53bda0f58f73f5c5429693c96ed57f7abdb38fdfc28ae06da4101a257adb7faf" +checksum = "611f64e82d98f447787e82b8e7b0ebc681e1eb78fc1252668b2c605ffb4e1eb8" dependencies = [ "proc-macro2", "quote", @@ -1446,7 +1446,7 @@ dependencies = [ [[package]] name = "rust-apt" version = "0.3.0" -source = "git+https://gitlab.com/volian/rust-apt?branch=feat/install-cpp-go-boom-boom#93a8bbf7f5ade4c398738262834469cbaf788679" +source = "git+https://gitlab.com/volian/rust-apt?branch=feat/install-cpp-go-boom-boom#0bf91aa5c1d0569e0a9cc51cc0151b54bd1ffdb1" dependencies = [ "cxx", "cxx-build", @@ -1528,18 +1528,18 @@ checksum = "93f6841e709003d68bb2deee8c343572bf446003ec20a583e76f7b15cebf3711" [[package]] name = "serde" -version = "1.0.143" +version = "1.0.144" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "53e8e5d5b70924f74ff5c6d64d9a5acd91422117c60f48c4e07855238a254553" +checksum = "0f747710de3dcd43b88c9168773254e809d8ddbdf9653b84e2554ab219f17860" dependencies = [ "serde_derive", ] [[package]] name = "serde_derive" -version = "1.0.143" +version = "1.0.144" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d3d8e8de557aee63c26b85b947f5e59b690d0454c753f3adeb5cd7835ab88391" +checksum = "94ed3a816fb1d101812f83e789f888322c34e291f894f19590dc310963e87a00" dependencies = [ "proc-macro2", "quote", @@ -1548,9 +1548,9 @@ dependencies = [ [[package]] name = "serde_json" -version = "1.0.83" +version = "1.0.85" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "38dd04e3c8279e75b31ef29dbdceebfe5ad89f4d0937213c53f7d49d01b3d5a7" +checksum = "e55a28e3aaef9d5ce0506d0a14dbba8054ddc7e499ef522dd8b26859ec9d4a44" dependencies = [ "itoa", "ryu", diff --git a/makedeb/PKGBUILD b/makedeb/PKGBUILD index 4605053..0f0a90e 100644 --- a/makedeb/PKGBUILD +++ b/makedeb/PKGBUILD @@ -2,7 +2,7 @@ pkgname=mist pkgver=0.8.0 pkgrel=1 -pkgdesc='The official helper for the makedeb Package Repository' +pkgdesc='The official command-line interface for the makedeb Package Repository' arch=('any') depends=( 'libapt-pkg-dev' diff --git a/man/mist.1.adoc b/man/mist.1.adoc index 74a12cc..821bf7a 100644 --- a/man/mist.1.adoc +++ b/man/mist.1.adoc @@ -5,7 +5,7 @@ :mansource: Git == NAME -mist - The official helper for the makedeb Package Repository +mist - The official command-line interface for the makedeb Package Repository == SYNOPSIS *mist* clone _pkgbase_ [_options_] ... diff --git a/rustfmt.toml b/rustfmt.toml new file mode 100644 index 0000000..606e292 --- /dev/null +++ b/rustfmt.toml @@ -0,0 +1 @@ +wrap_comments = true \ No newline at end of file diff --git a/src/cache.rs b/src/cache.rs index 13a08ca..a6c23ba 100644 --- a/src/cache.rs +++ b/src/cache.rs @@ -7,7 +7,6 @@ use crate::{ use flate2::{read::GzDecoder, write::GzEncoder, Compression}; use rust_apt::{ cache::{Cache as AptCache, PackageSort}, - pkgmanager::OrderResult, progress::{AcquireProgress, InstallProgress}, }; use serde::{Deserialize, Serialize}; @@ -104,7 +103,8 @@ pub struct MprCache { } impl MprCache { - // Convert a Vector of MPR packages (the way they're stored on the MPR itself) into a HashMap that's accessible via key-value pairs. + // Convert a Vector of MPR packages (the way they're stored on the MPR itself) + // into a HashMap that's accessible via key-value pairs. fn vec_to_map(packages: Vec) -> HashMap { let mut map = HashMap::new(); @@ -117,8 +117,8 @@ impl MprCache { } pub fn new(mpr_url: &str) -> Self { - // Try reading the cache file. If it doesn't exist or it's older than five minutes, we have to - // update the cache file. + // Try reading the cache file. If it doesn't exist or it's older than five + // minutes, we have to update the cache file. let mut cache_file_path = util::xdg::get_cache_dir(); cache_file_path.push("cache.gz"); @@ -204,7 +204,8 @@ impl MprCache { } }; - // Now that the JSON has been verified, let's write out the archive to the cache file. + // Now that the JSON has been verified, let's write out the archive to the cache + // file. let mut config_compressor = GzEncoder::new(Vec::new(), Compression::default()); config_compressor .write_all(serde_json::to_string(&cache).unwrap().as_bytes()) @@ -227,8 +228,8 @@ impl MprCache { packages: Self::vec_to_map(cache), } } else { - // The cache is less than 5 minutes old. We still need to validate that the cache is valid - // though. + // The cache is less than 5 minutes old. We still need to validate that the + // cache is valid though. let cache_file = match fs::File::open(cache_file_path.clone()) { Ok(file) => file, Err(err) => { @@ -281,8 +282,9 @@ fn valid_archive(file: impl Read) -> Result, u32> { // Stuff to handled shared APT/MPR caches. // ///////////////////////////////////////////// // -// Some of these fields only make sense to one type of package, but this kind of cache allows us to -// combine both types when needed, such as when providing search results. +// Some of these fields only make sense to one type of package, but this kind of +// cache allows us to combine both types when needed, such as when providing +// search results. #[derive(Clone, PartialEq, Eq)] pub enum CachePackageSource { @@ -311,7 +313,8 @@ pub struct Cache { mpr_cache: MprCache, /// A combined list of all packages in the cache. //pkglist: Vec, - /// A map for getting all packages with a certain pkgname. Can be quicker than looping over [`Self::pkglist`]. + /// A map for getting all packages with a certain pkgname. Can be quicker + /// than looping over [`Self::pkglist`]. pkgmap: HashMap>, } @@ -447,7 +450,11 @@ impl Cache { if !to_purge.is_empty() { println!( "{}", - format!("The following packages (along with their configuration files) will be {}:", "removed".red()).bold() + format!( + "The following packages (along with their configuration files) will be {}:", + "removed".red() + ) + .bold() ); util::format_apt_pkglist(&to_purge); println!(); @@ -536,25 +543,21 @@ impl Cache { } let mut installer: Box = Box::new(MistInstallProgress {}); - match self.apt_cache().do_install(&mut installer) { - OrderResult::Completed => (), - OrderResult::Incomplete => { - message::error("`cache.do_install()` returned `OrderResult::Incomplete`, which Mist doesn't know how to handle. Please report this as an issue.\n"); - quit::with_code(exitcode::UNAVAILABLE); - } - OrderResult::Failed => { - message::error("There was an issue running the transaction.\n"); - quit::with_code(exitcode::UNAVAILABLE); - } + if let Err(err) = self.apt_cache().do_install(&mut installer) { + util::handle_errors(&err); + quit::with_code(exitcode::UNAVAILABLE); } } - /// Get a reference to the generated pkglist (contains a combined APT+MPR cache). + /// Get a reference to the generated pkglist (contains a combined APT+MPR + /// cache). /*pub fn pkglist(&self) -> &Vec { &self.pkglist }*/ - /// Get a reference to the generated pkgmap (a key-value pair with keys of pkgnames and values of lists of packages). Can be quicker than [`Cache::pkglist`] if you're trying to lookup a package. + /// Get a reference to the generated pkgmap (a key-value pair with keys of + /// pkgnames and values of lists of packages). Can be quicker than + /// [`Cache::pkglist`] if you're trying to lookup a package. pub fn pkgmap(&self) -> &HashMap> { &self.pkgmap } @@ -593,155 +596,3 @@ impl Cache { None } } - -// Run a transaction using our progress reporting. -pub fn run_transaction(cache: &AptCache, purge: bool) { - let mut to_install: Vec = Vec::new(); - let mut to_remove: Vec = Vec::new(); - let mut to_upgrade: Vec = Vec::new(); - let mut to_downgrade: Vec = Vec::new(); - - for pkg in cache.packages(&PackageSort::default()) { - let pkgname = pkg.name(); - - if pkg.marked_install() { - to_install.push(pkgname); - } else if pkg.marked_delete() { - to_remove.push(pkgname); - } else if pkg.marked_downgrade() { - to_downgrade.push(pkgname); - } else if pkg.marked_upgrade() { - to_upgrade.push(pkgname); - } - } - - // Print out the transaction to the user. - let is_to_install = !to_install.is_empty(); - let is_to_remove = !to_remove.is_empty(); - let is_to_upgrade = !to_upgrade.is_empty(); - let is_to_downgrade = !to_downgrade.is_empty(); - - if is_to_install { - println!("{}", "The following packages will be installed:".bold()); - util::format_apt_pkglist(&to_install); - println!(); - } - - if is_to_remove { - if purge { - println!( - "{}", - "The following packages (and their configuration files) will be removed:".bold() - ); - } else { - println!("{}", "The following packages will be removed:".bold()); - } - - util::format_apt_pkglist(&to_remove); - println!(); - } - - if is_to_upgrade { - println!("{}", "The following packages will be upgraded:".bold()); - util::format_apt_pkglist(&to_upgrade); - println!(); - } - - if is_to_downgrade { - println!("{}", "The following packages will be DOWNGRADED:".bold()); - util::format_apt_pkglist(&to_downgrade); - println!(); - } - - if vec![is_to_install, is_to_remove, is_to_upgrade, is_to_downgrade].contains(&true) { - let to_install_string = match is_to_install { - true => "install".purple(), - false => "install".green(), - }; - let to_remove_string = match is_to_remove { - true => "remove".purple(), - false => "remove".green(), - }; - let to_upgrade_string = match is_to_upgrade { - true => "upgrade".purple(), - false => "upgrade".green(), - }; - let to_downgrade_string = match is_to_downgrade { - true => "downgrade".purple(), - false => "downgrade".green(), - }; - - println!("{}", "Review:".bold()); - - println!( - "{}", - format!( - "- {} to {}", - to_install.len().to_string().blue(), - to_install_string, - ) - .bold() - ); - println!( - "{}", - format!( - "- {} to {}", - to_remove.len().to_string().blue(), - to_remove_string - ) - .bold() - ); - println!( - "{}", - format!( - "- {} to {}", - to_upgrade.len().to_string().blue(), - to_upgrade_string - ) - .bold() - ); - println!( - "{}", - format!( - "- {} to {}", - to_downgrade.len().to_string().blue(), - to_downgrade_string - ) - .bold() - ); - } else { - println!("{}", "Nothing found to do, quitting.".bold()); - quit::with_code(exitcode::OK); - } - - print!("{}", "\nWould you like to continue? [Y/n] ".bold()); - io::stdout().flush().unwrap(); - - let mut resp = String::new(); - io::stdin().read_line(&mut resp).unwrap(); - resp.pop(); - - if !util::is_yes(&resp, true) { - println!("{}", "Aborting...".bold()); - quit::with_code(exitcode::OK); - } - - let mut updater: Box = Box::new(MistAcquireProgress {}); - if cache.get_archives(&mut updater).is_err() { - message::error("Failed to fetch needed archives.\n"); - quit::with_code(exitcode::UNAVAILABLE); - } - - let mut installer: Box = Box::new(MistInstallProgress {}); - match cache.do_install(&mut installer) { - OrderResult::Completed => (), - OrderResult::Incomplete => { - message::error("`cache.do_install()`returned `OrderResult::Incomplete`, which Mist doesn't know how to handle. Please report this as an issue.\n"); - quit::with_code(exitcode::UNAVAILABLE); - } - OrderResult::Failed => { - message::error("There was an issue running the transaction.\n"); - quit::with_code(exitcode::UNAVAILABLE); - } - } -} diff --git a/src/clone.rs b/src/clone.rs index 71707d2..16e3cc6 100644 --- a/src/clone.rs +++ b/src/clone.rs @@ -22,8 +22,8 @@ pub fn clone(args: &clap::ArgMatches) { pkg )); - // If there's a pkgbase that builds this package, guide the user to clone that package - // instead. + // If there's a pkgbase that builds this package, guide the user to clone that + // package instead. if let Some(pkgbase) = cache.find_pkgbase(pkg) { message::error(&format!( "Package base '{}' exists on the MPR though, which builds '{}'. You probably want to clone that instead:\n", diff --git a/src/install.rs b/src/install.rs index 0ecd7c3..5637947 100644 --- a/src/install.rs +++ b/src/install.rs @@ -15,7 +15,9 @@ pub fn install(args: &clap::ArgMatches) { let mut apt_pkgs: Vec<&str> = Vec::new(); let mut mpr_pkgs: Vec<&str> = Vec::new(); - // Check real quick for any packages that cannot be found. We don't want to ask the user anything else if there's packages that cannot be found, instead we should just show those packages and abort. + // Check real quick for any packages that cannot be found. We don't want to ask + // the user anything else if there's packages that cannot be found, instead we + // should just show those packages and abort. let mut unfindable = false; for pkg in &pkglist { diff --git a/src/install_util.rs b/src/install_util.rs index 0cd2ca1..60ee496 100644 --- a/src/install_util.rs +++ b/src/install_util.rs @@ -5,7 +5,7 @@ use crate::{ util, }; use makedeb_srcinfo::SplitPackage; -use rust_apt::config::Config; +use rust_apt::{config::Config, package::Version}; use std::{env, fs}; pub fn exit_with_git_error(pkg: &str, res: &util::CommandResult) { @@ -121,7 +121,9 @@ pub fn clone_mpr_pkgs(pkglist: &Vec<&str>, mpr_url: &str) { /// Mark an MPR package for installation, as well as its dependencies. /// This function gets recursively called until a resolution is met. -/// This returns a list of the package's dependencies that were marked to be installed. Note that ordering of said dependencies must be handled outside of this function though. +/// This returns a list of the package's dependencies that were marked to be +/// installed. Note that ordering of said dependencies must be handled outside +/// of this function though. fn resolve_mpr_package( cache: &Cache, pkg: &str, @@ -145,12 +147,14 @@ fn resolve_mpr_package( // Get the keys to get dependency and conflicts variables from. // Each dep group is a string such as 'pkg1|pkg2>=3'. - // Conflicting packages can't have the `|` operator, so reflect that in the variable name here. + // Conflicting packages can't have the `|` operator, so reflect that in the + // variable name here. let mut dep_groups: Vec = Vec::new(); let mut conflicts: Vec = Vec::new(); - // See if we can find dependencies in the order makedeb resolves distro-arch variables. - // We're calling the struct's methods directly so we don't have to repeat the same code three times in a row. Who'd want that? + // See if we can find dependencies in the order makedeb resolves distro-arch + // variables. We're calling the struct's methods directly so we don't have + // to repeat the same code three times in a row. Who'd want that? for dep_func in [ MprPackage::get_depends, MprPackage::get_makedepends, @@ -167,8 +171,9 @@ fn resolve_mpr_package( } } - // Sadly we must duplicate the above code for our 'conflicts' vector, at least from what I've currently tried. - // TODO: Simplify so we don't duplicate, thanks! :D + // Sadly we must duplicate the above code for our 'conflicts' vector, at least + // from what I've currently tried. TODO: Simplify so we don't duplicate, + // thanks! :D if let Some(mut deps) = mpr_pkg.get_conflicts(Some(&system_distro), Some(&system_arch)) { conflicts.append(&mut deps); } else if let Some(mut deps) = mpr_pkg.get_conflicts(Some(&system_distro), None) { @@ -184,61 +189,64 @@ fn resolve_mpr_package( let mut good_dep_found = false; let deps: Vec<&str> = dep_group.split('|').collect(); - for dep_str in deps { + 'dep: for dep_str in deps { let dep = SplitPackage::new(dep_str); // Find a version of a package that satisfies our requirements. - let cache_apt_pkg = cache.get_apt_pkg(&dep.pkgname); let mpr_pkg = cache.mpr_cache().packages().get(&dep.pkgname); - // We want to prefer the APT package for any dependencies, so test that first. - if let Some(pkg) = cache_apt_pkg { - let version_satisfied: bool; - let apt_pkg = cache.apt_cache().get(&pkg.pkgname).unwrap(); - - if let Some(dep_version) = dep.version { - let apt_version = apt_pkg.candidate().unwrap().version(); - version_satisfied = util::check_version_requirement( - &apt_version, - &dep.operator.unwrap(), - &dep_version, - ); + if cache.get_apt_pkg(&dep.pkgname).is_some() { + // Get any package versions (as well as provided package versions) that can + // satisfy the version specified by `dep.operator`. If there is + // no operator, then all versions match. + let mut versions: Vec = Vec::new(); + let apt_pkg = cache.apt_cache().get(&dep.pkgname).unwrap(); + + if dep.version.is_none() { + for ver in apt_pkg.versions() { + versions.push(ver); + } + + for ver in apt_pkg.rev_provides_list(None) { + versions.push(ver); + } } else { - version_satisfied = true; + let dep_operator = dep.operator.as_ref().unwrap(); + let dep_version = dep.version.as_ref().unwrap(); + + for ver in apt_pkg.versions() { + if util::check_version_requirement( + &ver.version(), + dep_operator, + dep_version, + ) { + versions.push(ver); + } + } + + for ver in apt_pkg.rev_provides_list(Some((dep_operator, dep_version))) { + versions.push(ver); + } } - if version_satisfied { - if apt_pkg.marked_install() { - good_dep_found = true; - break; - } else if apt_pkg.marked_keep() { - apt_pkg.mark_install(true, false).then_some(()).unwrap(); - apt_pkg.protect(); + // If one of the available versions is installed, then it satisfies the dep. + for ver in &versions { + if ver.parent().is_installed() && &ver.parent().candidate().unwrap() == ver { good_dep_found = true; - break; + break 'dep; } } - // The APT package didn't meet our requirements, so check the MPR package. - } else if let Some(pkg) = mpr_pkg { - let version_satisfied: bool; - - if let Some(dep_version) = dep.version { - version_satisfied = util::check_version_requirement( - &pkg.version, - &dep.operator.unwrap(), - &dep_version, - ); - } else { - version_satisfied = true; - } - if version_satisfied { - mpr_pkglist.append(&mut resolve_mpr_package( - cache, - &pkg.pkgname, - current_recursion + 1, - recursion_limit, - )); + // Otherwise just mark the first available version as satisfying the dep. + if let Some(ver) = versions.get(0) { + ver.set_candidate(); + ver.parent() + .mark_install(false, false) + .then_some(()) + .unwrap(); + ver.parent().protect(); + good_dep_found = true; + break 'dep; } } } @@ -273,7 +281,8 @@ pub fn order_mpr_packages(cache: &Cache, pkglist: &Vec<&str>) -> Vec { mpr_pkglist.append(&mut resolve_mpr_package(cache, pkg, 1, recursion_limit)); } - // TODO: This list needs ordered before returning it so that MPR packages are installed in the correct way. + // TODO: This list needs ordered before returning it so that MPR packages are + // installed in the correct way. message::warning("PLEASE ORDER BEFORE MERGE {:?} THX!\n"); mpr_pkglist } diff --git a/src/main.rs b/src/main.rs index 4ec0b90..aef5751 100644 --- a/src/main.rs +++ b/src/main.rs @@ -169,6 +169,7 @@ fn get_cli() -> Command<'static> { .help("Automatically remove any unneeded packages") .long("autoremove") ) + .arg(mpr_url_arg.clone().hide(true)) ) .subcommand( Command::new("search") diff --git a/src/remove.rs b/src/remove.rs index fa193b9..cddead9 100644 --- a/src/remove.rs +++ b/src/remove.rs @@ -1,8 +1,11 @@ -use crate::{apt_util, cache::run_transaction, message, util}; +use crate::{ + apt_util, + cache::{Cache, MprCache}, + message, util, +}; use rust_apt::cache::{Cache as AptCache, PackageSort}; pub fn remove(args: &clap::ArgMatches) { - let cache = AptCache::new(); let pkglist: Vec<&String> = { if let Some(pkglist) = args.get_many("pkg") { pkglist.collect() @@ -12,6 +15,8 @@ pub fn remove(args: &clap::ArgMatches) { }; let purge = args.is_present("purge"); let autoremove = args.is_present("autoremove"); + let mpr_url: &String = args.get_one("mpr-url").unwrap(); + let cache = Cache::new(AptCache::new(), MprCache::new(mpr_url)); // Lock the cache. if let Err(err) = apt_util::apt_lock() { @@ -21,7 +26,7 @@ pub fn remove(args: &clap::ArgMatches) { // Remove the user requested packages. for pkgname in pkglist { - if let Some(pkg) = cache.get(pkgname) { + if let Some(pkg) = cache.apt_cache().get(pkgname) { if !pkg.is_installed() { message::warning(&format!( "Package '{}' isn't installed, so not removing.\n", @@ -37,7 +42,7 @@ pub fn remove(args: &clap::ArgMatches) { // Remove any packages that are no longer needed. if autoremove { - for pkg in cache.packages(&PackageSort::default()) { + for pkg in cache.apt_cache().packages(&PackageSort::default()) { if pkg.is_auto_removable() { pkg.mark_delete(purge).then_some(()).unwrap(); pkg.protect(); @@ -45,16 +50,14 @@ pub fn remove(args: &clap::ArgMatches) { } } - if let Err(err) = cache.resolve(true) { + if let Err(err) = cache.apt_cache().resolve(true) { util::handle_errors(&err); quit::with_code(exitcode::UNAVAILABLE); } // Unlock the cache so our transaction can complete. - if let Err(err) = apt_util::apt_unlock() { - util::handle_errors(&err); - quit::with_code(exitcode::UNAVAILABLE); - } + apt_util::apt_unlock(); - run_transaction(&cache, purge); + // Commit our changes. + cache.commit(&Vec::new()); } diff --git a/src/style.rs b/src/style.rs index 691ff74..1ad8456 100644 --- a/src/style.rs +++ b/src/style.rs @@ -92,7 +92,8 @@ pub fn generate_pkginfo_entry( pkgdesc = apt_pkg_unwrapped.pkgdesc.clone(); } - // Add the first line and description, at long last. This string is the one we'll return at the end of the function. + // Add the first line and description, at long last. This string is the one + // we'll return at the end of the function. write!(return_string, "/{} {}", pkgver, src_str).unwrap(); if let Some(unwrapped_pkgdesc) = pkgdesc { diff --git a/src/util.rs b/src/util.rs index 7b06abb..dbd6703 100644 --- a/src/util.rs +++ b/src/util.rs @@ -40,13 +40,13 @@ impl<'a> AuthenticatedRequest<'a> { } }; - // Check the response and see if we got a bad API token error. If we did, go ahead and - // abort the program. + // Check the response and see if we got a bad API token error. If we did, go + // ahead and abort the program. let resp_text = resp.text().unwrap(); if let Ok(json) = serde_json::from_str::(&resp_text) { - // TODO: We need to define a more suitable way for machine parsing of errors in the - // MPR. Maybe something like '{"err_type": "invalid_api_key"}'. + // TODO: We need to define a more suitable way for machine parsing of errors in + // the MPR. Maybe something like '{"err_type": "invalid_api_key"}'. if json.resp_type == "error" && json.code == "err_invalid_api_key" { message::error("Invalid API key was passed in.\n"); quit::with_code(exitcode::USAGE); @@ -105,8 +105,8 @@ impl<'a> Command<'a> { pub fn run(&self) -> CommandResult { let cmd_name = self.args.first().unwrap(); let cmd_args = &self.args[1..]; - // Functions like 'ProcCommand::stdin()' return references to the object created by - // 'ProcCommand::new()', which returns the object itself. + // Functions like 'ProcCommand::stdin()' return references to the object created + // by 'ProcCommand::new()', which returns the object itself. // We want to only interact with references to the object from hereon out. let mut _result = ProcCommand::new(cmd_name); let mut result = &mut _result; @@ -170,7 +170,8 @@ pub fn handle_errors(err_str: &apt_util::Exception) { /// Format a list of package names in the way APT would. pub fn format_apt_pkglist + Display>(pkgnames: &Vec) { - // All package lines always start with two spaces, so pretend like we have two less characters. + // All package lines always start with two spaces, so pretend like we have two + // less characters. let term_width = apt_util::terminal_width() - 2; let mut output = String::from(" "); let mut current_width = 0; @@ -191,7 +192,8 @@ pub fn format_apt_pkglist + Display>(pkgnames: &Vec) { println!("{}", output); } -/// Check if a response was a "yes" response. 'default' is what to return if 'resp' is empty. +/// Check if a response was a "yes" response. 'default' is what to return if +/// 'resp' is empty. pub fn is_yes(resp: &str, default: bool) -> bool { resp.to_lowercase() == "y" || (resp.is_empty() && default) } @@ -203,7 +205,9 @@ pub fn ask_question(question: &str, options: &Vec<&str>, multi_allowed: bool) -> let options_len = options.len(); message::question(question); - // Panic if no options were passed in, there's nothing to work with there. This function should only be used internally anyway, so this just gives a heads up that it's being used incorrectly. + // Panic if no options were passed in, there's nothing to work with there. This + // function should only be used internally anyway, so this just gives a heads up + // that it's being used incorrectly. if options.is_empty() { panic!("No values passed in for `options` parameter"); } @@ -300,7 +304,8 @@ pub fn ask_question(question: &str, options: &Vec<&str>, multi_allowed: bool) -> result.unwrap() } -/// Get the system's distro and architecture. The first value returned is the distribution, and the second is the architecture. +/// Get the system's distro and architecture. The first value returned is the +/// distribution, and the second is the architecture. pub fn get_distro_arch_info() -> (String, String) { let distro_cmd = Command::new(vec!["lsb_release", "-cs"], true, None).run(); let arch_cmd = Command::new(vec!["dpkg", "--print-architecture"], true, None).run();