diff options
author | Asher Gomez <ashersaupingomez@gmail.com> | 2024-01-24 10:31:52 +1100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-01-24 00:31:52 +0100 |
commit | 2f47ec6c3a583c8323a06c386feeaee4fbf75edc (patch) | |
tree | 92511f544d3b8466fb84fa40f3e68163a4e97324 /ext | |
parent | 947ce41e99637dae4cf46126b8bb2d4107fb9913 (diff) |
feat: `Deno.FsFile.dataSync()` and `Deno.FsFile.dataSyncSync()` (#22019)
This change:
1. Implements `Deno.FsFile.dataSync()` and `Deno.FsFile.dataSyncSync()`.
2. Deprecates `Deno.fdatasync()` and `Deno.fdatasyncSync()` for removal
in Deno v2, in favour of the above corresponding methods.
3. Replaces use of `Deno.fdatasync()` and `Deno.fdatasyncSync()` with
the above instance methods.
Related #21995
Diffstat (limited to 'ext')
-rw-r--r-- | ext/fs/30_fs.js | 20 | ||||
-rw-r--r-- | ext/node/polyfills/_fs/_fs_fdatasync.ts | 5 |
2 files changed, 22 insertions, 3 deletions
diff --git a/ext/fs/30_fs.js b/ext/fs/30_fs.js index 277a1c73c..3c888f1f1 100644 --- a/ext/fs/30_fs.js +++ b/ext/fs/30_fs.js @@ -1,6 +1,6 @@ // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. -import { core, primordials } from "ext:core/mod.js"; +import { core, internals, primordials } from "ext:core/mod.js"; const { isDate, } = core; @@ -558,10 +558,20 @@ async function symlink( } function fdatasyncSync(rid) { + internals.warnOnDeprecatedApi( + "Deno.fdatasyncSync()", + new Error().stack, + "Use `file.dataSyncSync()` instead.", + ); op_fs_fdatasync_sync(rid); } async function fdatasync(rid) { + internals.warnOnDeprecatedApi( + "Deno.fdatasync()", + new Error().stack, + "Use `await file.dataSync()` instead.", + ); await op_fs_fdatasync_async(rid); } @@ -703,6 +713,14 @@ class FsFile { return fstatSync(this.rid); } + async dataSync() { + await op_fs_fdatasync_async(this.rid); + } + + dataSyncSync() { + op_fs_fdatasync_sync(this.rid); + } + close() { core.close(this.rid); } diff --git a/ext/node/polyfills/_fs/_fs_fdatasync.ts b/ext/node/polyfills/_fs/_fs_fdatasync.ts index f6ed4a39b..482b4378c 100644 --- a/ext/node/polyfills/_fs/_fs_fdatasync.ts +++ b/ext/node/polyfills/_fs/_fs_fdatasync.ts @@ -4,14 +4,15 @@ // deno-lint-ignore-file prefer-primordials import { CallbackWithError } from "ext:deno_node/_fs/_fs_common.ts"; +import { FsFile } from "ext:deno_fs/30_fs.js"; export function fdatasync( fd: number, callback: CallbackWithError, ) { - Deno.fdatasync(fd).then(() => callback(null), callback); + new FsFile(fd).dataSync().then(() => callback(null), callback); } export function fdatasyncSync(fd: number) { - Deno.fdatasyncSync(fd); + new FsFile(fd).dataSyncSync(); } |