diff --git a/apps/dav/lib/Connector/Sabre/CopyEtagHeaderPlugin.php b/apps/dav/lib/Connector/Sabre/CopyEtagHeaderPlugin.php index 9d58b25aa5acd..0da15c113eeb8 100644 --- a/apps/dav/lib/Connector/Sabre/CopyEtagHeaderPlugin.php +++ b/apps/dav/lib/Connector/Sabre/CopyEtagHeaderPlugin.php @@ -25,6 +25,7 @@ namespace OCA\DAV\Connector\Sabre; +use Sabre\DAV\Exception\NotFound; use Sabre\HTTP\RequestInterface; use Sabre\HTTP\ResponseInterface; @@ -74,7 +75,13 @@ public function afterMethod(RequestInterface $request, ResponseInterface $respon * @return void */ public function afterMove($source, $destination) { - $node = $this->server->tree->getNodeForPath($destination); + try { + $node = $this->server->tree->getNodeForPath($destination); + } catch (NotFound $e) { + // Don't care + return; + } + if ($node instanceof File) { $eTag = $node->getETag(); $this->server->httpResponse->setHeader('OC-ETag', $eTag); diff --git a/apps/dav/tests/unit/Connector/Sabre/CopyEtagHeaderPluginTest.php b/apps/dav/tests/unit/Connector/Sabre/CopyEtagHeaderPluginTest.php index 487fb2b628563..010d8af5a6629 100644 --- a/apps/dav/tests/unit/Connector/Sabre/CopyEtagHeaderPluginTest.php +++ b/apps/dav/tests/unit/Connector/Sabre/CopyEtagHeaderPluginTest.php @@ -29,6 +29,7 @@ use OCA\DAV\Connector\Sabre\CopyEtagHeaderPlugin; use OCA\DAV\Connector\Sabre\File; +use Sabre\DAV\Exception\NotFound; use Sabre\DAV\Server; use Sabre\DAV\Tree; use Test\TestCase; @@ -73,6 +74,19 @@ public function testNoopWhenEmpty() { $this->assertNull($response->getHeader('OC-Etag')); } + public function testAfterMoveNodeNotFound(): void { + $tree = $this->createMock(Tree::class); + $tree->expects(self::once()) + ->method('getNodeForPath') + ->with('test.txt') + ->willThrowException(new NotFound()); + + $this->server->tree = $tree; + $this->plugin->afterMove('', 'test.txt'); + + // Nothing to assert, we are just testing if the exception is handled + } + public function testAfterMove() { $node = $this->getMockBuilder(File::class) ->disableOriginalConstructor()