diff options
-rw-r--r-- | cli/tools/test/fmt.rs | 6 | ||||
-rw-r--r-- | cli/tsc/dts/lib.deno.ns.d.ts | 12 | ||||
-rw-r--r-- | ext/fs/30_fs.js | 12 | ||||
-rw-r--r-- | ext/fs/lib.rs | 8 | ||||
-rw-r--r-- | ext/fs/ops.rs | 50 |
5 files changed, 68 insertions, 20 deletions
diff --git a/cli/tools/test/fmt.rs b/cli/tools/test/fmt.rs index 966b488b1..77cc3d1ad 100644 --- a/cli/tools/test/fmt.rs +++ b/cli/tools/test/fmt.rs @@ -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"], diff --git a/cli/tsc/dts/lib.deno.ns.d.ts b/cli/tsc/dts/lib.deno.ns.d.ts index c6b9df222..21b47a466 100644 --- a/cli/tsc/dts/lib.deno.ns.d.ts +++ b/cli/tsc/dts/lib.deno.ns.d.ts @@ -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; diff --git a/ext/fs/30_fs.js b/ext/fs/30_fs.js index d65f8560d..3a35749d8 100644 --- a/ext/fs/30_fs.js +++ b/ext/fs/30_fs.js @@ -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( diff --git a/ext/fs/lib.rs b/ext/fs/lib.rs index 0c3b99c24..d6794d3ac 100644 --- a/ext/fs/lib.rs +++ b/ext/fs/lib.rs @@ -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, diff --git a/ext/fs/ops.rs b/ext/fs/ops.rs index 71edc7d11..8e715d825 100644 --- a/ext/fs/ops.rs +++ b/ext/fs/ops.rs @@ -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> { @@ -1544,6 +1544,48 @@ pub async fn op_fs_funlock_async( } #[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, #[smi] rid: ResourceId, |