summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBartek IwaƄczuk <biwanczuk@gmail.com>2024-01-25 23:51:29 +0100
committerGitHub <noreply@github.com>2024-01-25 23:51:29 +0100
commit0b0fb94ce2489da642cffd82e0498446d4a1fe1f (patch)
treeaf3fd4fd60e0e9fdf5301ac2881b8e5c43f25cbb
parent7038074c8583465872b16083f54f2211312f0943 (diff)
fix(fs): instanceof check for Deno.FsFile (#22121)
Regression caused by https://github.com/denoland/deno/pull/22072. I added a relevant test so we don't regress again. Fixes https://github.com/denoland/deno/issues/22115
-rw-r--r--cli/tests/unit/files_test.ts2
-rw-r--r--ext/fs/30_fs.js14
-rw-r--r--ext/node/polyfills/_fs/_fs_fdatasync.ts7
-rw-r--r--ext/node/polyfills/_fs/_fs_fstat.ts4
-rw-r--r--ext/node/polyfills/_fs/_fs_fsync.ts7
-rw-r--r--ext/node/polyfills/_fs/_fs_ftruncate.ts7
-rw-r--r--ext/node/polyfills/_fs/_fs_futimes.ts7
-rw-r--r--ext/node/polyfills/_fs/_fs_readFile.ts2
-rw-r--r--ext/node/polyfills/_fs/_fs_writeFile.ts4
-rw-r--r--runtime/js/40_process.js13
-rw-r--r--runtime/js/90_deno_ns.js13
11 files changed, 49 insertions, 31 deletions
diff --git a/cli/tests/unit/files_test.ts b/cli/tests/unit/files_test.ts
index 150aa5c6e..a96f60a7a 100644
--- a/cli/tests/unit/files_test.ts
+++ b/cli/tests/unit/files_test.ts
@@ -19,6 +19,8 @@ Deno.test(function filesStdioFileDescriptors() {
Deno.test({ permissions: { read: true } }, async function filesCopyToStdout() {
const filename = "cli/tests/testdata/assets/fixture.json";
using file = await Deno.open(filename);
+ assert(file instanceof Deno.File);
+ assert(file instanceof Deno.FsFile);
assert(file.rid > 2);
const bytesWritten = await copy(file, Deno.stdout);
const fileSize = Deno.statSync(filename).size;
diff --git a/ext/fs/30_fs.js b/ext/fs/30_fs.js
index f752c559a..2e7eba242 100644
--- a/ext/fs/30_fs.js
+++ b/ext/fs/30_fs.js
@@ -88,6 +88,7 @@ const {
StringPrototypeStartsWith,
SymbolAsyncIterator,
SymbolIterator,
+ SymbolFor,
Uint32Array,
} = primordials;
@@ -619,7 +620,7 @@ function openSync(
options,
);
- return new FsFile(rid);
+ return new FsFile(rid, SymbolFor("Deno.internal.FsFile"));
}
async function open(
@@ -632,7 +633,7 @@ async function open(
options,
);
- return new FsFile(rid);
+ return new FsFile(rid, SymbolFor("Deno.internal.FsFile"));
}
function createSync(path) {
@@ -659,8 +660,15 @@ class FsFile {
#readable;
#writable;
- constructor(rid) {
+ constructor(rid, symbol) {
this.#rid = rid;
+ if (!symbol || symbol !== SymbolFor("Deno.internal.FsFile")) {
+ internals.warnOnDeprecatedApi(
+ "new Deno.FsFile()",
+ new Error().stack,
+ "Use `Deno.open` or `Deno.openSync` instead.",
+ );
+ }
}
get rid() {
diff --git a/ext/node/polyfills/_fs/_fs_fdatasync.ts b/ext/node/polyfills/_fs/_fs_fdatasync.ts
index 41990b070..0c3f50f1c 100644
--- a/ext/node/polyfills/_fs/_fs_fdatasync.ts
+++ b/ext/node/polyfills/_fs/_fs_fdatasync.ts
@@ -10,9 +10,12 @@ export function fdatasync(
fd: number,
callback: CallbackWithError,
) {
- new FsFile(fd).syncData().then(() => callback(null), callback);
+ new FsFile(fd, Symbol.for("Deno.internal.FsFile")).syncData().then(
+ () => callback(null),
+ callback,
+ );
}
export function fdatasyncSync(fd: number) {
- new FsFile(fd).syncDataSync();
+ new FsFile(fd, Symbol.for("Deno.internal.FsFile")).syncDataSync();
}
diff --git a/ext/node/polyfills/_fs/_fs_fstat.ts b/ext/node/polyfills/_fs/_fs_fstat.ts
index fe97235bf..c1722487e 100644
--- a/ext/node/polyfills/_fs/_fs_fstat.ts
+++ b/ext/node/polyfills/_fs/_fs_fstat.ts
@@ -41,7 +41,7 @@ export function fstat(
if (!callback) throw new Error("No callback function supplied");
- new FsFile(fd).stat().then(
+ new FsFile(fd, Symbol.for("Deno.internal.FsFile")).stat().then(
(stat) => callback(null, CFISBIS(stat, options.bigint)),
(err) => callback(err),
);
@@ -60,6 +60,6 @@ export function fstatSync(
fd: number,
options?: statOptions,
): Stats | BigIntStats {
- const origin = new FsFile(fd).statSync();
+ const origin = new FsFile(fd, Symbol.for("Deno.internal.FsFile")).statSync();
return CFISBIS(origin, options?.bigint || false);
}
diff --git a/ext/node/polyfills/_fs/_fs_fsync.ts b/ext/node/polyfills/_fs/_fs_fsync.ts
index 942aecf6a..75d4b3756 100644
--- a/ext/node/polyfills/_fs/_fs_fsync.ts
+++ b/ext/node/polyfills/_fs/_fs_fsync.ts
@@ -10,9 +10,12 @@ export function fsync(
fd: number,
callback: CallbackWithError,
) {
- new FsFile(fd).sync().then(() => callback(null), callback);
+ new FsFile(fd, Symbol.for("Deno.internal.FsFile")).sync().then(
+ () => callback(null),
+ callback,
+ );
}
export function fsyncSync(fd: number) {
- new FsFile(fd).syncSync();
+ new FsFile(fd, Symbol.for("Deno.internal.FsFile")).syncSync();
}
diff --git a/ext/node/polyfills/_fs/_fs_ftruncate.ts b/ext/node/polyfills/_fs/_fs_ftruncate.ts
index 71186e868..92af46f52 100644
--- a/ext/node/polyfills/_fs/_fs_ftruncate.ts
+++ b/ext/node/polyfills/_fs/_fs_ftruncate.ts
@@ -20,9 +20,12 @@ export function ftruncate(
if (!callback) throw new Error("No callback function supplied");
- new FsFile(fd).truncate(len).then(() => callback(null), callback);
+ new FsFile(fd, Symbol.for("Deno.internal.FsFile")).truncate(len).then(
+ () => callback(null),
+ callback,
+ );
}
export function ftruncateSync(fd: number, len?: number) {
- new FsFile(fd).truncateSync(len);
+ new FsFile(fd, Symbol.for("Deno.internal.FsFile")).truncateSync(len);
}
diff --git a/ext/node/polyfills/_fs/_fs_futimes.ts b/ext/node/polyfills/_fs/_fs_futimes.ts
index 9bd41e114..cc4e35b0b 100644
--- a/ext/node/polyfills/_fs/_fs_futimes.ts
+++ b/ext/node/polyfills/_fs/_fs_futimes.ts
@@ -40,7 +40,10 @@ export function futimes(
mtime = getValidTime(mtime, "mtime");
// TODO(@littledivy): Treat `fd` as real file descriptor.
- new FsFile(fd).utime(atime, mtime).then(() => callback(null), callback);
+ new FsFile(fd, Symbol.for("Deno.internal.FsFile")).utime(atime, mtime).then(
+ () => callback(null),
+ callback,
+ );
}
export function futimesSync(
@@ -52,5 +55,5 @@ export function futimesSync(
mtime = getValidTime(mtime, "mtime");
// TODO(@littledivy): Treat `fd` as real file descriptor.
- new FsFile(fd).utimeSync(atime, mtime);
+ new FsFile(fd, Symbol.for("Deno.internal.FsFile")).utimeSync(atime, mtime);
}
diff --git a/ext/node/polyfills/_fs/_fs_readFile.ts b/ext/node/polyfills/_fs/_fs_readFile.ts
index de1a2a30d..0f05ee167 100644
--- a/ext/node/polyfills/_fs/_fs_readFile.ts
+++ b/ext/node/polyfills/_fs/_fs_readFile.ts
@@ -73,7 +73,7 @@ export function readFile(
let p: Promise<Uint8Array>;
if (path instanceof FileHandle) {
- const fsFile = new FsFile(path.fd);
+ const fsFile = new FsFile(path.fd, Symbol.for("Deno.internal.FsFile"));
p = readAll(fsFile);
} else {
p = Deno.readFile(path);
diff --git a/ext/node/polyfills/_fs/_fs_writeFile.ts b/ext/node/polyfills/_fs/_fs_writeFile.ts
index 40d368566..60b31897e 100644
--- a/ext/node/polyfills/_fs/_fs_writeFile.ts
+++ b/ext/node/polyfills/_fs/_fs_writeFile.ts
@@ -74,7 +74,7 @@ export function writeFile(
(async () => {
try {
file = isRid
- ? new FsFile(pathOrRid as number)
+ ? new FsFile(pathOrRid as number, Symbol.for("Deno.internal.FsFile"))
: await Deno.open(pathOrRid as string, openOptions);
// ignore mode because it's not supported on windows
@@ -139,7 +139,7 @@ export function writeFileSync(
let error: Error | null = null;
try {
file = isRid
- ? new FsFile(pathOrRid as number)
+ ? new FsFile(pathOrRid as number, Symbol.for("Deno.internal.FsFile"))
: Deno.openSync(pathOrRid as string, openOptions);
// ignore mode because it's not supported on windows
diff --git a/runtime/js/40_process.js b/runtime/js/40_process.js
index e6a62dcf7..ea99bcd97 100644
--- a/runtime/js/40_process.js
+++ b/runtime/js/40_process.js
@@ -21,6 +21,7 @@ const {
PromisePrototypeThen,
SafePromiseAll,
Symbol,
+ SymbolFor,
} = primordials;
import { FsFile } from "ext:deno_fs/30_fs.js";
@@ -76,15 +77,21 @@ class Process {
this.pid = res.pid;
if (res.stdinRid && res.stdinRid > 0) {
- this.stdin = new FsFile(res.stdinRid);
+ this.stdin = new FsFile(res.stdinRid, SymbolFor("Deno.internal.FsFile"));
}
if (res.stdoutRid && res.stdoutRid > 0) {
- this.stdout = new FsFile(res.stdoutRid);
+ this.stdout = new FsFile(
+ res.stdoutRid,
+ SymbolFor("Deno.internal.FsFile"),
+ );
}
if (res.stderrRid && res.stderrRid > 0) {
- this.stderr = new FsFile(res.stderrRid);
+ this.stderr = new FsFile(
+ res.stderrRid,
+ SymbolFor("Deno.internal.FsFile"),
+ );
}
}
diff --git a/runtime/js/90_deno_ns.js b/runtime/js/90_deno_ns.js
index 33fc2a6ff..98cc9f14d 100644
--- a/runtime/js/90_deno_ns.js
+++ b/runtime/js/90_deno_ns.js
@@ -31,17 +31,6 @@ import * as kv from "ext:deno_kv/01_db.ts";
import * as cron from "ext:deno_cron/01_cron.ts";
import * as webgpuSurface from "ext:deno_webgpu/02_surface.js";
-class FsFile extends fs.FsFile {
- constructor(rid) {
- super(rid);
- internals.warnOnDeprecatedApi(
- "Deno.Fs",
- new Error().stack,
- "Use `Deno.open()` or `Deno.openSync()` instead.",
- );
- }
-}
-
const denoNs = {
metrics: () => {
internals.warnOnDeprecatedApi("Deno.metrics()", new Error().stack);
@@ -171,7 +160,7 @@ const denoNs = {
return io.writeSync(rid, data);
},
File: fs.File,
- FsFile,
+ FsFile: fs.FsFile,
open: fs.open,
openSync: fs.openSync,
create: fs.create,