Skip to content

Commit 3aa6c17

Browse files
committed
Merge pull request #9 from garymathews/windows
2 parents 06a11b8 + eb86e4e commit 3aa6c17

File tree

1 file changed

+18
-3
lines changed

1 file changed

+18
-3
lines changed

src/data_types.rs

100644100755
Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// src/data_types.rs
22

3+
use std::borrow::Cow;
34
use std::hash::{Hash, Hasher, DefaultHasher};
45
use std::path::PathBuf;
56
use std::io::Write;
@@ -223,12 +224,26 @@ pub struct DataDirMnemonic<'a> {
223224
pub deriv_index: u32,
224225
}
225226

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+
226239
impl<'a> DataDir<'a> {
227240
// ... (All existing file system impls remain here for migration compatibility)
228241
// ...
229242
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+
230245
let mut path = PathBuf::from(base_dir);
231-
path.push(challenge_id);
246+
path.push(challenge_id_normalized.as_ref());
232247
Ok(path)
233248
}
234249

@@ -287,7 +302,7 @@ impl<'a> DataDir<'a> {
287302
.map_err(|e| format!("Could not create pending_submissions directory: {}", e))?;
288303

289304
// 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));
291306

292307
let solution_json = serde_json::to_string(solution)
293308
.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:
344359
if let Some(filename) = entry.file_name().to_str() {
345360
// Check if the filename starts with the required prefix and is a JSON file
346361
// 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") {
348363
return Ok(true);
349364
}
350365
}

0 commit comments

Comments
 (0)