From 6ce647a3e0bc7070dabb007695154bf24c6e408f Mon Sep 17 00:00:00 2001 From: Brooks Date: Mon, 7 Aug 2023 12:15:01 -0400 Subject: [PATCH] Do not drop AppendVec in store-tool (#32739) --- runtime/store-tool/src/main.rs | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/runtime/store-tool/src/main.rs b/runtime/store-tool/src/main.rs index f1ad3d01d3..e242a73792 100644 --- a/runtime/store-tool/src/main.rs +++ b/runtime/store-tool/src/main.rs @@ -7,6 +7,7 @@ use { hash::Hash, pubkey::Pubkey, }, + std::mem::ManuallyDrop, }; fn main() { @@ -34,8 +35,11 @@ fn main() { let len = value_t!(matches, "len", usize) .unwrap_or_else(|_| std::fs::metadata(&file).unwrap().len() as usize); - let mut store = AppendVec::new_from_file_unchecked(file, len).expect("should succeed"); - store.set_no_remove_on_drop(); + // When the AppendVec is dropped, the backing file will be removed. We do not want to remove + // the backing file here in the store-tool, so prevent dropping. + let store = ManuallyDrop::new( + AppendVec::new_from_file_unchecked(file, len).expect("new AppendVec from file"), + ); info!("store: len: {} capacity: {}", store.len(), store.capacity()); let mut num_accounts: usize = 0; let mut stored_accounts_len: usize = 0; @@ -67,6 +71,3 @@ fn is_account_zeroed(account: &StoredAccountMeta) -> bool { && account.pubkey() == &Pubkey::default() && account.to_account_shared_data() == AccountSharedData::default() } - -#[cfg(test)] -pub mod test {}