From c73b4a0877ca134a05262dc15524f54ff471cc3a Mon Sep 17 00:00:00 2001 From: Asher Gomez Date: Thu, 5 Sep 2024 20:37:28 +1000 Subject: [PATCH] BREAKING(fs): remove `Deno.seek[Sync]()` (#25449) Towards #22079 --- cli/tools/test/fmt.rs | 2 +- cli/tsc/dts/lib.deno.ns.d.ts | 98 ------------------- ext/fs/30_fs.js | 22 +---- ext/node/polyfills/_fs/_fs_read.ts | 18 ++-- ext/node/polyfills/_fs/_fs_readv.ts | 6 +- ext/node/polyfills/_fs/_fs_write.mjs | 6 +- ext/node/polyfills/_fs/_fs_writev.mjs | 6 +- .../polyfills/internal_binding/node_file.ts | 4 +- runtime/js/90_deno_ns.js | 18 +--- runtime/js/99_main.js | 4 - tests/specs/future/runtime_api/main.js | 2 - tests/specs/future/runtime_api/main.out | 2 - 12 files changed, 26 insertions(+), 162 deletions(-) diff --git a/cli/tools/test/fmt.rs b/cli/tools/test/fmt.rs index 5201bead65..733e860d22 100644 --- a/cli/tools/test/fmt.rs +++ b/cli/tools/test/fmt.rs @@ -338,7 +338,7 @@ pub const OP_DETAILS: phf::Map<&'static str, [&'static str; 2]> = phf_map! { "op_fs_realpath_async" => ["resolve a path", "awaiting the result of a `Deno.realpath` call"], "op_fs_remove_async" => ["remove a file or directory", "awaiting the result of a `Deno.remove` call"], "op_fs_rename_async" => ["rename a file or directory", "awaiting the result of a `Deno.rename` call"], - "op_fs_seek_async" => ["seek in a file", "awaiting the result of a `Deno.seek` or `Deno.FsFile.seek` call"], + "op_fs_seek_async" => ["seek in a file", "awaiting the result of a `Deno.FsFile.prototype.seek` call"], "op_fs_stat_async" => ["get file metadata", "awaiting the result of a `Deno.stat` call"], "op_fs_symlink_async" => ["create a symlink", "awaiting the result of a `Deno.symlink` call"], "op_fs_truncate_async" => ["truncate a file", "awaiting the result of a `Deno.truncate` call"], diff --git a/cli/tsc/dts/lib.deno.ns.d.ts b/cli/tsc/dts/lib.deno.ns.d.ts index cc6a1d4a88..fe845bd5f5 100644 --- a/cli/tsc/dts/lib.deno.ns.d.ts +++ b/cli/tsc/dts/lib.deno.ns.d.ts @@ -1920,104 +1920,6 @@ declare namespace Deno { */ export function createSync(path: string | URL): FsFile; - /** Seek a resource ID (`rid`) to the given `offset` under mode given by `whence`. - * The call resolves to the new position within the resource (bytes from the start). - * - * ```ts - * // Given file.rid pointing to file with "Hello world", which is 11 bytes long: - * using file = await Deno.open( - * "hello.txt", - * { read: true, write: true, truncate: true, create: true }, - * ); - * await file.write(new TextEncoder().encode("Hello world")); - * - * // advance cursor 6 bytes - * const cursorPosition = await Deno.seek(file.rid, 6, Deno.SeekMode.Start); - * console.log(cursorPosition); // 6 - * const buf = new Uint8Array(100); - * await file.read(buf); - * console.log(new TextDecoder().decode(buf)); // "world" - * ``` - * - * The seek modes work as follows: - * - * ```ts - * // Given file.rid pointing to file with "Hello world", which is 11 bytes long: - * using file = await Deno.open( - * "hello.txt", - * { read: true, write: true, truncate: true, create: true }, - * ); - * await file.write(new TextEncoder().encode("Hello world")); - * - * // Seek 6 bytes from the start of the file - * console.log(await Deno.seek(file.rid, 6, Deno.SeekMode.Start)); // "6" - * // Seek 2 more bytes from the current position - * console.log(await Deno.seek(file.rid, 2, Deno.SeekMode.Current)); // "8" - * // Seek backwards 2 bytes from the end of the file - * console.log(await Deno.seek(file.rid, -2, Deno.SeekMode.End)); // "9" (i.e. 11-2) - * ``` - * - * @deprecated This will be removed in Deno 2.0. See the - * {@link https://docs.deno.com/runtime/manual/advanced/migrate_deprecations | Deno 1.x to 2.x Migration Guide} - * for migration instructions. - * - * @category I/O - */ - export function seek( - rid: number, - offset: number | bigint, - whence: SeekMode, - ): Promise; - - /** Synchronously seek a resource ID (`rid`) to the given `offset` under mode - * given by `whence`. The new position within the resource (bytes from the - * start) is returned. - * - * ```ts - * using file = Deno.openSync( - * "hello.txt", - * { read: true, write: true, truncate: true, create: true }, - * ); - * file.writeSync(new TextEncoder().encode("Hello world")); - * - * // advance cursor 6 bytes - * const cursorPosition = Deno.seekSync(file.rid, 6, Deno.SeekMode.Start); - * console.log(cursorPosition); // 6 - * const buf = new Uint8Array(100); - * file.readSync(buf); - * console.log(new TextDecoder().decode(buf)); // "world" - * ``` - * - * The seek modes work as follows: - * - * ```ts - * // Given file.rid pointing to file with "Hello world", which is 11 bytes long: - * using file = Deno.openSync( - * "hello.txt", - * { read: true, write: true, truncate: true, create: true }, - * ); - * file.writeSync(new TextEncoder().encode("Hello world")); - * - * // Seek 6 bytes from the start of the file - * console.log(Deno.seekSync(file.rid, 6, Deno.SeekMode.Start)); // "6" - * // Seek 2 more bytes from the current position - * console.log(Deno.seekSync(file.rid, 2, Deno.SeekMode.Current)); // "8" - * // Seek backwards 2 bytes from the end of the file - * console.log(Deno.seekSync(file.rid, -2, Deno.SeekMode.End)); // "9" (i.e. 11-2) - * ``` - * - * @deprecated This will be removed in Deno 2.0. See the - * {@link https://docs.deno.com/runtime/manual/advanced/migrate_deprecations | Deno 1.x to 2.x Migration Guide} - * for migration instructions. - * - * @category I/O - */ - export function seekSync( - rid: number, - offset: number | bigint, - whence: SeekMode, - ): number; - /** * Flushes any pending data and metadata operations of the given file stream * to disk. diff --git a/ext/fs/30_fs.js b/ext/fs/30_fs.js index f979badb97..3509a61d7b 100644 --- a/ext/fs/30_fs.js +++ b/ext/fs/30_fs.js @@ -543,22 +543,6 @@ async function funlock(rid) { await op_fs_funlock_async_unstable(rid); } -function seekSync( - rid, - offset, - whence, -) { - return op_fs_seek_sync(rid, offset, whence); -} - -function seek( - rid, - offset, - whence, -) { - return op_fs_seek_async(rid, offset, whence); -} - function openSync( path, options, @@ -663,11 +647,11 @@ class FsFile { } seek(offset, whence) { - return seek(this.#rid, offset, whence); + return op_fs_seek_async(this.#rid, offset, whence); } seekSync(offset, whence) { - return seekSync(this.#rid, offset, whence); + return op_fs_seek_sync(this.#rid, offset, whence); } async stat() { @@ -979,8 +963,6 @@ export { removeSync, rename, renameSync, - seek, - seekSync, stat, statSync, symlink, diff --git a/ext/node/polyfills/_fs/_fs_read.ts b/ext/node/polyfills/_fs/_fs_read.ts index 90255195fb..dec3a8bbdf 100644 --- a/ext/node/polyfills/_fs/_fs_read.ts +++ b/ext/node/polyfills/_fs/_fs_read.ts @@ -6,7 +6,6 @@ import { Buffer } from "node:buffer"; import { ERR_INVALID_ARG_TYPE } from "ext:deno_node/internal/errors.ts"; import * as io from "ext:deno_io/12_io.js"; -import * as fs from "ext:deno_fs/30_fs.js"; import { ReadOptions } from "ext:deno_node/_fs/_fs_common.ts"; import { arrayBufferViewToUint8Array, @@ -18,6 +17,7 @@ import { validateInteger, } from "ext:deno_node/internal/validators.mjs"; import { isArrayBufferView } from "ext:deno_node/internal/util/types.ts"; +import { op_fs_seek_async, op_fs_seek_sync } from "ext:core/ops"; type readSyncOptions = { offset: number; @@ -119,15 +119,19 @@ export function read( try { let nread: number | null; if (typeof position === "number" && position >= 0) { - const currentPosition = await fs.seek(fd, 0, io.SeekMode.Current); + const currentPosition = await op_fs_seek_async( + fd, + 0, + io.SeekMode.Current, + ); // We use sync calls below to avoid being affected by others during // these calls. - fs.seekSync(fd, position, io.SeekMode.Start); + op_fs_seek_sync(fd, position, io.SeekMode.Start); nread = io.readSync( fd, arrayBufferViewToUint8Array(buffer).subarray(offset, offset + length), ); - fs.seekSync(fd, currentPosition, io.SeekMode.Start); + op_fs_seek_sync(fd, currentPosition, io.SeekMode.Start); } else { nread = await io.read( fd, @@ -191,8 +195,8 @@ export function readSync( let currentPosition = 0; if (typeof position === "number" && position >= 0) { - currentPosition = fs.seekSync(fd, 0, io.SeekMode.Current); - fs.seekSync(fd, position, io.SeekMode.Start); + currentPosition = op_fs_seek_sync(fd, 0, io.SeekMode.Current); + op_fs_seek_sync(fd, position, io.SeekMode.Start); } const numberOfBytesRead = io.readSync( @@ -201,7 +205,7 @@ export function readSync( ); if (typeof position === "number" && position >= 0) { - fs.seekSync(fd, currentPosition, io.SeekMode.Start); + op_fs_seek_sync(fd, currentPosition, io.SeekMode.Start); } return numberOfBytesRead ?? 0; diff --git a/ext/node/polyfills/_fs/_fs_readv.ts b/ext/node/polyfills/_fs/_fs_readv.ts index 7d87c51f78..384f5e319a 100644 --- a/ext/node/polyfills/_fs/_fs_readv.ts +++ b/ext/node/polyfills/_fs/_fs_readv.ts @@ -14,7 +14,7 @@ import { import { maybeCallback } from "ext:deno_node/_fs/_fs_common.ts"; import { validateInteger } from "ext:deno_node/internal/validators.mjs"; import * as io from "ext:deno_io/12_io.js"; -import * as fs from "ext:deno_fs/30_fs.js"; +import { op_fs_seek_async, op_fs_seek_sync } from "ext:core/ops"; type Callback = ( err: ErrnoException | null, @@ -56,7 +56,7 @@ export function readv( position: number | null, ) => { if (typeof position === "number") { - await fs.seek(fd, position, io.SeekMode.Start); + await op_fs_seek_async(fd, position, io.SeekMode.Start); } let readTotal = 0; @@ -104,7 +104,7 @@ export function readvSync( } if (typeof position === "number") { validateInteger(position, "position", 0); - fs.seekSync(fd, position, io.SeekMode.Start); + op_fs_seek_sync(fd, position, io.SeekMode.Start); } let readTotal = 0; diff --git a/ext/node/polyfills/_fs/_fs_write.mjs b/ext/node/polyfills/_fs/_fs_write.mjs index b4b133222f..254094c9ad 100644 --- a/ext/node/polyfills/_fs/_fs_write.mjs +++ b/ext/node/polyfills/_fs/_fs_write.mjs @@ -10,7 +10,6 @@ import { validateInteger, } from "ext:deno_node/internal/validators.mjs"; import * as io from "ext:deno_io/12_io.js"; -import * as fs from "ext:deno_fs/30_fs.js"; import { arrayBufferViewToUint8Array, getValidatedFd, @@ -19,6 +18,7 @@ import { } from "ext:deno_node/internal/fs/utils.mjs"; import { isArrayBufferView } from "ext:deno_node/internal/util/types.ts"; import { maybeCallback } from "ext:deno_node/_fs/_fs_common.ts"; +import { op_fs_seek_async, op_fs_seek_sync } from "ext:core/ops"; export function writeSync(fd, buffer, offset, length, position) { fd = getValidatedFd(fd); @@ -26,7 +26,7 @@ export function writeSync(fd, buffer, offset, length, position) { const innerWriteSync = (fd, buffer, offset, length, position) => { buffer = arrayBufferViewToUint8Array(buffer); if (typeof position === "number") { - fs.seekSync(fd, position, io.SeekMode.Start); + op_fs_seek_sync(fd, position, io.SeekMode.Start); } let currentOffset = offset; const end = offset + length; @@ -70,7 +70,7 @@ export function write(fd, buffer, offset, length, position, callback) { const innerWrite = async (fd, buffer, offset, length, position) => { buffer = arrayBufferViewToUint8Array(buffer); if (typeof position === "number") { - await fs.seek(fd, position, io.SeekMode.Start); + await op_fs_seek_async(fd, position, io.SeekMode.Start); } let currentOffset = offset; const end = offset + length; diff --git a/ext/node/polyfills/_fs/_fs_writev.mjs b/ext/node/polyfills/_fs/_fs_writev.mjs index 2f65c570e1..055bce0b24 100644 --- a/ext/node/polyfills/_fs/_fs_writev.mjs +++ b/ext/node/polyfills/_fs/_fs_writev.mjs @@ -9,7 +9,7 @@ import { validateBufferArray } from "ext:deno_node/internal/fs/utils.mjs"; import { getValidatedFd } from "ext:deno_node/internal/fs/utils.mjs"; import { maybeCallback } from "ext:deno_node/_fs/_fs_common.ts"; import * as io from "ext:deno_io/12_io.js"; -import * as fs from "ext:deno_fs/30_fs.js"; +import { op_fs_seek_async, op_fs_seek_sync } from "ext:core/ops"; export function writev(fd, buffers, position, callback) { const innerWritev = async (fd, buffers, position) => { @@ -23,7 +23,7 @@ export function writev(fd, buffers, position, callback) { } } if (typeof position === "number") { - await fs.seekSync(fd, position, io.SeekMode.Start); + await op_fs_seek_async(fd, position, io.SeekMode.Start); } const buffer = Buffer.concat(chunks); let currentOffset = 0; @@ -64,7 +64,7 @@ export function writevSync(fd, buffers, position) { } } if (typeof position === "number") { - fs.seekSync(fd, position, io.SeekMode.Start); + op_fs_seek_sync(fd, position, io.SeekMode.Start); } const buffer = Buffer.concat(chunks); let currentOffset = 0; diff --git a/ext/node/polyfills/internal_binding/node_file.ts b/ext/node/polyfills/internal_binding/node_file.ts index c7b0bb7e6e..6c134ec4bc 100644 --- a/ext/node/polyfills/internal_binding/node_file.ts +++ b/ext/node/polyfills/internal_binding/node_file.ts @@ -30,7 +30,7 @@ import { assert } from "ext:deno_node/_util/asserts.ts"; import * as io from "ext:deno_io/12_io.js"; -import * as fs from "ext:deno_fs/30_fs.js"; +import { op_fs_seek_sync } from "ext:core/ops"; /** * Write to the given file from the given buffer synchronously. @@ -63,7 +63,7 @@ export function writeBuffer( ); if (position) { - fs.seekSync(fd, position, io.SeekMode.Current); + op_fs_seek_sync(fd, position, io.SeekMode.Current); } const subarray = buffer.subarray(offset, offset + length); diff --git a/runtime/js/90_deno_ns.js b/runtime/js/90_deno_ns.js index 6f5d85da2c..db928bdfd3 100644 --- a/runtime/js/90_deno_ns.js +++ b/runtime/js/90_deno_ns.js @@ -1,6 +1,6 @@ // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. -import { core, internals } from "ext:core/mod.js"; +import { core } from "ext:core/mod.js"; import { op_net_listen_udp, op_net_listen_unixpacket, @@ -96,22 +96,6 @@ const denoNs = { stdin: io.stdin, stdout: io.stdout, stderr: io.stderr, - seek(rid, offset, whence) { - internals.warnOnDeprecatedApi( - "Deno.seek()", - new Error().stack, - "Use `file.seek()` instead.", - ); - return fs.seek(rid, offset, whence); - }, - seekSync(rid, offset, whence) { - internals.warnOnDeprecatedApi( - "Deno.seekSync()", - new Error().stack, - "Use `file.seekSync()` instead.", - ); - return fs.seekSync(rid, offset, whence); - }, connect: net.connect, listen: net.listen, loadavg: os.loadavg, diff --git a/runtime/js/99_main.js b/runtime/js/99_main.js index 913761f6a8..1b80487251 100644 --- a/runtime/js/99_main.js +++ b/runtime/js/99_main.js @@ -804,8 +804,6 @@ function bootstrapMainRuntime(runtimeOptions, warmup = false) { delete Deno.FsFile.prototype.rid; delete Deno.funlock; delete Deno.funlockSync; - delete Deno.seek; - delete Deno.seekSync; } } else { // Warmup @@ -967,8 +965,6 @@ function bootstrapWorkerRuntime( delete Deno.FsFile.prototype.rid; delete Deno.funlock; delete Deno.funlockSync; - delete Deno.seek; - delete Deno.seekSync; } } else { // Warmup diff --git a/tests/specs/future/runtime_api/main.js b/tests/specs/future/runtime_api/main.js index 95b10eecd0..1a0275e531 100644 --- a/tests/specs/future/runtime_api/main.js +++ b/tests/specs/future/runtime_api/main.js @@ -6,8 +6,6 @@ console.log( ); console.log("Deno.funlock is", Deno.funlock); console.log("Deno.funlockSync is", Deno.funlockSync); -console.log("Deno.seek is", Deno.seek); -console.log("Deno.seekSync is", Deno.seekSync); // TCP // Since these tests may run in parallel, ensure this port is unique to this file diff --git a/tests/specs/future/runtime_api/main.out b/tests/specs/future/runtime_api/main.out index 489dd4636b..e04fce76af 100644 --- a/tests/specs/future/runtime_api/main.out +++ b/tests/specs/future/runtime_api/main.out @@ -3,8 +3,6 @@ Deno.Buffer is undefined Deno.FsFile.prototype.rid is undefined Deno.funlock is undefined Deno.funlockSync is undefined -Deno.seek is undefined -Deno.seekSync is undefined Deno.Listener.prototype.rid is undefined Deno.Conn.prototype.rid is undefined Deno.UnixConn.prototype.rid is undefined