From c5cc4baf15e80cc69d209693146ec442b431c327 Mon Sep 17 00:00:00 2001 From: Julian T Date: Mon, 6 Feb 2023 21:50:43 +0100 Subject: Remove folder config thing from setwall --- scripts/resc/setwall/src/main.rs | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) (limited to 'scripts/resc/setwall/src') diff --git a/scripts/resc/setwall/src/main.rs b/scripts/resc/setwall/src/main.rs index b9e4f01..4bc3626 100644 --- a/scripts/resc/setwall/src/main.rs +++ b/scripts/resc/setwall/src/main.rs @@ -30,12 +30,13 @@ enum Rule { #[derive(Debug, Deserialize)] struct Config { - #[serde(default = "default_folder")] - folder: String, #[serde(default)] rules: Vec<(String, Rule)>, #[serde(default = "default_background")] background: String, + + #[serde(skip, default = "default_folder")] + folder: String, } #[derive(Debug)] @@ -56,7 +57,8 @@ impl fmt::Display for Error { } impl error::Error for Error {} -fn default_folder() -> String { String::from(".") } +// Default used if we could not get the parent folder of the config file +fn default_folder() -> String { String::from("/") } fn default_background() -> String { String::from("black") } fn main() -> Result<(), Box> { @@ -85,8 +87,10 @@ impl Config { let f = File::open(file)?; let mut config: Config = serde_yaml::from_reader(f)?; - config.folder = file.parent().unwrap_or(Path::new("/")). - join(config.folder).to_string_lossy().to_string(); + if let Some(folder) = file.parent() { + config.folder = folder.to_string_lossy().into(); + } + Ok(config) } @@ -118,8 +122,6 @@ impl Config { let file_name = String::from(entry.file_name().to_string_lossy()); if let Some(index) = rs.matches(&file_name).iter().next() { imgs.push((entry.path(), self.rules[index].1)); - } else { - return Err(Box::new(Error::NoRule(file_name.into()))); } // deja vu } -- cgit v1.2.3