summaryrefslogtreecommitdiff
path: root/runtime/permissions
diff options
context:
space:
mode:
authorLuca Casonato <hello@lcas.dev>2023-04-12 15:13:32 +0200
committerGitHub <noreply@github.com>2023-04-12 15:13:32 +0200
commitf90caa821c5a4acf28f7dec4071994ecf6f26e57 (patch)
treefa4af65399a16a9f2d17fa2b249f21be2c00b976 /runtime/permissions
parent0e3f62d4446ae7b9a64dacf7befcaecede118222 (diff)
refactor(ext/fs): abstract FS via FileSystem trait (#18599)
This commit abstracts out the specifics of the underlying system calls FS operations behind a new `FileSystem` and `File` trait in the `ext/fs` extension. This allows other embedders to re-use ext/fs, but substituting in a different FS backend. This is likely not the final form of these traits. Eventually they will be entirely `deno_core::Resource` agnostic, and will live in a seperate crate. --------- Co-authored-by: Bartek IwaƄczuk <biwanczuk@gmail.com>
Diffstat (limited to 'runtime/permissions')
-rw-r--r--runtime/permissions/mod.rs53
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))
}