Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 15 additions & 15 deletions rust-code-analysis-cli/src/formats.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use regex::Regex;
use std::fs::File;
use std::io::Write;
use std::io::{Error, ErrorKind};
Expand Down Expand Up @@ -62,22 +61,23 @@ impl Format {
Format::Yaml => ".yml",
};

let output_path = output_path.as_ref().unwrap();

let mut file = path.as_path().file_name().unwrap().to_os_string();
file.push(format_ext);
// Remove . / \ .. symbols from a path to create a unique filename
let cleaned_path: Vec<&str> = path
.iter()
.filter(|v| {
if let Some(s) = v.to_str() {
![".", ".."].contains(&s)
} else {
false
}
})
.map(|s| s.to_str().unwrap())
.collect();

let mut format_path = output_path.clone();
format_path.push(file);
// Create the filename
let filename = cleaned_path.join("_") + format_ext;

if format_path.as_path().exists() {
let mut new_filename = path.to_str().unwrap().to_string();
let re = Regex::new(r"[\\:/]").unwrap();
new_filename = re.replace_all(&new_filename, "_").to_string();
new_filename.push_str(format_ext);
format_path.pop();
format_path.push(new_filename);
}
let format_path = output_path.as_ref().unwrap().join(filename);

let mut format_file = File::create(format_path)?;
match self {
Expand Down