ソースを参照

up archive save write into temps, the file was corrupt by premature write hang

Thomas 7 ヶ月 前
コミット
66f362b3f5
1 ファイル変更12 行追加3 行削除
  1. 12 3
      src/collection/flowcells.rs

+ 12 - 3
src/collection/flowcells.rs

@@ -2,7 +2,7 @@ use std::{
     collections::{HashMap, HashSet},
     fmt,
     fs::{self, File, OpenOptions},
-    io::{BufReader, Read},
+    io::{BufReader, Read, Write},
     os::unix::fs::MetadataExt,
     path::Path,
 };
@@ -177,11 +177,20 @@ impl FlowCells {
         //     .truncate(true)
         //     .open(archive_path)
         //     .with_context(|| format!("Failed to open archive file for writing: {archive_path}"))?;
-        let file = get_gz_writer(archive_path, true)
+        let tmp_path = format!("/tmp/{}.tmp", uuid::Uuid::new_v4());
+
+        let mut file = get_gz_writer(&tmp_path, true)
             .with_context(|| format!("Failed to open archive file for writing: {archive_path}"))?;
 
-        serde_json::to_writer_pretty(file, &self.flow_cells)
+
+
+        serde_json::to_writer_pretty(&mut file, &self.flow_cells)
             .with_context(|| format!("Failed to write FlowCells to: {archive_path}"))?;
+        file.flush()?;
+        // file.get_ref().sync_all()?;
+        std::fs::rename(&tmp_path, archive_path)?;
+
+
 
         Ok(())
     }