From a445ebd74fc4bb2a949828e155fcfe1d39d9f617 Mon Sep 17 00:00:00 2001 From: Asher Gomez Date: Tue, 10 Sep 2024 08:39:56 +1000 Subject: [PATCH] BREAKING(fs): remove `Deno.fsync[Sync]()` (#25448) Towards #22079 --------- Signed-off-by: Asher Gomez --- cli/tools/test/fmt.rs | 2 +- cli/tsc/dts/lib.deno.ns.d.ts | 38 ------------------------------ ext/fs/30_fs.js | 18 ++++---------- ext/fs/lib.rs | 4 ++-- ext/fs/ops.rs | 4 ++-- runtime/js/90_deno_ns.js | 2 -- tests/integration/js_unit_tests.rs | 1 - tests/unit/sync_test.ts | 36 ---------------------------- 8 files changed, 9 insertions(+), 96 deletions(-) delete mode 100644 tests/unit/sync_test.ts diff --git a/cli/tools/test/fmt.rs b/cli/tools/test/fmt.rs index a1c3922a96..0f6a9ed2b4 100644 --- a/cli/tools/test/fmt.rs +++ b/cli/tools/test/fmt.rs @@ -321,7 +321,7 @@ pub const OP_DETAILS: phf::Map<&'static str, [&'static str; 2]> = phf_map! { "op_fs_file_sync_data_async" => ["flush pending data operations for a file to disk", "awaiting the result of a `Deno.FsFile.prototype.syncData` call"], "op_fs_file_stat_async" => ["get file metadata", "awaiting the result of a `Deno.FsFile.prototype.stat` call"], "op_fs_flock_async" => ["lock a file", "awaiting the result of a `Deno.FsFile.lock` call"], - "op_fs_fsync_async" => ["flush pending data operations for a file to disk", "awaiting the result of a `Deno.fsync` or `Deno.FsFile.sync` call"], + "op_fs_file_sync_async" => ["flush pending data operations for a file to disk", "awaiting the result of a `Deno.FsFile.sync` call"], "op_fs_file_truncate_async" => ["truncate a file", "awaiting the result of a `Deno.FsFile.prototype.truncate` call"], "op_fs_funlock_async" => ["unlock a file", "awaiting the result of a `Deno.FsFile.unlock` call"], "op_fs_link_async" => ["create a hard link", "awaiting the result of a `Deno.link` call"], diff --git a/cli/tsc/dts/lib.deno.ns.d.ts b/cli/tsc/dts/lib.deno.ns.d.ts index 178f7d3cbc..adda5791b9 100644 --- a/cli/tsc/dts/lib.deno.ns.d.ts +++ b/cli/tsc/dts/lib.deno.ns.d.ts @@ -1785,44 +1785,6 @@ declare namespace Deno { */ export function createSync(path: string | URL): FsFile; - /** - * Flushes any pending data and metadata operations of the given file stream - * to disk. - * - * ```ts - * const file = await Deno.open( - * "my_file.txt", - * { read: true, write: true, create: true }, - * ); - * await file.write(new TextEncoder().encode("Hello World")); - * await file.truncate(1); - * await Deno.fsync(file.rid); - * console.log(await Deno.readTextFile("my_file.txt")); // H - * ``` - * - * @category File System - */ - export function fsync(rid: number): Promise; - - /** - * Synchronously flushes any pending data and metadata operations of the given - * file stream to disk. - * - * ```ts - * const file = Deno.openSync( - * "my_file.txt", - * { read: true, write: true, create: true }, - * ); - * file.writeSync(new TextEncoder().encode("Hello World")); - * file.truncateSync(1); - * Deno.fsyncSync(file.rid); - * console.log(Deno.readTextFileSync("my_file.txt")); // H - * ``` - * - * @category File System - */ - export function fsyncSync(rid: number): void; - /** The Deno abstraction for reading and writing files. * * This is the most straight forward way of handling files within Deno and is diff --git a/ext/fs/30_fs.js b/ext/fs/30_fs.js index 8def881aa3..48e09c032f 100644 --- a/ext/fs/30_fs.js +++ b/ext/fs/30_fs.js @@ -17,13 +17,13 @@ import { op_fs_cwd, op_fs_file_stat_async, op_fs_file_stat_sync, + op_fs_file_sync_async, op_fs_file_sync_data_async, op_fs_file_sync_data_sync, + op_fs_file_sync_sync, op_fs_file_truncate_async, op_fs_flock_async, op_fs_flock_sync, - op_fs_fsync_async, - op_fs_fsync_sync, op_fs_ftruncate_sync, op_fs_funlock_async, op_fs_funlock_sync, @@ -517,14 +517,6 @@ async function symlink( ); } -function fsyncSync(rid) { - op_fs_fsync_sync(rid); -} - -async function fsync(rid) { - await op_fs_fsync_async(rid); -} - function openSync( path, options, @@ -666,11 +658,11 @@ class FsFile { } async sync() { - await op_fs_fsync_async(this.#rid); + await op_fs_file_sync_async(this.#rid); } syncSync() { - op_fs_fsync_sync(this.#rid); + op_fs_file_sync_sync(this.#rid); } async utime(atime, mtime) { @@ -907,8 +899,6 @@ export { createSync, cwd, FsFile, - fsync, - fsyncSync, link, linkSync, lstat, diff --git a/ext/fs/lib.rs b/ext/fs/lib.rs index b84565d722..161eaa3672 100644 --- a/ext/fs/lib.rs +++ b/ext/fs/lib.rs @@ -231,8 +231,8 @@ deno_core::extension!(deno_fs, op_fs_seek_async, op_fs_file_sync_data_sync, op_fs_file_sync_data_async, - op_fs_fsync_sync, - op_fs_fsync_async, + op_fs_file_sync_sync, + op_fs_file_sync_async, op_fs_file_stat_sync, op_fs_file_stat_async, op_fs_flock_async, diff --git a/ext/fs/ops.rs b/ext/fs/ops.rs index c9eec94fa4..dc279b60d3 100644 --- a/ext/fs/ops.rs +++ b/ext/fs/ops.rs @@ -1450,7 +1450,7 @@ pub async fn op_fs_file_sync_data_async( } #[op2(fast)] -pub fn op_fs_fsync_sync( +pub fn op_fs_file_sync_sync( state: &mut OpState, #[smi] rid: ResourceId, ) -> Result<(), AnyError> { @@ -1460,7 +1460,7 @@ pub fn op_fs_fsync_sync( } #[op2(async)] -pub async fn op_fs_fsync_async( +pub async fn op_fs_file_sync_async( state: Rc>, #[smi] rid: ResourceId, ) -> Result<(), AnyError> { diff --git a/runtime/js/90_deno_ns.js b/runtime/js/90_deno_ns.js index 23f7da95c6..f2de16627a 100644 --- a/runtime/js/90_deno_ns.js +++ b/runtime/js/90_deno_ns.js @@ -98,8 +98,6 @@ const denoNs = { connectTls: tls.connectTls, listenTls: tls.listenTls, startTls: tls.startTls, - fsyncSync: fs.fsyncSync, - fsync: fs.fsync, symlink: fs.symlink, symlinkSync: fs.symlinkSync, link: fs.link, diff --git a/tests/integration/js_unit_tests.rs b/tests/integration/js_unit_tests.rs index 0246802b53..be2af84a82 100644 --- a/tests/integration/js_unit_tests.rs +++ b/tests/integration/js_unit_tests.rs @@ -84,7 +84,6 @@ util::unit_test_factory!( structured_clone_test, symbol_test, symlink_test, - sync_test, test_util, testing_test, text_encoding_test, diff --git a/tests/unit/sync_test.ts b/tests/unit/sync_test.ts deleted file mode 100644 index a683c7acbe..0000000000 --- a/tests/unit/sync_test.ts +++ /dev/null @@ -1,36 +0,0 @@ -// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. -import { assertEquals, DENO_FUTURE } from "./test_util.ts"; - -Deno.test( - { ignore: DENO_FUTURE, permissions: { read: true, write: true } }, - function fsyncSyncSuccess() { - const filename = Deno.makeTempDirSync() + "/test_fsyncSync.txt"; - using file = Deno.openSync(filename, { - read: true, - write: true, - create: true, - }); - const size = 64; - file.truncateSync(size); - Deno.fsyncSync(file.rid); - assertEquals(Deno.statSync(filename).size, size); - Deno.removeSync(filename); - }, -); - -Deno.test( - { ignore: DENO_FUTURE, permissions: { read: true, write: true } }, - async function fsyncSuccess() { - const filename = (await Deno.makeTempDir()) + "/test_fsync.txt"; - using file = await Deno.open(filename, { - read: true, - write: true, - create: true, - }); - const size = 64; - await file.truncate(size); - await Deno.fsync(file.rid); - assertEquals((await Deno.stat(filename)).size, size); - await Deno.remove(filename); - }, -);