From 13c2e6570d050eac5e949a6f5e963067a81235c3 Mon Sep 17 00:00:00 2001 From: Aiden McClelland Date: Tue, 6 Sep 2022 12:48:24 -0600 Subject: [PATCH] fix db serialization --- patch-db-util/src/main.rs | 3 +-- patch-db/src/store.rs | 4 +++- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/patch-db-util/src/main.rs b/patch-db-util/src/main.rs index 10637d0..b4b26bb 100644 --- a/patch-db-util/src/main.rs +++ b/patch-db-util/src/main.rs @@ -25,7 +25,7 @@ async fn main() { Some(("dump", matches)) => { let path = matches.value_of("PATH").unwrap(); let db = patch_db::PatchDb::open(path).await.unwrap(); - let dump = db.dump().await; + let dump = db.dump().await.unwrap(); serde_json::to_writer_pretty(&mut std::io::stdout(), &dump.value).unwrap(); println!(); } @@ -36,7 +36,6 @@ async fn main() { db.put( &JsonPointer::<&str, (&[PtrSegment], &[PtrSegment])>::default(), &value, - None, ) .await .unwrap(); diff --git a/patch-db/src/store.rs b/patch-db/src/store.rs index 4ecfc6e..35e98a7 100644 --- a/patch-db/src/store.rs +++ b/patch-db/src/store.rs @@ -96,7 +96,8 @@ impl Store { OpenOptions::new() .create(true) .read(true) - .append(true) + .write(true) + .truncate(false) .open(&path)?, fd_lock_rs::LockType::Exclusive, true, @@ -199,6 +200,7 @@ impl Store { self.file.flush().await?; self.file.sync_all().await?; tokio::fs::remove_file(&bak).await?; + self.file_cursor = self.file.stream_position().await?; Ok(()) } pub(crate) async fn apply(&mut self, patch: DiffPatch) -> Result>, Error> {