1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-11-24 15:19:26 -05:00

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

For removal in Deno v2.
This commit is contained in:
Asher Gomez 2024-01-25 04:53:20 +11:00 committed by GitHub
parent abaffad028
commit 48c19d0bab
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 32 additions and 7 deletions

View file

@ -18,7 +18,7 @@ Deno.test({
}) })
.then( .then(
(stat) => { (stat) => {
assertStats(stat, Deno.fstatSync(file.rid)); assertStats(stat, file.statSync());
}, },
() => fail(), () => fail(),
) )
@ -45,7 +45,7 @@ Deno.test({
); );
}) })
.then( .then(
(stat) => assertStatsBigInt(stat, Deno.fstatSync(file.rid)), (stat) => assertStatsBigInt(stat, file.statSync()),
() => fail(), () => fail(),
) )
.finally(() => { .finally(() => {
@ -61,7 +61,7 @@ Deno.test({
using file = Deno.openSync(filePath); using file = Deno.openSync(filePath);
try { try {
assertStats(fstatSync(file.rid), Deno.fstatSync(file.rid)); assertStats(fstatSync(file.rid), file.statSync());
} finally { } finally {
Deno.removeSync(filePath); Deno.removeSync(filePath);
} }
@ -75,10 +75,14 @@ Deno.test({
using file = Deno.openSync(filePath); using file = Deno.openSync(filePath);
try { try {
// HEAD
assertStatsBigInt(fstatSync(file.rid, { bigint: true }), file.statSync());
//
assertStatsBigInt( assertStatsBigInt(
fstatSync(file.rid, { bigint: true }), fstatSync(file.rid, { bigint: true }),
Deno.fstatSync(file.rid), Deno.fstatSync(file.rid),
); );
//main
} finally { } finally {
Deno.removeSync(filePath); Deno.removeSync(filePath);
} }

View file

@ -5448,6 +5448,9 @@ declare namespace Deno {
* assert(fileInfo.isFile); * assert(fileInfo.isFile);
* ``` * ```
* *
* @deprecated Use `file.stat()` instead.
* {@linkcode Deno.fstat} will be removed in Deno 2.0.
*
* @category File System * @category File System
*/ */
export function fstat(rid: number): Promise<FileInfo>; export function fstat(rid: number): Promise<FileInfo>;
@ -5464,6 +5467,9 @@ declare namespace Deno {
* assert(fileInfo.isFile); * assert(fileInfo.isFile);
* ``` * ```
* *
* @deprecated Use `file.statSync()` instead.
* {@linkcode Deno.fstatSync} will be removed in Deno 2.0.
*
* @category File System * @category File System
*/ */
export function fstatSync(rid: number): FileInfo; export function fstatSync(rid: number): FileInfo;

View file

@ -11,6 +11,7 @@ import {
statOptions, statOptions,
Stats, Stats,
} from "ext:deno_node/_fs/_fs_stat.ts"; } 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(fd: number, callback: statCallback): void;
export function fstat( export function fstat(
@ -40,7 +41,7 @@ export function fstat(
if (!callback) throw new Error("No callback function supplied"); 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)), (stat) => callback(null, CFISBIS(stat, options.bigint)),
(err) => callback(err), (err) => callback(err),
); );
@ -59,6 +60,6 @@ export function fstatSync(
fd: number, fd: number,
options?: statOptions, options?: statOptions,
): Stats | BigIntStats { ): Stats | BigIntStats {
const origin = Deno.fstatSync(fd); const origin = new FsFile(fd).statSync();
return CFISBIS(origin, options?.bigint || false); return CFISBIS(origin, options?.bigint || false);
} }

View file

@ -209,8 +209,22 @@ const denoNs = {
); );
net.shutdown(rid); net.shutdown(rid);
}, },
fstatSync: fs.fstatSync, fstatSync(rid) {
fstat: fs.fstat, internals.warnOnDeprecatedApi(
"Deno.fstatSync()",
new Error().stack,
"Use `Deno.FsFile.statSync()` instead.",
);
return fs.fstatSync(rid);
},
fstat(rid) {
internals.warnOnDeprecatedApi(
"Deno.fstat()",
new Error().stack,
"Use `Deno.FsFile.stat()` instead.",
);
return fs.fstat(rid);
},
fsyncSync(rid) { fsyncSync(rid) {
internals.warnOnDeprecatedApi( internals.warnOnDeprecatedApi(
"Deno.fsyncSync()", "Deno.fsyncSync()",