mirror of
https://github.com/nextcloud/server.git
synced 2026-05-28 04:32:30 -04:00
dont needlessly resolve path when getting internalPath/storage from Node
Signed-off-by: Robin Appelman <robin@icewind.nl>
This commit is contained in:
parent
8b12c75ca2
commit
754603a04e
4 changed files with 37 additions and 55 deletions
|
|
@ -154,12 +154,11 @@ class Node implements \OCP\Files\Node {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \OC\Files\Storage\Storage
|
||||
* @throws \OCP\Files\NotFoundException
|
||||
*/
|
||||
public function getStorage() {
|
||||
[$storage,] = $this->view->resolvePath($this->path);
|
||||
$storage = $this->getMountPoint()->getStorage();
|
||||
if (!$storage) {
|
||||
throw new \Exception("No storage for node");
|
||||
}
|
||||
return $storage;
|
||||
}
|
||||
|
||||
|
|
@ -174,8 +173,7 @@ class Node implements \OCP\Files\Node {
|
|||
* @return string
|
||||
*/
|
||||
public function getInternalPath() {
|
||||
[, $internalPath] = $this->view->resolvePath($this->path);
|
||||
return $internalPath;
|
||||
return $this->getFileInfo()->getInternalPath();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -16,8 +16,12 @@ namespace Test\Files\Node;
|
|||
* @package Test\Files\Node
|
||||
*/
|
||||
class FileTest extends NodeTest {
|
||||
protected function createTestNode($root, $view, $path) {
|
||||
return new \OC\Files\Node\File($root, $view, $path);
|
||||
protected function createTestNode($root, $view, $path, array $data = [], $internalPath = '', $storage = null) {
|
||||
if ($data || $internalPath || $storage) {
|
||||
return new \OC\Files\Node\File($root, $view, $path, $this->getFileInfo($data, $internalPath, $storage));
|
||||
} else {
|
||||
return new \OC\Files\Node\File($root, $view, $path);
|
||||
}
|
||||
}
|
||||
|
||||
protected function getNodeClass() {
|
||||
|
|
|
|||
|
|
@ -38,8 +38,12 @@ use OCP\Files\Storage;
|
|||
* @package Test\Files\Node
|
||||
*/
|
||||
class FolderTest extends NodeTest {
|
||||
protected function createTestNode($root, $view, $path) {
|
||||
return new Folder($root, $view, $path);
|
||||
protected function createTestNode($root, $view, $path, array $data = [], $internalPath = '', $storage = null) {
|
||||
if ($data || $internalPath || $storage) {
|
||||
return new Folder($root, $view, $path, $this->getFileInfo($data, $internalPath, $storage));
|
||||
} else {
|
||||
return new Folder($root, $view, $path);
|
||||
}
|
||||
}
|
||||
|
||||
protected function getNodeClass() {
|
||||
|
|
@ -512,9 +516,8 @@ class FolderTest extends NodeTest {
|
|||
->with('/bar/foo')
|
||||
->willReturn([]);
|
||||
|
||||
$root->method('getMount')
|
||||
->with('/bar/foo')
|
||||
->willReturn($mount);
|
||||
$manager->method('getMountsByMountProvider')
|
||||
->willReturn([$mount]);
|
||||
|
||||
$node = new Folder($root, $view, '/bar/foo');
|
||||
$result = $node->getById(1);
|
||||
|
|
@ -559,9 +562,8 @@ class FolderTest extends NodeTest {
|
|||
->with(1)
|
||||
->willReturn($fileInfo);
|
||||
|
||||
$root->method('getMount')
|
||||
->with('/bar')
|
||||
->willReturn($mount);
|
||||
$manager->method('getMountsByMountProvider')
|
||||
->willReturn([$mount]);
|
||||
|
||||
$node = new Folder($root, $view, '/bar');
|
||||
$result = $node->getById(1);
|
||||
|
|
@ -606,13 +608,8 @@ class FolderTest extends NodeTest {
|
|||
->with(1)
|
||||
->willReturn($fileInfo);
|
||||
|
||||
$root->method('getMountsIn')
|
||||
->with('/bar/foo')
|
||||
->willReturn([]);
|
||||
|
||||
$root->method('getMount')
|
||||
->with('/bar/foo')
|
||||
->willReturn($mount);
|
||||
$manager->method('getMountsByMountProvider')
|
||||
->willReturn([$mount]);
|
||||
|
||||
$node = new Folder($root, $view, '/bar/foo');
|
||||
$result = $node->getById(1);
|
||||
|
|
@ -661,13 +658,8 @@ class FolderTest extends NodeTest {
|
|||
->with(1)
|
||||
->willReturn($fileInfo);
|
||||
|
||||
$root->method('getMountsIn')
|
||||
->with('/bar/foo')
|
||||
->willReturn([$mount2]);
|
||||
|
||||
$root->method('getMount')
|
||||
->with('/bar/foo')
|
||||
->willReturn($mount1);
|
||||
$manager->method('getMountsByMountProvider')
|
||||
->willReturn([$mount1, $mount2]);
|
||||
|
||||
$node = new Folder($root, $view, '/bar/foo');
|
||||
$result = $node->getById(1);
|
||||
|
|
|
|||
|
|
@ -13,6 +13,7 @@ use OC\Files\Mount\Manager;
|
|||
use OC\Files\View;
|
||||
use OCP\EventDispatcher\IEventDispatcher;
|
||||
use OCP\Files\IRootFolder;
|
||||
use OCP\Files\Mount\IMountPoint;
|
||||
use OCP\Files\Node;
|
||||
use OCP\Files\NotFoundException;
|
||||
use OCP\Files\Storage;
|
||||
|
|
@ -70,7 +71,7 @@ abstract class NodeTest extends \Test\TestCase {
|
|||
* @param string $path
|
||||
* @return Node
|
||||
*/
|
||||
abstract protected function createTestNode($root, $view, $path);
|
||||
abstract protected function createTestNode($root, $view, $path, array $data = [], $internalPath = '', $storage = null);
|
||||
|
||||
/**
|
||||
* @return string
|
||||
|
|
@ -97,8 +98,11 @@ abstract class NodeTest extends \Test\TestCase {
|
|||
return $storage;
|
||||
}
|
||||
|
||||
protected function getFileInfo($data) {
|
||||
return new FileInfo('', $this->getMockStorage(), '', $data, null);
|
||||
protected function getFileInfo($data, $internalPath = '', $storage = null) {
|
||||
$mount = $this->createMock(IMountPoint::class);
|
||||
$mount->method('getStorage')
|
||||
->willReturn($storage);
|
||||
return new FileInfo('', $this->getMockStorage(), $internalPath, $data, $mount);
|
||||
}
|
||||
|
||||
public function testDelete() {
|
||||
|
|
@ -165,18 +169,13 @@ abstract class NodeTest extends \Test\TestCase {
|
|||
$this->view->expects($this->any())
|
||||
->method('getFileInfo')
|
||||
->with('/bar/foo')
|
||||
->willReturn($this->getFileInfo(['permissions' => \OCP\Constants::PERMISSION_ALL, 'fileid' => 1, 'mimetype' => 'text/plain']));
|
||||
->willReturn($this->getFileInfo(['permissions' => \OCP\Constants::PERMISSION_ALL, 'fileid' => 1, 'mimetype' => 'text/plain'], 'foo'));
|
||||
|
||||
$this->view->expects($this->once())
|
||||
->method($this->getViewDeleteMethod())
|
||||
->with('/bar/foo')
|
||||
->willReturn(true);
|
||||
|
||||
$this->view->expects($this->any())
|
||||
->method('resolvePath')
|
||||
->with('/bar/foo')
|
||||
->willReturn([null, 'foo']);
|
||||
|
||||
$node = $this->createTestNode($root, $this->view, '/bar/foo');
|
||||
$node->delete();
|
||||
$this->assertEquals(2, $hooksRun);
|
||||
|
|
@ -318,13 +317,7 @@ abstract class NodeTest extends \Test\TestCase {
|
|||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$this->view->expects($this->once())
|
||||
->method('resolvePath')
|
||||
->with('/bar/foo')
|
||||
->willReturn([$storage, 'foo']);
|
||||
|
||||
|
||||
$node = $this->createTestNode($this->root, $this->view, '/bar/foo');
|
||||
$node = $this->createTestNode($this->root, $this->view, '/bar/foo', [], 'foo', $storage);
|
||||
$this->assertEquals($storage, $node->getStorage());
|
||||
}
|
||||
|
||||
|
|
@ -349,9 +342,9 @@ abstract class NodeTest extends \Test\TestCase {
|
|||
->getMock();
|
||||
|
||||
$this->view->expects($this->once())
|
||||
->method('resolvePath')
|
||||
->method('getFileInfo')
|
||||
->with('/bar/foo')
|
||||
->willReturn([$storage, 'foo']);
|
||||
->willReturn($this->getFileInfo([], 'foo'));
|
||||
|
||||
|
||||
$node = $this->createTestNode($this->root, $this->view, '/bar/foo');
|
||||
|
|
@ -425,15 +418,10 @@ abstract class NodeTest extends \Test\TestCase {
|
|||
->with('/bar/foo', 100)
|
||||
->willReturn(true);
|
||||
|
||||
$this->view->expects($this->any())
|
||||
->method('resolvePath')
|
||||
->with('/bar/foo')
|
||||
->willReturn([null, 'foo']);
|
||||
|
||||
$this->view->expects($this->any())
|
||||
->method('getFileInfo')
|
||||
->with('/bar/foo')
|
||||
->willReturn($this->getFileInfo(['permissions' => \OCP\Constants::PERMISSION_ALL]));
|
||||
->willReturn($this->getFileInfo(['permissions' => \OCP\Constants::PERMISSION_ALL], 'foo'));
|
||||
|
||||
$node = $this->createTestNode($root, $this->view, '/bar/foo');
|
||||
$node->touch(100);
|
||||
|
|
|
|||
Loading…
Reference in a new issue