From 349ffcbed3158f76f0fa3f0c0865e02f1ef466c2 Mon Sep 17 00:00:00 2001 From: Manuel Raimann Date: Thu, 12 Feb 2026 08:13:48 +0100 Subject: [PATCH] fix: update journal file handling to support reading and writing --- src/storage/journal.rs | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/storage/journal.rs b/src/storage/journal.rs index 33c7653..9e4ca68 100644 --- a/src/storage/journal.rs +++ b/src/storage/journal.rs @@ -2,7 +2,7 @@ use core::marker::PhantomData; use std::fs::{File, OpenOptions}; -use std::io::{BufRead, BufReader, Write}; +use std::io::{BufRead, BufReader, Seek, SeekFrom, Write}; use std::path::{Path, PathBuf}; use std::sync::Arc; @@ -83,18 +83,23 @@ impl JournalStorage { let mut file = OpenOptions::new() .create(true) - .append(true) + .truncate(false) + .read(true) + .write(true) .open(&self.path) .map_err(|e| crate::Error::Storage(e.to_string()))?; file.lock_exclusive() .map_err(|e| crate::Error::Storage(e.to_string()))?; + file.seek(SeekFrom::End(0)) + .map_err(|e| crate::Error::Storage(e.to_string()))?; + let line = serde_json::to_string(trial).map_err(|e| crate::Error::Storage(e.to_string()))?; writeln!(file, "{line}").map_err(|e| crate::Error::Storage(e.to_string()))?; - file.flush() + file.sync_data() .map_err(|e| crate::Error::Storage(e.to_string()))?; file.unlock()