diff --git a/src/shim_filesystem.rs b/src/shim_filesystem.rs index d539a630..459a1c5b 100644 --- a/src/shim_filesystem.rs +++ b/src/shim_filesystem.rs @@ -288,19 +288,21 @@ cfg_if! { static IN_MEMORY_DIRS: RwLock>> = RwLock::new(None); pub fn add_in_memory_file(path: &str, content: &str) { + // store the keys the same way they are looked up (get_in_memory_key), so that "/" in 'path' + // still matches on Windows, where the lookup key is built with "\" + let path_obj = Path::new(path); { let mut files = IN_MEMORY_FILES.write().unwrap(); - files.get_or_insert_with(HashMap::new).insert(path.to_string(), content.to_string()); + files.get_or_insert_with(HashMap::new).insert(get_in_memory_key(path_obj), content.to_string()); } - let path_obj = Path::new(path); { let mut dirs = IN_MEMORY_DIRS.write().unwrap(); let dirs = dirs.get_or_insert_with(HashSet::new); for parent in path_obj.ancestors().skip(1) { - let parent_str = parent.to_str().unwrap_or_default(); + let parent_str = get_in_memory_key(parent); if !parent_str.is_empty() { - dirs.insert(parent_str.to_string()); + dirs.insert(parent_str); } } }