Skip to content

Commit

Permalink
fs-store: ensure flush on drop
Browse files Browse the repository at this point in the history
  • Loading branch information
dignifiedquire committed Dec 17, 2024
1 parent 6adbf49 commit 43e1435
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
1 change: 0 additions & 1 deletion deny.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,4 @@ ignore = [
[sources]
allow-git = [
"https://github.com/n0-computer/iroh-blobs.git",
"https://github.com/n0-computer/iroh-gossip.git",
]
11 changes: 9 additions & 2 deletions src/store/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ use ed25519_dalek::{SignatureError, VerifyingKey};
use iroh_blobs::Hash;
use rand_core::CryptoRngCore;
use redb::{Database, DatabaseError, ReadableMultimapTable, ReadableTable, ReadableTableMetadata};
use tracing::warn;

use super::{
pubkeys::MemPublicKeyStore, DownloadPolicy, ImportNamespaceOutcome, OpenError, PublicKeyStore,
Expand Down Expand Up @@ -55,6 +56,14 @@ pub struct Store {
pubkeys: MemPublicKeyStore,
}

impl Drop for Store {
fn drop(&mut self) {
if let Err(err) = self.flush() {
warn!("failed to trigger final flush: {:?}", err);
}
}
}

impl AsRef<Store> for Store {
fn as_ref(&self) -> &Store {
self
Expand Down Expand Up @@ -1121,7 +1130,6 @@ mod tests {
.collect::<Result<Vec<_>>>()?;

assert_eq!(expected, actual);
store.flush()?;
Ok(())
}

Expand All @@ -1138,7 +1146,6 @@ mod tests {
}

// TODO: write test checking that the indexing is done correctly
store.flush()?;
Ok(())
}
}

0 comments on commit 43e1435

Please sign in to comment.