mirror of
https://github.com/denoland/deno.git
synced 2024-10-29 08:58:01 -04:00
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
This commit is contained in:
parent
2072fed1ee
commit
cd3af196e3
11 changed files with 49 additions and 31 deletions
|
@ -19,6 +19,8 @@ Deno.test(function filesStdioFileDescriptors() {
|
||||||
Deno.test({ permissions: { read: true } }, async function filesCopyToStdout() {
|
Deno.test({ permissions: { read: true } }, async function filesCopyToStdout() {
|
||||||
const filename = "cli/tests/testdata/assets/fixture.json";
|
const filename = "cli/tests/testdata/assets/fixture.json";
|
||||||
using file = await Deno.open(filename);
|
using file = await Deno.open(filename);
|
||||||
|
assert(file instanceof Deno.File);
|
||||||
|
assert(file instanceof Deno.FsFile);
|
||||||
assert(file.rid > 2);
|
assert(file.rid > 2);
|
||||||
const bytesWritten = await copy(file, Deno.stdout);
|
const bytesWritten = await copy(file, Deno.stdout);
|
||||||
const fileSize = Deno.statSync(filename).size;
|
const fileSize = Deno.statSync(filename).size;
|
||||||
|
|
|
@ -88,6 +88,7 @@ const {
|
||||||
StringPrototypeStartsWith,
|
StringPrototypeStartsWith,
|
||||||
SymbolAsyncIterator,
|
SymbolAsyncIterator,
|
||||||
SymbolIterator,
|
SymbolIterator,
|
||||||
|
SymbolFor,
|
||||||
Uint32Array,
|
Uint32Array,
|
||||||
} = primordials;
|
} = primordials;
|
||||||
|
|
||||||
|
@ -619,7 +620,7 @@ function openSync(
|
||||||
options,
|
options,
|
||||||
);
|
);
|
||||||
|
|
||||||
return new FsFile(rid);
|
return new FsFile(rid, SymbolFor("Deno.internal.FsFile"));
|
||||||
}
|
}
|
||||||
|
|
||||||
async function open(
|
async function open(
|
||||||
|
@ -632,7 +633,7 @@ async function open(
|
||||||
options,
|
options,
|
||||||
);
|
);
|
||||||
|
|
||||||
return new FsFile(rid);
|
return new FsFile(rid, SymbolFor("Deno.internal.FsFile"));
|
||||||
}
|
}
|
||||||
|
|
||||||
function createSync(path) {
|
function createSync(path) {
|
||||||
|
@ -659,8 +660,15 @@ class FsFile {
|
||||||
#readable;
|
#readable;
|
||||||
#writable;
|
#writable;
|
||||||
|
|
||||||
constructor(rid) {
|
constructor(rid, symbol) {
|
||||||
this.#rid = rid;
|
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() {
|
get rid() {
|
||||||
|
|
|
@ -10,9 +10,12 @@ export function fdatasync(
|
||||||
fd: number,
|
fd: number,
|
||||||
callback: CallbackWithError,
|
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) {
|
export function fdatasyncSync(fd: number) {
|
||||||
new FsFile(fd).syncDataSync();
|
new FsFile(fd, Symbol.for("Deno.internal.FsFile")).syncDataSync();
|
||||||
}
|
}
|
||||||
|
|
|
@ -41,7 +41,7 @@ export function fstat(
|
||||||
|
|
||||||
if (!callback) throw new Error("No callback function supplied");
|
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)),
|
(stat) => callback(null, CFISBIS(stat, options.bigint)),
|
||||||
(err) => callback(err),
|
(err) => callback(err),
|
||||||
);
|
);
|
||||||
|
@ -60,6 +60,6 @@ export function fstatSync(
|
||||||
fd: number,
|
fd: number,
|
||||||
options?: statOptions,
|
options?: statOptions,
|
||||||
): Stats | BigIntStats {
|
): 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);
|
return CFISBIS(origin, options?.bigint || false);
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,9 +10,12 @@ export function fsync(
|
||||||
fd: number,
|
fd: number,
|
||||||
callback: CallbackWithError,
|
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) {
|
export function fsyncSync(fd: number) {
|
||||||
new FsFile(fd).syncSync();
|
new FsFile(fd, Symbol.for("Deno.internal.FsFile")).syncSync();
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,9 +20,12 @@ export function ftruncate(
|
||||||
|
|
||||||
if (!callback) throw new Error("No callback function supplied");
|
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) {
|
export function ftruncateSync(fd: number, len?: number) {
|
||||||
new FsFile(fd).truncateSync(len);
|
new FsFile(fd, Symbol.for("Deno.internal.FsFile")).truncateSync(len);
|
||||||
}
|
}
|
||||||
|
|
|
@ -40,7 +40,10 @@ export function futimes(
|
||||||
mtime = getValidTime(mtime, "mtime");
|
mtime = getValidTime(mtime, "mtime");
|
||||||
|
|
||||||
// TODO(@littledivy): Treat `fd` as real file descriptor.
|
// 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(
|
export function futimesSync(
|
||||||
|
@ -52,5 +55,5 @@ export function futimesSync(
|
||||||
mtime = getValidTime(mtime, "mtime");
|
mtime = getValidTime(mtime, "mtime");
|
||||||
|
|
||||||
// TODO(@littledivy): Treat `fd` as real file descriptor.
|
// 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);
|
||||||
}
|
}
|
||||||
|
|
|
@ -73,7 +73,7 @@ export function readFile(
|
||||||
|
|
||||||
let p: Promise<Uint8Array>;
|
let p: Promise<Uint8Array>;
|
||||||
if (path instanceof FileHandle) {
|
if (path instanceof FileHandle) {
|
||||||
const fsFile = new FsFile(path.fd);
|
const fsFile = new FsFile(path.fd, Symbol.for("Deno.internal.FsFile"));
|
||||||
p = readAll(fsFile);
|
p = readAll(fsFile);
|
||||||
} else {
|
} else {
|
||||||
p = Deno.readFile(path);
|
p = Deno.readFile(path);
|
||||||
|
|
|
@ -74,7 +74,7 @@ export function writeFile(
|
||||||
(async () => {
|
(async () => {
|
||||||
try {
|
try {
|
||||||
file = isRid
|
file = isRid
|
||||||
? new FsFile(pathOrRid as number)
|
? new FsFile(pathOrRid as number, Symbol.for("Deno.internal.FsFile"))
|
||||||
: await Deno.open(pathOrRid as string, openOptions);
|
: await Deno.open(pathOrRid as string, openOptions);
|
||||||
|
|
||||||
// ignore mode because it's not supported on windows
|
// ignore mode because it's not supported on windows
|
||||||
|
@ -139,7 +139,7 @@ export function writeFileSync(
|
||||||
let error: Error | null = null;
|
let error: Error | null = null;
|
||||||
try {
|
try {
|
||||||
file = isRid
|
file = isRid
|
||||||
? new FsFile(pathOrRid as number)
|
? new FsFile(pathOrRid as number, Symbol.for("Deno.internal.FsFile"))
|
||||||
: Deno.openSync(pathOrRid as string, openOptions);
|
: Deno.openSync(pathOrRid as string, openOptions);
|
||||||
|
|
||||||
// ignore mode because it's not supported on windows
|
// ignore mode because it's not supported on windows
|
||||||
|
|
|
@ -21,6 +21,7 @@ const {
|
||||||
PromisePrototypeThen,
|
PromisePrototypeThen,
|
||||||
SafePromiseAll,
|
SafePromiseAll,
|
||||||
Symbol,
|
Symbol,
|
||||||
|
SymbolFor,
|
||||||
} = primordials;
|
} = primordials;
|
||||||
|
|
||||||
import { FsFile } from "ext:deno_fs/30_fs.js";
|
import { FsFile } from "ext:deno_fs/30_fs.js";
|
||||||
|
@ -76,15 +77,21 @@ class Process {
|
||||||
this.pid = res.pid;
|
this.pid = res.pid;
|
||||||
|
|
||||||
if (res.stdinRid && res.stdinRid > 0) {
|
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) {
|
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) {
|
if (res.stderrRid && res.stderrRid > 0) {
|
||||||
this.stderr = new FsFile(res.stderrRid);
|
this.stderr = new FsFile(
|
||||||
|
res.stderrRid,
|
||||||
|
SymbolFor("Deno.internal.FsFile"),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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 cron from "ext:deno_cron/01_cron.ts";
|
||||||
import * as webgpuSurface from "ext:deno_webgpu/02_surface.js";
|
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 = {
|
const denoNs = {
|
||||||
metrics: () => {
|
metrics: () => {
|
||||||
internals.warnOnDeprecatedApi("Deno.metrics()", new Error().stack);
|
internals.warnOnDeprecatedApi("Deno.metrics()", new Error().stack);
|
||||||
|
@ -171,7 +160,7 @@ const denoNs = {
|
||||||
return io.writeSync(rid, data);
|
return io.writeSync(rid, data);
|
||||||
},
|
},
|
||||||
File: fs.File,
|
File: fs.File,
|
||||||
FsFile,
|
FsFile: fs.FsFile,
|
||||||
open: fs.open,
|
open: fs.open,
|
||||||
openSync: fs.openSync,
|
openSync: fs.openSync,
|
||||||
create: fs.create,
|
create: fs.create,
|
||||||
|
|
Loading…
Reference in a new issue