From c976c9199d9abc921b267a754d525f3c03c42b8a Mon Sep 17 00:00:00 2001 From: Denis Isidoro Date: Mon, 9 Aug 2021 10:23:07 -0300 Subject: [PATCH] Ignore paths with invalid env vars --- src/filesystem.rs | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/filesystem.rs b/src/filesystem.rs index cb16804..fd4eb74 100644 --- a/src/filesystem.rs +++ b/src/filesystem.rs @@ -67,19 +67,20 @@ fn without_first(string: &str) -> String { .to_string() } -fn interpolate_paths(paths: String) -> Result { +fn interpolate_paths(paths: String) -> String { let re = Regex::new(r#"\$\{?[a-zA-Z_][a-zA-Z_0-9]*"#).unwrap(); let mut newtext = paths.to_string(); for capture in re.captures_iter(&paths) { if let Some(c) = capture.get(0) { let varname = c.as_str().replace("$", "").replace("{", "").replace("}", ""); - let replacement = &env_var::get(&varname)?; - newtext = newtext - .replace(&format!("${}", varname), replacement) - .replace(&format!("${{{}}}", varname), replacement); + if let Ok(replacement) = &env_var::get(&varname) { + newtext = newtext + .replace(&format!("${}", varname), replacement) + .replace(&format!("${{{}}}", varname), replacement); + } } } - Ok(newtext) + newtext } fn gen_lists(tag_rules: Option) -> (Option>, Option>) { @@ -142,7 +143,7 @@ impl fetcher::Fetcher for Fetcher { }; let paths = paths.expect("Unable to get paths"); - let interpolated_paths = interpolate_paths(paths)?; + let interpolated_paths = interpolate_paths(paths); let folders = paths_from_path_param(&interpolated_paths); let home_regex = Regex::new(r"^~").unwrap();