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

feat(runtime): stabilize Deno.fstat and Deno.fstatSync (#10108)

This commit stabilizes Deno.fstat and Deno.fstatSync 
which are well known system calls and have a stable interface.
This commit is contained in:
Casper Beyer 2021-04-12 17:27:38 +08:00 committed by GitHub
parent bf99039ea9
commit 875ac73f1e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 24 additions and 28 deletions

View file

@ -48,8 +48,6 @@ const UNSTABLE_DENO_PROPS: &[&str] = &[
"createHttpClient", "createHttpClient",
"emit", "emit",
"formatDiagnostics", "formatDiagnostics",
"fstat",
"fstatSync",
"futime", "futime",
"futimeSync", "futimeSync",
"hostname", "hostname",

View file

@ -2386,4 +2386,26 @@ declare namespace Deno {
* ``` * ```
*/ */
export function ftruncate(rid: number, len?: number): Promise<void>; export function ftruncate(rid: number, len?: number): Promise<void>;
/**
* Synchronously returns a `Deno.FileInfo` for the given file stream.
*
* ```ts
* const file = Deno.openSync("file.txt", { read: true });
* const fileInfo = Deno.fstatSync(file.rid);
* assert(fileInfo.isFile);
* ```
*/
export function fstatSync(rid: number): FileInfo;
/**
* Returns a `Deno.FileInfo` for the given file stream.
*
* ```ts
* const file = await Deno.open("file.txt", { read: true });
* const fileInfo = await Deno.fstat(file.rid);
* assert(fileInfo.isFile);
* ```
*/
export function fstat(rid: number): Promise<FileInfo>;
} }

View file

@ -1042,28 +1042,6 @@ declare namespace Deno {
*/ */
export function hostname(): string; export function hostname(): string;
/** **UNSTABLE**: New API, yet to be vetted.
* Synchronously returns a `Deno.FileInfo` for the given file stream.
*
* ```ts
* const file = Deno.openSync("file.txt", { read: true });
* const fileInfo = Deno.fstatSync(file.rid);
* assert(fileInfo.isFile);
* ```
*/
export function fstatSync(rid: number): FileInfo;
/** **UNSTABLE**: New API, yet to be vetted.
* Returns a `Deno.FileInfo` for the given file stream.
*
* ```ts
* const file = await Deno.open("file.txt", { read: true });
* const fileInfo = await Deno.fstat(file.rid);
* assert(fileInfo.isFile);
* ```
*/
export function fstat(rid: number): Promise<FileInfo>;
/** **UNSTABLE**: New API, yet to be vetted. /** **UNSTABLE**: New API, yet to be vetted.
* The pid of the current process's parent. * The pid of the current process's parent.
*/ */

View file

@ -86,6 +86,8 @@
connectTls: __bootstrap.tls.connectTls, connectTls: __bootstrap.tls.connectTls,
listenTls: __bootstrap.tls.listenTls, listenTls: __bootstrap.tls.listenTls,
sleepSync: __bootstrap.timers.sleepSync, sleepSync: __bootstrap.timers.sleepSync,
fstatSync: __bootstrap.fs.fstatSync,
fstat: __bootstrap.fs.fstat,
fsyncSync: __bootstrap.fs.fsyncSync, fsyncSync: __bootstrap.fs.fsyncSync,
fsync: __bootstrap.fs.fsync, fsync: __bootstrap.fs.fsync,
fdatasyncSync: __bootstrap.fs.fdatasyncSync, fdatasyncSync: __bootstrap.fs.fdatasyncSync,
@ -124,8 +126,6 @@
listenDatagram: __bootstrap.netUnstable.listenDatagram, listenDatagram: __bootstrap.netUnstable.listenDatagram,
serveHttp: __bootstrap.http.serveHttp, serveHttp: __bootstrap.http.serveHttp,
startTls: __bootstrap.tls.startTls, startTls: __bootstrap.tls.startTls,
fstatSync: __bootstrap.fs.fstatSync,
fstat: __bootstrap.fs.fstat,
umask: __bootstrap.fs.umask, umask: __bootstrap.fs.umask,
futime: __bootstrap.fs.futime, futime: __bootstrap.fs.futime,
futimeSync: __bootstrap.fs.futimeSync, futimeSync: __bootstrap.fs.futimeSync,

View file

@ -338,7 +338,6 @@ fn op_fstat_sync(
rid: ResourceId, rid: ResourceId,
_zero_copy: Option<ZeroCopyBuf>, _zero_copy: Option<ZeroCopyBuf>,
) -> Result<FsStat, AnyError> { ) -> Result<FsStat, AnyError> {
super::check_unstable(state, "Deno.fstat");
let metadata = StdFileResource::with(state, rid, |r| match r { let metadata = StdFileResource::with(state, rid, |r| match r {
Ok(std_file) => std_file.metadata().map_err(AnyError::from), Ok(std_file) => std_file.metadata().map_err(AnyError::from),
Err(_) => Err(type_error("cannot stat this type of resource".to_string())), Err(_) => Err(type_error("cannot stat this type of resource".to_string())),
@ -351,7 +350,6 @@ async fn op_fstat_async(
rid: ResourceId, rid: ResourceId,
_zero_copy: Option<ZeroCopyBuf>, _zero_copy: Option<ZeroCopyBuf>,
) -> Result<FsStat, AnyError> { ) -> Result<FsStat, AnyError> {
super::check_unstable2(&state, "Deno.fstat");
let resource = state let resource = state
.borrow_mut() .borrow_mut()
.resource_table .resource_table