UNPKG

ailock

Version:

AI-Proof File Guard - Protect sensitive files from accidental AI modifications

103 lines 2.8 kB
export interface LockInfo { lockId: string; pid: number; timestamp: number; filePath: string; userId: string; checksum?: string; } export interface AtomicOperationOptions { timeout?: number; retries?: number; checkIntegrity?: boolean; backup?: boolean; } /** * Atomic file manager that prevents race conditions and ensures data integrity * during file operations */ export declare class AtomicFileManager { private readonly workingDir; private readonly lockDir; private readonly defaultTimeout; private readonly activeLocks; private readonly lockCleanupTimers; constructor(workingDir?: string); /** * Acquires an exclusive lock on a file with automatic cleanup */ acquireLock(filePath: string, options?: AtomicOperationOptions): Promise<string>; /** * Releases a file lock with validation */ releaseLock(filePath: string, lockId: string): Promise<void>; /** * Performs an atomic write operation with lock protection */ atomicWrite(filePath: string, data: string | Buffer, options?: AtomicOperationOptions): Promise<void>; /** * Performs an atomic read operation with lock protection */ atomicRead(filePath: string, options?: AtomicOperationOptions): Promise<string>; /** * Checks if a file is currently locked */ isFileLocked(filePath: string): Promise<boolean>; /** * Gets information about the current lock on a file */ getLockInfo(filePath: string): Promise<LockInfo | null>; /** * Forces release of a lock (emergency cleanup) */ forceReleaseLock(filePath: string): Promise<void>; /** * Cleans up all locks held by this process */ cleanup(): Promise<void>; /** * Ensure lock directory exists */ private ensureLockDirectory; /** * Get lock directory path */ private getLockDir; /** * Store lock information in metadata file */ private storeLockInfo; /** * Read lock information from metadata file */ private readLockInfo; /** * Remove lock information metadata file */ private removeLockInfo; /** * Calculate file checksum for integrity verification */ private calculateChecksum; /** * Update checksum in lock metadata after write operation */ private updateChecksumAfterWrite; /** * Verify file integrity against stored checksum */ private verifyIntegrity; /** * Create backup of file */ private createBackup; /** * Restore file from backup */ private restoreBackup; /** * Get current user ID for lock tracking */ private getCurrentUserId; } //# sourceMappingURL=AtomicFileManager.d.ts.map