2023-01-02 16:00:42 -05:00
|
|
|
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
|
2023-03-07 04:13:44 -05:00
|
|
|
|
2023-04-12 09:13:32 -04:00
|
|
|
mod interface;
|
|
|
|
mod ops;
|
|
|
|
mod std_fs;
|
|
|
|
|
|
|
|
pub use crate::interface::File;
|
|
|
|
pub use crate::interface::FileSystem;
|
|
|
|
pub use crate::interface::FsDirEntry;
|
|
|
|
pub use crate::interface::FsError;
|
|
|
|
pub use crate::interface::FsFileType;
|
|
|
|
pub use crate::interface::FsPermissions;
|
|
|
|
pub use crate::interface::FsResult;
|
|
|
|
pub use crate::interface::FsStat;
|
|
|
|
pub use crate::interface::OpenOptions;
|
|
|
|
use crate::ops::*;
|
|
|
|
|
|
|
|
pub use crate::std_fs::StdFs;
|
|
|
|
|
2020-09-10 09:57:45 -04:00
|
|
|
use deno_core::OpState;
|
|
|
|
use std::cell::RefCell;
|
2019-08-14 11:03:02 -04:00
|
|
|
use std::convert::From;
|
2020-08-18 08:07:57 -04:00
|
|
|
use std::rc::Rc;
|
2023-03-07 04:13:44 -05:00
|
|
|
|
|
|
|
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.
|
2023-04-12 09:13:32 -04:00
|
|
|
pub(crate) fn check_unstable(state: &OpState, api_name: &str) {
|
2023-03-07 04:13:44 -05:00
|
|
|
state.borrow::<UnstableChecker>().check_unstable(api_name)
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Helper for checking unstable features. Used for async ops.
|
2023-04-12 09:13:32 -04:00
|
|
|
pub(crate) fn check_unstable2(state: &Rc<RefCell<OpState>>, api_name: &str) {
|
2023-03-07 04:13:44 -05:00
|
|
|
let state = state.borrow();
|
|
|
|
state.borrow::<UnstableChecker>().check_unstable(api_name)
|
|
|
|
}
|
|
|
|
|
2023-03-17 14:22:15 -04:00
|
|
|
deno_core::extension!(deno_fs,
|
2023-04-12 09:13:32 -04:00
|
|
|
deps = [ deno_web ],
|
|
|
|
parameters = [Fs: FileSystem, P: FsPermissions],
|
2023-03-17 14:22:15 -04:00
|
|
|
ops = [
|
2023-04-12 09:13:32 -04:00
|
|
|
op_cwd<Fs, P>,
|
|
|
|
op_umask<Fs>,
|
|
|
|
op_chdir<Fs, P>,
|
|
|
|
|
|
|
|
op_open_sync<Fs, P>,
|
|
|
|
op_open_async<Fs, P>,
|
|
|
|
op_mkdir_sync<Fs, P>,
|
|
|
|
op_mkdir_async<Fs, P>,
|
|
|
|
op_chmod_sync<Fs, P>,
|
|
|
|
op_chmod_async<Fs, P>,
|
|
|
|
op_chown_sync<Fs, P>,
|
|
|
|
op_chown_async<Fs, P>,
|
|
|
|
op_remove_sync<Fs, P>,
|
|
|
|
op_remove_async<Fs, P>,
|
|
|
|
op_copy_file_sync<Fs, P>,
|
|
|
|
op_copy_file_async<Fs, P>,
|
|
|
|
op_stat_sync<Fs, P>,
|
|
|
|
op_stat_async<Fs, P>,
|
|
|
|
op_lstat_sync<Fs, P>,
|
|
|
|
op_lstat_async<Fs, P>,
|
|
|
|
op_realpath_sync<Fs, P>,
|
|
|
|
op_realpath_async<Fs, P>,
|
|
|
|
op_read_dir_sync<Fs, P>,
|
|
|
|
op_read_dir_async<Fs, P>,
|
|
|
|
op_rename_sync<Fs, P>,
|
|
|
|
op_rename_async<Fs, P>,
|
|
|
|
op_link_sync<Fs, P>,
|
|
|
|
op_link_async<Fs, P>,
|
|
|
|
op_symlink_sync<Fs, P>,
|
|
|
|
op_symlink_async<Fs, P>,
|
|
|
|
op_read_link_sync<Fs, P>,
|
|
|
|
op_read_link_async<Fs, P>,
|
|
|
|
op_truncate_sync<Fs, P>,
|
|
|
|
op_truncate_async<Fs, P>,
|
|
|
|
op_utime_sync<Fs, P>,
|
|
|
|
op_utime_async<Fs, P>,
|
|
|
|
op_make_temp_dir_sync<Fs, P>,
|
|
|
|
op_make_temp_dir_async<Fs, P>,
|
|
|
|
op_make_temp_file_sync<Fs, P>,
|
|
|
|
op_make_temp_file_async<Fs, P>,
|
|
|
|
op_write_file_sync<Fs, P>,
|
|
|
|
op_write_file_async<Fs, P>,
|
|
|
|
op_read_file_sync<Fs, P>,
|
|
|
|
op_read_file_async<Fs, P>,
|
|
|
|
op_read_file_text_sync<Fs, P>,
|
|
|
|
op_read_file_text_async<Fs, P>,
|
|
|
|
|
|
|
|
op_seek_sync<Fs>,
|
|
|
|
op_seek_async<Fs>,
|
|
|
|
op_fdatasync_sync<Fs>,
|
|
|
|
op_fdatasync_async<Fs>,
|
|
|
|
op_fsync_sync<Fs>,
|
|
|
|
op_fsync_async<Fs>,
|
|
|
|
op_fstat_sync<Fs>,
|
|
|
|
op_fstat_async<Fs>,
|
|
|
|
op_flock_sync<Fs>,
|
|
|
|
op_flock_async<Fs>,
|
|
|
|
op_funlock_sync<Fs>,
|
|
|
|
op_funlock_async<Fs>,
|
|
|
|
op_ftruncate_sync<Fs>,
|
|
|
|
op_ftruncate_async<Fs>,
|
|
|
|
op_futime_sync<Fs>,
|
|
|
|
op_futime_async<Fs>,
|
|
|
|
|
2023-03-17 14:22:15 -04:00
|
|
|
],
|
|
|
|
esm = [ "30_fs.js" ],
|
2023-03-17 18:15:27 -04:00
|
|
|
options = {
|
2023-04-12 09:13:32 -04:00
|
|
|
unstable: bool,
|
|
|
|
fs: Fs,
|
2023-03-17 14:22:15 -04:00
|
|
|
},
|
2023-03-17 18:15:27 -04:00
|
|
|
state = |state, options| {
|
|
|
|
state.put(UnstableChecker { unstable: options.unstable });
|
2023-04-12 09:13:32 -04:00
|
|
|
state.put(options.fs);
|
2023-03-17 14:22:15 -04:00
|
|
|
},
|
|
|
|
);
|