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

feat(ext/fs): stabilize Deno.FsFile.syncData[Sync]() and Deno.FsFile.sync[Sync]() (#23733)

Closes #22230
This commit is contained in:
Asher Gomez 2024-05-23 07:59:51 +10:00 committed by GitHub
parent cbddf468e3
commit 6c167c64d6
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 9 additions and 67 deletions

View file

@ -308,12 +308,10 @@ pub const OP_DETAILS: phf::Map<&'static str, [&'static str; 2]> = phf_map! {
"op_fs_chown_async" => ["change the owner of a file", "awaiting the result of a `Deno.chown` 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_fdatasync_async" => ["flush pending data operations for a file to disk", "awaiting the result of a `Deno.fdatasync` call"],
"op_fs_fdatasync_async_unstable" => ["flush pending data operations for a file to disk", "awaiting the result of a `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_flock_async" => ["lock a file", "awaiting the result of a `Deno.flock` or `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_unstable" => ["flush pending data operations for a file to disk", "awaiting the result of a `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_funlock_async" => ["unlock a file", "awaiting the result of a `Deno.funlock` or `Deno.FsFile.unlock` call"],
"op_fs_futime_async" => ["change file timestamps", "awaiting the result of a `Deno.futime` or `Deno.FsFile.utime` call"],

View file

@ -2563,8 +2563,7 @@ declare namespace Deno {
* ```
*/
statSync(): FileInfo;
/** **UNSTABLE**: New API, yet to be vetted.
*
/**
* Flushes any pending data and metadata operations of the given file
* stream to disk.
*
@ -2582,8 +2581,7 @@ declare namespace Deno {
* @category I/O
*/
sync(): Promise<void>;
/** **UNSTABLE**: New API, yet to be vetted.
*
/**
* Synchronously flushes any pending data and metadata operations of the given
* file stream to disk.
*
@ -2601,8 +2599,7 @@ declare namespace Deno {
* @category I/O
*/
syncSync(): void;
/** **UNSTABLE**: New API, yet to be vetted.
*
/**
* Flushes any pending data operations of the given file stream to disk.
* ```ts
* using file = await Deno.open(
@ -2617,8 +2614,7 @@ declare namespace Deno {
* @category I/O
*/
syncData(): Promise<void>;
/** **UNSTABLE**: New API, yet to be vetted.
*
/**
* Synchronously flushes any pending data operations of the given file stream
* to disk.
*

View file

@ -16,17 +16,13 @@ import {
op_fs_copy_file_sync,
op_fs_cwd,
op_fs_fdatasync_async,
op_fs_fdatasync_async_unstable,
op_fs_fdatasync_sync,
op_fs_fdatasync_sync_unstable,
op_fs_file_stat_async,
op_fs_file_stat_sync,
op_fs_flock_async,
op_fs_flock_sync,
op_fs_fsync_async,
op_fs_fsync_async_unstable,
op_fs_fsync_sync,
op_fs_fsync_sync_unstable,
op_fs_ftruncate_async,
op_fs_ftruncate_sync,
op_fs_funlock_async,
@ -732,11 +728,11 @@ class FsFile {
}
async syncData() {
await op_fs_fdatasync_async_unstable(this.#rid);
await op_fs_fdatasync_async(this.#rid);
}
syncDataSync() {
op_fs_fdatasync_sync_unstable(this.#rid);
op_fs_fdatasync_sync(this.#rid);
}
close() {
@ -758,11 +754,11 @@ class FsFile {
}
async sync() {
await op_fs_fsync_async_unstable(this.#rid);
await op_fs_fsync_async(this.#rid);
}
syncSync() {
op_fs_fsync_sync_unstable(this.#rid);
op_fs_fsync_sync(this.#rid);
}
async utime(atime, mtime) {

View file

@ -144,12 +144,8 @@ deno_core::extension!(deno_fs,
op_fs_seek_async,
op_fs_fdatasync_sync,
op_fs_fdatasync_async,
op_fs_fdatasync_sync_unstable,
op_fs_fdatasync_async_unstable,
op_fs_fsync_sync,
op_fs_fsync_async,
op_fs_fsync_sync_unstable,
op_fs_fsync_async_unstable,
op_fs_file_stat_sync,
op_fs_file_stat_async,
op_fs_flock_sync,

View file

@ -1443,17 +1443,6 @@ pub fn op_fs_fdatasync_sync(
Ok(())
}
#[op2(fast)]
pub fn op_fs_fdatasync_sync_unstable(
state: &mut OpState,
#[smi] rid: ResourceId,
) -> Result<(), AnyError> {
check_unstable(state, "Deno.FsFile.syncDataSync");
let file = FileResource::get_file(state, rid)?;
file.datasync_sync()?;
Ok(())
}
#[op2(async)]
pub async fn op_fs_fdatasync_async(
state: Rc<RefCell<OpState>>,
@ -1464,17 +1453,6 @@ pub async fn op_fs_fdatasync_async(
Ok(())
}
#[op2(async)]
pub async fn op_fs_fdatasync_async_unstable(
state: Rc<RefCell<OpState>>,
#[smi] rid: ResourceId,
) -> Result<(), AnyError> {
check_unstable(&state.borrow(), "Deno.FsFile.syncData");
let file = FileResource::get_file(&state.borrow(), rid)?;
file.datasync_async().await?;
Ok(())
}
#[op2(fast)]
pub fn op_fs_fsync_sync(
state: &mut OpState,
@ -1485,17 +1463,6 @@ pub fn op_fs_fsync_sync(
Ok(())
}
#[op2(fast)]
pub fn op_fs_fsync_sync_unstable(
state: &mut OpState,
#[smi] rid: ResourceId,
) -> Result<(), AnyError> {
check_unstable(state, "Deno.FsFile.syncSync");
let file = FileResource::get_file(state, rid)?;
file.sync_sync()?;
Ok(())
}
#[op2(async)]
pub async fn op_fs_fsync_async(
state: Rc<RefCell<OpState>>,
@ -1506,17 +1473,6 @@ pub async fn op_fs_fsync_async(
Ok(())
}
#[op2(async)]
pub async fn op_fs_fsync_async_unstable(
state: Rc<RefCell<OpState>>,
#[smi] rid: ResourceId,
) -> Result<(), AnyError> {
check_unstable(&state.borrow(), "Deno.FsFile.sync");
let file = FileResource::get_file(&state.borrow(), rid)?;
file.sync_async().await?;
Ok(())
}
#[op2(fast)]
pub fn op_fs_file_stat_sync(
state: &mut OpState,