about summary refs log tree commit diff
diff options
context:
space:
mode:
authorAlyssa Ross <hi@alyssa.is>2022-05-03 16:58:18 +0000
committerAlyssa Ross <hi@alyssa.is>2022-05-03 16:59:30 +0000
commitc0fc5db58ce8c6d903067225ef7acdd799e37eab (patch)
tree78d59be5c72e71e9e205344200ab102f43bfbf31
parentec7c061fc7a6d13b00030ab9726d0b060524db9d (diff)
downloadhydrasect-c0fc5db58ce8c6d903067225ef7acdd799e37eab.tar
hydrasect-c0fc5db58ce8c6d903067225ef7acdd799e37eab.tar.gz
hydrasect-c0fc5db58ce8c6d903067225ef7acdd799e37eab.tar.bz2
hydrasect-c0fc5db58ce8c6d903067225ef7acdd799e37eab.tar.lz
hydrasect-c0fc5db58ce8c6d903067225ef7acdd799e37eab.tar.xz
hydrasect-c0fc5db58ce8c6d903067225ef7acdd799e37eab.tar.zst
hydrasect-c0fc5db58ce8c6d903067225ef7acdd799e37eab.zip
Don't try to rename the history file if curl failed
-rw-r--r--hydrasect-search.rs23
1 files 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<File, String> {
         .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))
 }