From d3fe111a06661b6397d85cb0d98625c136b4362c Mon Sep 17 00:00:00 2001 From: Olivier 'reivilibre Date: Sun, 20 Nov 2022 19:44:21 +0000 Subject: [PATCH] Replace debug rmp with new implementation --- yama/src/debug.rs | 50 +++-------------------------------------------- 1 file changed, 3 insertions(+), 47 deletions(-) diff --git a/yama/src/debug.rs b/yama/src/debug.rs index 3e5a375..4bd43a6 100644 --- a/yama/src/debug.rs +++ b/yama/src/debug.rs @@ -15,13 +15,12 @@ You should have received a copy of the GNU General Public License along with Yama. If not, see . */ -use crate::commands::{fully_integrate_pointer_node, retrieve_tree_node, store_tree_node}; +use crate::commands::retrieve_tree_node; use crate::definitions::{FilesystemOwnership, FilesystemPermissions, TreeNode}; +use crate::operations::remove_pointer_safely; use crate::pile::{Pile, PileDescriptor, RawPile}; -use crate::tree::integrate_node_in_place; use anyhow::anyhow; use clap::Parser; -use log::info; use rustyline::error::ReadlineError; use rustyline::Editor; @@ -123,50 +122,7 @@ pub fn debug_command( } } DebugCommand::DeletePointer { name } => { - // retrieve this pointer - let mut this_pointer = pile.read_pointer(name.as_str())?.ok_or_else(|| { - anyhow!("Pointer {:?} does not exist so can not be deleted.", name) - })?; - let mut this_node = retrieve_tree_node(&pile, this_pointer.chunk_ref.clone())?; - - // fully integrate the pointer - fully_integrate_pointer_node(&pile, &mut this_node.node, &mut this_pointer)?; - assert!(this_pointer.parent_pointer.is_none()); - - // now integrate any pointers that rely on this one - // so that they no longer rely on this one. - for pointer in pile.list_pointers()?.iter() { - if pointer == name { - continue; - } - if let Some(mut pointer_data) = pile.read_pointer(pointer.as_str())? { - if let Some(parent_pointer) = pointer_data.parent_pointer.as_ref() { - if parent_pointer == name { - info!("Pointer would be an orphan: {:?}; integrating", pointer); - - // need to integrate this node, so retrieve it - let mut node = retrieve_tree_node(&pile, pointer_data.chunk_ref)?; - - // integrate it in-place - integrate_node_in_place(&mut node.node, &this_node.node)?; - - // mark it as orphaned (no parent) - pointer_data.parent_pointer = None; - - // store the orphaned node - let new_chunk_ref = store_tree_node(&pile, &node)?; - // associate the orphaned node with the orphaned pointer - pointer_data.chunk_ref = new_chunk_ref; - // write the pointer back. - pile.write_pointer(pointer.as_str(), &pointer_data)?; - } - } - } - } - - // then delete the pointer - pile.delete_pointer(name)?; - info!("Deleted pointer: {:?}", name); + remove_pointer_safely(pile, name)?; } DebugCommand::PointerInfo { name } => { let this_pointer = pile