Skip to content

Conversation

@streamich
Copy link
Owner

Closes #1220
Closes #1018

Copilot AI review requested due to automatic review settings January 18, 2026 11:51
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This pull request implements exclusive file locking for File System Access (FSA) API handles, specifically for FileSystemSyncAccessHandle and FileSystemWritableFileStream. The implementation follows the FSA specification by preventing concurrent access when a file is locked, throwing NoModificationAllowedError when lock acquisition is attempted on an already-locked file.

Changes:

  • Introduced FileLockManager class to manage file locks using a path-to-boolean map
  • Integrated lock checking and acquisition/release into sync access handles and writable streams for both node-to-fsa and core FSA implementations
  • Added comprehensive test coverage for locking behavior across different scenarios

Reviewed changes

Copilot reviewed 16 out of 16 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
src/fsa/FileLockManager.ts New lock manager class with acquire/release/check operations
src/fsa/tests/FileLockManager.test.ts Comprehensive unit tests for FileLockManager
src/fsa/types.ts Added locks field to CoreFsaContext
src/fsa/util.ts Added newNoModificationAllowedError helper and locks to context creation
src/fsa/index.ts Exported FileLockManager class
src/fsa/CoreFileSystemFileHandle.ts Added lock checks before creating sync handles and writable streams
src/fsa/CoreFileSystemSyncAccessHandle.ts Acquires lock in constructor, releases in close()
src/fsa/CoreFileSystemWritableFileStream.ts Acquires lock in start(), releases in close() and abort()
src/fsa/tests/CoreFileSystemFileHandle.test.ts Added comprehensive locking tests
src/node-to-fsa/types.ts Added locks field to NodeFsaContext
src/node-to-fsa/util.ts Added newNoModificationAllowedError helper and locks to context creation
src/node-to-fsa/NodeFileSystemFileHandle.ts Added lock checks before creating sync handles and writable streams
src/node-to-fsa/NodeFileSystemSyncAccessHandle.ts Acquires lock in constructor, releases in close()
src/node-to-fsa/NodeFileSystemWritableFileStream.ts Acquires lock in start(), releases in close() and abort() with error handling
src/node-to-fsa/tests/NodeFileSystemFileHandle.test.ts Added comprehensive locking tests
src/node-to-fsa/tests/NodeFileSystemSyncAccessHandle.test.ts Added locking tests for sync access handles

Comment on lines +1 to +23
export class FileLockManager {
private locks: Map<string, boolean> = new Map();

public acquireLock(path: string): boolean {
if (this.locks.get(path)) {
return false;
}
this.locks.set(path, true);
return true;
}

public releaseLock(path: string): void {
this.locks.delete(path);
}

public isLocked(path: string): boolean {
return this.locks.get(path) ?? false;
}

public clear(): void {
this.locks.clear();
}
}
Copy link

Copilot AI Jan 18, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing documentation: The FileLockManager class and its public methods lack JSDoc comments. Consider adding documentation to explain the purpose of the class, the locking mechanism, and the expected behavior of each method, especially the return value of acquireLock.

Copilot uses AI. Check for mistakes.
@streamich streamich merged commit f119a0a into master Jan 18, 2026
12 checks passed
@streamich streamich deleted the fsa-locks branch January 18, 2026 11:58
@github-actions
Copy link

🎉 This PR is included in version 4.54.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

File System API locking

2 participants