mirror of
https://github.com/sigoden/dufs.git
synced 2026-04-08 16:49:02 +03:00
[GH-ISSUE #413] Upload if hash matches #223
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @zareith on GitHub (Jul 13, 2024).
Original GitHub issue: https://github.com/sigoden/dufs/issues/413
Hello, thanks for creating and open sourcing dufs. This looks really useful.
Specific
DemandRequestIt would be very useful for me if we could have a way to upload file only if the current version matches a specific sha.
The idea is to build a web ui that fetches file from dufs, allows user to edit it and while uploading if the hash doesn't match what we had when receiving we ask user to resolve conflict first.
Implement Suggestion
Similar to how we can do the following for download:
We could support:
and the server fails with an error code if the file has been modified by another user, causing a hash mismatch.
@sigoden commented on GitHub (Jul 13, 2024):
This strategy does not solve the problem. This policy has a race condition that cannot be resolved.
Let me explain:
Assume ClientA and ClientB edit file1 at the same time
ClientA gets hash1 of file1
ClientB gets hash1 of file1
ClientB starts writing file1, hash of file1 still be hash1, read to write
ClientA starts writing file2, hash of file1 still be hash1, read to write
Ops, Two writing at the same time.
Using locks can solve such problems. However, dufs is stateless and doesn't support locks. If you need to support concurrent writes, consider software that provides locking mechanisms.