Skip to content

Commit

Permalink
Use -o to ignore optional deps with --clean
Browse files Browse the repository at this point in the history
  • Loading branch information
Morganamilo committed Nov 12, 2022
1 parent 492f5b1 commit bed91b2
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 6 deletions.
3 changes: 2 additions & 1 deletion man/paru.8
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,8 @@ date. Updates will then be detected on the next commit.
Remove unneeded dependencies.

Make and check dependencies are considered for
foreign packages. Pass this twice to ignore these.
foreign packages. Pass this twice to ignore these. Pass \-o to
ignore optional dependencies.

.SH SHOW OPTIONS (APPLY TO \-P AND \-\-SHOW)
.TP
Expand Down
1 change: 1 addition & 0 deletions src/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ pub static PACMAN_FLAGS: &[&str] = &[
"recursive",
"unneeded",
"clean",
"optional",
"sysupgrade",
"w",
"downloadonly",
Expand Down
7 changes: 6 additions & 1 deletion src/command_line.rs
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,11 @@ impl Config {
self.stats = true;
self.ssh = true;
}
Arg::Long("order") | Arg::Short('o') => self.order = true,
Arg::Long("order") => self.order = true,
Arg::Short('o') => {
self.order = true;
self.optional = true;
}
Arg::Long("removemake") => {
self.remove_make = YesNoAsk::Yes.default_or(argkey, value.ok())?
}
Expand Down Expand Up @@ -261,6 +265,7 @@ impl Config {
}
Arg::Long("nosudoloop") => self.sudo_loop.clear(),
Arg::Long("clean") => self.clean += 1,
Arg::Long("optional") => self.optional = true,
Arg::Long("complete") => self.complete = true,
Arg::Short('c') => {
self.complete = true;
Expand Down
1 change: 1 addition & 0 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,7 @@ pub struct Config {
pub use_ask: bool,
pub save_changes: bool,
pub clean: usize,
pub optional: bool,
pub complete: bool,
pub print: bool,
pub news_on_upgrade: bool,
Expand Down
3 changes: 2 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -242,10 +242,11 @@ async fn handle_yay(config: &mut Config) -> Result<i32> {
Ok(0)
} else if config.clean > 0 {
config.need_root = true;
let unneeded = util::unneeded_pkgs(config, config.clean == 1);
let unneeded = util::unneeded_pkgs(config, config.clean == 1, !config.optional);
if !unneeded.is_empty() {
let mut args = config.pacman_args();
args.remove("c").remove("clean");
args.remove("o");
args.targets = unneeded;
args.op = "remove";
Ok(exec::pacman(config, &args)?.code())
Expand Down
6 changes: 3 additions & 3 deletions src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ enum State {
Keep,
}

pub fn unneeded_pkgs(config: &Config, optional: bool) -> Vec<&str> {
pub fn unneeded_pkgs(config: &Config, keep_make: bool, keep_optional: bool) -> Vec<&str> {
let mut states = HashMap::new();
let mut remove = Vec::new();
let mut providers = HashMap::<_, Vec<_>>::new();
Expand Down Expand Up @@ -221,11 +221,11 @@ pub fn unneeded_pkgs(config: &Config, optional: bool) -> Vec<&str> {
state.set(State::Keep);
check_deps(pkg.depends());

if optional {
if keep_optional {
check_deps(pkg.optdepends());
}

if config.clean > 1 {
if keep_make {
continue;
}

Expand Down

0 comments on commit bed91b2

Please sign in to comment.