diff --git a/CHANGELOG.md b/CHANGELOG.md index 518b451..a1d8d45 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -25,6 +25,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Improved accuracy of Selene type definitions, strongly typed arrays are now used where possible - Improve error handling and messages for `net.serve` - Improve error handling and messages for `stdio.prompt` +- File path representations on Windows now use legacy paths instead of UNC paths wherever possible, preventing some confusing cases where file paths don't work as expected ### Fixed diff --git a/Cargo.lock b/Cargo.lock index 16d810c..0cf1391 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -307,6 +307,12 @@ dependencies = [ "winapi", ] +[[package]] +name = "dunce" +version = "1.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0bd4b30a6560bbd9b4620f4de34c3f14f60848e58a9b7216801afcb4c7b31c3c" + [[package]] name = "encode_unicode" version = "0.3.6" @@ -786,6 +792,7 @@ dependencies = [ "console", "dialoguer", "directories", + "dunce", "futures-util", "hyper", "hyper-tungstenite", diff --git a/packages/lib/Cargo.toml b/packages/lib/Cargo.toml index 274a8ea..fb00df3 100644 --- a/packages/lib/Cargo.toml +++ b/packages/lib/Cargo.toml @@ -34,6 +34,7 @@ hyper = { version = "0.14.24", features = ["full"] } hyper-tungstenite = { version = "0.9.0" } tokio-tungstenite = { version = "0.18.0" } mlua = { version = "0.8.7", features = ["luau", "serialize"] } +dunce = "1.0.3" [dev-dependencies] anyhow = "1.0.69" diff --git a/packages/lib/src/globals/process.rs b/packages/lib/src/globals/process.rs index 4a1163e..8f268d3 100644 --- a/packages/lib/src/globals/process.rs +++ b/packages/lib/src/globals/process.rs @@ -6,6 +6,7 @@ use std::{ }; use directories::UserDirs; +use dunce::canonicalize; use mlua::prelude::*; use os_str_bytes::RawOsString; use tokio::process::Command; @@ -21,7 +22,7 @@ yield() pub fn create(lua: &'static Lua, args_vec: Vec) -> LuaResult { let cwd_str = { - let cwd = env::current_dir()?.canonicalize()?; + let cwd = canonicalize(env::current_dir()?)?; let cwd_str = cwd.to_string_lossy().to_string(); if !cwd_str.ends_with(path::MAIN_SEPARATOR) { format!("{cwd_str}{}", path::MAIN_SEPARATOR) diff --git a/packages/lib/src/globals/require.rs b/packages/lib/src/globals/require.rs index 5d7d9fe..f04bb30 100644 --- a/packages/lib/src/globals/require.rs +++ b/packages/lib/src/globals/require.rs @@ -1,9 +1,10 @@ use std::{ env::{self, current_dir}, fs, - path::PathBuf, + path::{self, PathBuf}, }; +use dunce::canonicalize; use mlua::prelude::*; use crate::lua::table::TableBuilder; @@ -35,8 +36,8 @@ pub fn create(lua: &'static Lua) -> LuaResult { } // Store the current pwd, and make the functions for path conversions & loading a file let mut require_pwd = current_dir()?.to_string_lossy().to_string(); - if !require_pwd.ends_with('/') { - require_pwd = format!("{require_pwd}/") + if !require_pwd.ends_with(path::MAIN_SEPARATOR) { + require_pwd = format!("{require_pwd}{}", path::MAIN_SEPARATOR) } let require_info: LuaFunction = lua.named_registry_value("dbg.info")?; let require_error: LuaFunction = lua.named_registry_value("error")?; @@ -53,8 +54,8 @@ pub fn create(lua: &'static Lua) -> LuaResult { .join(&require_path); // Try to normalize and resolve relative path segments such as './' and '../' let file_path = match ( - path_relative_to_pwd.with_extension("luau").canonicalize(), - path_relative_to_pwd.with_extension("lua").canonicalize(), + canonicalize(path_relative_to_pwd.with_extension("luau")), + canonicalize(path_relative_to_pwd.with_extension("lua")), ) { (Ok(luau), _) => luau, (_, Ok(lua)) => lua,