diff options
Diffstat (limited to 'ext/fs')
-rw-r--r-- | ext/fs/lib.rs | 32 | ||||
-rw-r--r-- | ext/fs/ops.rs | 5 |
2 files changed, 6 insertions, 31 deletions
diff --git a/ext/fs/lib.rs b/ext/fs/lib.rs index b028b12c1..ab19540b5 100644 --- a/ext/fs/lib.rs +++ b/ext/fs/lib.rs @@ -18,9 +18,7 @@ use crate::ops::*; use deno_core::error::AnyError; use deno_core::OpState; -use std::cell::RefCell; use std::path::Path; -use std::rc::Rc; pub trait FsPermissions { fn check_read(&mut self, path: &Path, api_name: &str) @@ -66,31 +64,11 @@ pub trait FsPermissions { } } -struct UnstableChecker { - pub unstable: bool, -} - -impl UnstableChecker { - // NOTE(bartlomieju): keep in sync with `cli/program_state.rs` - pub fn check_unstable(&self, api_name: &str) { - if !self.unstable { - eprintln!( - "Unstable API '{api_name}'. The --unstable flag must be provided." - ); - std::process::exit(70); - } - } -} - /// Helper for checking unstable features. Used for sync ops. -pub(crate) fn check_unstable(state: &OpState, api_name: &str) { - state.borrow::<UnstableChecker>().check_unstable(api_name) -} - -/// Helper for checking unstable features. Used for async ops. -pub(crate) fn check_unstable2(state: &Rc<RefCell<OpState>>, api_name: &str) { - let state = state.borrow(); - state.borrow::<UnstableChecker>().check_unstable(api_name) +fn check_unstable(state: &OpState, api_name: &str) { + state + .feature_checker + .check_legacy_unstable_or_exit(api_name); } deno_core::extension!(deno_fs, @@ -164,11 +142,9 @@ deno_core::extension!(deno_fs, ], esm = [ "30_fs.js" ], options = { - unstable: bool, fs: FileSystemRc, }, state = |state, options| { - state.put(UnstableChecker { unstable: options.unstable }); state.put(options.fs); }, ); diff --git a/ext/fs/ops.rs b/ext/fs/ops.rs index bc09a4a25..9fa8cf918 100644 --- a/ext/fs/ops.rs +++ b/ext/fs/ops.rs @@ -27,7 +27,6 @@ use rand::Rng; use serde::Serialize; use crate::check_unstable; -use crate::check_unstable2; use crate::interface::FileSystemRc; use crate::interface::FsDirEntry; use crate::interface::FsFileType; @@ -1422,7 +1421,7 @@ pub async fn op_fs_flock_async( #[smi] rid: ResourceId, exclusive: bool, ) -> Result<(), AnyError> { - check_unstable2(&state, "Deno.flock"); + check_unstable(&state.borrow(), "Deno.flock"); let file = FileResource::get_file(&state.borrow(), rid)?; file.lock_async(exclusive).await?; Ok(()) @@ -1444,7 +1443,7 @@ pub async fn op_fs_funlock_async( state: Rc<RefCell<OpState>>, #[smi] rid: ResourceId, ) -> Result<(), AnyError> { - check_unstable2(&state, "Deno.funlock"); + check_unstable(&state.borrow(), "Deno.funlock"); let file = FileResource::get_file(&state.borrow(), rid)?; file.unlock_async().await?; Ok(()) |