Skip to content

Commit

Permalink
Fix removing locks in recursive mode (#251)
Browse files Browse the repository at this point in the history
* Fix removing locks in recursive mode

* remove explicit statement & force named args

* Fix typo in changelog

* Keeps locks & properties recursion on resources to preserve compatibility with old WEBDAV clients

* tox -e format

Co-authored-by: johaven <johan@sync-in.com>
Co-authored-by: Martin Wendt <mar10@wwwendt.de>
  • Loading branch information
3 people committed Mar 24, 2022
1 parent fcb883b commit 45cd5a2
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 7 deletions.
5 changes: 3 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

## 4.0.2 / Unreleased

- #251 Fix removing locks in recursive mode

## 4.0.1 / 2022-01-11

- #241: Add SSL libs to MSI installer
Expand Down Expand Up @@ -31,8 +33,7 @@

**Other changes**

- Provider root paths are evaluated relative to the location of the configuration
file
- Provider root paths are evaluated relative to the location of the configuration file
- DAVCollection, DAVNonCollection, DAVProvider are now ABCs.
- Deprecate hotfixes.winxp_accept_root_share_login and hotfixes.win_accept_anonymous_options
- DirBrowser supports `?davmount` URLs by default (option `dir_browser.davmount`).
Expand Down
4 changes: 3 additions & 1 deletion wsgidav/dav_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -852,7 +852,9 @@ def is_locked(self):

def remove_all_locks(self, *, recursive):
if self.provider.lock_manager:
self.provider.lock_manager.remove_all_locks_from_url(self.get_ref_url())
self.provider.lock_manager.remove_all_locks_from_url(
self.get_ref_url(), recursive=recursive
)

# --- Read / write -------------------------------------------------------

Expand Down
8 changes: 4 additions & 4 deletions wsgidav/lock_man/lock_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -278,14 +278,14 @@ def is_token_locked_by_user(self, token, principal):
"""Return True, if <token> exists, is valid, and bound to <principal>."""
return self.get_lock(token, key="principal") == principal

def get_url_lock_list(self, url):
def get_url_lock_list(self, url, *, recursive=False):
"""Return list of lock_dict, if <url> is protected by at least one direct, valid lock.
Side effect: expired locks for this url are purged.
"""
url = normalize_lock_root(url)
lockList = self.storage.get_lock_list(
url, include_root=True, include_children=False, token_only=False
url, include_root=True, include_children=recursive, token_only=False
)
return lockList

Expand Down Expand Up @@ -324,10 +324,10 @@ def is_url_locked_by_token(self, url, lock_token):
lockUrl = self.get_lock(lock_token, key="root")
return lockUrl and util.is_equal_or_child_uri(lockUrl, url)

def remove_all_locks_from_url(self, url):
def remove_all_locks_from_url(self, url, *, recursive=False):
self._lock.acquire_write()
try:
lockList = self.get_url_lock_list(url)
lockList = self.get_url_lock_list(url, recursive=recursive)
for lock in lockList:
self.release(lock["token"])
finally:
Expand Down

0 comments on commit 45cd5a2

Please sign in to comment.