Skip to content

Commit

Permalink
Try fix for Windows paths on non-Windows machines
Browse files Browse the repository at this point in the history
  • Loading branch information
CraftSpider committed Dec 2, 2024
1 parent e19deaa commit f1bb77d
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/shims/windows/fs.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use std::borrow::Cow;
use std::fs::{File, Metadata, OpenOptions};
use std::io;
use std::io::{IsTerminal, Read, Seek, SeekFrom, Write};
Expand Down Expand Up @@ -152,7 +153,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {

let file_name =
String::from_utf16_lossy(&this.read_wide_str(this.read_pointer(file_name)?)?);
let file_name = Path::new(&file_name);
let file_name = local_path(&file_name);
let desired_access = this.read_scalar(desired_access)?.to_u32()?;
let share_mode = this.read_scalar(share_mode)?.to_u32()?;
let security_attributes = this.read_pointer(security_attributes)?;
Expand Down Expand Up @@ -390,3 +391,13 @@ fn write_filetime_field<'tcx>(
&cx.project_field_named(val, name)?,
)
}

fn local_path(path: &str) -> Cow<'_, Path> {
if cfg!(windows) {
Cow::Borrowed(path.as_ref())
} else {
let stripped = if path.starts_with(r"\\?\") { &path[3..] } else { path };
let path = PathBuf::from(stripped.replace("\\", "/"));
Cow::Owned(path)
}
}

0 comments on commit f1bb77d

Please sign in to comment.