|
@@ -2,7 +2,7 @@ use std::{
|
|
|
collections::{HashMap, HashSet},
|
|
collections::{HashMap, HashSet},
|
|
|
fmt,
|
|
fmt,
|
|
|
fs::{self, File, OpenOptions},
|
|
fs::{self, File, OpenOptions},
|
|
|
- io::{BufReader, Read},
|
|
|
|
|
|
|
+ io::{BufReader, Read, Write},
|
|
|
os::unix::fs::MetadataExt,
|
|
os::unix::fs::MetadataExt,
|
|
|
path::Path,
|
|
path::Path,
|
|
|
};
|
|
};
|
|
@@ -177,11 +177,20 @@ impl FlowCells {
|
|
|
// .truncate(true)
|
|
// .truncate(true)
|
|
|
// .open(archive_path)
|
|
// .open(archive_path)
|
|
|
// .with_context(|| format!("Failed to open archive file for writing: {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}"))?;
|
|
.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}"))?;
|
|
.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(())
|
|
Ok(())
|
|
|
}
|
|
}
|