diff --git a/src/config/network/helper.rs b/src/config/network/helper.rs index c89427f9..b14cde6e 100644 --- a/src/config/network/helper.rs +++ b/src/config/network/helper.rs @@ -149,7 +149,7 @@ pub fn compute_file_diff(filename: &str, shadow: &str) -> Result .output() .map_err(|err| format_err!("failed to execute diff - {}", err))?; - let diff = crate::tools::command_output(output, Some(|c| c == 0 || c == 1)) + let diff = crate::tools::command_output_as_string(output, Some(|c| c == 0 || c == 1)) .map_err(|err| format_err!("diff failed: {}", err))?; Ok(diff) diff --git a/src/tools.rs b/src/tools.rs index 5cf674fe..33986b1c 100644 --- a/src/tools.rs +++ b/src/tools.rs @@ -405,7 +405,7 @@ pub fn normalize_uri_path(path: &str) -> Result<(String, Vec<&str>), Error> { pub fn command_output( output: std::process::Output, exit_code_check: Option bool>, -) -> Result { +) -> Result, Error> { if !output.status.success() { match output.status.code() { @@ -426,8 +426,19 @@ pub fn command_output( } } - let output = String::from_utf8(output.stdout)?; + Ok(output.stdout) +} +/// Helper to check result from std::process::Command output, returns String. +/// +/// The exit_code_check() function should return true if the exit code +/// is considered successful. +pub fn command_output_as_string( + output: std::process::Output, + exit_code_check: Option bool>, +) -> Result { + let output = command_output(output, exit_code_check)?; + let output = String::from_utf8(output)?; Ok(output) } @@ -439,7 +450,7 @@ pub fn run_command( let output = command.output() .map_err(|err| format_err!("failed to execute {:?} - {}", command, err))?; - let output = crate::tools::command_output(output, exit_code_check) + let output = crate::tools::command_output_as_string(output, exit_code_check) .map_err(|err| format_err!("command {:?} failed - {}", command, err))?; Ok(output)