Skip to content

Commit

Permalink
feat(core/windows): Convert UNC paths to simple paths in JS apis. (#9420
Browse files Browse the repository at this point in the history
)
  • Loading branch information
FabianLars committed Apr 15, 2024
1 parent 73c1c2d commit f1674fc
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 5 deletions.
5 changes: 5 additions & 0 deletions .changes/api-simplify-unc-paths.md
@@ -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 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions core/tauri/Cargo.toml
Expand Up @@ -73,6 +73,7 @@ http-range = { version = "0.1.5", optional = true }
tracing = { version = "0.1", optional = true }
heck = "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]
muda = { version = "0.13", default-features = false, features = [ "serde" ] }
Expand Down
11 changes: 6 additions & 5 deletions core/tauri/src/path/plugin.rs
Expand Up @@ -92,7 +92,7 @@ pub fn resolve_directory<R: Runtime>(
directory: BaseDirectory,
path: Option<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")]
Expand All @@ -107,12 +107,12 @@ pub fn resolve(paths: Vec<String>) -> Result<PathBuf> {
for p in paths {
path.push(p);
}
Ok(normalize_path(&path))
Ok(dunce::simplified(&normalize_path(&path)).to_path_buf())
}

#[command(root = "crate")]
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();

Expand Down Expand Up @@ -149,9 +149,10 @@ pub fn join(mut paths: Vec<String>) -> String {
.collect::<String>(),
);

let p = normalize_path_no_absolute(&path)
let p = dunce::simplified(&normalize_path_no_absolute(&path))
.to_string_lossy()
.to_string();

if p.is_empty() {
".".into()
} else {
Expand All @@ -162,7 +163,7 @@ pub fn join(mut paths: Vec<String>) -> String {
#[command(root = "crate")]
pub fn dirname(path: String) -> Result<PathBuf> {
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),
}
}
Expand Down

0 comments on commit f1674fc

Please sign in to comment.