mirror of
https://github.com/denoland/deno.git
synced 2025-08-03 10:33:54 +00:00
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>
This commit is contained in:
parent
0e3f62d444
commit
f90caa821c
15 changed files with 3350 additions and 2488 deletions
|
@ -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> {
|
||||
|
@ -1792,6 +1826,16 @@ impl PermissionsContainer {
|
|||
self.0.lock().write.check_all(Some(api_name))
|
||||
}
|
||||
|
||||
#[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,
|
||||
|
@ -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))
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue