skshetry / webdav4

WebDAV client library with a fsspec based filesystem and a CLI.
https://skshetry.github.io/webdav4
MIT License
61 stars 17 forks source link

how to lock a file? #177

Closed BommerG closed 4 months ago

BommerG commented 5 months ago

Hi, we store a KeePass database on webdav (apache with mod_dav). now I want write a script that can add/remove entries from the KeePass database. because this script can be execute by multiple clients, I have to lock the KeePass database during updates to avoid losing data. I was looking through the code of webdav4. I can see that webdav4 can detect locked files, but I can't see how I can lock/unlock a file myself. Kind regards Boomer

skshetry commented 5 months ago
from webdav4.client import Client

client = Client(...)
client.request("lock", path)
client.request("unlock", path)

There are no methods exposed to lock/unlock a resource. But I think the above snippet should work(?)

You can also bypass client and use http.lock and http.unlock primitives.

client = Client(...)
client.http.lock(client.join_url(path))
client.http.unlock(client.join_url(path))
BommerG commented 4 months ago

It is working. Thank you very much.

WebDAV is not straight forward, but the RFC was a great help.