From c0fc5db58ce8c6d903067225ef7acdd799e37eab Mon Sep 17 00:00:00 2001 From: Alyssa Ross Date: Tue, 3 May 2022 16:58:18 +0000 Subject: Don't try to rename the history file if curl failed --- hydrasect-search.rs | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/hydrasect-search.rs b/hydrasect-search.rs index 348b54f..1b43370 100644 --- a/hydrasect-search.rs +++ b/hydrasect-search.rs @@ -448,19 +448,22 @@ fn update_history_file(path: &Path) -> Result { .status() .map_err(|e| format!("spawning curl: {}", e))?; - if let Some(code) = status.code() { - if code > 4 && code != 48 { + match status.code() { + Some(0) => { + match rename(&tmp_path, path) { + // If the source file doesn't exist, we got a 304 Not Modified, + // so the existing file is up to date. + Err(e) if e.kind() == ErrorKind::NotFound => Ok(()), + r => r.map_err(|e| format!("moving new history file into place: {}", e)), + }?; + } + Some(code) if code > 4 && code != 48 => { eprintln!("Warning: failed to update the Hydra evaluation history file."); } + _ => { + status_to_result(status, "curl")?; + } } - status_to_result(status, "curl")?; - - match rename(&tmp_path, path) { - // If the source file doesn't exist, we got a 304 Not Modified, - // so the existing file is up to date. - Err(e) if e.kind() == ErrorKind::NotFound => Ok(()), - r => r.map_err(|e| format!("moving new history file into place: {}", e)), - }?; File::open(&path).map_err(|e| format!("opening updated history file: {}", e)) } -- cgit 1.4.1