From 3173ed29df07c7de9da241f43288eca8ca136dc5 Mon Sep 17 00:00:00 2001 From: Olivier Paroz Date: Fri, 2 Oct 2015 23:42:51 +0200 Subject: [PATCH 1/3] The minimum size for internalRootLength is 1 --- lib/private/files/node/folder.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/private/files/node/folder.php b/lib/private/files/node/folder.php index 23004fc3527..00bf738227d 100644 --- a/lib/private/files/node/folder.php +++ b/lib/private/files/node/folder.php @@ -222,7 +222,7 @@ class Folder extends Node implements \OCP\Files\Folder { $results = call_user_func_array(array($cache, $method), $args); foreach ($results as $result) { - if ($internalRootLength === 0 or substr($result['path'], 0, $internalRootLength) === $internalPath) { + if ($internalRootLength === 1 or substr($result['path'], 0, $internalRootLength) === $internalPath) { $result['internalPath'] = $result['path']; $result['path'] = substr($result['path'], $internalRootLength); $result['storage'] = $storage; From e28a2ff8882d4f0369cb32194975fc04a6080cb4 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Tue, 6 Oct 2015 15:02:33 +0200 Subject: [PATCH 2/3] Add unit test for searching in storage root --- tests/lib/files/node/folder.php | 39 +++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/tests/lib/files/node/folder.php b/tests/lib/files/node/folder.php index b30f352847d..8c98256575e 100644 --- a/tests/lib/files/node/folder.php +++ b/tests/lib/files/node/folder.php @@ -421,6 +421,45 @@ class Folder extends \Test\TestCase { $this->assertEquals('/foo', $result[0]->getPath()); } + public function testSearchInStorageRoot() { + $manager = $this->getMock('\OC\Files\Mount\Manager'); + /** + * @var \OC\Files\View | \PHPUnit_Framework_MockObject_MockObject $view + */ + $view = $this->getMock('\OC\Files\View'); + $root = $this->getMock('\OC\Files\Node\Root', array(), array($manager, $view, $this->user)); + $root->expects($this->any()) + ->method('getUser') + ->will($this->returnValue($this->user)); + $storage = $this->getMock('\OC\Files\Storage\Storage'); + $cache = $this->getMock('\OC\Files\Cache\Cache', array(), array('')); + + $storage->expects($this->once()) + ->method('getCache') + ->will($this->returnValue($cache)); + + $cache->expects($this->once()) + ->method('search') + ->with('%qw%') + ->will($this->returnValue(array( + array('fileid' => 3, 'path' => 'foo/qwerty', 'name' => 'qwerty', 'size' => 200, 'mtime' => 55, 'mimetype' => 'text/plain') + ))); + + $root->expects($this->once()) + ->method('getMountsIn') + ->with('/bar') + ->will($this->returnValue(array())); + + $view->expects($this->once()) + ->method('resolvePath') + ->will($this->returnValue(array($storage, ''))); + + $node = new \OC\Files\Node\Folder($root, $view, '/bar'); + $result = $node->search('qw'); + $this->assertEquals(1, count($result)); + $this->assertEquals('/bar/foo/qwerty', $result[0]->getPath()); + } + public function testSearchByTag() { $manager = $this->getMock('\OC\Files\Mount\Manager'); /** From c2d76d201075733a89d5167faf1091e589249a77 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Tue, 6 Oct 2015 15:02:47 +0200 Subject: [PATCH 3/3] fix internal path when searching in storage root --- lib/private/files/node/folder.php | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/lib/private/files/node/folder.php b/lib/private/files/node/folder.php index 00bf738227d..9032c2bfb9d 100644 --- a/lib/private/files/node/folder.php +++ b/lib/private/files/node/folder.php @@ -215,14 +215,17 @@ class Folder extends Node implements \OCP\Files\Folder { * @var \OC\Files\Storage\Storage $storage */ list($storage, $internalPath) = $this->view->resolvePath($this->path); - $internalPath = rtrim($internalPath, '/') . '/'; + $internalPath = rtrim($internalPath, '/'); + if ($internalPath !== '') { + $internalPath = $internalPath . '/'; + } $internalRootLength = strlen($internalPath); $cache = $storage->getCache(''); $results = call_user_func_array(array($cache, $method), $args); foreach ($results as $result) { - if ($internalRootLength === 1 or substr($result['path'], 0, $internalRootLength) === $internalPath) { + if ($internalRootLength === 0 or substr($result['path'], 0, $internalRootLength) === $internalPath) { $result['internalPath'] = $result['path']; $result['path'] = substr($result['path'], $internalRootLength); $result['storage'] = $storage;