diff --git a/src/data_types.rs b/src/data_types.rs old mode 100644 new mode 100755 index d073d45..cb0be73 --- a/src/data_types.rs +++ b/src/data_types.rs @@ -1,5 +1,6 @@ // src/data_types.rs +use std::borrow::Cow; use std::hash::{Hash, Hasher, DefaultHasher}; use std::path::PathBuf; use std::io::Write; @@ -180,10 +181,24 @@ pub struct DataDirMnemonic<'a> { pub deriv_index: u32, } +fn normalize_challenge_id(challenge_id: &str) -> Cow { + #[cfg(target_os = "windows")] + { + // Directories with '*' are not supported on windows + challenge_id.replace("*", "") + } + #[cfg(not(target_os = "windows"))] + { + Cow::from(challenge_id) + } +} + impl<'a> DataDir<'a> { pub fn challenge_dir(&'a self, base_dir: &str, challenge_id: &str) -> Result { + let challenge_id_normalized = normalize_challenge_id(challenge_id); + let mut path = PathBuf::from(base_dir); - path.push(challenge_id); + path.push(challenge_id_normalized.as_ref()); Ok(path) } @@ -263,7 +278,7 @@ impl<'a> DataDir<'a> { .map_err(|e| format!("Could not create pending_submissions directory: {}", e))?; // Use a unique file name based on challenge, address, and nonce - path.push(format!("{}_{}_{}.json", solution.address, solution.challenge_id, solution.nonce)); + path.push(format!("{}_{}_{}.json", solution.address, normalize_challenge_id(&solution.challenge_id), solution.nonce)); let solution_json = serde_json::to_string(solution) .map_err(|e| format!("Could not serialize pending solution: {}", e))?; @@ -320,7 +335,7 @@ pub fn is_solution_pending_in_queue(base_dir: &str, address: &str, challenge_id: if let Some(filename) = entry.file_name().to_str() { // Check if the filename starts with the required prefix and is a JSON file // The filename format is: address_challenge_id_nonce.json - if filename.starts_with(&format!("{}_{}_", address, challenge_id)) && filename.ends_with(".json") { + if filename.starts_with(&format!("{}_{}_", address, normalize_challenge_id(&challenge_id))) && filename.ends_with(".json") { return Ok(true); } }