Split up store_fully so that we can avoid pointer ops in a restricted context

This commit is contained in:
Olivier 'reivilibre' 2022-05-28 23:52:38 +01:00
parent db0d9dd493
commit f1b73b28ee
1 changed files with 29 additions and 14 deletions

View File

@ -240,6 +240,34 @@ pub fn store_fully<PT: ProgressTracker>(
parent: Option<String>, parent: Option<String>,
num_workers: u8, num_workers: u8,
progress_bar: &mut PT, 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<Pile<Box<dyn RawPile>>>,
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<Pile<Box<dyn RawPile>>>,
mut root_node: &mut TreeNode,
parent: &Option<String>,
) -> anyhow::Result<()> { ) -> anyhow::Result<()> {
if let Some(parent) = parent.as_ref() { if let Some(parent) = parent.as_ref() {
let mut parent_pointer = pile.read_pointer(parent)?.ok_or_else(|| { let mut parent_pointer = pile.read_pointer(parent)?.ok_or_else(|| {
@ -253,23 +281,10 @@ pub fn store_fully<PT: ProgressTracker>(
fully_integrate_pointer_node(&pile, &mut parent_node.node, &mut parent_pointer)?; fully_integrate_pointer_node(&pile, &mut parent_node.node, &mut parent_pointer)?;
differentiate_node_in_place(&mut root_node, &parent_node.node)?; 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(()) Ok(())
} }
fn store_without_pointer_ops<PT: ProgressTracker>( pub fn store_without_pointer_ops<PT: ProgressTracker>(
pile: &Arc<Pile<Box<dyn RawPile>>>, pile: &Arc<Pile<Box<dyn RawPile>>>,
root_dir: &PathBuf, root_dir: &PathBuf,
mut root_node: TreeNode, mut root_node: TreeNode,