mirror of
https://github.com/denoland/deno.git
synced 2024-11-24 15:19:26 -05:00
feat(ext/fs): stabilize Deno.FsFile.unlock[Sync]()
and Deno.FsFile.lock[Sync]()
(#23754)
Related #22230 CC @dyedgreen
This commit is contained in:
parent
8ea9370c55
commit
4908d45758
5 changed files with 68 additions and 20 deletions
|
@ -310,10 +310,12 @@ pub const OP_DETAILS: phf::Map<&'static str, [&'static str; 2]> = phf_map! {
|
|||
"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_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_flock_async_unstable" => ["lock a file", "awaiting the result of a `Deno.flock` 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_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_funlock_async_unstable" => ["unlock a file", "awaiting the result of a `Deno.funlock` call"],
|
||||
"op_fs_funlock_async" => ["unlock a file", "awaiting the result of a `Deno.FsFile.unlock` call"],
|
||||
"op_fs_futime_async" => ["change file timestamps", "awaiting the result of a `Deno.futime` or `Deno.FsFile.utime` call"],
|
||||
"op_fs_link_async" => ["create a hard link", "awaiting the result of a `Deno.link` call"],
|
||||
"op_fs_lstat_async" => ["get file metadata", "awaiting the result of a `Deno.lstat` call"],
|
||||
|
|
12
cli/tsc/dts/lib.deno.ns.d.ts
vendored
12
cli/tsc/dts/lib.deno.ns.d.ts
vendored
|
@ -2682,27 +2682,23 @@ declare namespace Deno {
|
|||
* ```
|
||||
*/
|
||||
setRaw(mode: boolean, options?: SetRawOptions): void;
|
||||
/** **UNSTABLE**: New API, yet to be vetted.
|
||||
*
|
||||
/**
|
||||
* Acquire an advisory file-system lock for the file.
|
||||
*
|
||||
* @param [exclusive=false]
|
||||
*/
|
||||
lock(exclusive?: boolean): Promise<void>;
|
||||
/** **UNSTABLE**: New API, yet to be vetted.
|
||||
*
|
||||
/**
|
||||
* Synchronously acquire an advisory file-system lock synchronously for the file.
|
||||
*
|
||||
* @param [exclusive=false]
|
||||
*/
|
||||
lockSync(exclusive?: boolean): void;
|
||||
/** **UNSTABLE**: New API, yet to be vetted.
|
||||
*
|
||||
/**
|
||||
* Release an advisory file-system lock for the file.
|
||||
*/
|
||||
unlock(): Promise<void>;
|
||||
/** **UNSTABLE**: New API, yet to be vetted.
|
||||
*
|
||||
/**
|
||||
* Synchronously release an advisory file-system lock for the file.
|
||||
*/
|
||||
unlockSync(): void;
|
||||
|
|
|
@ -20,13 +20,17 @@ import {
|
|||
op_fs_file_stat_async,
|
||||
op_fs_file_stat_sync,
|
||||
op_fs_flock_async,
|
||||
op_fs_flock_async_unstable,
|
||||
op_fs_flock_sync,
|
||||
op_fs_flock_sync_unstable,
|
||||
op_fs_fsync_async,
|
||||
op_fs_fsync_sync,
|
||||
op_fs_ftruncate_async,
|
||||
op_fs_ftruncate_sync,
|
||||
op_fs_funlock_async,
|
||||
op_fs_funlock_async_unstable,
|
||||
op_fs_funlock_sync,
|
||||
op_fs_funlock_sync_unstable,
|
||||
op_fs_futime_async,
|
||||
op_fs_futime_sync,
|
||||
op_fs_link_async,
|
||||
|
@ -577,19 +581,19 @@ async function fsync(rid) {
|
|||
}
|
||||
|
||||
function flockSync(rid, exclusive) {
|
||||
op_fs_flock_sync(rid, exclusive === true);
|
||||
op_fs_flock_sync_unstable(rid, exclusive === true);
|
||||
}
|
||||
|
||||
async function flock(rid, exclusive) {
|
||||
await op_fs_flock_async(rid, exclusive === true);
|
||||
await op_fs_flock_async_unstable(rid, exclusive === true);
|
||||
}
|
||||
|
||||
function funlockSync(rid) {
|
||||
op_fs_funlock_sync(rid);
|
||||
op_fs_funlock_sync_unstable(rid);
|
||||
}
|
||||
|
||||
async function funlock(rid) {
|
||||
await op_fs_funlock_async(rid);
|
||||
await op_fs_funlock_async_unstable(rid);
|
||||
}
|
||||
|
||||
function seekSync(
|
||||
|
|
|
@ -148,10 +148,14 @@ deno_core::extension!(deno_fs,
|
|||
op_fs_fsync_async,
|
||||
op_fs_file_stat_sync,
|
||||
op_fs_file_stat_async,
|
||||
op_fs_flock_sync,
|
||||
op_fs_flock_sync_unstable,
|
||||
op_fs_flock_async_unstable,
|
||||
op_fs_funlock_sync_unstable,
|
||||
op_fs_funlock_async_unstable,
|
||||
op_fs_flock_async,
|
||||
op_fs_funlock_sync,
|
||||
op_fs_flock_sync,
|
||||
op_fs_funlock_async,
|
||||
op_fs_funlock_sync,
|
||||
op_fs_ftruncate_sync,
|
||||
op_fs_ftruncate_async,
|
||||
op_fs_futime_sync,
|
||||
|
|
|
@ -1498,7 +1498,7 @@ pub async fn op_fs_file_stat_async(
|
|||
}
|
||||
|
||||
#[op2(fast)]
|
||||
pub fn op_fs_flock_sync(
|
||||
pub fn op_fs_flock_sync_unstable(
|
||||
state: &mut OpState,
|
||||
#[smi] rid: ResourceId,
|
||||
exclusive: bool,
|
||||
|
@ -1510,7 +1510,7 @@ pub fn op_fs_flock_sync(
|
|||
}
|
||||
|
||||
#[op2(async)]
|
||||
pub async fn op_fs_flock_async(
|
||||
pub async fn op_fs_flock_async_unstable(
|
||||
state: Rc<RefCell<OpState>>,
|
||||
#[smi] rid: ResourceId,
|
||||
exclusive: bool,
|
||||
|
@ -1522,7 +1522,7 @@ pub async fn op_fs_flock_async(
|
|||
}
|
||||
|
||||
#[op2(fast)]
|
||||
pub fn op_fs_funlock_sync(
|
||||
pub fn op_fs_funlock_sync_unstable(
|
||||
state: &mut OpState,
|
||||
#[smi] rid: ResourceId,
|
||||
) -> Result<(), AnyError> {
|
||||
|
@ -1533,7 +1533,7 @@ pub fn op_fs_funlock_sync(
|
|||
}
|
||||
|
||||
#[op2(async)]
|
||||
pub async fn op_fs_funlock_async(
|
||||
pub async fn op_fs_funlock_async_unstable(
|
||||
state: Rc<RefCell<OpState>>,
|
||||
#[smi] rid: ResourceId,
|
||||
) -> Result<(), AnyError> {
|
||||
|
@ -1543,6 +1543,48 @@ pub async fn op_fs_funlock_async(
|
|||
Ok(())
|
||||
}
|
||||
|
||||
#[op2(fast)]
|
||||
pub fn op_fs_flock_sync(
|
||||
state: &mut OpState,
|
||||
#[smi] rid: ResourceId,
|
||||
exclusive: bool,
|
||||
) -> Result<(), AnyError> {
|
||||
let file = FileResource::get_file(state, rid)?;
|
||||
file.lock_sync(exclusive)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[op2(async)]
|
||||
pub async fn op_fs_flock_async(
|
||||
state: Rc<RefCell<OpState>>,
|
||||
#[smi] rid: ResourceId,
|
||||
exclusive: bool,
|
||||
) -> Result<(), AnyError> {
|
||||
let file = FileResource::get_file(&state.borrow(), rid)?;
|
||||
file.lock_async(exclusive).await?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[op2(fast)]
|
||||
pub fn op_fs_funlock_sync(
|
||||
state: &mut OpState,
|
||||
#[smi] rid: ResourceId,
|
||||
) -> Result<(), AnyError> {
|
||||
let file = FileResource::get_file(state, rid)?;
|
||||
file.unlock_sync()?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[op2(async)]
|
||||
pub async fn op_fs_funlock_async(
|
||||
state: Rc<RefCell<OpState>>,
|
||||
#[smi] rid: ResourceId,
|
||||
) -> Result<(), AnyError> {
|
||||
let file = FileResource::get_file(&state.borrow(), rid)?;
|
||||
file.unlock_async().await?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[op2(fast)]
|
||||
pub fn op_fs_ftruncate_sync(
|
||||
state: &mut OpState,
|
||||
|
|
Loading…
Reference in a new issue