From a6c47ee74023f6ef683988cabc8caa95406e3c99 Mon Sep 17 00:00:00 2001 From: David Sherret Date: Fri, 5 May 2023 12:44:24 -0400 Subject: refactor(ext/node): combine `deno_node::Fs` with `deno_fs::FileSystem` (#18991) --- ext/node/ops/require.rs | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) (limited to 'ext/node/ops') diff --git a/ext/node/ops/require.rs b/ext/node/ops/require.rs index 4a2b97187..972815995 100644 --- a/ext/node/ops/require.rs +++ b/ext/node/ops/require.rs @@ -16,7 +16,6 @@ use std::rc::Rc; use std::sync::Arc; use crate::resolution; -use crate::NodeFs; use crate::NodeModuleKind; use crate::NodePermissions; use crate::NodeResolutionMode; @@ -94,11 +93,11 @@ pub fn op_require_node_module_paths

( where P: NodePermissions + 'static, { - let fs = state.borrow::>(); + let fs = state.borrow::>(); // Guarantee that "from" is absolute. let from = deno_core::resolve_path( &from, - &(fs.current_dir()).context("Unable to get CWD")?, + &(fs.cwd().map_err(AnyError::from)).context("Unable to get CWD")?, ) .unwrap() .to_file_path() @@ -263,8 +262,8 @@ where { let path = PathBuf::from(path); ensure_read_permission::

(state, &path)?; - let fs = state.borrow::>(); - if let Ok(metadata) = fs.metadata(&path) { + let fs = state.borrow::>(); + if let Ok(metadata) = fs.stat_sync(&path) { if metadata.is_file { return Ok(0); } else { @@ -285,8 +284,9 @@ where { let path = PathBuf::from(request); ensure_read_permission::

(state, &path)?; - let fs = state.borrow::>(); - let canonicalized_path = deno_core::strip_unc_prefix(fs.canonicalize(&path)?); + let fs = state.borrow::>(); + let canonicalized_path = + deno_core::strip_unc_prefix(fs.realpath_sync(&path)?); Ok(canonicalized_path.to_string_lossy().to_string()) } @@ -346,8 +346,8 @@ where if let Some(parent_id) = maybe_parent_id { if parent_id == "" || parent_id == "internal/preload" { - let fs = state.borrow::>(); - if let Ok(cwd) = fs.current_dir() { + let fs = state.borrow::>(); + if let Ok(cwd) = fs.cwd() { ensure_read_permission::

(state, &cwd)?; return Ok(Some(cwd.to_string_lossy().to_string())); } @@ -429,7 +429,7 @@ where { let file_path = PathBuf::from(file_path); ensure_read_permission::

(state, &file_path)?; - let fs = state.borrow::>(); + let fs = state.borrow::>(); Ok(fs.read_to_string(&file_path)?) } @@ -457,7 +457,7 @@ fn op_require_resolve_exports

( where P: NodePermissions + 'static, { - let fs = state.borrow::>(); + let fs = state.borrow::>(); let npm_resolver = state.borrow::>(); let node_resolver = state.borrow::>(); let permissions = state.borrow::

(); -- cgit v1.2.3