Skip to content

Commit

Permalink
remove rust-apt dependency and un-comment the apt backend (#1)
Browse files Browse the repository at this point in the history
  • Loading branch information
ripytide authored Aug 29, 2024
1 parent 1b36fa8 commit a78bd15
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 85 deletions.
2 changes: 0 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@ toml = "0.8"
derive_more = "0.99"
itertools = "0.12"

# rust-apt = "0.7"

[profile.release]
lto = "off"
opt-level = "z"
Expand Down
153 changes: 74 additions & 79 deletions src/backend/apt.rs
Original file line number Diff line number Diff line change
@@ -1,91 +1,86 @@
// use std::collections::BTreeMap;
use std::collections::BTreeMap;

// use anyhow::Result;
// use rust_apt::cache::{PackageSort, Sort};
// use rust_apt::new_cache;
use anyhow::Result;

// use crate::cmd::{command_found, run_args};
// use crate::prelude::*;
use crate::cmd::{command_found, run_args, run_args_for_stdout};
use crate::prelude::*;

// #[derive(Debug, Copy, Clone, derive_more::Display)]
// pub struct Apt;
#[derive(Debug, Copy, Clone, derive_more::Display)]
pub struct Apt;

// #[derive(Debug, Clone)]
// pub struct AptQueryInfo {
// explicit: bool,
// }
#[derive(Debug, Clone)]
pub struct AptQueryInfo {
explicit: bool,
}

// pub struct AptMakeImplicit;
pub struct AptMakeImplicit;

// impl Backend for Apt {
// type PackageId = String;
// type RemoveOptions = ();
// type InstallOptions = ();
// type QueryInfo = AptQueryInfo;
// type Modification = AptMakeImplicit;
impl Backend for Apt {
type PackageId = String;
type RemoveOptions = ();
type InstallOptions = ();
type QueryInfo = AptQueryInfo;
type Modification = AptMakeImplicit;

// fn query_installed_packages(_: &Config) -> Result<BTreeMap<Self::PackageId, Self::QueryInfo>> {
// if !command_found("apt") {
// return Ok(BTreeMap::new());
// }
fn query_installed_packages(_: &Config) -> Result<BTreeMap<Self::PackageId, Self::QueryInfo>> {
if !command_found("apt-mark") {
return Ok(BTreeMap::new());
}

// let cache = new_cache!()?;
// See https://askubuntu.com/questions/2389/how-to-list-manually-installed-packages
// for a run-down of methods for finding lists of
// explicit/dependency packages. It doesn't seem as if apt was
// designed with this use-case in mind so there are lots and
// lots of different methods all of which seem to have
// caveats.
let explicit = run_args_for_stdout(["apt-mark", "showmanual"])?;
let dependency = run_args_for_stdout(["apt-mark", "showauto"])?;

// let packages = cache.packages(&PackageSort {
// names: true,
// upgradable: Sort::Enable,
// virtual_pkgs: Sort::Enable,
// installed: Sort::Enable,
// auto_installed: Sort::Enable,
// auto_removable: Sort::Enable,
// })?;
Ok(dependency
.lines()
.map(|x| (x.to_string(), AptQueryInfo { explicit: false }))
.chain(
explicit
.lines()
.map(|x| (x.to_string(), AptQueryInfo { explicit: true })),
)
.collect())
}

// Ok(packages
// .map(|x| {
// (
// x.name().to_string(),
// AptQueryInfo {
// explicit: !x.is_auto_installed(),
// },
// )
// })
// .collect())
// }
fn install_packages(
packages: &BTreeMap<Self::PackageId, Self::InstallOptions>,
no_confirm: bool,
_: &Config,
) -> Result<()> {
run_args(
["apt-get", "install"]
.into_iter()
.chain(Some("--yes").filter(|_| no_confirm))
.chain(packages.keys().map(String::as_str)),
)
}

// fn install_packages(
// packages: &BTreeMap<Self::PackageId, Self::InstallOptions>,
// no_confirm: bool,
// _: &Config,
// ) -> Result<()> {
// run_args(
// ["apt", "install"]
// .into_iter()
// .chain(Some("--yes").filter(|_| no_confirm))
// .chain(packages.keys().map(String::as_str)),
// )
// }
fn modify_packages(
packages: &BTreeMap<Self::PackageId, Self::Modification>,
_: &Config,
) -> Result<()> {
run_args(
["apt-mark", "auto"]
.into_iter()
.chain(packages.keys().map(String::as_str)),
)
}

// fn modify_packages(
// packages: &BTreeMap<Self::PackageId, Self::Modification>,
// _: &Config,
// ) -> Result<()> {
// run_args(
// ["apt-mark", "auto"]
// .into_iter()
// .chain(packages.keys().map(String::as_str)),
// )
// }

// fn remove_packages(
// packages: &BTreeMap<Self::PackageId, Self::RemoveOptions>,
// no_confirm: bool,
// _: &Config,
// ) -> Result<()> {
// run_args(
// ["apt", "remove"]
// .into_iter()
// .chain(Some("--yes").filter(|_| no_confirm))
// .chain(packages.keys().map(String::as_str)),
// )
// }
// }
fn remove_packages(
packages: &BTreeMap<Self::PackageId, Self::RemoveOptions>,
no_confirm: bool,
_: &Config,
) -> Result<()> {
run_args(
["apt-get", "remove"]
.into_iter()
.chain(Some("--yes").filter(|_| no_confirm))
.chain(packages.keys().map(String::as_str)),
)
}
}
9 changes: 5 additions & 4 deletions src/backend/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// pub mod apt;
pub mod apt;
pub mod arch;
pub mod cargo;
pub mod dnf;
Expand All @@ -12,10 +12,11 @@ use std::{collections::BTreeMap, str::FromStr};

use crate::prelude::*;
use anyhow::{Context, Result};
use apt::Apt;

#[derive(Debug, Copy, Clone, derive_more::Display)]
pub enum AnyBackend {
// Apt(Apt),
Apt(Apt),
Arch(Arch),
Cargo(Cargo),
Dnf(Dnf),
Expand All @@ -27,8 +28,8 @@ pub enum AnyBackend {
}

impl AnyBackend {
pub const ALL: [Self; 8] = [
// Self::Apt(Apt),
pub const ALL: [Self; 9] = [
Self::Apt(Apt),
Self::Arch(Arch),
Self::Cargo(Cargo),
Self::Dnf(Dnf),
Expand Down

0 comments on commit a78bd15

Please sign in to comment.