diff --git a/.changes/fix-fs-scope-unknown-path.md b/.changes/fix-fs-scope-unknown-path.md new file mode 100644 index 000000000..5e63a6fc1 --- /dev/null +++ b/.changes/fix-fs-scope-unknown-path.md @@ -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. \ No newline at end of file diff --git a/plugins/fs/src/commands.rs b/plugins/fs/src/commands.rs index 8f7a9ac0f..cb40c3eea 100644 --- a/plugins/fs/src/commands.rs +++ b/plugins/fs/src/commands.rs @@ -993,8 +993,8 @@ pub fn resolve_path( .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() @@ -1003,8 +1003,8 @@ pub fn resolve_path( .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, }, diff --git a/plugins/fs/src/lib.rs b/plugins/fs/src/lib.rs index 5cb903f8e..a1cf27669 100644 --- a/plugins/fs/src/lib.rs +++ b/plugins/fs/src/lib.rs @@ -353,17 +353,17 @@ impl ScopeObject for scope::Entry { app: &AppHandle, raw: Value, ) -> std::result::Result { - 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()), + } } } diff --git a/plugins/fs/src/scope.rs b/plugins/fs/src/scope.rs index f31c786a6..fd94b0ebb 100644 --- a/plugins/fs/src/scope.rs +++ b/plugins/fs/src/scope.rs @@ -23,7 +23,7 @@ pub enum EntryRaw { #[derive(Debug)] pub struct Entry { - pub path: PathBuf, + pub path: Option, } pub type EventId = u32;