Commit efa9531f authored by Sophie Herold's avatar Sophie Herold
Browse files

Add support for different exclude pattern styles

Closes #11
parent 0d9ef5da
......@@ -73,6 +73,6 @@ modules:
config-opts:
- "-Dprofile=dev"
sources:
- type: git
- type: dir
path: ../
......@@ -3,6 +3,6 @@
sed '0,/share=network/{//d;}' ci.manifest.yml\
| sed '0,/build-args/{//d;}' \
| sed 's/-Dprofile=dev/-Dprofile=release/' \
| sed 's/type: git/type: archive/' \
| sed 's/type: dir/type: archive/' \
| sed 's/path: ..\//url: \n sha256: /' \
> flathub.manifest.yml
......@@ -390,15 +390,23 @@ impl Default for Instruction {
}
}
fn pathmatch(entry: &walkdir::DirEntry, pattern: &shared::Pattern) -> bool {
match pattern {
shared::Pattern::PathPrefix(path) => entry.path() == path,
}
}
pub fn estimate_size(backup: &shared::BackupConfig, communication: &Communication) -> Option<u64> {
let mut exclude = backup.exclude_dirs_internal();
// Exclude .cache/borg
if let Some(cache_dir) = glib::get_user_cache_dir() {
exclude.push(cache_dir.join(std::path::Path::new("borg")));
exclude.push(shared::Pattern::PathPrefix(
cache_dir.join(std::path::Path::new("borg")),
));
}
let is_not_exluded = |e: &walkdir::DirEntry| !exclude.iter().any(|x| x == e.path());
let is_not_exluded = |e: &walkdir::DirEntry| !exclude.iter().any(|x| pathmatch(e, x));
let mut size = 0;
......
......@@ -102,7 +102,11 @@ impl BorgCall {
pub fn add_include_exclude(&mut self, borg: &Borg) -> &mut Self {
for exclude in &borg.config.exclude_dirs_internal() {
self.add_options(vec![format!("--exclude=pp:{}", exclude.to_string_lossy())]);
self.add_options(vec![format!(
"--exclude={}:{}",
exclude.selector(),
exclude.pattern()
)]);
}
self.positional.extend(
......
......@@ -11,7 +11,7 @@ pub struct BackupConfig {
pub repo: BackupRepo,
pub encrypted: bool,
pub include: BTreeSet<path::PathBuf>,
pub exclude: BTreeSet<path::PathBuf>,
pub exclude: BTreeSet<Pattern>,
pub last_run: Option<RunInfo>,
}
......@@ -26,19 +26,46 @@ impl BackupConfig {
dirs
}
pub fn exclude_dirs_internal(&self) -> Vec<path::PathBuf> {
pub fn exclude_dirs_internal(&self) -> Vec<Pattern> {
let mut dirs = Vec::new();
for dir in &self.exclude {
dirs.push(absolute(dir));
for Pattern::PathPrefix(dir) in &self.exclude {
dirs.push(Pattern::PathPrefix(absolute(dir)));
}
dirs.push(absolute(path::Path::new(crate::REPO_MOUNT_DIR)));
dirs.push(Pattern::PathPrefix(absolute(path::Path::new(
crate::REPO_MOUNT_DIR,
))));
dirs
}
}
#[derive(Serialize, Deserialize, Clone, Debug, Ord, PartialOrd, Eq, PartialEq)]
pub enum Pattern {
PathPrefix(path::PathBuf),
//Fnmatch(path::PathBuf),
}
impl Pattern {
pub fn selector(&self) -> String {
match self {
Self::PathPrefix(_) => "pp",
//Self::Fnmatch(_) => "fm",
}
.to_string()
}
pub fn pattern(&self) -> String {
match self {
Self::PathPrefix(p) => p,
//Self::Fnmatch(p) => p,
}
.to_string_lossy()
.to_string()
}
}
#[derive(Serialize, Deserialize, Clone, Debug)]
pub struct RunInfo {
pub end: DateTime<Local>,
......@@ -97,7 +124,7 @@ impl BackupConfig {
let mut include = std::collections::BTreeSet::new();
include.insert("".into());
let mut exclude = std::collections::BTreeSet::new();
exclude.insert(".cache".into());
exclude.insert(Pattern::PathPrefix(".cache".into()));
Self {
id: glib::uuid_string_random().unwrap().to_string(),
......
......@@ -314,17 +314,18 @@ pub fn refresh() {
// exclude list
ui::utils::clear(&main_ui().backup_exclude());
for file in backup.exclude.iter().rev() {
for shared::Pattern::PathPrefix(file) in backup.exclude.iter().rev() {
let button = add_list_row(&main_ui().backup_exclude(), file, 0);
let path = file.clone();
button.connect_clicked(move |_| {
SETTINGS.update(|settings| {
let path = path.clone();
SETTINGS.update(move |settings| {
settings
.backups
.get_active_mut()
.unwrap()
.exclude
.remove(&path);
.remove(&shared::Pattern::PathPrefix(path.clone()));
});
super::write_config();
refresh();
......@@ -378,7 +379,7 @@ fn add_exclude() {
.get_active_mut()
.unwrap()
.exclude
.insert(rel_path(&path));
.insert(shared::Pattern::PathPrefix(rel_path(&path)));
});
super::write_config();
refresh();
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment