Skip to content

Conversation

yschimke
Copy link
Collaborator

@yschimke yschimke commented Aug 8, 2025

This commit introduces file locking capabilities to the Okio FileSystem.

For discussion of #1464

TODO

  • Consider blocking for availability
  • Demonstrate API for reading/writing exclusively within a lock. Fail if outside.
  • Consider upgrade from Shared to Exclusive
  • Implement for Node - npm proper-lockfile ?

Key changes:

  • Added FileSystem.lock() method to acquire exclusive or shared locks on files.
  • Implemented FileLock interface for managing lock state and lifecycle.
  • Provided JVM-specific implementation using java.nio.channels.FileChannel.lock().
  • Added FakeFileSystemLock for testing purposes.
  • Included base and platform-specific tests for file locking functionality.
  • Default implementations in common, JS, Native, and Wasm FileSystem throw IOException as locking is not supported on these platforms by default.
  • Updated NioFileSystemWrappingFileSystem and JvmSystemFileSystem to delegate to the new locking mechanism.

This commit introduces file locking capabilities to the Okio FileSystem.

Key changes:
- Added `FileSystem.lock()` method to acquire exclusive or shared locks on files.
- Implemented `FileLock` interface for managing lock state and lifecycle.
- Provided JVM-specific implementation using `java.nio.channels.FileChannel.lock()`.
- Added `FakeFileSystemLock` for testing purposes.
- Included base and platform-specific tests for file locking functionality.
- Default implementations in common, JS, Native, and Wasm `FileSystem` throw `IOException` as locking is not supported on these platforms by default.
- Updated `NioFileSystemWrappingFileSystem` and `JvmSystemFileSystem` to delegate to the new locking mechanism.
@yschimke yschimke requested a review from swankjesse August 8, 2025 21:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant