Skip to content

Commit

Permalink
Define paths to keep and to prune
Browse files Browse the repository at this point in the history
  • Loading branch information
isbm committed Sep 13, 2023
1 parent 72dcb60 commit 9bc8e6c
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 4 deletions.
10 changes: 10 additions & 0 deletions src/procdata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,16 @@ impl TintProcessor {
paths.extend(databuf);
}

// Explicitly keep paths
// XXX: Support globbing
paths.extend(self.profile.get_keep_paths());

// Explicitly knock-out paths
// XXX: Support globbing
for p in self.profile.get_prune_paths() {
paths.remove(&p);
}

// Scan rootfs
log::debug!("Scanning existing rootfs");
let mut p = rootfs::RootFS::new()
Expand Down
40 changes: 36 additions & 4 deletions src/profile.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
use serde::{Deserialize, Serialize};
use std::fmt::Debug;
use std::{fmt::Debug, path::PathBuf};
use std::{fs, io::Error, path::Path};

#[derive(Serialize, Deserialize, PartialEq, Debug)]
pub struct PConfig {
filters: Option<Vec<String>>,
prune: Option<Vec<String>>,
keep: Option<Vec<String>>,
}

#[derive(Serialize, Deserialize, PartialEq, Debug)]
Expand All @@ -24,7 +25,8 @@ pub struct Profile {
f_man: bool,
f_dir: bool,
f_log: bool,
f_prune: Vec<String>,
f_expl_prune: Vec<PathBuf>,
f_expl_keep: Vec<PathBuf>,

packages: Vec<String>,
targets: Vec<String>,
Expand All @@ -43,7 +45,8 @@ impl Profile {
f_log: true,
packages: vec![],
targets: vec![],
f_prune: vec![],
f_expl_prune: vec![],
f_expl_keep: vec![],
}
}

Expand Down Expand Up @@ -77,8 +80,13 @@ impl Profile {
}
}
}

if let Some(prn) = cfg.prune {
self.f_prune.extend(prn);
self.f_expl_prune.extend(prn.iter().map(PathBuf::from).collect::<Vec<PathBuf>>());
}

if let Some(keep) = cfg.keep {
self.f_expl_keep.extend(keep.iter().map(PathBuf::from).collect::<Vec<PathBuf>>());
}
}

Expand Down Expand Up @@ -135,11 +143,35 @@ impl Profile {
self
}

/// Add path prune
#[allow(dead_code)]
pub fn prune_path(&mut self, pth: String) -> &mut Self {
self.f_expl_prune.push(PathBuf::from(pth));
self
}

/// Add path to be kept
#[allow(dead_code)]
pub fn keep_path(&mut self, pth: String) -> &mut Self {
self.f_expl_keep.push(PathBuf::from(pth));
self
}

/// Get targets
pub fn get_targets(&self) -> &Vec<String> {
&self.targets
}

/// Get paths to be explicitly pruned
pub fn get_prune_paths(&self) -> Vec<PathBuf> {
self.f_expl_prune.clone()
}

/// Get paths to be explicitly kept
pub fn get_keep_paths(&self) -> Vec<PathBuf> {
self.f_expl_keep.clone()
}

/// Returns true if localisation data needs to be removed
pub fn filter_l10n(&self) -> bool {
!self.f_l10n
Expand Down

0 comments on commit 9bc8e6c

Please sign in to comment.