From 1b2ec10ca078cd956bafaff5ec36b841999e3ef3 Mon Sep 17 00:00:00 2001 From: Luni-4 Date: Tue, 22 Dec 2020 10:11:17 +0100 Subject: [PATCH] Clean up filenames produced by the cli - Remove root - Remove current directory symbol - Avoid having duplicates filenames --- rust-code-analysis-cli/src/formats.rs | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/rust-code-analysis-cli/src/formats.rs b/rust-code-analysis-cli/src/formats.rs index 9a4e8a7ce..130a1c3f8 100644 --- a/rust-code-analysis-cli/src/formats.rs +++ b/rust-code-analysis-cli/src/formats.rs @@ -61,17 +61,23 @@ impl Format { Format::Yaml => ".yml", }; - // Remove . / \ .. symbols from a path to create a unique filename + // Remove root / + let path = path.strip_prefix("/").unwrap_or(path); + + // Remove root ./ + let path = path.strip_prefix("./").unwrap_or(path); + + // Replace .. symbol with "_" to create a unique filename let cleaned_path: Vec<&str> = path .iter() - .filter(|v| { - if let Some(s) = v.to_str() { - ![".", ".."].contains(&s) + .map(|os_str| { + let s_str = os_str.to_str().unwrap(); + if s_str == ".." { + "_" } else { - false + s_str } }) - .map(|s| s.to_str().unwrap()) .collect(); // Create the filename