mirror of
https://github.com/denoland/deno.git
synced 2025-09-26 12:19:12 +00:00
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
This commit is contained in:
parent
53606de634
commit
a0ddf73058
2 changed files with 29 additions and 4 deletions
|
@ -3,6 +3,7 @@
|
||||||
// TODO(petamoriken): enable prefer-primordials for node polyfills
|
// TODO(petamoriken): enable prefer-primordials for node polyfills
|
||||||
// deno-lint-ignore-file prefer-primordials
|
// deno-lint-ignore-file prefer-primordials
|
||||||
|
|
||||||
|
import { denoErrorToNodeError } from "ext:deno_node/internal/errors.ts";
|
||||||
import {
|
import {
|
||||||
BigIntStats,
|
BigIntStats,
|
||||||
CFISBIS,
|
CFISBIS,
|
||||||
|
@ -56,16 +57,31 @@ export const lstatPromise = promisify(lstat) as (
|
||||||
export function lstatSync(path: string | URL): Stats;
|
export function lstatSync(path: string | URL): Stats;
|
||||||
export function lstatSync(
|
export function lstatSync(
|
||||||
path: string | URL,
|
path: string | URL,
|
||||||
options: { bigint: false },
|
options: { bigint: false; throwIfNoEntry?: boolean },
|
||||||
): Stats;
|
): Stats;
|
||||||
export function lstatSync(
|
export function lstatSync(
|
||||||
path: string | URL,
|
path: string | URL,
|
||||||
options: { bigint: true },
|
options: { bigint: true; throwIfNoEntry?: boolean },
|
||||||
): BigIntStats;
|
): BigIntStats;
|
||||||
export function lstatSync(
|
export function lstatSync(
|
||||||
path: string | URL,
|
path: string | URL,
|
||||||
options?: statOptions,
|
options?: statOptions,
|
||||||
): Stats | BigIntStats {
|
): Stats | BigIntStats {
|
||||||
const origin = Deno.lstatSync(path);
|
try {
|
||||||
return CFISBIS(origin, options?.bigint || false);
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,6 +7,7 @@ import {
|
||||||
constants,
|
constants,
|
||||||
createWriteStream,
|
createWriteStream,
|
||||||
existsSync,
|
existsSync,
|
||||||
|
lstatSync,
|
||||||
mkdtempSync,
|
mkdtempSync,
|
||||||
promises,
|
promises,
|
||||||
readFileSync,
|
readFileSync,
|
||||||
|
@ -156,3 +157,11 @@ Deno.test("[node/fs createWriteStream", async () => {
|
||||||
await Deno.remove(tempDir, { recursive: true });
|
await Deno.remove(tempDir, { recursive: true });
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Deno.test(
|
||||||
|
"[node/fs lstatSync] supports throwIfNoEntry option",
|
||||||
|
() => {
|
||||||
|
const result = lstatSync("non-existing-path", { throwIfNoEntry: false });
|
||||||
|
assertEquals(result, undefined);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue