Skip to content

Commit

Permalink
refactor: Drop run_shell_command()
Browse files Browse the repository at this point in the history
run_shell_command() is no longer used and related error variant and
tests can be dropped.

Signed-off-by: Takahiro Itazuri <[email protected]>
  • Loading branch information
zulinx86 committed Jul 18, 2024
1 parent 643349a commit f91b800
Showing 1 changed file with 0 additions and 36 deletions.
36 changes: 0 additions & 36 deletions src/cpu-template-helper/src/fingerprint/dump.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ pub enum FingerprintDumpError {
ReadSysfsFile(String, std::io::Error),
/// Failed to get kernel version: {0}
GetKernelVersion(std::io::Error),
/// `{0}` failed: {1}
ShellCommand(String, String),
}

pub fn dump(vmm: Arc<Mutex<Vmm>>) -> Result<Fingerprint, FingerprintDumpError> {
Expand Down Expand Up @@ -61,26 +59,6 @@ fn read_sysfs_file(path: &str) -> Result<String, FingerprintDumpError> {
Ok(s.trim_end_matches('\n').to_string())
}

fn run_shell_command(cmd: &str) -> Result<String, FingerprintDumpError> {
let output = std::process::Command::new("bash")
.args(["-c", cmd])
.output()
.map_err(|err| FingerprintDumpError::ShellCommand(cmd.to_string(), err.to_string()))?;

if !output.status.success() {
return Err(FingerprintDumpError::ShellCommand(
cmd.to_string(),
format!(
"code: {:?}\nstdout: {}\nstderr: {}",
output.status.code(),
std::str::from_utf8(&output.stdout).unwrap(),
std::str::from_utf8(&output.stderr).unwrap(),
),
));
}
Ok(std::str::from_utf8(&output.stdout).unwrap().to_string())
}

#[cfg(test)]
mod tests {
use super::*;
Expand All @@ -105,18 +83,4 @@ mod tests {
panic!("Should fail with `No such file or directory`");
}
}

#[test]
fn test_run_valid_shell_command() {
let valid_cmd = "ls";
run_shell_command(valid_cmd).unwrap();
}

#[test]
fn test_run_invalid_shell_command() {
let invalid_cmd = "unknown_command";
if run_shell_command(invalid_cmd).is_ok() {
panic!("Should fail with `unknown_command: not found`");
}
}
}

0 comments on commit f91b800

Please sign in to comment.