Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 15 additions & 13 deletions bubblewrap-pilot/src/bubblewrap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};

Expand Down Expand Up @@ -93,17 +93,6 @@ pub fn create(program_name: &str) -> Result<String, FlakeError> {
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) == "/" {
Expand Down Expand Up @@ -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() {
Expand Down
16 changes: 6 additions & 10 deletions common/src/lookup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
//
use std::collections::HashMap;
use std::env;
use std::fs;

use crate::flakelog::FlakeLog;

Expand Down Expand Up @@ -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()
}
}
Loading