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:
Luca Casonato 2023-04-12 15:13:32 +02:00 committed by GitHub
parent 0e3f62d444
commit f90caa821c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
15 changed files with 3350 additions and 2488 deletions

View file

@ -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))
}