Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(fs): ignore OS specific paths in scope deserialization #1837

Merged
merged 3 commits into from
Sep 25, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changes/fix-fs-scope-unknown-path.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
fs: patch
---

Fixed an issue causing any `fs` APIs to throw an `error deserializing scope: unknown path` error when the permissions/scopes allowed OS specific paths that aren't available on the currently running OS.
FabianLars marked this conversation as resolved.
Show resolved Hide resolved
8 changes: 4 additions & 4 deletions plugins/fs/src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -993,8 +993,8 @@ pub fn resolve_path<R: Runtime>(
.unwrap()
.clone()
.into_iter()
.chain(global_scope.allows().iter().map(|e| e.path.clone()))
.chain(command_scope.allows().iter().map(|e| e.path.clone()))
.chain(global_scope.allows().iter().filter_map(|e| e.path.clone()))
.chain(command_scope.allows().iter().filter_map(|e| e.path.clone()))
.collect(),
deny: webview
.fs_scope()
Expand All @@ -1003,8 +1003,8 @@ pub fn resolve_path<R: Runtime>(
.unwrap()
.clone()
.into_iter()
.chain(global_scope.denies().iter().map(|e| e.path.clone()))
.chain(command_scope.denies().iter().map(|e| e.path.clone()))
.chain(global_scope.denies().iter().filter_map(|e| e.path.clone()))
.chain(command_scope.denies().iter().filter_map(|e| e.path.clone()))
.collect(),
require_literal_leading_dot: webview.fs_scope().require_literal_leading_dot,
},
Expand Down
18 changes: 9 additions & 9 deletions plugins/fs/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -353,17 +353,17 @@ impl ScopeObject for scope::Entry {
app: &AppHandle<R>,
raw: Value,
) -> std::result::Result<Self, Self::Error> {
let entry = serde_json::from_value(raw.into()).map(|raw| {
let path = match raw {
scope::EntryRaw::Value(path) => path,
scope::EntryRaw::Object { path } => path,
};
Self { path }
let path = serde_json::from_value(raw.into()).map(|raw| match raw {
scope::EntryRaw::Value(path) => path,
scope::EntryRaw::Object { path } => path,
})?;

Ok(Self {
path: app.path().parse(entry.path)?,
})
match app.path().parse(path) {
Ok(path) => Ok(Self { path: Some(path) }),
#[cfg(not(target_os = "android"))]
FabianLars marked this conversation as resolved.
Show resolved Hide resolved
Err(tauri::Error::UnknownPath) => Ok(Self { path: None }),
Err(err) => Err(err.into()),
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion plugins/fs/src/scope.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ pub enum EntryRaw {

#[derive(Debug)]
pub struct Entry {
pub path: PathBuf,
pub path: Option<PathBuf>,
}

pub type EventId = u32;
Expand Down
Loading