Skip to content

Commit 49b5453

Browse files
committed
fix(vm): look for e2fsprogs tools in /usr/sbin and /sbin
The VM driver only checked PATH and the Homebrew e2fsprogs dirs for mke2fs, e2fsck and debugfs. On Linux these live in /usr/sbin or /sbin, which usually isn't on a regular user's PATH, so provisioning failed with "mke2fs not found" even with e2fsprogs installed. Add /usr/local/sbin, /usr/sbin and /sbin to the search list. macOS behavior is unchanged. Closes #3400 Signed-off-by: natedemoss <ndemoss28@gmail.com>
1 parent bed9e5e commit 49b5453

1 file changed

Lines changed: 23 additions & 0 deletions

File tree

‎crates/openshell-driver-vm/src/rootfs.rs‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1107,8 +1107,17 @@ fn run_debugfs(image_path: &Path, command: &str) -> Result<(), String> {
11071107
))
11081108
}
11091109

1110+
/// Resolve the places an e2fsprogs binary may live, starting with `PATH`.
1111+
///
1112+
/// Distributions install `mke2fs`, `e2fsck`, and `debugfs` under `/usr/sbin`
1113+
/// or `/sbin`, which most Linux hosts leave out of a non-root user's `PATH`,
1114+
/// so those directories are probed explicitly. Homebrew keeps e2fsprogs
1115+
/// keg-only on macOS, so its prefixes are probed as well.
11101116
fn e2fs_tool_candidates(tool: &str) -> Vec<PathBuf> {
11111117
let mut candidates = vec![PathBuf::from(tool)];
1118+
for dir in ["/usr/local/sbin", "/usr/sbin", "/sbin"] {
1119+
candidates.push(Path::new(dir).join(tool));
1120+
}
11121121
for root in ["/opt/homebrew/opt/e2fsprogs", "/usr/local/opt/e2fsprogs"] {
11131122
candidates.push(Path::new(root).join("sbin").join(tool));
11141123
candidates.push(Path::new(root).join("bin").join(tool));
@@ -1668,6 +1677,20 @@ mod tests {
16681677
assert_eq!(debugfs_quote_argument("/tmp/bad\npath"), None);
16691678
}
16701679

1680+
#[test]
1681+
fn e2fs_tool_candidates_probe_path_then_system_sbin_directories() {
1682+
let candidates = e2fs_tool_candidates("mke2fs");
1683+
1684+
assert_eq!(candidates.first(), Some(&PathBuf::from("mke2fs")));
1685+
for expected in ["/usr/local/sbin/mke2fs", "/usr/sbin/mke2fs", "/sbin/mke2fs"] {
1686+
assert!(
1687+
candidates.contains(&PathBuf::from(expected)),
1688+
"expected {expected} in {candidates:?}"
1689+
);
1690+
}
1691+
assert!(candidates.contains(&PathBuf::from("/opt/homebrew/opt/e2fsprogs/sbin/mke2fs")));
1692+
}
1693+
16711694
#[test]
16721695
fn formatter_candidates_preserve_executed_failure_over_missing_fallback() {
16731696
let candidates = vec![PathBuf::from("mke2fs"), PathBuf::from("missing")];

0 commit comments

Comments
 (0)