From 801ed74118baabef49842bbfb2164f971d2cdb03 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartek=20Iwa=C5=84czuk?= Date: Wed, 24 Jan 2024 23:38:18 +0100 Subject: [PATCH] revert: Remove deprecations of file sync APIs (#22085) - `Deno.FsFile.dataSync` -> `Deno.FsFile.syncData` - `Deno.FsFile.dataSyncSync` -> `Deno.FsFile.syncDataSync` Also marks these APIs as unstable --- cli/tests/unit/files_test.ts | 4 +-- cli/tests/unit/utime_test.ts | 8 ++--- cli/tsc/dts/lib.deno.ns.d.ts | 32 +++++++----------- ext/fs/30_fs.js | 26 ++++++--------- ext/fs/lib.rs | 4 +++ ext/fs/ops.rs | 44 +++++++++++++++++++++++++ ext/node/polyfills/_fs/_fs_fdatasync.ts | 4 +-- runtime/js/90_deno_ns.js | 18 ++-------- 8 files changed, 80 insertions(+), 60 deletions(-) diff --git a/cli/tests/unit/files_test.ts b/cli/tests/unit/files_test.ts index b38a798d79..150aa5c6ed 100644 --- a/cli/tests/unit/files_test.ts +++ b/cli/tests/unit/files_test.ts @@ -836,7 +836,7 @@ Deno.test( }); const data = new Uint8Array(64); file.writeSync(data); - file.dataSyncSync(); + file.syncDataSync(); assertEquals(Deno.readFileSync(filename), data); file.close(); Deno.removeSync(filename); @@ -854,7 +854,7 @@ Deno.test( }); const data = new Uint8Array(64); await file.write(data); - await file.dataSync(); + await file.syncData(); assertEquals(await Deno.readFile(filename), data); file.close(); await Deno.remove(filename); diff --git a/cli/tests/unit/utime_test.ts b/cli/tests/unit/utime_test.ts index 5101cb376f..9f5f25beea 100644 --- a/cli/tests/unit/utime_test.ts +++ b/cli/tests/unit/utime_test.ts @@ -19,7 +19,7 @@ Deno.test( const atime = 1000; const mtime = 50000; await Deno.futime(file.rid, atime, mtime); - await file.dataSync(); + await file.syncData(); const fileInfo = Deno.statSync(filename); assertEquals(fileInfo.atime, new Date(atime * 1000)); @@ -40,7 +40,7 @@ Deno.test( const atime = 1000; const mtime = 50000; await file.utime(atime, mtime); - await file.dataSync(); + await file.syncData(); const fileInfo = Deno.statSync(filename); assertEquals(fileInfo.atime, new Date(atime * 1000)); @@ -61,7 +61,7 @@ Deno.test( const atime = 1000; const mtime = 50000; Deno.futimeSync(file.rid, atime, mtime); - file.dataSyncSync(); + file.syncDataSync(); const fileInfo = Deno.statSync(filename); assertEquals(fileInfo.atime, new Date(atime * 1000)); @@ -82,7 +82,7 @@ Deno.test( const atime = 1000; const mtime = 50000; file.utimeSync(atime, mtime); - file.dataSyncSync(); + file.syncDataSync(); const fileInfo = Deno.statSync(filename); assertEquals(fileInfo.atime, new Date(atime * 1000)); diff --git a/cli/tsc/dts/lib.deno.ns.d.ts b/cli/tsc/dts/lib.deno.ns.d.ts index 1ac86db981..9caa52950a 100644 --- a/cli/tsc/dts/lib.deno.ns.d.ts +++ b/cli/tsc/dts/lib.deno.ns.d.ts @@ -2182,9 +2182,6 @@ declare namespace Deno { * console.log(await Deno.readTextFile("my_file.txt")); // H * ``` * - * @deprecated Use {@linkcode Deno.FsFile.sync} instead. - * {@linkcode Deno.fsync} will be removed in Deno 2.0. - * * @category I/O */ export function fsync(rid: number): Promise; @@ -2204,9 +2201,6 @@ declare namespace Deno { * console.log(Deno.readTextFileSync("my_file.txt")); // H * ``` * - * @deprecated Use {@linkcode Deno.FsFile.syncSync} instead. - * {@linkcode Deno.fsyncSync} will be removed in Deno 2.0. - * * @category I/O */ export function fsyncSync(rid: number): void; @@ -2223,9 +2217,6 @@ declare namespace Deno { * console.log(await Deno.readTextFile("my_file.txt")); // Hello World * ``` * - * @deprecated Use {@linkcode Deno.FsFile.dataSync} instead. - * {@linkcode Deno.fdatasync} will be removed in v2.0.0. - * * @category I/O */ export function fdatasync(rid: number): Promise; @@ -2244,9 +2235,6 @@ declare namespace Deno { * console.log(Deno.readTextFileSync("my_file.txt")); // Hello World * ``` * - * @deprecated Use {@linkcode Deno.FsFile.dataSyncSync} instead. - * {@linkcode Deno.fdatasyncSync} will be removed in v2.0.0. - * * @category I/O */ export function fdatasyncSync(rid: number): void; @@ -2564,7 +2552,8 @@ declare namespace Deno { * ``` */ statSync(): FileInfo; - /** + /** **UNSTABLE**: New API, yet to be vetted. + * * Flushes any pending data and metadata operations of the given file * stream to disk. * @@ -2582,7 +2571,8 @@ declare namespace Deno { * @category I/O */ sync(): Promise; - /** + /** **UNSTABLE**: New API, yet to be vetted. + * * Synchronously flushes any pending data and metadata operations of the given * file stream to disk. * @@ -2600,7 +2590,8 @@ declare namespace Deno { * @category I/O */ syncSync(): void; - /** + /** **UNSTABLE**: New API, yet to be vetted. + * * Flushes any pending data operations of the given file stream to disk. * ```ts * using file = await Deno.open( @@ -2608,14 +2599,15 @@ declare namespace Deno { * { read: true, write: true, create: true }, * ); * await file.write(new TextEncoder().encode("Hello World")); - * await file.dataSync(); + * await file.syncData(); * console.log(await Deno.readTextFile("my_file.txt")); // Hello World * ``` * * @category I/O */ - dataSync(): Promise; - /** + syncData(): Promise; + /** **UNSTABLE**: New API, yet to be vetted. + * * Synchronously flushes any pending data operations of the given file stream * to disk. * @@ -2625,13 +2617,13 @@ declare namespace Deno { * { read: true, write: true, create: true }, * ); * file.writeSync(new TextEncoder().encode("Hello World")); - * file.dataSyncSync(); + * file.syncDataSync(); * console.log(Deno.readTextFileSync("my_file.txt")); // Hello World * ``` * * @category I/O */ - dataSyncSync(): void; + syncDataSync(): void; /** * Changes the access (`atime`) and modification (`mtime`) times of the * file stream resource. Given times are either in seconds (UNIX epoch diff --git a/ext/fs/30_fs.js b/ext/fs/30_fs.js index 2136d88f65..f752c559aa 100644 --- a/ext/fs/30_fs.js +++ b/ext/fs/30_fs.js @@ -15,12 +15,16 @@ const { op_fs_cwd, op_fs_fdatasync_async, op_fs_fdatasync_sync, + op_fs_fdatasync_async_unstable, + op_fs_fdatasync_sync_unstable, op_fs_flock_async, op_fs_flock_sync, op_fs_fstat_async, op_fs_fstat_sync, op_fs_fsync_async, op_fs_fsync_sync, + op_fs_fsync_async_unstable, + op_fs_fsync_sync_unstable, op_fs_ftruncate_async, op_fs_ftruncate_sync, op_fs_funlock_async, @@ -558,20 +562,10 @@ 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); } @@ -718,12 +712,12 @@ class FsFile { return fstatSync(this.#rid); } - async dataSync() { - await op_fs_fdatasync_async(this.#rid); + async syncData() { + await op_fs_fdatasync_async_unstable(this.#rid); } - dataSyncSync() { - op_fs_fdatasync_sync(this.#rid); + syncDataSync() { + op_fs_fdatasync_sync_unstable(this.#rid); } close() { @@ -745,11 +739,11 @@ class FsFile { } async sync() { - await op_fs_fsync_async(this.#rid); + await op_fs_fsync_async_unstable(this.#rid); } syncSync() { - op_fs_fsync_sync(this.#rid); + op_fs_fsync_sync_unstable(this.#rid); } async utime(atime, mtime) { diff --git a/ext/fs/lib.rs b/ext/fs/lib.rs index 5cfa6e5d9c..0bf5462f8c 100644 --- a/ext/fs/lib.rs +++ b/ext/fs/lib.rs @@ -130,8 +130,12 @@ deno_core::extension!(deno_fs, op_fs_seek_async, op_fs_fdatasync_sync, op_fs_fdatasync_async, + op_fs_fdatasync_sync_unstable, + op_fs_fdatasync_async_unstable, op_fs_fsync_sync, op_fs_fsync_async, + op_fs_fsync_sync_unstable, + op_fs_fsync_async_unstable, op_fs_fstat_sync, op_fs_fstat_async, op_fs_flock_sync, diff --git a/ext/fs/ops.rs b/ext/fs/ops.rs index e41d3308f0..e8573229b7 100644 --- a/ext/fs/ops.rs +++ b/ext/fs/ops.rs @@ -1349,6 +1349,17 @@ pub fn op_fs_fdatasync_sync( Ok(()) } +#[op2(fast)] +pub fn op_fs_fdatasync_sync_unstable( + state: &mut OpState, + #[smi] rid: ResourceId, +) -> Result<(), AnyError> { + check_unstable(state, "Deno.FsFile.syncDataSync"); + let file = FileResource::get_file(state, rid)?; + file.datasync_sync()?; + Ok(()) +} + #[op2(async)] pub async fn op_fs_fdatasync_async( state: Rc>, @@ -1359,6 +1370,17 @@ pub async fn op_fs_fdatasync_async( Ok(()) } +#[op2(async)] +pub async fn op_fs_fdatasync_async_unstable( + state: Rc>, + #[smi] rid: ResourceId, +) -> Result<(), AnyError> { + check_unstable(&state.borrow(), "Deno.FsFile.syncData"); + let file = FileResource::get_file(&state.borrow(), rid)?; + file.datasync_async().await?; + Ok(()) +} + #[op2(fast)] pub fn op_fs_fsync_sync( state: &mut OpState, @@ -1369,6 +1391,17 @@ pub fn op_fs_fsync_sync( Ok(()) } +#[op2(fast)] +pub fn op_fs_fsync_sync_unstable( + state: &mut OpState, + #[smi] rid: ResourceId, +) -> Result<(), AnyError> { + check_unstable(state, "Deno.FsFile.syncSync"); + let file = FileResource::get_file(state, rid)?; + file.sync_sync()?; + Ok(()) +} + #[op2(async)] pub async fn op_fs_fsync_async( state: Rc>, @@ -1379,6 +1412,17 @@ pub async fn op_fs_fsync_async( Ok(()) } +#[op2(async)] +pub async fn op_fs_fsync_async_unstable( + state: Rc>, + #[smi] rid: ResourceId, +) -> Result<(), AnyError> { + check_unstable(&state.borrow(), "Deno.FsFile.sync"); + let file = FileResource::get_file(&state.borrow(), rid)?; + file.sync_async().await?; + Ok(()) +} + #[op2(fast)] pub fn op_fs_fstat_sync( state: &mut OpState, diff --git a/ext/node/polyfills/_fs/_fs_fdatasync.ts b/ext/node/polyfills/_fs/_fs_fdatasync.ts index 482b4378c3..41990b0708 100644 --- a/ext/node/polyfills/_fs/_fs_fdatasync.ts +++ b/ext/node/polyfills/_fs/_fs_fdatasync.ts @@ -10,9 +10,9 @@ export function fdatasync( fd: number, callback: CallbackWithError, ) { - new FsFile(fd).dataSync().then(() => callback(null), callback); + new FsFile(fd).syncData().then(() => callback(null), callback); } export function fdatasyncSync(fd: number) { - new FsFile(fd).dataSyncSync(); + new FsFile(fd).syncDataSync(); } diff --git a/runtime/js/90_deno_ns.js b/runtime/js/90_deno_ns.js index 4340abc951..33fc2a6ff1 100644 --- a/runtime/js/90_deno_ns.js +++ b/runtime/js/90_deno_ns.js @@ -225,22 +225,8 @@ const denoNs = { ); return fs.fstat(rid); }, - fsyncSync(rid) { - internals.warnOnDeprecatedApi( - "Deno.fsyncSync()", - new Error().stack, - "Use `Deno.FsFile.syncSync()` instead.", - ); - fs.fsyncSync(rid); - }, - async fsync(rid) { - internals.warnOnDeprecatedApi( - "Deno.fsync()", - new Error().stack, - "Use `Deno.FsFile.sync()` instead.", - ); - await fs.fsync(rid); - }, + fsyncSync: fs.fsyncSync, + fsync: fs.fsync, fdatasyncSync: fs.fdatasyncSync, fdatasync: fs.fdatasync, symlink: fs.symlink,