Skip to content

Commit 8c35425

Browse files
committed
fix(vm): resolve debugfs through augmented path in ext4 directory probe
ext4_image_has_directory landed on main in #3524 using the removed e2fs_tool_candidates helper. Route it and its test through e2fs_command so it uses the same PATH lookup as the other e2fsprogs callers. Signed-off-by: Nathan DeMoss <ndemoss28@gmail.com>
1 parent 84b7f03 commit 8c35425

1 file changed

Lines changed: 39 additions & 46 deletions

File tree

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

Lines changed: 39 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -876,52 +876,40 @@ pub fn ext4_image_has_directory(image_path: &Path, guest_path: &str) -> Result<b
876876
let quoted_path = debugfs_quote_absolute_path(guest_path)
877877
.ok_or_else(|| format!("invalid debugfs guest path '{guest_path}'"))?;
878878
let command = format!("stat {quoted_path}");
879-
let mut last_error = None;
880-
881-
for candidate in e2fs_tool_candidates("debugfs") {
882-
let label = candidate.display().to_string();
883-
match Command::new(&candidate)
884-
.arg("-R")
885-
.arg(&command)
886-
.arg(image_path)
887-
.output()
888-
{
889-
Ok(output) if output.status.success() => {
890-
// debugfs exits 0 whether or not the path exists; the answer
891-
// is only in its output.
892-
let stdout = String::from_utf8_lossy(&output.stdout);
893-
let stderr = String::from_utf8_lossy(&output.stderr);
894-
if stdout.contains("Type: directory") {
895-
return Ok(true);
896-
}
897-
if stdout.contains("Type: ") || stderr.contains("File not found") {
898-
return Ok(false);
899-
}
900-
return Err(format!(
901-
"debugfs command '{command}' produced unrecognized output for {}\nstdout: {stdout}\nstderr: {stderr}",
902-
image_path.display()
903-
));
904-
}
905-
Ok(output) => {
906-
last_error = Some(format!(
907-
"{label} failed with status {}\nstdout: {}\nstderr: {}",
908-
output.status,
909-
String::from_utf8_lossy(&output.stdout),
910-
String::from_utf8_lossy(&output.stderr)
911-
));
879+
let output = e2fs_command("debugfs")?
880+
.arg("-R")
881+
.arg(&command)
882+
.arg(image_path)
883+
.output();
884+
match output {
885+
Ok(output) if output.status.success() => {
886+
// debugfs exits 0 whether or not the path exists; the answer
887+
// is only in its output.
888+
let stdout = String::from_utf8_lossy(&output.stdout);
889+
let stderr = String::from_utf8_lossy(&output.stderr);
890+
if stdout.contains("Type: directory") {
891+
return Ok(true);
912892
}
913-
Err(error) if error.kind() == std::io::ErrorKind::NotFound => {
914-
last_error = Some(format!("{label} not found"));
893+
if stdout.contains("Type: ") || stderr.contains("File not found") {
894+
return Ok(false);
915895
}
916-
Err(error) => last_error = Some(format!("run {label}: {error}")),
896+
Err(format!(
897+
"debugfs command '{command}' produced unrecognized output for {}\nstdout: {stdout}\nstderr: {stderr}",
898+
image_path.display()
899+
))
917900
}
901+
Ok(output) => Err(format!(
902+
"debugfs command '{command}' failed for {}: debugfs failed with status {}\nstdout: {}\nstderr: {}. Install e2fsprogs (debugfs) and retry",
903+
image_path.display(),
904+
output.status,
905+
String::from_utf8_lossy(&output.stdout),
906+
String::from_utf8_lossy(&output.stderr)
907+
)),
908+
Err(error) => Err(format!(
909+
"debugfs command '{command}' failed for {}: {error}. Install e2fsprogs (debugfs) and retry",
910+
image_path.display()
911+
)),
918912
}
919-
920-
Err(format!(
921-
"debugfs command '{command}' failed for {}: {}. Install e2fsprogs (debugfs) and retry",
922-
image_path.display(),
923-
last_error.unwrap_or_else(|| "debugfs not found".to_string())
924-
))
925913
}
926914

927915
fn sandbox_guest_user_ids_from_image_path(
@@ -1563,10 +1551,15 @@ mod tests {
15631551

15641552
#[test]
15651553
fn ext4_image_has_directory_distinguishes_directories_files_and_missing_paths() {
1566-
if !e2fs_tool_candidates("debugfs")
1567-
.iter()
1568-
.any(|candidate| Command::new(candidate).arg("-V").output().is_ok())
1569-
{
1554+
let available = e2fs_command("debugfs")
1555+
.and_then(|mut command| {
1556+
command
1557+
.arg("-V")
1558+
.output()
1559+
.map_err(|error| error.to_string())
1560+
})
1561+
.is_ok();
1562+
if !available {
15701563
return;
15711564
}
15721565

0 commit comments

Comments
 (0)