diff options
Diffstat (limited to 'runtime/permissions/mod.rs')
-rw-r--r-- | runtime/permissions/mod.rs | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/runtime/permissions/mod.rs b/runtime/permissions/mod.rs index 7e1772ee3..b15750313 100644 --- a/runtime/permissions/mod.rs +++ b/runtime/permissions/mod.rs @@ -667,6 +667,40 @@ impl UnaryPermission<WriteDescriptor> { } result } + + /// As `check()`, but permission error messages will anonymize the path + /// by replacing it with the given `display`. + pub fn check_blind( + &mut self, + path: &Path, + display: &str, + api_name: &str, + ) -> Result<(), AnyError> { + let resolved_path = resolve_from_cwd(path)?; + let (result, prompted, is_allow_all) = + self.query(Some(&resolved_path)).check( + self.name, + Some(api_name), + Some(&format!("<{display}>")), + self.prompt, + ); + if prompted { + if result.is_ok() { + if is_allow_all { + self.granted_list.clear(); + self.global_state = PermissionState::Granted; + } else { + self.granted_list.insert(WriteDescriptor(resolved_path)); + } + } else { + self.global_state = PermissionState::Denied; + if !is_allow_all { + self.denied_list.insert(WriteDescriptor(resolved_path)); + } + } + } + result + } } impl Default for UnaryPermission<WriteDescriptor> { @@ -1793,6 +1827,16 @@ impl PermissionsContainer { } #[inline(always)] + pub fn check_write_blind( + &mut self, + path: &Path, + display: &str, + api_name: &str, + ) -> Result<(), AnyError> { + self.0.lock().write.check_blind(path, display, api_name) + } + + #[inline(always)] pub fn check_run( &mut self, cmd: &str, @@ -1931,6 +1975,15 @@ impl deno_fs::FsPermissions for PermissionsContainer { self.0.lock().write.check(path, Some(api_name)) } + fn check_write_blind( + &mut self, + p: &Path, + display: &str, + api_name: &str, + ) -> Result<(), AnyError> { + self.0.lock().write.check_blind(p, display, api_name) + } + fn check_read_all(&mut self, api_name: &str) -> Result<(), AnyError> { self.0.lock().read.check_all(Some(api_name)) } |