Skip to content

Commit 75e3e88

Browse files
authored
Merge pull request #1335 from tbsmark86/fix-parent-lock
Fix: don't remove lock on dir when deleting a child node
2 parents ba97a9f + 76d6592 commit 75e3e88

File tree

2 files changed

+43
-0
lines changed

2 files changed

+43
-0
lines changed

lib/DAV/Locks/Plugin.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,10 @@ public function afterUnbind($path)
295295
{
296296
$locks = $this->getLocks($path, $includeChildren = true);
297297
foreach ($locks as $lock) {
298+
// don't delete a lock on a parent dir
299+
if (0 !== strpos($lock->uri, $path)) {
300+
continue;
301+
}
298302
$this->unlockNode($path, $lock);
299303
}
300304
}

tests/Sabre/DAV/Locks/PluginTest.php

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -521,6 +521,45 @@ public function testLockDeleteSucceed()
521521
$this->assertEquals('application/xml; charset=utf-8', $this->response->getHeader('Content-Type'));
522522
}
523523

524+
/**
525+
* @depends testLock
526+
* Similar to testLockDeleteParent but don't lock the file but the Parent-DIR.
527+
*/
528+
public function testParentLockDelete()
529+
{
530+
$request = new HTTP\Request('LOCK', '/dir/');
531+
$request->setBody('<?xml version="1.0"?>
532+
<D:lockinfo xmlns:D="DAV:">
533+
<D:lockscope><D:exclusive/></D:lockscope>
534+
<D:locktype><D:write/></D:locktype>
535+
<D:owner>
536+
<D:href>http://example.org/~ejw/contact.html</D:href>
537+
</D:owner>
538+
</D:lockinfo>');
539+
540+
$this->server->httpRequest = $request;
541+
$this->server->exec();
542+
543+
$this->assertEquals(200, $this->response->status);
544+
$lockToken = $this->response->getHeader('Lock-Token');
545+
546+
$request = new HTTP\Request('DELETE', '/dir/child.txt', [
547+
'If' => '('.$lockToken.')',
548+
]);
549+
$this->server->httpRequest = $request;
550+
$this->server->exec();
551+
552+
$this->assertEquals(204, $this->response->status);
553+
554+
// verify that the LOCK on /dir/ itself continues to exist by unlocking:
555+
$request = new HTTP\Request('UNLOCK', '/dir/', ['Lock-Token' => $lockToken]);
556+
$this->server->httpRequest = $request;
557+
$this->server->httpResponse = new HTTP\ResponseMock();
558+
$this->server->invokeMethod($request, $this->server->httpResponse);
559+
560+
$this->assertEquals(204, $this->server->httpResponse->status, 'Got an incorrect status code. Full response body: '.$this->response->getBodyAsString());
561+
}
562+
524563
/**
525564
* @depends testLock
526565
*/

0 commit comments

Comments
 (0)