diff options
author | Bartek IwaĆczuk <biwanczuk@gmail.com> | 2023-01-07 17:25:34 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-01-07 17:25:34 +0100 |
commit | fac64478157ee563b185edb5734688e4523df3a1 (patch) | |
tree | 888d562982e1fc37dfb9a4459928bcec84d55dfc /runtime/ops/permissions.rs | |
parent | 82e930726ee5dbac8e6eae0962c07c72daf9843c (diff) |
refactor(permissions): add PermissionsContainer struct for internal mutability (#17134)
Turns out we were cloning permissions which after prompting were discarded,
so the state of permissions was never preserved. To handle that we need to store
all permissions behind "Arc<Mutex<>>" (because there are situations where we
need to send them to other thread).
Testing and benching code still uses "Permissions" in most places - it's undesirable
to share the same permission set between various test/bench files - otherwise
granting or revoking permissions in one file would influence behavior of other test
files.
Diffstat (limited to 'runtime/ops/permissions.rs')
-rw-r--r-- | runtime/ops/permissions.rs | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/runtime/ops/permissions.rs b/runtime/ops/permissions.rs index 8a2244676..d0b0cdd8b 100644 --- a/runtime/ops/permissions.rs +++ b/runtime/ops/permissions.rs @@ -1,7 +1,7 @@ // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. use crate::permissions::parse_sys_kind; -use crate::permissions::Permissions; +use crate::permissions::PermissionsContainer; use deno_core::error::custom_error; use deno_core::error::uri_error; use deno_core::error::AnyError; @@ -37,7 +37,7 @@ pub fn op_query_permission( state: &mut OpState, args: PermissionArgs, ) -> Result<String, AnyError> { - let permissions = state.borrow::<Permissions>(); + let permissions = state.borrow::<PermissionsContainer>().0.lock(); let path = args.path.as_deref(); let perm = match args.name.as_ref() { "read" => permissions.read.query(path.map(Path::new)), @@ -71,7 +71,7 @@ pub fn op_revoke_permission( state: &mut OpState, args: PermissionArgs, ) -> Result<String, AnyError> { - let permissions = state.borrow_mut::<Permissions>(); + let mut permissions = state.borrow_mut::<PermissionsContainer>().0.lock(); let path = args.path.as_deref(); let perm = match args.name.as_ref() { "read" => permissions.read.revoke(path.map(Path::new)), @@ -105,7 +105,7 @@ pub fn op_request_permission( state: &mut OpState, args: PermissionArgs, ) -> Result<String, AnyError> { - let permissions = state.borrow_mut::<Permissions>(); + let mut permissions = state.borrow_mut::<PermissionsContainer>().0.lock(); let path = args.path.as_deref(); let perm = match args.name.as_ref() { "read" => permissions.read.request(path.map(Path::new)), |