Skip to content

Commit bb51a41

Browse files
authored
feat: Remove UNC prefix in paths returned to the frontend (#1168)
* feat: Remove UNC prefix in paths returned to the frontend * that one doesn't count * map instead of mut * revert accidental ipc::response change * move dunce to workspace root
1 parent 6698774 commit bb51a41

7 files changed

Lines changed: 35 additions & 6 deletions

File tree

.changes/remove-unc-path-prefix.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
dialog: patch
3+
fs: patch
4+
store: patch
5+
---
6+
7+
**Breaking Change:** All apis that return paths to the frontend will now remove the `\\?\` UNC prefix on Windows.

Cargo.lock

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ serde_json = "1"
1717
thiserror = "1"
1818
url = "2"
1919
schemars = "0.8"
20+
dunce = "1"
2021

2122
[workspace.package]
2223
edition = "2021"

plugins/dialog/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ serde_json = { workspace = true }
2323
tauri = { workspace = true }
2424
log = { workspace = true }
2525
thiserror = { workspace = true }
26+
dunce = { workspace = true }
2627
tauri-plugin-fs = { path = "../fs", version = "2.0.0-beta.4" }
2728

2829
[target."cfg(any(target_os = \"macos\", windows, target_os = \"linux\", target_os = \"dragonfly\", target_os = \"freebsd\", target_os = \"openbsd\", target_os = \"netbsd\"))".dependencies]

plugins/dialog/src/commands.rs

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -129,15 +129,20 @@ pub(crate) async fn open<R: Runtime>(
129129
}
130130
}
131131
}
132-
OpenResponse::Folders(folders)
132+
OpenResponse::Folders(folders.map(|folders| {
133+
folders
134+
.iter()
135+
.map(|p| dunce::simplified(p).to_path_buf())
136+
.collect()
137+
}))
133138
} else {
134139
let folder = dialog_builder.blocking_pick_folder();
135140
if let Some(path) = &folder {
136141
if let Some(s) = window.try_fs_scope() {
137142
s.allow_directory(path, options.recursive);
138143
}
139144
}
140-
OpenResponse::Folder(folder)
145+
OpenResponse::Folder(folder.map(|p| dunce::simplified(&p).to_path_buf()))
141146
}
142147
}
143148
#[cfg(mobile)]
@@ -154,7 +159,15 @@ pub(crate) async fn open<R: Runtime>(
154159
.allow_file(&file.path)?;
155160
}
156161
}
157-
OpenResponse::Files(files)
162+
OpenResponse::Files(files.map(|files| {
163+
files
164+
.into_iter()
165+
.map(|mut f| {
166+
f.path = dunce::simplified(&f.path).to_path_buf();
167+
f
168+
})
169+
.collect()
170+
}))
158171
} else {
159172
let file = dialog_builder.blocking_pick_file();
160173
if let Some(file) = &file {
@@ -165,7 +178,10 @@ pub(crate) async fn open<R: Runtime>(
165178
.state::<tauri::scope::Scopes>()
166179
.allow_file(&file.path)?;
167180
}
168-
OpenResponse::File(file)
181+
OpenResponse::File(file.map(|mut f| {
182+
f.path = dunce::simplified(&f.path).to_path_buf();
183+
f
184+
}))
169185
};
170186
Ok(res)
171187
}
@@ -208,7 +224,7 @@ pub(crate) async fn save<R: Runtime>(
208224
window.state::<tauri::scope::Scopes>().allow_file(p)?;
209225
}
210226

211-
Ok(path)
227+
Ok(path.map(|p| dunce::simplified(&p).to_path_buf()))
212228
}
213229
}
214230

plugins/store/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,4 @@ serde_json = { workspace = true }
2222
tauri = { workspace = true }
2323
log = { workspace = true }
2424
thiserror = { workspace = true }
25+
dunce = { workspace = true }

plugins/store/src/store.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,8 @@ impl<R: Runtime> StoreBuilder<R> {
5858
/// ```
5959
pub fn new<P: AsRef<Path>>(path: P) -> Self {
6060
Self {
61-
path: path.as_ref().to_path_buf(),
61+
// Since Store.path is only exposed to the user in emit calls we may as well simplify it here already.
62+
path: dunce::simplified(path.as_ref()).to_path_buf(),
6263
defaults: None,
6364
cache: Default::default(),
6465
serialize: default_serialize,

0 commit comments

Comments
 (0)