mirror of
https://github.com/denoland/deno.git
synced 2024-11-21 15:04:11 -05:00
parent
1f51b5310f
commit
9bf10aa1e0
12 changed files with 0 additions and 271 deletions
|
@ -320,7 +320,6 @@ 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_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"],
|
||||
|
|
|
@ -46,8 +46,6 @@ delete Object.prototype.__proto__;
|
|||
"UnixListenOptions",
|
||||
"createHttpClient",
|
||||
"dlopen",
|
||||
"flock",
|
||||
"flockSync",
|
||||
"funlock",
|
||||
"funlockSync",
|
||||
"listen",
|
||||
|
|
20
cli/tsc/dts/lib.deno.unstable.d.ts
vendored
20
cli/tsc/dts/lib.deno.unstable.d.ts
vendored
|
@ -1216,26 +1216,6 @@ declare namespace Deno {
|
|||
options: UnixListenOptions & { transport: "unixpacket" },
|
||||
): DatagramConn;
|
||||
|
||||
/** **UNSTABLE**: New API, yet to be vetted.
|
||||
*
|
||||
* Acquire an advisory file-system lock for the provided file.
|
||||
*
|
||||
* @param [exclusive=false]
|
||||
* @category File System
|
||||
* @experimental
|
||||
*/
|
||||
export function flock(rid: number, exclusive?: boolean): Promise<void>;
|
||||
|
||||
/** **UNSTABLE**: New API, yet to be vetted.
|
||||
*
|
||||
* Acquire an advisory file-system lock synchronously for the provided file.
|
||||
*
|
||||
* @param [exclusive=false]
|
||||
* @category File System
|
||||
* @experimental
|
||||
*/
|
||||
export function flockSync(rid: number, exclusive?: boolean): void;
|
||||
|
||||
/** **UNSTABLE**: New API, yet to be vetted.
|
||||
*
|
||||
* Release an advisory file-system lock for the provided file.
|
||||
|
|
|
@ -20,9 +20,7 @@ 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,
|
||||
|
@ -554,14 +552,6 @@ async function fsync(rid) {
|
|||
await op_fs_fsync_async(rid);
|
||||
}
|
||||
|
||||
function flockSync(rid, exclusive) {
|
||||
op_fs_flock_sync_unstable(rid, exclusive === true);
|
||||
}
|
||||
|
||||
async function flock(rid, exclusive) {
|
||||
await op_fs_flock_async_unstable(rid, exclusive === true);
|
||||
}
|
||||
|
||||
function funlockSync(rid) {
|
||||
op_fs_funlock_sync_unstable(rid);
|
||||
}
|
||||
|
@ -977,8 +967,6 @@ export {
|
|||
fdatasync,
|
||||
fdatasyncSync,
|
||||
File,
|
||||
flock,
|
||||
flockSync,
|
||||
FsFile,
|
||||
fstat,
|
||||
fstatSync,
|
||||
|
|
|
@ -235,8 +235,6 @@ deno_core::extension!(deno_fs,
|
|||
op_fs_fsync_async,
|
||||
op_fs_file_stat_sync,
|
||||
op_fs_file_stat_async,
|
||||
op_fs_flock_sync_unstable,
|
||||
op_fs_flock_async_unstable,
|
||||
op_fs_funlock_sync_unstable,
|
||||
op_fs_funlock_async_unstable,
|
||||
op_fs_flock_async,
|
||||
|
|
|
@ -1493,30 +1493,6 @@ pub async fn op_fs_file_stat_async(
|
|||
Ok(stat.into())
|
||||
}
|
||||
|
||||
#[op2(fast)]
|
||||
pub fn op_fs_flock_sync_unstable(
|
||||
state: &mut OpState,
|
||||
#[smi] rid: ResourceId,
|
||||
exclusive: bool,
|
||||
) -> Result<(), AnyError> {
|
||||
check_unstable(state, "Deno.flockSync");
|
||||
let file = FileResource::get_file(state, rid)?;
|
||||
file.lock_sync(exclusive)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[op2(async)]
|
||||
pub async fn op_fs_flock_async_unstable(
|
||||
state: Rc<RefCell<OpState>>,
|
||||
#[smi] rid: ResourceId,
|
||||
exclusive: bool,
|
||||
) -> Result<(), AnyError> {
|
||||
check_unstable(&state.borrow(), "Deno.flock");
|
||||
let file = FileResource::get_file(&state.borrow(), rid)?;
|
||||
file.lock_async(exclusive).await?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[op2(fast)]
|
||||
pub fn op_fs_funlock_sync_unstable(
|
||||
state: &mut OpState,
|
||||
|
|
|
@ -251,8 +251,6 @@ denoNsUnstableById[unstableIds.ffi] = {
|
|||
};
|
||||
|
||||
denoNsUnstableById[unstableIds.fs] = {
|
||||
flock: fs.flock,
|
||||
flockSync: fs.flockSync,
|
||||
funlock: fs.funlock,
|
||||
funlockSync: fs.funlockSync,
|
||||
umask: fs.umask,
|
||||
|
@ -301,8 +299,6 @@ const denoNsUnstable = {
|
|||
UnsafePointerView: ffi.UnsafePointerView,
|
||||
UnsafeFnPointer: ffi.UnsafeFnPointer,
|
||||
UnsafeWindowSurface: webgpuSurface.UnsafeWindowSurface,
|
||||
flock: fs.flock,
|
||||
flockSync: fs.flockSync,
|
||||
funlock: fs.funlock,
|
||||
funlockSync: fs.funlockSync,
|
||||
openKv: kv.openKv,
|
||||
|
|
|
@ -820,8 +820,6 @@ function bootstrapMainRuntime(runtimeOptions, warmup = false) {
|
|||
delete Deno.fstatSync;
|
||||
delete Deno.ftruncate;
|
||||
delete Deno.ftruncateSync;
|
||||
delete Deno.flock;
|
||||
delete Deno.flockSync;
|
||||
delete Deno.FsFile.prototype.rid;
|
||||
delete Deno.funlock;
|
||||
delete Deno.funlockSync;
|
||||
|
@ -1000,8 +998,6 @@ function bootstrapWorkerRuntime(
|
|||
delete Deno.fstatSync;
|
||||
delete Deno.ftruncate;
|
||||
delete Deno.ftruncateSync;
|
||||
delete Deno.flock;
|
||||
delete Deno.flockSync;
|
||||
delete Deno.FsFile.prototype.rid;
|
||||
delete Deno.funlock;
|
||||
delete Deno.funlockSync;
|
||||
|
|
|
@ -38,7 +38,6 @@ util::unit_test_factory!(
|
|||
file_test,
|
||||
filereader_test,
|
||||
files_test,
|
||||
flock_test,
|
||||
fs_events_test,
|
||||
get_random_values_test,
|
||||
globals_test,
|
||||
|
|
|
@ -6,8 +6,6 @@ console.log("Deno.fstat is", Deno.fstat);
|
|||
console.log("Deno.fstatSync is", Deno.fstatSync);
|
||||
console.log("Deno.ftruncate is", Deno.ftruncate);
|
||||
console.log("Deno.ftruncateSync is", Deno.ftruncateSync);
|
||||
console.log("Deno.flock is", Deno.flock);
|
||||
console.log("Deno.flockSync is", Deno.flockSync);
|
||||
console.log(
|
||||
"Deno.FsFile.prototype.rid is",
|
||||
Deno.openSync(import.meta.filename).rid,
|
||||
|
|
|
@ -6,8 +6,6 @@ Deno.fstat is undefined
|
|||
Deno.fstatSync is undefined
|
||||
Deno.ftruncate is undefined
|
||||
Deno.ftruncateSync is undefined
|
||||
Deno.flock is undefined
|
||||
Deno.flockSync is undefined
|
||||
Deno.FsFile.prototype.rid is undefined
|
||||
Deno.funlock is undefined
|
||||
Deno.funlockSync is undefined
|
||||
|
|
|
@ -1,197 +0,0 @@
|
|||
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
|
||||
import { assertEquals, DENO_FUTURE } from "./test_util.ts";
|
||||
|
||||
Deno.test(
|
||||
{ ignore: DENO_FUTURE, permissions: { read: true, run: true, hrtime: true } },
|
||||
async function flockFileSync() {
|
||||
await runFlockTests({ sync: true });
|
||||
},
|
||||
);
|
||||
|
||||
Deno.test(
|
||||
{ ignore: DENO_FUTURE, permissions: { read: true, run: true, hrtime: true } },
|
||||
async function flockFileAsync() {
|
||||
await runFlockTests({ sync: false });
|
||||
},
|
||||
);
|
||||
|
||||
async function runFlockTests(opts: { sync: boolean }) {
|
||||
assertEquals(
|
||||
await checkFirstBlocksSecond({
|
||||
firstExclusive: true,
|
||||
secondExclusive: false,
|
||||
sync: opts.sync,
|
||||
}),
|
||||
true,
|
||||
"exclusive blocks shared",
|
||||
);
|
||||
assertEquals(
|
||||
await checkFirstBlocksSecond({
|
||||
firstExclusive: false,
|
||||
secondExclusive: true,
|
||||
sync: opts.sync,
|
||||
}),
|
||||
true,
|
||||
"shared blocks exclusive",
|
||||
);
|
||||
assertEquals(
|
||||
await checkFirstBlocksSecond({
|
||||
firstExclusive: true,
|
||||
secondExclusive: true,
|
||||
sync: opts.sync,
|
||||
}),
|
||||
true,
|
||||
"exclusive blocks exclusive",
|
||||
);
|
||||
assertEquals(
|
||||
await checkFirstBlocksSecond({
|
||||
firstExclusive: false,
|
||||
secondExclusive: false,
|
||||
sync: opts.sync,
|
||||
// need to wait for both to enter the lock to prevent the case where the
|
||||
// first process enters and exits the lock before the second even enters
|
||||
waitBothEnteredLock: true,
|
||||
}),
|
||||
false,
|
||||
"shared does not block shared",
|
||||
);
|
||||
}
|
||||
|
||||
async function checkFirstBlocksSecond(opts: {
|
||||
firstExclusive: boolean;
|
||||
secondExclusive: boolean;
|
||||
sync: boolean;
|
||||
waitBothEnteredLock?: boolean;
|
||||
}) {
|
||||
const firstProcess = runFlockTestProcess({
|
||||
exclusive: opts.firstExclusive,
|
||||
sync: opts.sync,
|
||||
});
|
||||
const secondProcess = runFlockTestProcess({
|
||||
exclusive: opts.secondExclusive,
|
||||
sync: opts.sync,
|
||||
});
|
||||
try {
|
||||
const sleep = (time: number) => new Promise((r) => setTimeout(r, time));
|
||||
|
||||
await Promise.all([
|
||||
firstProcess.waitStartup(),
|
||||
secondProcess.waitStartup(),
|
||||
]);
|
||||
|
||||
await firstProcess.enterLock();
|
||||
await firstProcess.waitEnterLock();
|
||||
|
||||
await secondProcess.enterLock();
|
||||
await sleep(100);
|
||||
|
||||
if (!opts.waitBothEnteredLock) {
|
||||
await firstProcess.exitLock();
|
||||
}
|
||||
|
||||
await secondProcess.waitEnterLock();
|
||||
|
||||
if (opts.waitBothEnteredLock) {
|
||||
await firstProcess.exitLock();
|
||||
}
|
||||
|
||||
await secondProcess.exitLock();
|
||||
|
||||
// collect the final output
|
||||
const firstPsTimes = await firstProcess.getTimes();
|
||||
const secondPsTimes = await secondProcess.getTimes();
|
||||
return firstPsTimes.exitTime < secondPsTimes.enterTime;
|
||||
} finally {
|
||||
await firstProcess.close();
|
||||
await secondProcess.close();
|
||||
}
|
||||
}
|
||||
|
||||
function runFlockTestProcess(opts: { exclusive: boolean; sync: boolean }) {
|
||||
const path = "tests/testdata/assets/lock_target.txt";
|
||||
const scriptText = `
|
||||
const { rid } = Deno.openSync("${path}");
|
||||
|
||||
// ready signal
|
||||
Deno.stdout.writeSync(new Uint8Array(1));
|
||||
// wait for enter lock signal
|
||||
Deno.stdin.readSync(new Uint8Array(1));
|
||||
|
||||
// entering signal
|
||||
Deno.stdout.writeSync(new Uint8Array(1));
|
||||
// lock and record the entry time
|
||||
${
|
||||
opts.sync
|
||||
? `Deno.flockSync(rid, ${opts.exclusive ? "true" : "false"});`
|
||||
: `await Deno.flock(rid, ${opts.exclusive ? "true" : "false"});`
|
||||
}
|
||||
const enterTime = new Date().getTime();
|
||||
// entered signal
|
||||
Deno.stdout.writeSync(new Uint8Array(1));
|
||||
|
||||
// wait for exit lock signal
|
||||
Deno.stdin.readSync(new Uint8Array(1));
|
||||
|
||||
// record the exit time and wait a little bit before releasing
|
||||
// the lock so that the enter time of the next process doesn't
|
||||
// occur at the same time as this exit time
|
||||
const exitTime = new Date().getTime();
|
||||
await new Promise(resolve => setTimeout(resolve, 100));
|
||||
|
||||
// release the lock
|
||||
${opts.sync ? "Deno.funlockSync(rid);" : "await Deno.funlock(rid);"}
|
||||
|
||||
// exited signal
|
||||
Deno.stdout.writeSync(new Uint8Array(1));
|
||||
|
||||
// output the enter and exit time
|
||||
console.log(JSON.stringify({ enterTime, exitTime }));
|
||||
`;
|
||||
|
||||
const process = new Deno.Command(Deno.execPath(), {
|
||||
args: ["eval", "--unstable", scriptText],
|
||||
stdin: "piped",
|
||||
stdout: "piped",
|
||||
stderr: "null",
|
||||
}).spawn();
|
||||
|
||||
const waitSignal = async () => {
|
||||
const reader = process.stdout.getReader({ mode: "byob" });
|
||||
await reader.read(new Uint8Array(1));
|
||||
reader.releaseLock();
|
||||
};
|
||||
const signal = async () => {
|
||||
const writer = process.stdin.getWriter();
|
||||
await writer.write(new Uint8Array(1));
|
||||
writer.releaseLock();
|
||||
};
|
||||
|
||||
return {
|
||||
async waitStartup() {
|
||||
await waitSignal();
|
||||
},
|
||||
async enterLock() {
|
||||
await signal();
|
||||
await waitSignal(); // entering signal
|
||||
},
|
||||
async waitEnterLock() {
|
||||
await waitSignal();
|
||||
},
|
||||
async exitLock() {
|
||||
await signal();
|
||||
await waitSignal();
|
||||
},
|
||||
getTimes: async () => {
|
||||
const { stdout } = await process.output();
|
||||
const text = new TextDecoder().decode(stdout);
|
||||
return JSON.parse(text) as {
|
||||
enterTime: number;
|
||||
exitTime: number;
|
||||
};
|
||||
},
|
||||
close: async () => {
|
||||
await process.status;
|
||||
await process.stdin.close();
|
||||
},
|
||||
};
|
||||
}
|
Loading…
Reference in a new issue