summaryrefslogtreecommitdiff
path: root/ext/node/polyfills/_fs
diff options
context:
space:
mode:
authorMarvin Hagemeister <marvin@deno.com>2024-05-28 12:24:54 +0200
committerGitHub <noreply@github.com>2024-05-28 12:24:54 +0200
commita0ddf7305895e2920ef5d9208fc9ec767ebb11d5 (patch)
tree691145ccdb10118be3e2ce9cf2f42a4988dc7133 /ext/node/polyfills/_fs
parent53606de6344fca63c40fde37056910b72a3c4f8d (diff)
fix(ext/node): add `throwIfNoEntry` option in `fs.lstatSync` (#24006)
We didn't support the `throwIfNoEntry` option for Node's `fs.lstatSync` method. Note that the async variant doesn't have this option. Fixes https://github.com/denoland/deno/issues/23996
Diffstat (limited to 'ext/node/polyfills/_fs')
-rw-r--r--ext/node/polyfills/_fs/_fs_lstat.ts24
1 files changed, 20 insertions, 4 deletions
diff --git a/ext/node/polyfills/_fs/_fs_lstat.ts b/ext/node/polyfills/_fs/_fs_lstat.ts
index c8cdfc4e4..6ce401444 100644
--- a/ext/node/polyfills/_fs/_fs_lstat.ts
+++ b/ext/node/polyfills/_fs/_fs_lstat.ts
@@ -3,6 +3,7 @@
// TODO(petamoriken): enable prefer-primordials for node polyfills
// deno-lint-ignore-file prefer-primordials
+import { denoErrorToNodeError } from "ext:deno_node/internal/errors.ts";
import {
BigIntStats,
CFISBIS,
@@ -56,16 +57,31 @@ export const lstatPromise = promisify(lstat) as (
export function lstatSync(path: string | URL): Stats;
export function lstatSync(
path: string | URL,
- options: { bigint: false },
+ options: { bigint: false; throwIfNoEntry?: boolean },
): Stats;
export function lstatSync(
path: string | URL,
- options: { bigint: true },
+ options: { bigint: true; throwIfNoEntry?: boolean },
): BigIntStats;
export function lstatSync(
path: string | URL,
options?: statOptions,
): Stats | BigIntStats {
- const origin = Deno.lstatSync(path);
- return CFISBIS(origin, options?.bigint || false);
+ try {
+ const origin = Deno.lstatSync(path);
+ return CFISBIS(origin, options?.bigint || false);
+ } catch (err) {
+ if (
+ options?.throwIfNoEntry === false &&
+ err instanceof Deno.errors.NotFound
+ ) {
+ return;
+ }
+
+ if (err instanceof Error) {
+ throw denoErrorToNodeError(err, { syscall: "stat" });
+ } else {
+ throw err;
+ }
+ }
}