-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
remove rust-apt dependency and un-comment the apt backend (#1)
- Loading branch information
Showing
3 changed files
with
79 additions
and
85 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)), | ||
) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters