Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: don't remove lock on dir when deleting a child node #1335

Merged
merged 1 commit into from
Nov 17, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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