Skip to content

Commit

Permalink
Fix: don't remove lock on dir when deleting a child node
Browse files Browse the repository at this point in the history
  • Loading branch information
Tobias authored and phil-davis committed Nov 16, 2021
1 parent ba97a9f commit 76d6592
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/DAV/Locks/Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,10 @@ public function afterUnbind($path)
{
$locks = $this->getLocks($path, $includeChildren = true);
foreach ($locks as $lock) {
// don't delete a lock on a parent dir
if (0 !== strpos($lock->uri, $path)) {
continue;
}
$this->unlockNode($path, $lock);
}
}
Expand Down
39 changes: 39 additions & 0 deletions tests/Sabre/DAV/Locks/PluginTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -521,6 +521,45 @@ public function testLockDeleteSucceed()
$this->assertEquals('application/xml; charset=utf-8', $this->response->getHeader('Content-Type'));
}

/**
* @depends testLock
* Similar to testLockDeleteParent but don't lock the file but the Parent-DIR.
*/
public function testParentLockDelete()
{
$request = new HTTP\Request('LOCK', '/dir/');
$request->setBody('<?xml version="1.0"?>
<D:lockinfo xmlns:D="DAV:">
<D:lockscope><D:exclusive/></D:lockscope>
<D:locktype><D:write/></D:locktype>
<D:owner>
<D:href>http://example.org/~ejw/contact.html</D:href>
</D:owner>
</D:lockinfo>');

$this->server->httpRequest = $request;
$this->server->exec();

$this->assertEquals(200, $this->response->status);
$lockToken = $this->response->getHeader('Lock-Token');

$request = new HTTP\Request('DELETE', '/dir/child.txt', [
'If' => '('.$lockToken.')',
]);
$this->server->httpRequest = $request;
$this->server->exec();

$this->assertEquals(204, $this->response->status);

// verify that the LOCK on /dir/ itself continues to exist by unlocking:
$request = new HTTP\Request('UNLOCK', '/dir/', ['Lock-Token' => $lockToken]);
$this->server->httpRequest = $request;
$this->server->httpResponse = new HTTP\ResponseMock();
$this->server->invokeMethod($request, $this->server->httpResponse);

$this->assertEquals(204, $this->server->httpResponse->status, 'Got an incorrect status code. Full response body: '.$this->response->getBodyAsString());
}

/**
* @depends testLock
*/
Expand Down

0 comments on commit 76d6592

Please sign in to comment.