1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-11-25 15:29:32 -05:00

BREAKING(fs): remove Deno.fstat[Sync]() (#25351)

Towards #22079

Signed-off-by: Asher Gomez <ashersaupingomez@gmail.com>
This commit is contained in:
Asher Gomez 2024-09-04 11:28:15 +10:00 committed by GitHub
parent 105c571fb6
commit b72d1a7256
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
8 changed files with 5 additions and 113 deletions

View file

@ -319,7 +319,7 @@ pub const OP_DETAILS: phf::Map<&'static str, [&'static str; 2]> = phf_map! {
"op_fs_copy_file_async" => ["copy a file", "awaiting the result of a `Deno.copyFile` call"], "op_fs_copy_file_async" => ["copy a file", "awaiting the result of a `Deno.copyFile` call"],
"op_fs_events_poll" => ["get the next file system event", "breaking out of a for await loop looping over `Deno.FsEvents`"], "op_fs_events_poll" => ["get the next file system event", "breaking out of a for await loop looping over `Deno.FsEvents`"],
"op_fs_fdatasync_async" => ["flush pending data operations for a file to disk", "awaiting the result of a `Deno.fdatasync` or `Deno.FsFile.syncData` call"], "op_fs_fdatasync_async" => ["flush pending data operations for a file to disk", "awaiting the result of a `Deno.fdatasync` or `Deno.FsFile.syncData` call"],
"op_fs_file_stat_async" => ["get file metadata", "awaiting the result of a `Deno.fstat` or `Deno.FsFile.stat` call"], "op_fs_file_stat_async" => ["get file metadata", "awaiting the result of a `Deno.FsFile.prototype.stat` call"],
"op_fs_flock_async" => ["lock a file", "awaiting the result of a `Deno.FsFile.lock` call"], "op_fs_flock_async" => ["lock a file", "awaiting the result of a `Deno.FsFile.lock` call"],
"op_fs_fsync_async" => ["flush pending data operations for a file to disk", "awaiting the result of a `Deno.fsync` or `Deno.FsFile.sync` call"], "op_fs_fsync_async" => ["flush pending data operations for a file to disk", "awaiting the result of a `Deno.fsync` or `Deno.FsFile.sync` call"],
"op_fs_ftruncate_async" => ["truncate a file", "awaiting the result of a `Deno.ftruncate` or `Deno.FsFile.truncate` call"], "op_fs_ftruncate_async" => ["truncate a file", "awaiting the result of a `Deno.ftruncate` or `Deno.FsFile.truncate` call"],

View file

@ -5326,45 +5326,6 @@ declare namespace Deno {
*/ */
export function ftruncateSync(rid: number, len?: number): void; export function ftruncateSync(rid: number, len?: number): void;
/**
* Returns a `Deno.FileInfo` for the given file stream.
*
* ```ts
* import { assert } from "jsr:@std/assert";
*
* const file = await Deno.open("file.txt", { read: true });
* const fileInfo = await Deno.fstat(file.rid);
* assert(fileInfo.isFile);
* ```
*
* @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 File System
*/
export function fstat(rid: number): Promise<FileInfo>;
/**
* Synchronously returns a {@linkcode Deno.FileInfo} for the given file
* stream.
*
* ```ts
* import { assert } from "jsr:@std/assert";
*
* const file = Deno.openSync("file.txt", { read: true });
* const fileInfo = Deno.fstatSync(file.rid);
* assert(fileInfo.isFile);
* ```
*
* @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 File System
*/
export function fstatSync(rid: number): FileInfo;
/** /**
* Synchronously changes the access (`atime`) and modification (`mtime`) times * Synchronously changes the access (`atime`) and modification (`mtime`) times
* of a file system object referenced by `path`. Given times are either in * of a file system object referenced by `path`. Given times are either in

View file

@ -395,15 +395,6 @@ function parseFileInfo(response) {
}; };
} }
function fstatSync(rid) {
op_fs_file_stat_sync(rid, statBuf);
return statStruct(statBuf);
}
async function fstat(rid) {
return parseFileInfo(await op_fs_file_stat_async(rid));
}
async function lstat(path) { async function lstat(path) {
const res = await op_fs_lstat_async(pathFromURL(path)); const res = await op_fs_lstat_async(pathFromURL(path));
return parseFileInfo(res); return parseFileInfo(res);
@ -687,12 +678,13 @@ class FsFile {
return seekSync(this.#rid, offset, whence); return seekSync(this.#rid, offset, whence);
} }
stat() { async stat() {
return fstat(this.#rid); return parseFileInfo(await op_fs_file_stat_async(this.#rid));
} }
statSync() { statSync() {
return fstatSync(this.#rid); op_fs_file_stat_sync(this.#rid, statBuf);
return statStruct(statBuf);
} }
async syncData() { async syncData() {
@ -968,8 +960,6 @@ export {
fdatasyncSync, fdatasyncSync,
File, File,
FsFile, FsFile,
fstat,
fstatSync,
fsync, fsync,
fsyncSync, fsyncSync,
ftruncate, ftruncate,

View file

@ -168,22 +168,6 @@ const denoNs = {
connectTls: tls.connectTls, connectTls: tls.connectTls,
listenTls: tls.listenTls, listenTls: tls.listenTls,
startTls: tls.startTls, startTls: tls.startTls,
fstatSync(rid) {
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: fs.fsyncSync, fsyncSync: fs.fsyncSync,
fsync: fs.fsync, fsync: fs.fsync,
fdatasyncSync: fs.fdatasyncSync, fdatasyncSync: fs.fdatasyncSync,

View file

@ -802,8 +802,6 @@ function bootstrapMainRuntime(runtimeOptions, warmup = false) {
delete globalThis.window; delete globalThis.window;
delete Deno.Buffer; delete Deno.Buffer;
delete Deno.File; delete Deno.File;
delete Deno.fstat;
delete Deno.fstatSync;
delete Deno.ftruncate; delete Deno.ftruncate;
delete Deno.ftruncateSync; delete Deno.ftruncateSync;
delete Deno.FsFile.prototype.rid; delete Deno.FsFile.prototype.rid;
@ -979,8 +977,6 @@ function bootstrapWorkerRuntime(
if (future) { if (future) {
delete Deno.Buffer; delete Deno.Buffer;
delete Deno.File; delete Deno.File;
delete Deno.fstat;
delete Deno.fstatSync;
delete Deno.ftruncate; delete Deno.ftruncate;
delete Deno.ftruncateSync; delete Deno.ftruncateSync;
delete Deno.FsFile.prototype.rid; delete Deno.FsFile.prototype.rid;

View file

@ -1,8 +1,6 @@
console.log("window is", globalThis.window); console.log("window is", globalThis.window);
console.log("Deno.Buffer is", Deno.Buffer); console.log("Deno.Buffer is", Deno.Buffer);
console.log("Deno.File is", Deno.File); console.log("Deno.File is", Deno.File);
console.log("Deno.fstat is", Deno.fstat);
console.log("Deno.fstatSync is", Deno.fstatSync);
console.log("Deno.ftruncate is", Deno.ftruncate); console.log("Deno.ftruncate is", Deno.ftruncate);
console.log("Deno.ftruncateSync is", Deno.ftruncateSync); console.log("Deno.ftruncateSync is", Deno.ftruncateSync);
console.log( console.log(

View file

@ -1,8 +1,6 @@
window is undefined window is undefined
Deno.Buffer is undefined Deno.Buffer is undefined
Deno.File is undefined Deno.File is undefined
Deno.fstat is undefined
Deno.fstatSync is undefined
Deno.ftruncate is undefined Deno.ftruncate is undefined
Deno.ftruncateSync is undefined Deno.ftruncateSync is undefined
Deno.FsFile.prototype.rid is undefined Deno.FsFile.prototype.rid is undefined

View file

@ -1,48 +1,13 @@
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
// deno-lint-ignore-file no-deprecated-deno-api
import { import {
assert, assert,
assertEquals, assertEquals,
assertRejects, assertRejects,
assertThrows, assertThrows,
DENO_FUTURE,
pathToAbsoluteFileUrl, pathToAbsoluteFileUrl,
} from "./test_util.ts"; } from "./test_util.ts";
Deno.test(
{ ignore: DENO_FUTURE, permissions: { read: true } },
function fstatSyncSuccess() {
using file = Deno.openSync("README.md");
const fileInfo = Deno.fstatSync(file.rid);
assert(fileInfo.isFile);
assert(!fileInfo.isSymlink);
assert(!fileInfo.isDirectory);
assert(fileInfo.size);
assert(fileInfo.atime);
assert(fileInfo.mtime);
// The `birthtime` field is not available on Linux before kernel version 4.11.
assert(fileInfo.birthtime || Deno.build.os === "linux");
},
);
Deno.test(
{ ignore: DENO_FUTURE, permissions: { read: true } },
async function fstatSuccess() {
using file = await Deno.open("README.md");
const fileInfo = await Deno.fstat(file.rid);
assert(fileInfo.isFile);
assert(!fileInfo.isSymlink);
assert(!fileInfo.isDirectory);
assert(fileInfo.size);
assert(fileInfo.atime);
assert(fileInfo.mtime);
// The `birthtime` field is not available on Linux before kernel version 4.11.
assert(fileInfo.birthtime || Deno.build.os === "linux");
},
);
Deno.test( Deno.test(
{ permissions: { read: true, write: true } }, { permissions: { read: true, write: true } },
function statSyncSuccess() { function statSyncSuccess() {