Extract load_labelling_rules

This commit is contained in:
Olivier 'reivilibre' 2022-07-08 15:17:51 +01:00
parent e25e92b273
commit bd5e18bc9f
2 changed files with 10 additions and 6 deletions

View File

@ -17,7 +17,9 @@ along with Yama. If not, see <https://www.gnu.org/licenses/>.
use crate::descriptor::{Descriptor, DestPileDescriptor, SourceDescriptor, VirtualSourceKind}; use crate::descriptor::{Descriptor, DestPileDescriptor, SourceDescriptor, VirtualSourceKind};
use crate::get_hostname; use crate::get_hostname;
use crate::labelling::{label_node, load_labelling_rules, str_to_label, Label, State}; use crate::labelling::{
label_node, load_labelling_rules, str_to_label, Label, LabellingRules, State,
};
use crate::tree::{scan, FileTree, FileTree1}; use crate::tree::{scan, FileTree, FileTree1};
use anyhow::{anyhow, bail}; use anyhow::{anyhow, bail};
use arc_interner::ArcIntern; use arc_interner::ArcIntern;
@ -76,8 +78,8 @@ pub fn open_stdout_backup_process(
pub fn label_filter_and_convert( pub fn label_filter_and_convert(
tree: FileTree1<()>, tree: FileTree1<()>,
descriptor: &Descriptor, descriptor: &Descriptor,
desc_path: &Path,
source_name: &str, source_name: &str,
rules: &LabellingRules,
dest: &DestPileDescriptor, dest: &DestPileDescriptor,
) -> anyhow::Result<Option<TreeNode>> { ) -> anyhow::Result<Option<TreeNode>> {
info!("Labelling."); info!("Labelling.");
@ -87,8 +89,7 @@ pub fn label_filter_and_convert(
.iter() .iter()
.map(|l| Label(ArcIntern::new(l.clone()))) .map(|l| Label(ArcIntern::new(l.clone())))
.collect(); .collect();
let rules = load_labelling_rules(desc_path, source_name)?; label_node("".to_owned(), None, &mut tree, &labels, rules)?;
label_node("".to_owned(), None, &mut tree, &labels, &rules)?;
let included_labels: HashSet<Label> = dest.included_labels.iter().map(str_to_label).collect(); let included_labels: HashSet<Label> = dest.included_labels.iter().map(str_to_label).collect();
@ -158,8 +159,9 @@ pub fn backup_source_to_destination<PT: ProgressTracker>(
let absolute_dest_path = desc_path.join(&dest.path); let absolute_dest_path = desc_path.join(&dest.path);
let pile_descriptor = load_pile_descriptor(&absolute_dest_path)?; let pile_descriptor = load_pile_descriptor(&absolute_dest_path)?;
let pile = open_pile(&absolute_dest_path, &pile_descriptor)?; let pile = open_pile(&absolute_dest_path, &pile_descriptor)?;
let rules = load_labelling_rules(desc_path, source_name)?;
let root = if let Some(root) = let root = if let Some(root) =
label_filter_and_convert(tree, descriptor, desc_path, source_name, dest)? label_filter_and_convert(tree, descriptor, source_name, &rules, dest)?
{ {
root root
} else { } else {

View File

@ -1,5 +1,6 @@
use crate::commands::backup::{get_pointer_name_at, label_filter_and_convert}; use crate::commands::backup::{get_pointer_name_at, label_filter_and_convert};
use crate::descriptor::{Descriptor, DestPileDescriptor, SourceDescriptor}; use crate::descriptor::{Descriptor, DestPileDescriptor, SourceDescriptor};
use crate::labelling::load_labelling_rules;
use crate::tree::FileTree; use crate::tree::FileTree;
use anyhow::{anyhow, bail}; use anyhow::{anyhow, bail};
use chrono::Utc; use chrono::Utc;
@ -209,8 +210,9 @@ pub fn backup_remote_source_to_destination<PT: ProgressTracker + Send + 'static>
)? )?
.ok_or_else(|| anyhow!("Remote scan failed (does the directory exist?)"))?; .ok_or_else(|| anyhow!("Remote scan failed (does the directory exist?)"))?;
let rules = load_labelling_rules(desc_path, source_name)?;
let mut root = let mut root =
label_filter_and_convert(scan_result, descriptor, desc_path, source_name, dest)? label_filter_and_convert(scan_result, descriptor, source_name, &rules, dest)?
.ok_or_else(|| anyhow!("Empty filter..."))?; .ok_or_else(|| anyhow!("Empty filter..."))?;
let absolute_dest_path = desc_path.join(&dest.path); let absolute_dest_path = desc_path.join(&dest.path);