-
Notifications
You must be signed in to change notification settings - Fork 5.6k
Feature Request: Add APIs for locking files #11511
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
I like the idea alot. and it seems really handy to have. How would the "shared" and "exclusive" mode work? |
Shared mode is like a read only lock, while exclusive mode is like a read-write lock (i.e. multiple shared locks can be held at once, but only one exclusive lock can be held at once). Note, however, that the locks don't actually prevent you from reading and writing to the file (depending on your OS). This means the processes using the file need to agree to observe the locks to coordinate. (Much like having a |
We should add those APIs, but |
I couldn't find anything about a file lock system in rust std but I did find this crate https://crates.io/crates/fd-lock |
Yes, this looks good |
idk if it is any relevant. But I also found this experimental web api for locking resources https://developer.mozilla.org/en-US/docs/Web/API/Web_Locks_API |
I think sticking closer to the existing fXXX APIs in the Deno namespace makes more sense. The web locks api is a lot more high level, and would eg not work very well for implementing file locking with SQLite (where a lock needs to be acquired and then passed off to WASM). I think the web locks api could be built on the more primitive “acquire the lock” and “release the lock” functions and the interface could be included in deno_std/fs. |
Here are some examples for reference: Golang implement: https://pkg.go.dev/cmd/go/internal/lockedfile/internal/filelock |
One concern I have with this crate is that their API (while very nice for the intended usage within a larger rust program) uses RAII guards for the locks, while we probably would want to expose a more low-level API (certainly for use within something like an SQLite VFS). Having to keep track of locks using a collection of those guard types might be awkward and would probably duplicate some book-keeping the filesystem is doing already. |
Add sync and async APIs to the
Deno
namespace which allow to acquire (advisory) file-system locks. The API could look something like this:One possible good candidate for implementing those on the Rust side would be the fs3 crate.
The motivation for having these APIs is that they would enable synchronization between different processes which access the same file. In particular, this functionality would enable the https://deno.land/x/sqlite library to provide the complete set of persistence guarantees native SQLite offers.
The text was updated successfully, but these errors were encountered: