From 5de1a7accff5e26d20776df3ad262d0f9d125aeb Mon Sep 17 00:00:00 2001 From: apfitzge Date: Tue, 26 Jul 2022 14:09:28 -0500 Subject: [PATCH] Add streaming_unpack_snapshot to send entry files during unpack (#26781) * Add streaming_unpack_snapshot to send entry files during unpack * Update unpack tests to call internal function --- runtime/src/hardened_unpack.rs | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/runtime/src/hardened_unpack.rs b/runtime/src/hardened_unpack.rs index 2f10af743..e3af85521 100644 --- a/runtime/src/hardened_unpack.rs +++ b/runtime/src/hardened_unpack.rs @@ -300,6 +300,7 @@ impl ParallelSelector { } } +/// Unpacks snapshot and collects AppendVec file names & paths pub fn unpack_snapshot( archive: &mut Archive, ledger_dir: &Path, @@ -321,6 +322,28 @@ pub fn unpack_snapshot( .map(|_| unpacked_append_vec_map) } +/// Unpacks snapshots and sends entry file paths through the `sender` channel +pub fn streaming_unpack_snapshot( + archive: &mut Archive, + ledger_dir: &Path, + account_paths: &[PathBuf], + parallel_selector: Option, + sender: &crossbeam_channel::Sender, +) -> Result<()> { + unpack_snapshot_with_processors( + archive, + ledger_dir, + account_paths, + parallel_selector, + |_, _| {}, + |entry_path_buf| { + if entry_path_buf.is_file() { + sender.send(entry_path_buf).unwrap(); + } + }, + ) +} + fn unpack_snapshot_with_processors( archive: &mut Archive, ledger_dir: &Path, @@ -760,7 +783,7 @@ mod tests { fn finalize_and_unpack_snapshot(archive: tar::Builder>) -> Result<()> { with_finalize_and_unpack(archive, |a, b| { - unpack_snapshot(a, b, &[PathBuf::new()], None).map(|_| ()) + unpack_snapshot_with_processors(a, b, &[PathBuf::new()], None, |_, _| {}, |_| {}) }) }