From: 志宇 Date: Thu, 6 Mar 2025 00:41:03 +0000 (+1100) Subject: docs(file_store): Show how to overwrite original file during recovery X-Git-Tag: wallet-1.2.0~18^2 X-Git-Url: http://internal-gitweb-vhost/script/%22https:/enum.AnyDatabaseConfig.html?a=commitdiff_plain;h=54251a7c9fdf08bced132be3851207917cbc36ab;p=bdk docs(file_store): Show how to overwrite original file during recovery --- diff --git a/crates/file_store/src/store.rs b/crates/file_store/src/store.rs index cad61af1..d870e530 100644 --- a/crates/file_store/src/store.rs +++ b/crates/file_store/src/store.rs @@ -109,18 +109,24 @@ where /// # let new_len = file.seek(SeekFrom::End(-2))?; /// # file.set_len(new_len)?; /// - /// let mut new_store = match Store::::load(&MAGIC_BYTES, &file_path) { + /// let (mut new_store, _aggregate_changeset) = + /// match Store::::load(&MAGIC_BYTES, &file_path) { /// # Ok(_) => panic!("should have errored"), - /// Ok((store, _aggregated_changeset)) => store, - /// Err(StoreErrorWithDump { changeset, .. }) => { - /// let new_file_path = file_path.with_extension("bkp"); - /// let mut new_store = Store::create(&MAGIC_BYTES, &new_file_path).unwrap(); - /// if let Some(aggregated_changeset) = changeset { - /// new_store.append(&aggregated_changeset)?; + /// Ok((store, changeset)) => (store, changeset), + /// Err(StoreErrorWithDump { changeset, .. }) => { + /// let new_file_path = file_path.with_extension("backup"); + /// let mut new_store = + /// Store::create(&MAGIC_BYTES, &new_file_path).expect("must create new file"); + /// if let Some(aggregated_changeset) = changeset { + /// new_store.append(&aggregated_changeset)?; + /// } + /// // The following will overwrite the original file. You will loose the corrupted + /// // portion of the original file forever. + /// drop(new_store); + /// std::fs::rename(&new_file_path, &file_path)?; + /// Store::load(&MAGIC_BYTES, &file_path).expect("must load new file") /// } - /// new_store - /// } - /// }; + /// }; /// # /// # assert_eq!( /// # new_store.dump().expect("should dump changeset: {1, 2, 3} "),