From 9de7c783ae6d3a92ea742d9aa20da7d8c01a3a8f Mon Sep 17 00:00:00 2001 From: Bruno BELANYI Date: Tue, 30 Mar 2021 16:11:36 +0000 Subject: [PATCH] job: add processing blacklist to global config --- Cargo.lock | 38 ++++++++++++++++++++++++++++++++++++++ Cargo.toml | 2 ++ src/job.rs | 7 +++++++ src/settings.rs | 4 ++++ 4 files changed, 51 insertions(+) diff --git a/Cargo.lock b/Cargo.lock index 72a6705..c0de7d0 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -56,6 +56,15 @@ dependencies = [ "opaque-debug", ] +[[package]] +name = "aho-corasick" +version = "0.7.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7404febffaa47dac81aa44dba71523c9d069b1bdc50a77db41195149e17f68e5" +dependencies = [ + "memchr", +] + [[package]] name = "anyhow" version = "1.0.40" @@ -503,10 +512,12 @@ dependencies = [ "hex", "hmac", "log 0.4.14", + "regex", "rocket", "rocket_contrib", "serde", "serde_json", + "serde_regex", "serde_yaml", "sha2", ] @@ -756,6 +767,23 @@ dependencies = [ "bitflags", ] +[[package]] +name = "regex" +version = "1.4.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "957056ecddbeba1b26965114e191d2e8589ce74db242b6ea25fc4062427a5c19" +dependencies = [ + "aho-corasick", + "memchr", + "regex-syntax", +] + +[[package]] +name = "regex-syntax" +version = "0.6.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "24d5f089152e60f62d28b835fbff2cd2e8dc0baf1ac13343bef92ab7eed84548" + [[package]] name = "rocket" version = "0.4.7" @@ -874,6 +902,16 @@ dependencies = [ "serde", ] +[[package]] +name = "serde_regex" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a8136f1a4ea815d7eac4101cfd0b16dc0cb5e1fe1b8609dfd728058656b7badf" +dependencies = [ + "regex", + "serde", +] + [[package]] name = "serde_yaml" version = "0.8.17" diff --git a/Cargo.toml b/Cargo.toml index 896e01a..cbbb9ae 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -15,9 +15,11 @@ anyhow = "1.0.40" hex = "0.4.3" hmac = "0.10.1" log = "0.4.14" +regex = "1" rocket = "0.4.7" rocket_contrib = { version = "0.4.7", features = [ "json" ] } serde = { version = "1.0.125", features = [ "derive" ] } serde_json = "1.0.64" +serde_regex = "1.1.0" serde_yaml = "0.8.17" sha2 = "0.9.3" diff --git a/src/job.rs b/src/job.rs index 2e91cf1..0477704 100644 --- a/src/job.rs +++ b/src/job.rs @@ -190,6 +190,13 @@ impl Job { } pub(crate) fn run(&mut self, homedir: &Path, config: &GlobalSettings) -> anyhow::Result<()> { + if config + .blacklist + .iter() + .any(|re| re.is_match(&self.repo.full_name)) + { + return Ok(()); + } let local_path = homedir.join(&self.repo.full_name); assert!(local_path.is_absolute()); self.local_path = Some(local_path); diff --git a/src/settings.rs b/src/settings.rs index bfe7744..976264f 100644 --- a/src/settings.rs +++ b/src/settings.rs @@ -10,4 +10,8 @@ pub(crate) struct GlobalSettings { /// List of remote stems to use for every repository #[serde(default)] pub additional_remotes: Vec, + /// List of regexes, if a repository's name matches any of the, it is not mirrored by `lohr` + /// even if it contains a `.lorh` file. + #[serde(with = "serde_regex")] + pub blacklist: Vec, }