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

[stable10] Handle invalid storage when getting storage root id #29278

Merged
merged 1 commit into from
Oct 19, 2017
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
15 changes: 13 additions & 2 deletions lib/private/Files/Mount/MountPoint.php
Original file line number Diff line number Diff line change
Expand Up @@ -245,9 +245,20 @@ public function getOptions() {
/**
* Get the file id of the root of the storage
*
* @return int
* @return int storage numeric id or -1 in case of invalid storage
*/
public function getStorageRootId() {
return (int)$this->getStorage()->getCache()->getId('');
$storage = $this->getStorage();
if ($storage === null || $this->invalidStorage) {
return -1;
}

$cache = $storage->getCache();

if ($cache === null) {
return -1;
}

return (int)$cache->getId('');
}
}
2 changes: 1 addition & 1 deletion lib/public/Files/Mount/IMountPoint.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ public function getOptions();
/**
* Get the file id of the root of the storage
*
* @return int
* @return int storage numeric id or -1 in case of invalid storage
* @since 9.1.0
*/
public function getStorageRootId();
Expand Down
37 changes: 35 additions & 2 deletions tests/lib/Files/Mount/MountPointTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,18 @@
class MountPointTest extends \Test\TestCase {

public function testGetStorage() {
$cache = $this->createMock('\OC\Files\Cache\Cache');
$cache->expects($this->once())
->method('getId')
->will($this->returnValue(123));

$storage = $this->createMock('\OCP\Files\Storage');
$storage->expects($this->once())
->method('getId')
->will($this->returnValue(123));
->will($this->returnValue('home:12345'));
$storage->expects($this->any())
->method('getCache')
->will($this->returnValue($cache));

$loader = $this->createMock('\OCP\Files\Storage\IStorageFactory');
$loader->expects($this->once())
Expand All @@ -30,7 +38,8 @@ public function testGetStorage() {
);

$this->assertEquals($storage, $mountPoint->getStorage());
$this->assertEquals(123, $mountPoint->getStorageId());
$this->assertEquals('home:12345', $mountPoint->getStorageId());
$this->assertEquals(123, $mountPoint->getStorageRootId());
$this->assertEquals('/mountpoint/', $mountPoint->getMountPoint());

$mountPoint->setMountPoint('another');
Expand Down Expand Up @@ -67,7 +76,31 @@ public function testInvalidStorage() {

$this->assertNull($mountPoint->getStorage());

$this->assertEquals(-1, $mountPoint->getStorageRootId());

// storage wrapper never called
$this->assertFalse($called);
}

public function testGetRootIdNullCache() {
$storage = $this->createMock('\OCP\Files\Storage');
$storage->expects($this->any())
->method('getCache')
->will($this->returnValue(null));

$loader = $this->createMock('\OCP\Files\Storage\IStorageFactory');
$loader->expects($this->once())
->method('getInstance')
->will($this->returnValue($storage));

$mountPoint = new \OC\Files\Mount\MountPoint(
// just use this because a real class is needed
'\Test\Files\Mount\MountPointTest',
'/mountpoint',
null,
$loader
);

$this->assertEquals(-1, $mountPoint->getStorageRootId());
}
}