From f1b73b28ee2e1f10e8c19e6e7450135f246b8843 Mon Sep 17 00:00:00 2001 From: Olivier 'reivilibre Date: Sat, 28 May 2022 23:52:38 +0100 Subject: [PATCH] Split up store_fully so that we can avoid pointer ops in a restricted context --- yama/src/operations/storing.rs | 43 +++++++++++++++++++++++----------- 1 file changed, 29 insertions(+), 14 deletions(-) diff --git a/yama/src/operations/storing.rs b/yama/src/operations/storing.rs index 9423a07..ee86daf 100644 --- a/yama/src/operations/storing.rs +++ b/yama/src/operations/storing.rs @@ -240,6 +240,34 @@ pub fn store_fully( parent: Option, num_workers: u8, progress_bar: &mut PT, +) -> anyhow::Result<()> { + pointer_ops_prepare_to_store(&pile, &mut root_node, &parent)?; + let pointer_data = store_without_pointer_ops( + &pile, + &root_dir, + root_node, + parent, + num_workers, + progress_bar, + )?; + pointers_ops_after_store(pile, &new_pointer_name, &pointer_data)?; + Ok(()) +} + +pub fn pointers_ops_after_store( + pile: Arc>>, + new_pointer_name: &&String, + pointer_data: &PointerData, +) -> anyhow::Result<()> { + pile.write_pointer(&new_pointer_name, &pointer_data)?; + pile.flush()?; + Ok(()) +} + +pub fn pointer_ops_prepare_to_store( + pile: &Arc>>, + mut root_node: &mut TreeNode, + parent: &Option, ) -> anyhow::Result<()> { if let Some(parent) = parent.as_ref() { let mut parent_pointer = pile.read_pointer(parent)?.ok_or_else(|| { @@ -253,23 +281,10 @@ pub fn store_fully( fully_integrate_pointer_node(&pile, &mut parent_node.node, &mut parent_pointer)?; differentiate_node_in_place(&mut root_node, &parent_node.node)?; } - - let pointer_data = store_without_pointer_ops( - &pile, - &root_dir, - root_node, - parent, - num_workers, - progress_bar, - )?; - - // TODO(newver) Allow the pointer to be returned separately. - pile.write_pointer(&new_pointer_name, &pointer_data)?; - pile.flush()?; Ok(()) } -fn store_without_pointer_ops( +pub fn store_without_pointer_ops( pile: &Arc>>, root_dir: &PathBuf, mut root_node: TreeNode,