(image_path: &Path, command: &str)
| 704 | } |
| 705 | |
| 706 | fn run_debugfs(image_path: &Path, command: &str) -> Result<(), String> { |
| 707 | let mut last_error = None; |
| 708 | for candidate in e2fs_tool_candidates("debugfs") { |
| 709 | let label = candidate.display().to_string(); |
| 710 | let output = Command::new(&candidate) |
| 711 | .arg("-w") |
| 712 | .arg("-R") |
| 713 | .arg(command) |
| 714 | .arg(image_path) |
| 715 | .output(); |
| 716 | match output { |
| 717 | Ok(output) if output.status.success() => return Ok(()), |
| 718 | Ok(output) => { |
| 719 | last_error = Some(format!( |
| 720 | "{label} failed with status {}\nstdout: {}\nstderr: {}", |
| 721 | output.status, |
| 722 | String::from_utf8_lossy(&output.stdout), |
| 723 | String::from_utf8_lossy(&output.stderr) |
| 724 | )); |
| 725 | } |
| 726 | Err(err) if err.kind() == std::io::ErrorKind::NotFound => { |
| 727 | last_error = Some(format!("{label} not found")); |
| 728 | } |
| 729 | Err(err) => { |
| 730 | last_error = Some(format!("run {label}: {err}")); |
| 731 | } |
| 732 | } |
| 733 | } |
| 734 | Err(format!( |
| 735 | "debugfs command '{command}' failed for {}: {}. Install e2fsprogs (debugfs) and retry", |
| 736 | image_path.display(), |
| 737 | last_error.unwrap_or_else(|| "debugfs not found".to_string()) |
| 738 | )) |
| 739 | } |
| 740 | |
| 741 | fn e2fs_tool_candidates(tool: &str) -> Vec<PathBuf> { |
| 742 | let mut candidates = vec![PathBuf::from(tool)]; |
no test coverage detected