Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
raincity committed Nov 21, 2023
2 parents f03282e + 801747e commit 55989de
Show file tree
Hide file tree
Showing 8 changed files with 44 additions and 2 deletions.
1 change: 1 addition & 0 deletions .test-replica/config/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ files = [
"file2.txt",
"big-file.pdf",
]
excludes = []
dbfile = ".replica/data/files.json"
compress = false
encrypt = false
1 change: 1 addition & 0 deletions .test-replica/config/plaza-config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@ logging_config = "config/console.yaml"
source_folders = ["photos", "Music", ".local/bin" ]
targets = ["/Volumes/plaza/plaza", "[email protected]:backup/plaza", "[email protected]:.backup/plaza"]
files = [ ".age/decrypt.sh", ".age/encrypt.sh", ".age/key.enc", ".alias", ".config", ".motd", ".profile", ".ssh/authorized_keys", ".ssh/plaza.pub", ".zprofile", ".zshenv", ".zshrc" ]
excludes = []
compress = false
encrypt = false
1 change: 1 addition & 0 deletions .test-replica/config/run-config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ files = [
"tests/big-file.pdf",
"tests/changed-file.txt",
]
excludes = []
dbfile = ".test-replica/data/run2-file.json"
compress = false
encrypt = false
1 change: 1 addition & 0 deletions .test-replica/config/run1-config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ files = [
"tests/big-file.pdf",
"tests/changed-file.txt",
]
excludes = []
dbfile = ".test-replica/data/run1-file.json"
compress = false
encrypt = false
1 change: 1 addition & 0 deletions .test-replica/config/tiburon-config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@ logging_config = "config/console.yaml"
source_folders = ["photos", "Music", ".local/bin"]
targets = ["[email protected]:/Volumes/plaza/tiburon", "[email protected]:backup/tiburon", "[email protected]:.backup/tiburon"]
files = [ ".alias", ".config", ".motd", ".profile", ".ssh/authorized_keys", ".ssh/id_rsa.pub", ".wget-hsts", ".zprofile", ".zshenv", ".zshrc" ]
excludes = []
compress = false
encrypt = false
6 changes: 6 additions & 0 deletions .test-replica/config/walk-config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@ files = [
"tests/file2.txt",
"tests/big-file.pdf",
]
excludes = [
".config/broot",
".config/chromium",
".config/configstore",
".config/dconf",
]
dbfile = ".replica/data/files.json"
compress = false
encrypt = false
2 changes: 2 additions & 0 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ pub struct Config {
pub source_folders: Vec<String>,
pub targets: Vec<String>,
pub files: Vec<String>,
pub excludes: Vec<String>,
pub dbfile: String,
pub compress: bool,
pub encrypt: bool,
Expand Down Expand Up @@ -48,6 +49,7 @@ impl Config {
source_folders: self.source_folders.clone(),
targets: self.targets.clone(),
files: self.files.clone(),
excludes: self.excludes.clone(),
dbfile: self.dbfile.clone(),
compress: self.compress,
encrypt: self.encrypt,
Expand Down
33 changes: 31 additions & 2 deletions src/file_walker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use crate::config::Config;
use crate::file_model::FileModel;
use anyhow::Result;
use log::{debug, error, info};
use std::path::PathBuf;
use std::path::{Path, PathBuf};
use walkdir::WalkDir;

pub struct FileWalker {
Expand Down Expand Up @@ -67,7 +67,7 @@ impl FileWalker {
let fname: PathBuf = [&self.home, folder].iter().collect();

for entry in WalkDir::new(fname).into_iter().filter_map(|e| e.ok()) {
if entry.file_name() == ".DS_Store" {
if self.exclude(entry.path()) || entry.file_name() == ".DS_Store" {
continue;
}

Expand All @@ -92,12 +92,41 @@ impl FileWalker {

Ok(files)
}

/// if the file path contains an exclude phrase return true, else false
fn exclude(&self, path: &Path) -> bool {
let excludes = &self.config.excludes;
let name = path.to_str().unwrap().to_string();

for ex in excludes.iter() {
if name.contains(ex.as_str()) {
info!("exclude: {} {}", name, ex);
return true;
}
}

false
}
}

#[cfg(test)]
mod tests {
use super::*;

#[test]
fn excludes() {
// [ ".config/broot", ".config/chromium", ".config/configstore", ".config/dconf" ]

let config = Config::read_config(".test-replica/config/walk-config.toml").unwrap();
let walker = FileWalker::new(config.clone());

let path = Path::new("/home/dpw/.config/chromium/thing");
assert!(walker.exclude(path));

let path = Path::new(".config/configstore/");
assert!(walker.exclude(path));
}

#[test]
fn walk_files_and_folders() {
// cd_test_home();
Expand Down

0 comments on commit 55989de

Please sign in to comment.