From 7cd19faf697dd34ef9e2ff0086739b9e86a9781b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcus=20Sch=C3=A4fer?= Date: Mon, 19 Oct 2026 21:23:11 +0200 Subject: [PATCH 1/2] Use the which crate Use the which crate to lookup a binary in PATH --- common/src/lookup.rs | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/common/src/lookup.rs b/common/src/lookup.rs index 8ceea6f3..0d2cefed 100644 --- a/common/src/lookup.rs +++ b/common/src/lookup.rs @@ -23,7 +23,6 @@ // use std::collections::HashMap; use std::env; -use std::fs; use crate::flakelog::FlakeLog; @@ -137,14 +136,11 @@ impl Lookup { } pub fn which(command: &str) -> bool { - if let Ok(path) = env::var("PATH") { - for path_entry in path.split(':') { - let abs_command = format!("{path_entry}/{command}"); - if fs::metadata(abs_command).is_ok() { - return true; - } - } - } - false + /*! + Check if the given command can be called. A command given + without a path is searched in $PATH the same way it is + found when it gets called. Only executable files count + !*/ + which::which(command).is_ok() } } From f97f2d82007e52f05e38265add869d3a307ab083 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcus=20Sch=C3=A4fer?= Date: Mon, 19 Oct 2026 21:23:58 +0200 Subject: [PATCH 2/2] Fix bwrap lookup in bubblewrwap-pilot bubblewrap-pilot checks that bwrap exists by searching PATH, but it then runs bwrap from the fixed path /usr/bin/bwrap. As such the search doesn't make any sense. This commit Fixes #174 --- bubblewrap-pilot/src/bubblewrap.rs | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/bubblewrap-pilot/src/bubblewrap.rs b/bubblewrap-pilot/src/bubblewrap.rs index 60bf2ab5..d960fcf0 100644 --- a/bubblewrap-pilot/src/bubblewrap.rs +++ b/bubblewrap-pilot/src/bubblewrap.rs @@ -37,7 +37,7 @@ use uzers::get_current_username; use std::env; use std::fs; -use std::io::Write; +use std::io::{self, Write}; use std::path::Path; use std::process::{Command, ExitCode}; @@ -93,17 +93,6 @@ pub fn create(program_name: &str) -> Result { name of the meta data file which represents the instance is returned by this method !*/ - // The sandbox is created by the bwrap program - if ! Lookup::which(defaults::BWRAP) { - return Err(FlakeError::IOError { - kind: "Sandbox engine not found".to_string(), - message: format!( - "{} is required to run this flake, please install it", - defaults::BWRAP - ) - }) - } - // A sandbox provides no entry point like a container image // does. The command to call in it has to be known if get_target_app_path(program_name) == "/" { @@ -251,7 +240,20 @@ fn run_sandbox( if spawned.is_err() { delete_sandbox_id_file(sandbox_id_file); } - let mut child = spawned?; + let mut child = match spawned { + Ok(child) => child, + // The sandbox is created by the bwrap program + Err(error) if error.kind() == io::ErrorKind::NotFound => { + return Err(FlakeError::IOError { + kind: "Sandbox engine not found".to_string(), + message: format!( + "{} is required to run this flake, please install it", + defaults::BWRAP_PATH + ) + }) + }, + Err(error) => return Err(error.into()) + }; let pid = child.id(); if Lookup::is_debug() {