feat(config): allow specifying a custom file filter
This commit is contained in:
parent
c5b7c9e493
commit
c018b6000d
|
@ -1 +1,2 @@
|
||||||
/target
|
/target
|
||||||
|
/config.toml
|
||||||
|
|
|
@ -17,6 +17,15 @@ version = "1.0.2"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe"
|
checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "aho-corasick"
|
||||||
|
version = "1.0.3"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "86b8f9420f797f2d9e935edf629310eb938a0d839f984e25327f3c7eed22300c"
|
||||||
|
dependencies = [
|
||||||
|
"memchr",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "anyhow"
|
name = "anyhow"
|
||||||
version = "1.0.72"
|
version = "1.0.72"
|
||||||
|
@ -88,6 +97,16 @@ version = "2.4.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "b4682ae6287fcf752ecaabbfcc7b6f9b72aa33933dc23a554d853aea8eea8635"
|
checksum = "b4682ae6287fcf752ecaabbfcc7b6f9b72aa33933dc23a554d853aea8eea8635"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "bstr"
|
||||||
|
version = "1.6.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "6798148dccfbff0fae41c7574d2fa8f1ef3492fba0face179de5d8d447d67b05"
|
||||||
|
dependencies = [
|
||||||
|
"memchr",
|
||||||
|
"serde",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "byteorder"
|
name = "byteorder"
|
||||||
version = "1.4.3"
|
version = "1.4.3"
|
||||||
|
@ -191,6 +210,7 @@ dependencies = [
|
||||||
"basic-toml",
|
"basic-toml",
|
||||||
"dirs",
|
"dirs",
|
||||||
"futures 0.3.28",
|
"futures 0.3.28",
|
||||||
|
"globset",
|
||||||
"serde",
|
"serde",
|
||||||
"serde_derive",
|
"serde_derive",
|
||||||
"tokio",
|
"tokio",
|
||||||
|
@ -319,6 +339,19 @@ version = "0.27.3"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "b6c80984affa11d98d1b88b66ac8853f143217b399d3c74116778ff8fdb4ed2e"
|
checksum = "b6c80984affa11d98d1b88b66ac8853f143217b399d3c74116778ff8fdb4ed2e"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "globset"
|
||||||
|
version = "0.4.13"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "759c97c1e17c55525b57192c06a267cda0ac5210b222d6b82189a2338fa1c13d"
|
||||||
|
dependencies = [
|
||||||
|
"aho-corasick",
|
||||||
|
"bstr",
|
||||||
|
"fnv",
|
||||||
|
"log",
|
||||||
|
"regex",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "hermit-abi"
|
name = "hermit-abi"
|
||||||
version = "0.3.2"
|
version = "0.3.2"
|
||||||
|
@ -545,6 +578,35 @@ dependencies = [
|
||||||
"thiserror",
|
"thiserror",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "regex"
|
||||||
|
version = "1.9.3"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "81bc1d4caf89fac26a70747fe603c130093b53c773888797a6329091246d651a"
|
||||||
|
dependencies = [
|
||||||
|
"aho-corasick",
|
||||||
|
"memchr",
|
||||||
|
"regex-automata",
|
||||||
|
"regex-syntax",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "regex-automata"
|
||||||
|
version = "0.3.6"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "fed1ceff11a1dddaee50c9dc8e4938bd106e9d89ae372f192311e7da498e3b69"
|
||||||
|
dependencies = [
|
||||||
|
"aho-corasick",
|
||||||
|
"memchr",
|
||||||
|
"regex-syntax",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "regex-syntax"
|
||||||
|
version = "0.7.4"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "e5ea92a5b6195c6ef2a0295ea818b312502c6fc94dde986c5553242e18fd4ce2"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "rustc-demangle"
|
name = "rustc-demangle"
|
||||||
version = "0.1.23"
|
version = "0.1.23"
|
||||||
|
|
|
@ -17,6 +17,7 @@ anyhow = "1.0.72"
|
||||||
basic-toml = "0.1.4"
|
basic-toml = "0.1.4"
|
||||||
dirs = "5.0.1"
|
dirs = "5.0.1"
|
||||||
futures = "0.3.28"
|
futures = "0.3.28"
|
||||||
|
globset = "0.4.13"
|
||||||
serde = "1.0.183"
|
serde = "1.0.183"
|
||||||
serde_derive = "1.0.183"
|
serde_derive = "1.0.183"
|
||||||
tokio = { version = "1.31.0", features = ["tokio-macros"] }
|
tokio = { version = "1.31.0", features = ["tokio-macros"] }
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
use anyhow::{anyhow, Result};
|
use anyhow::{anyhow, Result};
|
||||||
|
use globset::Glob;
|
||||||
use serde_derive::Deserialize;
|
use serde_derive::Deserialize;
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
use tracing::trace;
|
use tracing::trace;
|
||||||
|
@ -14,6 +15,18 @@ pub struct Bucket<'bucket> {
|
||||||
pub name: Option<&'bucket str>,
|
pub name: Option<&'bucket str>,
|
||||||
pub sources: Vec<PathBuf>,
|
pub sources: Vec<PathBuf>,
|
||||||
pub target: PathBuf,
|
pub target: PathBuf,
|
||||||
|
pub file_filter: Option<&'bucket str>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<'a> Root<'a> {
|
||||||
|
pub fn is_match(&self, file_name: &str) -> bool {
|
||||||
|
if let Some(pattern) = self.bucket.file_filter {
|
||||||
|
if let Ok(glob) = Glob::new(pattern) {
|
||||||
|
return glob.compile_matcher().is_match(file_name);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
true
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_path() -> Result<PathBuf> {
|
pub fn get_path() -> Result<PathBuf> {
|
||||||
|
@ -48,6 +61,7 @@ mod test {
|
||||||
"/mnt/data/Game 1/screenshots"
|
"/mnt/data/Game 1/screenshots"
|
||||||
]
|
]
|
||||||
target = "/home/test/screenshots"
|
target = "/home/test/screenshots"
|
||||||
|
file_filter = "*.mp4"
|
||||||
"#;
|
"#;
|
||||||
let config: Root<'_> = from_str(config)?;
|
let config: Root<'_> = from_str(config)?;
|
||||||
let bucket = &config.bucket;
|
let bucket = &config.bucket;
|
||||||
|
@ -57,5 +71,6 @@ mod test {
|
||||||
bucket.sources
|
bucket.sources
|
||||||
);
|
);
|
||||||
assert_eq!(PathBuf::from("/home/test/screenshots"), bucket.target);
|
assert_eq!(PathBuf::from("/home/test/screenshots"), bucket.target);
|
||||||
|
assert_eq!(Some("*.mp4"), config.bucket.file_filter);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -35,7 +35,7 @@ async fn run() -> Result<()> {
|
||||||
let name = file.name.as_path();
|
let name = file.name.as_path();
|
||||||
let exists = *file.exists;
|
let exists = *file.exists;
|
||||||
let empty = *file.size == 0;
|
let empty = *file.size == 0;
|
||||||
if exists && !empty {
|
if exists && !empty && config.is_match(name.to_str().unwrap()) {
|
||||||
let source = config.bucket.sources[index].join(name);
|
let source = config.bucket.sources[index].join(name);
|
||||||
let source = source.as_path();
|
let source = source.as_path();
|
||||||
let target = config.bucket.target.join(source.file_name().unwrap());
|
let target = config.bucket.target.join(source.file_name().unwrap());
|
||||||
|
|
Loading…
Reference in New Issue