mirror of
https://github.com/tauri-apps/tauri.git
synced 2024-08-17 03:40:23 +03:00
feat(core/windows): Convert UNC paths to simple paths in JS apis. (#9420)
This commit is contained in:
parent
73c1c2d338
commit
f1674fce6d
5
.changes/api-simplify-unc-paths.md
Normal file
5
.changes/api-simplify-unc-paths.md
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
tauri: patch:enhance
|
||||||
|
---
|
||||||
|
|
||||||
|
Tauri's built-in commands for the JS api will now return simplified paths on Windows, removing the `\\?\` prefix.
|
1
Cargo.lock
generated
1
Cargo.lock
generated
@ -3503,6 +3503,7 @@ dependencies = [
|
|||||||
"cocoa",
|
"cocoa",
|
||||||
"data-url",
|
"data-url",
|
||||||
"dirs-next",
|
"dirs-next",
|
||||||
|
"dunce",
|
||||||
"embed_plist",
|
"embed_plist",
|
||||||
"futures-util",
|
"futures-util",
|
||||||
"getrandom 0.2.12",
|
"getrandom 0.2.12",
|
||||||
|
@ -73,6 +73,7 @@ http-range = { version = "0.1.5", optional = true }
|
|||||||
tracing = { version = "0.1", optional = true }
|
tracing = { version = "0.1", optional = true }
|
||||||
heck = "0.4"
|
heck = "0.4"
|
||||||
log = "0.4"
|
log = "0.4"
|
||||||
|
dunce = "1"
|
||||||
|
|
||||||
[target."cfg(any(target_os = \"linux\", target_os = \"dragonfly\", target_os = \"freebsd\", target_os = \"openbsd\", target_os = \"netbsd\", target_os = \"windows\", target_os = \"macos\"))".dependencies]
|
[target."cfg(any(target_os = \"linux\", target_os = \"dragonfly\", target_os = \"freebsd\", target_os = \"openbsd\", target_os = \"netbsd\", target_os = \"windows\", target_os = \"macos\"))".dependencies]
|
||||||
muda = { version = "0.13", default-features = false, features = [ "serde" ] }
|
muda = { version = "0.13", default-features = false, features = [ "serde" ] }
|
||||||
|
@ -92,7 +92,7 @@ pub fn resolve_directory<R: Runtime>(
|
|||||||
directory: BaseDirectory,
|
directory: BaseDirectory,
|
||||||
path: Option<PathBuf>,
|
path: Option<PathBuf>,
|
||||||
) -> Result<PathBuf> {
|
) -> Result<PathBuf> {
|
||||||
super::resolve_path(&resolver, directory, path)
|
super::resolve_path(&resolver, directory, path).map(|p| dunce::simplified(&p).to_path_buf())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[command(root = "crate")]
|
#[command(root = "crate")]
|
||||||
@ -107,12 +107,12 @@ pub fn resolve(paths: Vec<String>) -> Result<PathBuf> {
|
|||||||
for p in paths {
|
for p in paths {
|
||||||
path.push(p);
|
path.push(p);
|
||||||
}
|
}
|
||||||
Ok(normalize_path(&path))
|
Ok(dunce::simplified(&normalize_path(&path)).to_path_buf())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[command(root = "crate")]
|
#[command(root = "crate")]
|
||||||
pub fn normalize(path: String) -> String {
|
pub fn normalize(path: String) -> String {
|
||||||
let mut p = normalize_path_no_absolute(Path::new(&path))
|
let mut p = dunce::simplified(&normalize_path_no_absolute(Path::new(&path)))
|
||||||
.to_string_lossy()
|
.to_string_lossy()
|
||||||
.to_string();
|
.to_string();
|
||||||
|
|
||||||
@ -149,9 +149,10 @@ pub fn join(mut paths: Vec<String>) -> String {
|
|||||||
.collect::<String>(),
|
.collect::<String>(),
|
||||||
);
|
);
|
||||||
|
|
||||||
let p = normalize_path_no_absolute(&path)
|
let p = dunce::simplified(&normalize_path_no_absolute(&path))
|
||||||
.to_string_lossy()
|
.to_string_lossy()
|
||||||
.to_string();
|
.to_string();
|
||||||
|
|
||||||
if p.is_empty() {
|
if p.is_empty() {
|
||||||
".".into()
|
".".into()
|
||||||
} else {
|
} else {
|
||||||
@ -162,7 +163,7 @@ pub fn join(mut paths: Vec<String>) -> String {
|
|||||||
#[command(root = "crate")]
|
#[command(root = "crate")]
|
||||||
pub fn dirname(path: String) -> Result<PathBuf> {
|
pub fn dirname(path: String) -> Result<PathBuf> {
|
||||||
match Path::new(&path).parent() {
|
match Path::new(&path).parent() {
|
||||||
Some(p) => Ok(p.to_path_buf()),
|
Some(p) => Ok(dunce::simplified(p).to_path_buf()),
|
||||||
None => Err(Error::NoParent),
|
None => Err(Error::NoParent),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user