Skip to content

Commit 54251a7

Browse files
committed
docs(file_store): Show how to overwrite original file during recovery
1 parent 52f2061 commit 54251a7

File tree

1 file changed

+16
-10
lines changed

1 file changed

+16
-10
lines changed

crates/file_store/src/store.rs

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -109,18 +109,24 @@ where
109109
/// # let new_len = file.seek(SeekFrom::End(-2))?;
110110
/// # file.set_len(new_len)?;
111111
///
112-
/// let mut new_store = match Store::<TestChangeSet>::load(&MAGIC_BYTES, &file_path) {
112+
/// let (mut new_store, _aggregate_changeset) =
113+
/// match Store::<TestChangeSet>::load(&MAGIC_BYTES, &file_path) {
113114
/// # Ok(_) => panic!("should have errored"),
114-
/// Ok((store, _aggregated_changeset)) => store,
115-
/// Err(StoreErrorWithDump { changeset, .. }) => {
116-
/// let new_file_path = file_path.with_extension("bkp");
117-
/// let mut new_store = Store::create(&MAGIC_BYTES, &new_file_path).unwrap();
118-
/// if let Some(aggregated_changeset) = changeset {
119-
/// new_store.append(&aggregated_changeset)?;
115+
/// Ok((store, changeset)) => (store, changeset),
116+
/// Err(StoreErrorWithDump { changeset, .. }) => {
117+
/// let new_file_path = file_path.with_extension("backup");
118+
/// let mut new_store =
119+
/// Store::create(&MAGIC_BYTES, &new_file_path).expect("must create new file");
120+
/// if let Some(aggregated_changeset) = changeset {
121+
/// new_store.append(&aggregated_changeset)?;
122+
/// }
123+
/// // The following will overwrite the original file. You will loose the corrupted
124+
/// // portion of the original file forever.
125+
/// drop(new_store);
126+
/// std::fs::rename(&new_file_path, &file_path)?;
127+
/// Store::load(&MAGIC_BYTES, &file_path).expect("must load new file")
120128
/// }
121-
/// new_store
122-
/// }
123-
/// };
129+
/// };
124130
/// #
125131
/// # assert_eq!(
126132
/// # new_store.dump().expect("should dump changeset: {1, 2, 3} "),

0 commit comments

Comments
 (0)