fix db serialization

This commit is contained in:
Aiden McClelland
2022-09-06 12:48:24 -06:00
parent bdf0b32be6
commit 188f7a6253
2 changed files with 4 additions and 3 deletions

View File

@@ -25,7 +25,7 @@ async fn main() {
Some(("dump", matches)) => { Some(("dump", matches)) => {
let path = matches.value_of("PATH").unwrap(); let path = matches.value_of("PATH").unwrap();
let db = patch_db::PatchDb::open(path).await.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(); serde_json::to_writer_pretty(&mut std::io::stdout(), &dump.value).unwrap();
println!(); println!();
} }
@@ -36,7 +36,6 @@ async fn main() {
db.put( db.put(
&JsonPointer::<&str, (&[PtrSegment], &[PtrSegment])>::default(), &JsonPointer::<&str, (&[PtrSegment], &[PtrSegment])>::default(),
&value, &value,
None,
) )
.await .await
.unwrap(); .unwrap();

View File

@@ -96,7 +96,8 @@ impl Store {
OpenOptions::new() OpenOptions::new()
.create(true) .create(true)
.read(true) .read(true)
.append(true) .write(true)
.truncate(false)
.open(&path)?, .open(&path)?,
fd_lock_rs::LockType::Exclusive, fd_lock_rs::LockType::Exclusive,
true, true,
@@ -199,6 +200,7 @@ impl Store {
self.file.flush().await?; self.file.flush().await?;
self.file.sync_all().await?; self.file.sync_all().await?;
tokio::fs::remove_file(&bak).await?; tokio::fs::remove_file(&bak).await?;
self.file_cursor = self.file.stream_position().await?;
Ok(()) Ok(())
} }
pub(crate) async fn apply(&mut self, patch: DiffPatch) -> Result<Option<Arc<Revision>>, Error> { pub(crate) async fn apply(&mut self, patch: DiffPatch) -> Result<Option<Arc<Revision>>, Error> {