1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-11-21 15:04:11 -05:00

fix(ext/node): properly map reparse point error in readlink (#26375)

This commit is contained in:
Nathan Whitaker 2024-10-18 10:11:06 -07:00 committed by GitHub
parent 85a99eb405
commit 1bccf45ecb
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 22 additions and 12 deletions

View file

@ -66,6 +66,7 @@ pub fn op_node_sys_to_uv_error(err: i32) -> String {
ERROR_INVALID_PARAMETER => "EINVAL", ERROR_INVALID_PARAMETER => "EINVAL",
WSAEINVAL => "EINVAL", WSAEINVAL => "EINVAL",
WSAEPFNOSUPPORT => "EINVAL", WSAEPFNOSUPPORT => "EINVAL",
ERROR_NOT_A_REPARSE_POINT => "EINVAL",
ERROR_BEGINNING_OF_MEDIA => "EIO", ERROR_BEGINNING_OF_MEDIA => "EIO",
ERROR_BUS_RESET => "EIO", ERROR_BUS_RESET => "EIO",
ERROR_CRC => "EIO", ERROR_CRC => "EIO",

View file

@ -4,13 +4,10 @@
// deno-lint-ignore-file prefer-primordials // deno-lint-ignore-file prefer-primordials
import { TextEncoder } from "ext:deno_web/08_text_encoding.js"; import { TextEncoder } from "ext:deno_web/08_text_encoding.js";
import { import { MaybeEmpty, notImplemented } from "ext:deno_node/_utils.ts";
intoCallbackAPIWithIntercept,
MaybeEmpty,
notImplemented,
} from "ext:deno_node/_utils.ts";
import { pathFromURL } from "ext:deno_web/00_infra.js"; import { pathFromURL } from "ext:deno_web/00_infra.js";
import { promisify } from "ext:deno_node/internal/util.mjs"; import { promisify } from "ext:deno_node/internal/util.mjs";
import { denoErrorToNodeError } from "ext:deno_node/internal/errors.ts";
type ReadlinkCallback = ( type ReadlinkCallback = (
err: MaybeEmpty<Error>, err: MaybeEmpty<Error>,
@ -69,12 +66,17 @@ export function readlink(
const encoding = getEncoding(optOrCallback); const encoding = getEncoding(optOrCallback);
intoCallbackAPIWithIntercept<string, Uint8Array | string>( Deno.readLink(path).then((data: string) => {
Deno.readLink, const res = maybeEncode(data, encoding);
(data: string): string | Uint8Array => maybeEncode(data, encoding), if (cb) cb(null, res);
cb, }, (err: Error) => {
path, if (cb) {
); (cb as (e: Error) => void)(denoErrorToNodeError(err, {
syscall: "readlink",
path,
}));
}
});
} }
export const readlinkPromise = promisify(readlink) as ( export const readlinkPromise = promisify(readlink) as (
@ -88,5 +90,12 @@ export function readlinkSync(
): string | Uint8Array { ): string | Uint8Array {
path = path instanceof URL ? pathFromURL(path) : path; path = path instanceof URL ? pathFromURL(path) : path;
return maybeEncode(Deno.readLinkSync(path), getEncoding(opt)); try {
return maybeEncode(Deno.readLinkSync(path), getEncoding(opt));
} catch (error) {
throw denoErrorToNodeError(error, {
syscall: "readlink",
path,
});
}
} }