From 47620641e7455a0f9df82d17ad0405693e4427a4 Mon Sep 17 00:00:00 2001 From: Asher Gomez Date: Wed, 24 Jan 2024 11:07:06 +1100 Subject: feat: `FsFile.sync()` and `FsFile.syncSync()` (#22017) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This change: 1. Implements `Deno.FsFile.sync()` and `Deno.FsFile.syncSync()`. 2. Deprecates `Deno.fsync()` and `Deno.fsyncSync()` for removal in Deno v2, in favour of the above corresponding methods. Related #21995 --------- Co-authored-by: Bartek IwaƄczuk --- ext/fs/30_fs.js | 18 ++++++++++++++++++ ext/node/polyfills/_fs/_fs_fsync.ts | 5 +++-- 2 files changed, 21 insertions(+), 2 deletions(-) (limited to 'ext') diff --git a/ext/fs/30_fs.js b/ext/fs/30_fs.js index 3c888f1f1..6923741ee 100644 --- a/ext/fs/30_fs.js +++ b/ext/fs/30_fs.js @@ -576,10 +576,20 @@ async function fdatasync(rid) { } function fsyncSync(rid) { + internals.warnOnDeprecatedApi( + "Deno.fsyncSync()", + new Error().stack, + "Use `file.syncSync()` instead.", + ); op_fs_fsync_sync(rid); } async function fsync(rid) { + internals.warnOnDeprecatedApi( + "Deno.fsync()", + new Error().stack, + "Use `file.sync()` instead.", + ); await op_fs_fsync_async(rid); } @@ -739,6 +749,14 @@ class FsFile { return this.#writable; } + async sync() { + await op_fs_fsync_async(this.rid); + } + + syncSync() { + op_fs_fsync_sync(this.rid); + } + [SymbolDispose]() { core.tryClose(this.rid); } diff --git a/ext/node/polyfills/_fs/_fs_fsync.ts b/ext/node/polyfills/_fs/_fs_fsync.ts index 489929227..942aecf6a 100644 --- a/ext/node/polyfills/_fs/_fs_fsync.ts +++ b/ext/node/polyfills/_fs/_fs_fsync.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 fsync( fd: number, callback: CallbackWithError, ) { - Deno.fsync(fd).then(() => callback(null), callback); + new FsFile(fd).sync().then(() => callback(null), callback); } export function fsyncSync(fd: number) { - Deno.fsyncSync(fd); + new FsFile(fd).syncSync(); } -- cgit v1.2.3