From 5858668c75b6b914f4a50282939842654c634424 Mon Sep 17 00:00:00 2001 From: b-yap <2826165+b-yap@users.noreply.github.com> Date: Mon, 22 Apr 2024 21:36:57 +0800 Subject: [PATCH] remove file every after use --- clients/vault/src/oracle/collector/proof_builder.rs | 6 ++++++ clients/vault/src/oracle/storage/traits.rs | 6 ++++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/clients/vault/src/oracle/collector/proof_builder.rs b/clients/vault/src/oracle/collector/proof_builder.rs index 24ca786fb..1594fb155 100644 --- a/clients/vault/src/oracle/collector/proof_builder.rs +++ b/clients/vault/src/oracle/collector/proof_builder.rs @@ -281,6 +281,8 @@ impl ScpMessageCollector { "get_envelopes_from_horizon_archive(): The contained archive entry fetched from {} for slot {slot} is invalid because it does not contain any externalized envelopes.", scp_archive_storage.0 ); + // remove the file since it's invalid. + scp_archive_storage.remove_file(slot); continue } @@ -297,6 +299,8 @@ impl ScpMessageCollector { // indicates that the data was taken from the archive from_archive_map.insert(slot, ()); + // remove the archive file after successfully retrieving envelopes + scp_archive_storage.remove_file(slot); break } } @@ -355,6 +359,8 @@ impl ScpMessageCollector { _ => TransactionSetType::new(target_history_entry.tx_set.clone()), }; tx_set_map.insert(slot, tx_set_type); + // remove the archive file after a txset has been found + tx_archive_storage.remove_file(slot); break } else { tracing::warn!( diff --git a/clients/vault/src/oracle/storage/traits.rs b/clients/vault/src/oracle/storage/traits.rs index 8baa029b9..0b4839922 100644 --- a/clients/vault/src/oracle/storage/traits.rs +++ b/clients/vault/src/oracle/storage/traits.rs @@ -138,9 +138,11 @@ pub trait ArchiveStorage { slot_index + ARCHIVE_NODE_LEDGER_BATCH - rest } - fn remove_file(&self, target_slot: Slot) -> std::io::Result<()> { + fn remove_file(&self, target_slot: Slot) { let (_, file) = self.get_url_and_file_name(target_slot); - fs::remove_file(file) + if let Err(e) = fs::remove_file(&file) { + tracing::warn!("remove_file(): failed to remove file {file} for slot {target_slot}: {e:?}"); + } } fn read_file_xdr(filename: &str) -> Result, Error> {