DEV: More Windows file path handling fixes.

This commit is contained in:
Jeremy Wall 2019-11-03 14:19:14 -06:00
parent ad97dfca57
commit db9b7aef43
2 changed files with 17 additions and 6 deletions

View File

@ -576,8 +576,9 @@ impl ModuleDef {
pub fn imports_to_absolute(&mut self, base: PathBuf) {
let rewrite_import = |e: &mut Expression| {
let main_separator = format!("{}", std::path::MAIN_SEPARATOR);
if let Expression::Include(ref mut def) = e {
let path = PathBuf::from(&def.path.fragment);
let path = PathBuf::from(&def.path.fragment.replace("/", &main_separator).replace("\\", &main_separator));
if path.is_relative() {
def.path.fragment = base
.join(path)
@ -588,9 +589,9 @@ impl ModuleDef {
}
}
if let Expression::Import(ref mut def) = e {
let path = PathBuf::from(&def.path.fragment);
let path = PathBuf::from(&def.path.fragment.replace("/", &main_separator).replace("\\", &main_separator));
// std/ paths are special and do not get made into absolute paths.
if path.starts_with("std/") {
if path.starts_with(format!("std{}", main_separator)) {
return;
}
if path.is_relative() {

View File

@ -120,7 +120,17 @@ impl Builtins {
} else {
normalized = path;
}
Ok(normalized.canonicalize()?)
// The canonicalize method on windows is not what we want so we'll
// do something a little different on windows that we would do on
// other Operating Systems.
#[cfg(target_os="windows")]
{
Ok(dbg!(normalized))
}
#[cfg(not(target_os="windows"))]
{
Ok(dbg!(normalized.canonicalize()?))
}
}
fn find_file<P, BP>(
@ -176,9 +186,9 @@ impl Builtins {
if let Some((val, path_pos)) = path {
if let &Value::P(Str(ref path)) = val.as_ref() {
// TODO(jwall): A bit hacky we should probably change import stacks to be pathbufs.
let normalized = decorate_error!(path_pos => self.normalize_path(base_path, false, path))?;
let normalized = decorate_error!(path_pos => self.normalize_path(base_path, false, dbg!(path)))?;
// first we chack the cache
let path = normalized.to_string_lossy().to_string();
let path = dbg!(normalized.to_string_lossy().to_string());
if let Some(val) = env.borrow().get_cached_path_val(&path) {
stack.push((val, path_pos));
return Ok(());