FileLock
Index
Methods
dispose
Close the file descriptor and release the native lock.
Returns void
findFirstConflictingByteRangeLock
Find the first conflicting byte range lock.
This method corresponds to the fcntl() F_GETLK command.
Parameters
desiredLock: Readonly<{ end: bigint; pid: number; start: bigint; type: shared | exclusive | unlocked }>
The desired byte range lock.
Returns Readonly<{ end: bigint; pid: number; start: bigint; type: shared | exclusive | unlocked }>
The first conflicting byte range lock, or undefined if no conflicting lock exists.
isUnlocked
Check if the file lock is unlocked.
Returns boolean
True if the file lock is unlocked, false otherwise.
lockFileByteRange
Lock a byte range.
This method corresponds to the fcntl() F_SETLK command.
Parameters
requestedLock: Readonly<{ end: bigint; pid: number; start: bigint; type: shared | exclusive | unlocked }>
The byte range lock to perform.
Returns boolean
True if the lock was granted, false otherwise.
lockWholeFile
Lock the whole file.
This method corresponds to the flock() function.
Parameters
op: WholeFileLockOp
The whole file lock operation to perform.
Returns boolean
True if the lock was granted, false otherwise.
releaseLocksForProcess
Release all locks for the given process.
Parameters
pid: number
The process ID to release locks for.
Returns void
releaseLocksForProcessFd
Release all locks for the given process and file descriptor.
Parameters
pid: number
The process ID to release locks for.
fd: number
The file descriptor to release locks for.
Returns void
staticmaybeCreate
Create a new FileLock instance for the given file and mode. Fail if the underlying native file lock cannot be acquired.
Parameters
path: string
The path to the file to lock
mode: shared | exclusive
The type of lock to acquire
Returns FileLock
A FileLock instance if the lock was acquired, undefined otherwise
A FileLock instance encapsulates a native whole-file lock and file locking between php-wasm processes.
A FileLock supports php-wasm whole-file locks and byte range locks. Before granting a php-wasm lock, a FileLock ensures that it first holds a compatible native lock. If a compatible native lock cannot be acquired, the php-wasm lock is not granted.