summaryrefslogtreecommitdiff
path: root/ext/fs/in_memory_fs.rs
diff options
context:
space:
mode:
authorMatt Mastracci <matthew@mastracci.com>2024-04-19 18:12:03 -0600
committerGitHub <noreply@github.com>2024-04-19 18:12:03 -0600
commit472a37064071c66cd1311cdea2e78de8d2bc0641 (patch)
tree94459f249eee0429480e2cea6ac37319e27de41d /ext/fs/in_memory_fs.rs
parent365e1f48f7059f94d4eeb8f5ba8b3949b686b355 (diff)
feat(runtime): Allow embedders to perform additional access checks on file open (#23208)
Embedders may have special requirements around file opening, so we add a new `check_open` permission check that is called as part of the file open process.
Diffstat (limited to 'ext/fs/in_memory_fs.rs')
-rw-r--r--ext/fs/in_memory_fs.rs32
1 files changed, 23 insertions, 9 deletions
diff --git a/ext/fs/in_memory_fs.rs b/ext/fs/in_memory_fs.rs
index fdd0ad7e7..153327ff6 100644
--- a/ext/fs/in_memory_fs.rs
+++ b/ext/fs/in_memory_fs.rs
@@ -19,6 +19,7 @@ use deno_io::fs::FsError;
use deno_io::fs::FsResult;
use deno_io::fs::FsStat;
+use crate::interface::AccessCheckCb;
use crate::interface::FsDirEntry;
use crate::interface::FsFileType;
use crate::FileSystem;
@@ -48,6 +49,7 @@ impl InMemoryFs {
.write_file_sync(
&path,
OpenOptions::write(true, false, false, None),
+ None,
&text.into_bytes(),
)
.unwrap();
@@ -82,15 +84,17 @@ impl FileSystem for InMemoryFs {
&self,
_path: &Path,
_options: OpenOptions,
+ _access_check: Option<AccessCheckCb>,
) -> FsResult<Rc<dyn File>> {
Err(FsError::NotSupported)
}
- async fn open_async(
- &self,
+ async fn open_async<'a>(
+ &'a self,
path: PathBuf,
options: OpenOptions,
+ access_check: Option<AccessCheckCb<'a>>,
) -> FsResult<Rc<dyn File>> {
- self.open_sync(&path, options)
+ self.open_sync(&path, options, access_check)
}
fn mkdir_sync(
@@ -350,6 +354,7 @@ impl FileSystem for InMemoryFs {
&self,
path: &Path,
options: OpenOptions,
+ _access_check: Option<AccessCheckCb>,
data: &[u8],
) -> FsResult<()> {
let path = normalize_path(path);
@@ -397,16 +402,21 @@ impl FileSystem for InMemoryFs {
}
}
- async fn write_file_async(
- &self,
+ async fn write_file_async<'a>(
+ &'a self,
path: PathBuf,
options: OpenOptions,
+ access_check: Option<AccessCheckCb<'a>>,
data: Vec<u8>,
) -> FsResult<()> {
- self.write_file_sync(&path, options, &data)
+ self.write_file_sync(&path, options, access_check, &data)
}
- fn read_file_sync(&self, path: &Path) -> FsResult<Vec<u8>> {
+ fn read_file_sync(
+ &self,
+ path: &Path,
+ _access_check: Option<AccessCheckCb>,
+ ) -> FsResult<Vec<u8>> {
let entry = self.get_entry(path);
match entry {
Some(entry) => match &*entry {
@@ -419,7 +429,11 @@ impl FileSystem for InMemoryFs {
None => Err(FsError::Io(Error::new(ErrorKind::NotFound, "Not found"))),
}
}
- async fn read_file_async(&self, path: PathBuf) -> FsResult<Vec<u8>> {
- self.read_file_sync(&path)
+ async fn read_file_async<'a>(
+ &'a self,
+ path: PathBuf,
+ access_check: Option<AccessCheckCb<'a>>,
+ ) -> FsResult<Vec<u8>> {
+ self.read_file_sync(&path, access_check)
}
}