Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: deprecate Deno.fstat() and Deno.fstatSync() #22068

Merged
merged 6 commits into from
Jan 24, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions cli/tests/unit/stat_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {

Deno.test({ permissions: { read: true } }, function fstatSyncSuccess() {
const file = Deno.openSync("README.md");
const fileInfo = Deno.fstatSync(file.rid);
iuioiua marked this conversation as resolved.
Show resolved Hide resolved
const fileInfo = file.statSync();
assert(fileInfo.isFile);
assert(!fileInfo.isSymlink);
assert(!fileInfo.isDirectory);
Expand All @@ -24,7 +24,7 @@ Deno.test({ permissions: { read: true } }, function fstatSyncSuccess() {

Deno.test({ permissions: { read: true } }, async function fstatSuccess() {
const file = await Deno.open("README.md");
const fileInfo = await Deno.fstat(file.rid);
const fileInfo = await file.stat();
assert(fileInfo.isFile);
assert(!fileInfo.isSymlink);
assert(!fileInfo.isDirectory);
Expand Down
50 changes: 25 additions & 25 deletions cli/tests/unit_node/_fs/_fs_fstat_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,77 +7,77 @@ import type { BigIntStats, Stats } from "node:fs";
Deno.test({
name: "ASYNC: get a file Stats",
async fn() {
const file = await Deno.makeTempFile();
const { rid } = await Deno.open(file);
const filePath = await Deno.makeTempFile();
using file = await Deno.open(filePath);

await new Promise<Stats>((resolve, reject) => {
fstat(rid, (err: Error | null, stat: Stats) => {
fstat(file.rid, (err: Error | null, stat: Stats) => {
if (err) reject(err);
resolve(stat);
});
})
.then(
(stat) => {
assertStats(stat, Deno.fstatSync(rid));
assertStats(stat, file.statSync());
},
() => fail(),
)
.finally(() => {
Deno.removeSync(file);
Deno.close(rid);
Deno.removeSync(filePath);
});
},
});

Deno.test({
name: "ASYNC: get a file BigInt Stats",
async fn() {
const file = await Deno.makeTempFile();
const { rid } = await Deno.open(file);
const filePath = await Deno.makeTempFile();
using file = await Deno.open(filePath);

await new Promise<BigIntStats>((resolve, reject) => {
fstat(rid, { bigint: true }, (err: Error | null, stat: BigIntStats) => {
if (err) reject(err);
resolve(stat);
});
fstat(
file.rid,
{ bigint: true },
(err: Error | null, stat: BigIntStats) => {
if (err) reject(err);
resolve(stat);
},
);
})
.then(
(stat) => assertStatsBigInt(stat, Deno.fstatSync(rid)),
(stat) => assertStatsBigInt(stat, file.statSync()),
() => fail(),
)
.finally(() => {
Deno.removeSync(file);
Deno.close(rid);
Deno.removeSync(filePath);
});
},
});

Deno.test({
name: "SYNC: get a file Stats",
fn() {
const file = Deno.makeTempFileSync();
const { rid } = Deno.openSync(file);
const filePath = Deno.makeTempFileSync();
using file = Deno.openSync(filePath);

try {
assertStats(fstatSync(rid), Deno.fstatSync(rid));
assertStats(fstatSync(file.rid), file.statSync());
} finally {
Deno.removeSync(file);
Deno.close(rid);
Deno.removeSync(filePath);
}
},
});

Deno.test({
name: "SYNC: get a file BigInt Stats",
fn() {
const file = Deno.makeTempFileSync();
const { rid } = Deno.openSync(file);
const filePath = Deno.makeTempFileSync();
using file = Deno.openSync(filePath);

try {
assertStatsBigInt(fstatSync(rid, { bigint: true }), Deno.fstatSync(rid));
assertStatsBigInt(fstatSync(file.rid, { bigint: true }), file.statSync());
} finally {
Deno.removeSync(file);
Deno.close(rid);
Deno.removeSync(filePath);
}
},
});
6 changes: 6 additions & 0 deletions cli/tsc/dts/lib.deno.ns.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5384,6 +5384,9 @@ declare namespace Deno {
* assert(fileInfo.isFile);
* ```
*
* @deprecated Use `file.stat()` instead.
* {@linkcode Deno.fstat} will be removed in Deno 2.0.
*
* @category File System
*/
export function fstat(rid: number): Promise<FileInfo>;
Expand All @@ -5400,6 +5403,9 @@ declare namespace Deno {
* assert(fileInfo.isFile);
* ```
*
* @deprecated Use `file.statSync()` instead.
* {@linkcode Deno.fstatSync} will be removed in Deno 2.0.
*
* @category File System
*/
export function fstatSync(rid: number): FileInfo;
Expand Down
5 changes: 3 additions & 2 deletions ext/node/polyfills/_fs/_fs_fstat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
statOptions,
Stats,
} from "ext:deno_node/_fs/_fs_stat.ts";
import { FsFile } from "ext:deno_fs/30_fs.js";

export function fstat(fd: number, callback: statCallback): void;
export function fstat(
Expand Down Expand Up @@ -40,7 +41,7 @@ export function fstat(

if (!callback) throw new Error("No callback function supplied");

Deno.fstat(fd).then(
new FsFile(fd).stat().then(
(stat) => callback(null, CFISBIS(stat, options.bigint)),
(err) => callback(err),
);
Expand All @@ -59,6 +60,6 @@ export function fstatSync(
fd: number,
options?: statOptions,
): Stats | BigIntStats {
const origin = Deno.fstatSync(fd);
const origin = new FsFile(fd).statSync();
return CFISBIS(origin, options?.bigint || false);
}
20 changes: 17 additions & 3 deletions runtime/js/90_deno_ns.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.

import { core } from "ext:core/mod.js";
import { core, internals } from "ext:core/mod.js";
const {
op_net_listen_udp,
op_net_listen_unixpacket,
Expand Down Expand Up @@ -119,8 +119,22 @@ const denoNs = {
startTls: tls.startTls,
shutdown: net.shutdown,
fstatSync: fs.fstatSync,
fstat: fs.fstat,
fsyncSync: fs.fsyncSync,
fstat(rid) {
internals.warnOnDeprecatedApi(
"Deno.fstat()",
new Error().stack,
"Use `Deno.FsFile.stat()` instead.",
);
return fs.fstatSync(rid);
},
fsyncSync(rid) {
internals.warnOnDeprecatedApi(
"Deno.fstatSync()",
new Error().stack,
"Use `Deno.FsFile.statSync()` instead.",
);
return fs.fsyncSync(rid);
},
fsync: fs.fsync,
fdatasyncSync: fs.fdatasyncSync,
fdatasync: fs.fdatasync,
Expand Down