diff options
| author | Nathan Whitaker <17734409+nathanwhit@users.noreply.github.com> | 2024-07-02 19:33:32 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-07-02 19:33:32 -0700 |
| commit | dadc606419096325ef0b03b6216ee20bef442045 (patch) | |
| tree | a09293a1f852d03d13a2b6eb9e4dfb3f552fb7a0 /ext/node/polyfills/_fs/_fs_utimes.ts | |
| parent | 3324d7203e8d00bb39cfae104e0aec61ba954e9b (diff) | |
fix(ext/node): Add `fs.lutimes` / `fs.lutimesSync` (#23172)
Part of #18218
- Adds `fs.lutimes` and `fs.lutimesSync` to our node polyfills. To do
this I added methods to the `FileSystem` trait + ops to expose the
functionality to JS.
- Exports `fs._toUnixTimestamp`. Node exposes an internal util
`toUnixTimestamp` from the fs module to be used by unit tests (so we
need it for the unit test to pass unmodified). It's weird because it's
only supposed to be used internally but it's still publicly accessible
- Matches up error handling and timestamp handling for fs.futimes and
fs.utimes with node
- Enables the node_compat utimes test - this exercises futimes, lutimes,
and utimes.
Diffstat (limited to 'ext/node/polyfills/_fs/_fs_utimes.ts')
| -rw-r--r-- | ext/node/polyfills/_fs/_fs_utimes.ts | 13 |
1 files changed, 8 insertions, 5 deletions
diff --git a/ext/node/polyfills/_fs/_fs_utimes.ts b/ext/node/polyfills/_fs/_fs_utimes.ts index 1d0e5c1ff..3fff4a462 100644 --- a/ext/node/polyfills/_fs/_fs_utimes.ts +++ b/ext/node/polyfills/_fs/_fs_utimes.ts @@ -4,13 +4,16 @@ // deno-lint-ignore-file prefer-primordials import type { CallbackWithError } from "ext:deno_node/_fs/_fs_common.ts"; -import { pathFromURL } from "ext:deno_web/00_infra.js"; import { promisify } from "ext:deno_node/internal/util.mjs"; +import { + getValidatedPath, + toUnixTimestamp, +} from "ext:deno_node/internal/fs/utils.mjs"; function getValidTime( time: number | string | Date, name: string, -): number | Date { +): number { if (typeof time === "string") { time = Number(time); } @@ -24,7 +27,7 @@ function getValidTime( ); } - return time; + return toUnixTimestamp(time); } export function utimes( @@ -33,7 +36,7 @@ export function utimes( mtime: number | string | Date, callback: CallbackWithError, ) { - path = path instanceof URL ? pathFromURL(path) : path; + path = getValidatedPath(path).toString(); if (!callback) { throw new Deno.errors.InvalidData("No callback function supplied"); @@ -56,7 +59,7 @@ export function utimesSync( atime: number | string | Date, mtime: number | string | Date, ) { - path = path instanceof URL ? pathFromURL(path) : path; + path = getValidatedPath(path).toString(); atime = getValidTime(atime, "atime"); mtime = getValidTime(mtime, "mtime"); |
