|
1 | 1 | // src/data_types.rs |
2 | 2 |
|
| 3 | +use std::borrow::Cow; |
3 | 4 | use std::hash::{Hash, Hasher, DefaultHasher}; |
4 | 5 | use std::path::PathBuf; |
5 | 6 | use std::io::Write; |
@@ -223,12 +224,26 @@ pub struct DataDirMnemonic<'a> { |
223 | 224 | pub deriv_index: u32, |
224 | 225 | } |
225 | 226 |
|
| 227 | +fn normalize_challenge_id(challenge_id: &str) -> Cow<str> { |
| 228 | + #[cfg(target_os = "windows")] |
| 229 | + { |
| 230 | + // Directories with '*' are not supported on windows |
| 231 | + challenge_id.replace("*", "").into() |
| 232 | + } |
| 233 | + #[cfg(not(target_os = "windows"))] |
| 234 | + { |
| 235 | + challenge_id.into() |
| 236 | + } |
| 237 | +} |
| 238 | + |
226 | 239 | impl<'a> DataDir<'a> { |
227 | 240 | // ... (All existing file system impls remain here for migration compatibility) |
228 | 241 | // ... |
229 | 242 | pub fn challenge_dir(&'a self, base_dir: &str, challenge_id: &str) -> Result<PathBuf, String> { |
| 243 | + let challenge_id_normalized = normalize_challenge_id(challenge_id); |
| 244 | + |
230 | 245 | let mut path = PathBuf::from(base_dir); |
231 | | - path.push(challenge_id); |
| 246 | + path.push(challenge_id_normalized.as_ref()); |
232 | 247 | Ok(path) |
233 | 248 | } |
234 | 249 |
|
@@ -287,7 +302,7 @@ impl<'a> DataDir<'a> { |
287 | 302 | .map_err(|e| format!("Could not create pending_submissions directory: {}", e))?; |
288 | 303 |
|
289 | 304 | // Use a unique file name based on challenge, address, and nonce |
290 | | - path.push(format!("{}_{}_{}.json", solution.address, solution.challenge_id, solution.nonce)); |
| 305 | + path.push(format!("{}_{}_{}.json", solution.address, normalize_challenge_id(&solution.challenge_id), solution.nonce)); |
291 | 306 |
|
292 | 307 | let solution_json = serde_json::to_string(solution) |
293 | 308 | .map_err(|e| format!("Could not serialize pending solution: {}", e))?; |
@@ -344,7 +359,7 @@ pub fn is_solution_pending_in_queue(base_dir: &str, address: &str, challenge_id: |
344 | 359 | if let Some(filename) = entry.file_name().to_str() { |
345 | 360 | // Check if the filename starts with the required prefix and is a JSON file |
346 | 361 | // The filename format is: address_challenge_id_nonce.json |
347 | | - if filename.starts_with(&format!("{}_{}_", address, challenge_id)) && filename.ends_with(".json") { |
| 362 | + if filename.starts_with(&format!("{}_{}_", address, normalize_challenge_id(&challenge_id))) && filename.ends_with(".json") { |
348 | 363 | return Ok(true); |
349 | 364 | } |
350 | 365 | } |
|
0 commit comments