Skip to content

Commit

Permalink
fix(fs): ignore OS specific paths in scope deserialization (#1837)
Browse files Browse the repository at this point in the history
  • Loading branch information
FabianLars authored Sep 25, 2024
1 parent b7ff3a6 commit fc9b189
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 14 deletions.
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
---

Fix failing to deserialize capability file when using an OS specific path in the scope that is not available on the current OS.
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"))]
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

0 comments on commit fc9b189

Please sign in to comment.