Skip to content
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

Preventing write access by multiple users at a time? #286

Open
anaestheticsapp opened this issue Mar 16, 2021 · 5 comments
Open

Preventing write access by multiple users at a time? #286

anaestheticsapp opened this issue Mar 16, 2021 · 5 comments

Comments

@anaestheticsapp
Copy link

There is currently no way to prevent more than one user from writing to a file that is currently being worked on with the Native File System API. This causes a problem when multiple users are editing the same file on a shared network drive. If User B opens a file after user A, user B can save changes whilst user A is still working on the same document. Once user A saves the file, changes made by user B are overwritten, causing data loss.

This is not possible in Excel, for example, where changes to a file are prevented whilst open by another process.

Is there a way to work around this issue?

@jimmywarting
Copy link

Is there a way to work around this issue?

for now maybe try to compare the lastModifiedDate from getFile() before saving?

@slaymaker1907
Copy link

I'm not sure this is a good idea since locking files is not always possible. For example, a network drive or FUSE drive might not provide the ability to lock files.

@ftreesmilo
Copy link

ftreesmilo commented Jul 18, 2021

It would be nice to have an event or some way of checking that a file was edited via an external editor... rather than having to try to read the file and getting error and hoping a retry will work... like #72

@mkruisselbrink
Copy link
Contributor

My hope is that we'll be able to expose the "locking" part of the AccessHandle proposal in #310 for arbitrary files, even if the "in-place" behavior of that API will be limited to files on the origin private file system. There is of course the problem as mentioned that actually locking files might not always be possible, but that might be better than nothing?

@slaymaker1907
Copy link

For anyone looking at this, I've come up with a few ways to implement this at the application level (obviously not ideal since it doesn't prevent external applications from violating the lock guarantees):

  1. Just use the Web Locks API which works across multiple tabs/windows (but not cross browser or with private windows).
  2. Use a consensus protocol like raft to elect a leader thread of execution which manages the lock(s). Care must be taken with this option to handle non-graceful exits (i.e. what happens when you kill one browser process). This option has the advantage of working where web locks work as well as with NFS and other tabs. You could even handle something like Google Drive/OneDrive which normally mess up read/write ordering depending on implementation.

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

No branches or pull requests

5 participants