Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Append hash to generated file names to avoid conflicts on case-insensitive filesystems #9

Merged
merged 3 commits into from
Nov 16, 2023
Merged
Show file tree
Hide file tree
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
10 changes: 9 additions & 1 deletion src/fs/dir.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
use std::collections::hash_map::DefaultHasher;
use std::fs::File;
use std::hash::{Hash, Hasher};
use std::io::Write;
use std::path::Path;

Expand Down Expand Up @@ -55,10 +57,16 @@ pub fn dump_dir(dump_dir: &str, output_strings: Vec<String>) {
.replace([' ', '/'], "_") // This is to handle the "tests/itest" in ARGS
.replace(&['<', '>', ':', '"', '/', '\\', '|', '?', '*'][..], "_"); // Sanitize for Windows

let file_path = dump_path.join(format!("ptest_{}.toml", args));
let file_path = dump_path.join(format!("ptest_{:x}.toml", hash(&args)));
let mut file = File::create(&file_path)
.unwrap_or_else(|_| panic!("Failed to create file at {:?}", file_path));
file.write_all(content.as_bytes())
.expect("Failed to write to file");
}
}

fn hash<T: Hash>(t: &T) -> u64 {
let mut hasher = DefaultHasher::new();
t.hash(&mut hasher);
hasher.finish()
}
1 change: 1 addition & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ fn main() -> std::io::Result<()> {
// NOTE: for some reason this is always true for u8, but I don't trust it
} else if let Some(stdin) = matches.get_one::<u8>("stdin") {
// If --stdin set
#[allow(clippy::suspicious_else_formatting)]
if stdin > &0 {
parse = crate::parser::parse(std::io::stdin().lock());
}
Expand Down