diff --git a/.changes/stronghold-arg-name.md b/.changes/stronghold-arg-name.md new file mode 100644 index 00000000..61efc0ed --- /dev/null +++ b/.changes/stronghold-arg-name.md @@ -0,0 +1,5 @@ +--- +"stronghold-js": patch +--- + +Change the argument name of the `Stronghold.remove` from `location` to `recordPath` to match the Stronghold command argument diff --git a/.changes/stronghold-constructor.md b/.changes/stronghold-constructor.md new file mode 100644 index 00000000..99966095 --- /dev/null +++ b/.changes/stronghold-constructor.md @@ -0,0 +1,5 @@ +--- +"stronghold-js": minor +--- + +Added `Stronghold.load` and removed its constructor. diff --git a/plugins/persisted-scope/CHANGELOG.md b/plugins/persisted-scope/CHANGELOG.md index e48c095a..fea6e6de 100644 --- a/plugins/persisted-scope/CHANGELOG.md +++ b/plugins/persisted-scope/CHANGELOG.md @@ -5,6 +5,11 @@ - [`ebb2eb2`](https://github.com/tauri-apps/plugins-workspace/commit/ebb2eb2fe2ebfbb70530d16a983d396aa5829aa1)([#274](https://github.com/tauri-apps/plugins-workspace/pull/274)) Recursively unescape saved patterns before allowing/forbidding them. This effectively prevents `.persisted-scope` files from blowing up, which caused Out-Of-Memory issues, while automatically fixing existing broken files seamlessly. - [`717ae67`](https://github.com/tauri-apps/plugins-workspace/commit/717ae670978feb4492fac1f295998b93f2b9347f)([#371](https://github.com/tauri-apps/plugins-workspace/pull/371)) First v2 alpha release! +## \[0.1.3] + +- Split up fs and asset scopes. **This will reset the asset protocol scope once!** + - [ad30286](https://github.com/tauri-apps/plugins-workspace/commit/ad3028646c96ed213a2f483823ffdc3c17b5fc1e) fix(persisted-scope): separately save asset protocol patterns ([#459](https://github.com/tauri-apps/plugins-workspace/pull/459)) on 2023-07-10 + ## \[0.1.2] - Fix usage of directory patterns by removing glob asterisks at the end before allowing/forbidding them. This was causing them to be escaped, and so undesirable paths were allowed/forbidden while polluting the `.persisted_scope` file. diff --git a/plugins/persisted-scope/src/lib.rs b/plugins/persisted-scope/src/lib.rs index 24c062c1..6df25860 100644 --- a/plugins/persisted-scope/src/lib.rs +++ b/plugins/persisted-scope/src/lib.rs @@ -15,7 +15,7 @@ use aho_corasick::AhoCorasick; use serde::{Deserialize, Serialize}; use tauri::{ plugin::{Builder, TauriPlugin}, - AppHandle, FsScope, FsScopeEvent, Manager, Runtime, + FsScope, FsScopeEvent, Manager, Runtime, }; use tauri_plugin_fs::{FsExt, ScopeEvent as FsScopeEvent}; @@ -25,7 +25,10 @@ use std::{ path::Path, }; +// Using 2 separate files so that we don't have to think about write conflicts and not break backwards compat. const SCOPE_STATE_FILENAME: &str = ".persisted-scope"; +#[cfg(feature = "protocol-asset")] +const ASSET_SCOPE_STATE_FILENAME: &str = ".persisted-scope-asset"; // Most of these patterns are just added to try to fix broken files in the wild. // After a while we can hopefully reduce it to something like [r"[?]", r"[*]", r"\\?\\\?\"] @@ -136,29 +139,27 @@ fn forbid_path(scope: &FsScope, path: &str) { } } -fn save_scopes(app: &AppHandle, app_dir: &Path, scope_state_path: &Path) { - if let Some(fs_scope) = app.try_fs_scope() { - let scope = Scope { - allowed_paths: fs_scope - .allowed_patterns() - .into_iter() - .map(|p| p.to_string()) - .collect(), - forbidden_patterns: fs_scope - .forbidden_patterns() - .into_iter() - .map(|p| p.to_string()) - .collect(), - }; - - let _ = create_dir_all(app_dir) - .and_then(|_| File::create(scope_state_path)) - .map_err(Error::Io) - .and_then(|mut f| { - f.write_all(&bincode::serialize(&scope).map_err(Error::from)?) - .map_err(Into::into) - }); - } +fn save_scopes(scope: &FsScope, app_dir: &Path, scope_state_path: &Path) { + let scope = Scope { + allowed_paths: scope + .allowed_patterns() + .into_iter() + .map(|p| p.to_string()) + .collect(), + forbidden_patterns: scope + .forbidden_patterns() + .into_iter() + .map(|p| p.to_string()) + .collect(), + }; + + let _ = create_dir_all(app_dir) + .and_then(|_| File::create(scope_state_path)) + .map_err(Error::Io) + .and_then(|mut f| { + f.write_all(&bincode::serialize(&scope).map_err(Error::from)?) + .map_err(Into::into) + }); } pub fn init() -> TauriPlugin { @@ -169,20 +170,21 @@ pub fn init() -> TauriPlugin { let app = app.clone(); let app_dir = app.path().app_data_dir(); - if let Ok(app_dir) = app_dir { - let scope_state_path = app_dir.join(SCOPE_STATE_FILENAME); + if let Some(app_dir) = app_dir { + let fs_scope_state_path = app_dir.join(SCOPE_STATE_FILENAME); + #[cfg(feature = "protocol-asset")] + let asset_scope_state_path = app_dir.join(ASSET_SCOPE_STATE_FILENAME); - if let Some(s) = fs_scope { - let _ = s.forbid_file(&scope_state_path); - } - let _ = core_scopes.forbid_file(&scope_state_path); + let _ = fs_scope.forbid_file(&fs_scope_state_path); + #[cfg(feature = "protocol-asset")] + let _ = asset_protocol_scope.forbid_file(&asset_scope_state_path); // We're trying to fix broken .persisted-scope files seamlessly, so we'll be running this on the values read on the saved file. // We will still save some semi-broken values because the scope events are quite spammy and we don't want to reduce runtime performance any further. let ac = AhoCorasick::new(PATTERNS).unwrap(/* This should be impossible to fail since we're using a small static input */); - if scope_state_path.exists() { - let scope: Scope = tauri::api::file::read_binary(&scope_state_path) + if fs_scope_state_path.exists() { + let scope: Scope = tauri::api::file::read_binary(&fs_scope_state_path) .map_err(Error::from) .and_then(|scope| bincode::deserialize(&scope).map_err(Into::into)) .unwrap_or_default(); @@ -190,28 +192,53 @@ pub fn init() -> TauriPlugin { for allowed in &scope.allowed_paths { let allowed = fix_pattern(&ac, allowed); allow_path(&fs_scope, &allowed); - #[cfg(feature = "protocol-asset")] - allow_path(&asset_protocol_scope, &allowed); } for forbidden in &scope.forbidden_patterns { let forbidden = fix_pattern(&ac, forbidden); forbid_path(&fs_scope, &forbidden); - #[cfg(feature = "protocol-asset")] - forbid_path(&asset_protocol_scope, &forbidden); } // Manually save the fixed scopes to disk once. // This is needed to fix broken .peristed-scope files in case the app doesn't update the scope itself. - save_scopes(&app, &app_dir, &scope_state_path); + save_scopes(&fs_scope, &app_dir, &fs_scope_state_path); } - if let Some(s) = fs_scope { - s.listen(move |event| { - if let FsScopeEvent::PathAllowed(_) = event { - save_scopes(&app, &app_dir, &scope_state_path); - } - }); + #[cfg(feature = "protocol-asset")] + if asset_scope_state_path.exists() { + let scope: Scope = tauri::api::file::read_binary(&asset_scope_state_path) + .map_err(Error::from) + .and_then(|scope| bincode::deserialize(&scope).map_err(Into::into)) + .unwrap_or_default(); + + for allowed in &scope.allowed_paths { + let allowed = fix_pattern(&ac, allowed); + allow_path(&asset_protocol_scope, &allowed); + } + for forbidden in &scope.forbidden_patterns { + let forbidden = fix_pattern(&ac, forbidden); + forbid_path(&asset_protocol_scope, &forbidden); + } + + // Manually save the fixed scopes to disk once. + save_scopes(&asset_protocol_scope, &app_dir, &asset_scope_state_path); } + + #[cfg(feature = "protocol-asset")] + let app_dir_ = app_dir.clone(); + let fs_scope_ = fs_scope.clone(); + fs_scope.listen(move |event| { + if let FsScopeEvent::PathAllowed(_) = event { + save_scopes(&fs_scope_, &app_dir, &fs_scope_state_path); + } + }); + #[cfg(feature = "protocol-asset")] + { + let asset_protocol_scope_ = asset_protocol_scope.clone(); + asset_protocol_scope.listen(move |event| { + if let FsScopeEvent::PathAllowed(_) = event { + save_scopes(&asset_protocol_scope_, &app_dir_, &asset_scope_state_path); + } + });} } Ok(()) })