Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

perf(node/fs): faster existsSync when not exists #21458

Merged
merged 7 commits into from
Dec 4, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Self review
  • Loading branch information
dsherret committed Dec 4, 2023
commit 0d38cb826891b72a66134e34b989472251558db7
8 changes: 4 additions & 4 deletions cli/tests/unit_node/fs_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,15 @@ Deno.test(
Deno.test(
"[node/fs existsSync] path",
{ permissions: { read: true } },
function () {
() => {
assert(existsSync("cli/tests/testdata/assets/fixture.json"));
},
);

Deno.test(
"[node/fs existsSync] url",
{ permissions: { read: true } },
function () {
() => {
assert(existsSync(
pathToAbsoluteFileUrl("cli/tests/testdata/assets/fixture.json"),
));
Expand All @@ -66,7 +66,7 @@ Deno.test(
Deno.test(
"[node/fs existsSync] no permission",
{ permissions: { read: false } },
function () {
() => {
assertThrows(() => {
existsSync("cli/tests/testdata/assets/fixture.json");
}, Deno.errors.PermissionDenied);
Expand All @@ -76,7 +76,7 @@ Deno.test(
Deno.test(
"[node/fs existsSync] not exists",
{ permissions: { read: true } },
function () {
() => {
assert(!existsSync("bad_filename"));
},
);
6 changes: 3 additions & 3 deletions ext/node/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,9 @@ pub trait NodePermissions {
api_name: &str,
) -> Result<(), AnyError>;
fn check_read(&self, path: &Path) -> Result<(), AnyError> {
self.check_read_api(path, None)
self.check_read_with_api_name(path, None)
}
fn check_read_api(
fn check_read_with_api_name(
&self,
path: &Path,
api_name: Option<&str>,
Expand All @@ -71,7 +71,7 @@ impl NodePermissions for AllowAllNodePermissions {
) -> Result<(), AnyError> {
Ok(())
}
fn check_read_api(
fn check_read_with_api_name(
&self,
_path: &Path,
_api_name: Option<&str>,
Expand Down
2 changes: 1 addition & 1 deletion ext/node/ops/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ where
let path = PathBuf::from(path);
state
.borrow_mut::<P>()
.check_read_api(&path, Some("node:fs.existsSync()"))?;
.check_read_with_api_name(&path, Some("node:fs.existsSync()"))?;
let fs = state.borrow::<FileSystemRc>();
Ok(fs.lstat_sync(&path).is_ok())
}
2 changes: 1 addition & 1 deletion runtime/permissions/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1376,7 +1376,7 @@ impl deno_node::NodePermissions for PermissionsContainer {
}

#[inline(always)]
fn check_read_api(
fn check_read_with_api_name(
&self,
path: &Path,
api_name: Option<&str>,
Expand Down
2 changes: 1 addition & 1 deletion runtime/snapshot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ impl deno_node::NodePermissions for Permissions {
) -> Result<(), deno_core::error::AnyError> {
unreachable!("snapshotting!")
}
fn check_read_api(
fn check_read_with_api_name(
&self,
_p: &Path,
_api_name: Option<&str>,
Expand Down