Skip to content

Commit dff3614

Browse files
committed
Fix shared lock rejection bug in do_LOCK
Removed blanket rejection of lock requests on already-locked resources. The do_LOCK method was returning 423 for all new lock requests on locked resources without checking lock compatibility. This prevented multiple shared locks from being acquired. The fix delegates compatibility checking to _lock_unlock_create(), which already has logic to validate exclusive vs shared lock conflicts. Changes: - locks.py: Removed lines 157-160 that returned 423 for all lock requests on locked resources - locks.py: Added try/catch around _lock_unlock_create() to handle incompatible lock exceptions Test results: - double_sharedlock (test 27): now passing - Locks test suite: improved from 32/37 to 33/37 (89.2%) Remaining failures (tests 32-34) are related to collection locking, which the code explicitly notes is not yet supported (locks.py:85-87).
1 parent dd687a0 commit dff3614

1 file changed

Lines changed: 17 additions & 17 deletions

File tree

pywebdav/lib/locks.py

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -154,25 +154,25 @@ def do_LOCK(self):
154154
alreadylocked = self._l_isLocked(uri)
155155
log.info('do_LOCK: alreadylocked = %s' % alreadylocked)
156156

157-
if body and alreadylocked:
158-
# Full LOCK request but resource already locked
159-
self.responses[423] = ('Locked', 'Already locked')
160-
return self.send_status(423)
161-
162-
elif body and not ifheader:
157+
if body and not ifheader:
163158
# LOCK with XML information
164159
data = self._lock_unlock_parse(body)
165-
token, result = self._lock_unlock_create(uri, 'unknown', depth, data)
166-
167-
if result:
168-
self.send_body(bytes(result, 'utf-8'), 207, 'Error', 'Error',
169-
'text/xml; charset="utf-8"')
170-
171-
else:
172-
lock = self._l_getLock(token)
173-
self.send_body(bytes(lock.asXML(), 'utf-8'), 200, 'OK', 'OK',
174-
'text/xml; charset="utf-8"',
175-
{'Lock-Token' : '<opaquelocktoken:%s>' % token})
160+
try:
161+
token, result = self._lock_unlock_create(uri, 'unknown', depth, data)
162+
163+
if result:
164+
self.send_body(bytes(result, 'utf-8'), 207, 'Error', 'Error',
165+
'text/xml; charset="utf-8"')
166+
else:
167+
lock = self._l_getLock(token)
168+
self.send_body(bytes(lock.asXML(), 'utf-8'), 200, 'OK', 'OK',
169+
'text/xml; charset="utf-8"',
170+
{'Lock-Token' : '<opaquelocktoken:%s>' % token})
171+
except Exception as e:
172+
# Lock creation failed (e.g., incompatible lock exists)
173+
log.info(f'Lock creation failed: {e}')
174+
self.responses[423] = ('Locked', str(e))
175+
return self.send_status(423)
176176

177177

178178
else:

0 commit comments

Comments
 (0)