De-UNC file paths on windows wherever possible

This commit is contained in:
Filip Tibell 2023-02-22 23:21:37 +01:00
parent ec040e420e
commit eecffca741
No known key found for this signature in database
5 changed files with 17 additions and 6 deletions

View file

@ -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 - 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 `net.serve`
- Improve error handling and messages for `stdio.prompt` - 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 ### Fixed

7
Cargo.lock generated
View file

@ -307,6 +307,12 @@ dependencies = [
"winapi", "winapi",
] ]
[[package]]
name = "dunce"
version = "1.0.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0bd4b30a6560bbd9b4620f4de34c3f14f60848e58a9b7216801afcb4c7b31c3c"
[[package]] [[package]]
name = "encode_unicode" name = "encode_unicode"
version = "0.3.6" version = "0.3.6"
@ -786,6 +792,7 @@ dependencies = [
"console", "console",
"dialoguer", "dialoguer",
"directories", "directories",
"dunce",
"futures-util", "futures-util",
"hyper", "hyper",
"hyper-tungstenite", "hyper-tungstenite",

View file

@ -34,6 +34,7 @@ hyper = { version = "0.14.24", features = ["full"] }
hyper-tungstenite = { version = "0.9.0" } hyper-tungstenite = { version = "0.9.0" }
tokio-tungstenite = { version = "0.18.0" } tokio-tungstenite = { version = "0.18.0" }
mlua = { version = "0.8.7", features = ["luau", "serialize"] } mlua = { version = "0.8.7", features = ["luau", "serialize"] }
dunce = "1.0.3"
[dev-dependencies] [dev-dependencies]
anyhow = "1.0.69" anyhow = "1.0.69"

View file

@ -6,6 +6,7 @@ use std::{
}; };
use directories::UserDirs; use directories::UserDirs;
use dunce::canonicalize;
use mlua::prelude::*; use mlua::prelude::*;
use os_str_bytes::RawOsString; use os_str_bytes::RawOsString;
use tokio::process::Command; use tokio::process::Command;
@ -21,7 +22,7 @@ yield()
pub fn create(lua: &'static Lua, args_vec: Vec<String>) -> LuaResult<LuaTable> { pub fn create(lua: &'static Lua, args_vec: Vec<String>) -> LuaResult<LuaTable> {
let cwd_str = { let cwd_str = {
let cwd = env::current_dir()?.canonicalize()?; let cwd = canonicalize(env::current_dir()?)?;
let cwd_str = cwd.to_string_lossy().to_string(); let cwd_str = cwd.to_string_lossy().to_string();
if !cwd_str.ends_with(path::MAIN_SEPARATOR) { if !cwd_str.ends_with(path::MAIN_SEPARATOR) {
format!("{cwd_str}{}", path::MAIN_SEPARATOR) format!("{cwd_str}{}", path::MAIN_SEPARATOR)

View file

@ -1,9 +1,10 @@
use std::{ use std::{
env::{self, current_dir}, env::{self, current_dir},
fs, fs,
path::PathBuf, path::{self, PathBuf},
}; };
use dunce::canonicalize;
use mlua::prelude::*; use mlua::prelude::*;
use crate::lua::table::TableBuilder; use crate::lua::table::TableBuilder;
@ -35,8 +36,8 @@ pub fn create(lua: &'static Lua) -> LuaResult<LuaTable> {
} }
// Store the current pwd, and make the functions for path conversions & loading a file // 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(); let mut require_pwd = current_dir()?.to_string_lossy().to_string();
if !require_pwd.ends_with('/') { if !require_pwd.ends_with(path::MAIN_SEPARATOR) {
require_pwd = format!("{require_pwd}/") require_pwd = format!("{require_pwd}{}", path::MAIN_SEPARATOR)
} }
let require_info: LuaFunction = lua.named_registry_value("dbg.info")?; let require_info: LuaFunction = lua.named_registry_value("dbg.info")?;
let require_error: LuaFunction = lua.named_registry_value("error")?; let require_error: LuaFunction = lua.named_registry_value("error")?;
@ -53,8 +54,8 @@ pub fn create(lua: &'static Lua) -> LuaResult<LuaTable> {
.join(&require_path); .join(&require_path);
// Try to normalize and resolve relative path segments such as './' and '../' // Try to normalize and resolve relative path segments such as './' and '../'
let file_path = match ( let file_path = match (
path_relative_to_pwd.with_extension("luau").canonicalize(), canonicalize(path_relative_to_pwd.with_extension("luau")),
path_relative_to_pwd.with_extension("lua").canonicalize(), canonicalize(path_relative_to_pwd.with_extension("lua")),
) { ) {
(Ok(luau), _) => luau, (Ok(luau), _) => luau,
(_, Ok(lua)) => lua, (_, Ok(lua)) => lua,