Aller au contenu principal

FileLockManagerForNode

This is the file lock manager for use within JS runtimes like Node.js.

A FileLockManagerForNode is a wrapper around a Map of FileLock instances. It provides methods for locking and unlocking files, as well as finding conflicting locks.

Implements

Index

Constructors

constructor

Properties

locks

locks: Map<string, FileLock>

Methods

findFirstConflictingByteRangeLock

  • findFirstConflictingByteRangeLock(path: string, desiredLock: Readonly<{ end: bigint; pid: number; start: bigint; type: shared | exclusive | unlocked }>): Omit<Readonly<{ end: bigint; pid: number; start: bigint; type: shared | exclusive | unlocked }>, fd>
  • Find the first conflicting byte range lock.


    Parameters

    • path: string

      The path to the file to find the conflicting lock for.

    • desiredLock: Readonly<{ end: bigint; pid: number; start: bigint; type: shared | exclusive | unlocked }>

      The desired byte range lock.

    Returns Omit<Readonly<{ end: bigint; pid: number; start: bigint; type: shared | exclusive | unlocked }>, fd>

    The first conflicting byte range lock, or undefined if no conflicting lock exists.

lockFileByteRange

  • lockFileByteRange(path: string, requestedLock: Readonly<{ end: bigint; pid: number; start: bigint; type: shared | exclusive | unlocked }>): boolean
  • Lock a byte range.


    Parameters

    • path: string

      The path to the file to lock. This should be the path of the file in the native filesystem.

    • 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.


    Parameters

    • path: string

      The path to the file to lock. This should be the path of the file in the native filesystem.

    • op: WholeFileLockOp

      The whole file lock operation to perform.

    Returns boolean

    True if the lock was granted, false otherwise.

releaseLocksForProcess

  • releaseLocksForProcess(pid: number): void
  • Release all locks for the given process.


    Parameters

    • pid: number

      The process ID to release locks for.

    Returns void

releaseLocksForProcessFd

  • releaseLocksForProcessFd(pid: number, fd: number, nativePath: string): void
  • 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.

    • nativePath: string

    Returns void