From 9e19bb7dab43af026367cec5b92c5f8cfbefebc3 Mon Sep 17 00:00:00 2001 From: amy null Date: Sat, 6 May 2023 23:15:09 -0400 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20fix:=200.7.1:=20Don't=20crash=20?= =?UTF-8?q?when=20`which`=20fails=20at=20binary=20comparison?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Cargo.lock | 2 +- Cargo.toml | 2 +- src/enclosure/rule.rs | 14 +++++++++++--- 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 478b208..e9baf62 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -171,7 +171,7 @@ dependencies = [ [[package]] name = "boxxy" -version = "0.7.0" +version = "0.7.1" dependencies = [ "atty", "bat", diff --git a/Cargo.toml b/Cargo.toml index 20120d2..1523512 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "boxxy" -version = "0.7.0" +version = "0.7.1" edition = "2021" repository = "https://github.com/queer/boxxy" diff --git a/src/enclosure/rule.rs b/src/enclosure/rule.rs index b81d10e..bbf088c 100644 --- a/src/enclosure/rule.rs +++ b/src/enclosure/rule.rs @@ -160,10 +160,18 @@ impl Rule { } // Resolve both program and rule_binary with `which` and compare. ex. /usr/bin/ls == /usr/bin/ls - let which_rule_binary = which::which(rule_binary)?; - let which_user_program = which::which(program)?; + let which_rule_binary = match which::which(rule_binary) { + Ok(which_rule_binary) => Some(which_rule_binary), + Err(_) => None, + }; + let which_user_program = match which::which(program) { + Ok(which_user_program) => Some(which_user_program), + Err(_) => None, + }; debug!("{}: comparing binaries with which(1): which_user_program={which_user_program:?}, which_rule_binary={which_rule_binary:?}", self.name); - if which_rule_binary == which_user_program { + if which_rule_binary == which_user_program + && (which_rule_binary.is_some() || which_user_program.is_some()) + { return Ok(true); }