Skip to content

Commit

Permalink
Fix mounting wrapped storages resulting in many-layered wrapping
Browse files Browse the repository at this point in the history
This usually doesn't cause issues, but in unit tests sometimes a wrapped
storage is passed to Filesystem::mount() and gets rewrapped, hitting the
XDebug function nesting level limit when used.
  • Loading branch information
Robin McCorkell committed Mar 20, 2015
1 parent af61c4b commit b96796c
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
7 changes: 6 additions & 1 deletion lib/private/files/mount/mountpoint.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use \OC\Files\Filesystem;
use OC\Files\Storage\StorageFactory;
use OC\Files\Storage\Storage;
use OC\Files\Storage\Wrapper\Wrapper;
use OCP\Files\Mount\IMountPoint;

class MountPoint implements IMountPoint {
Expand Down Expand Up @@ -74,7 +75,11 @@ public function __construct($storage, $mountpoint, $arguments = null, $loader =
$this->mountPoint = $mountpoint;
if ($storage instanceof Storage) {
$this->class = get_class($storage);
$this->storage = $this->loader->wrap($this, $storage);
$this->storage = $storage;
// only wrap if not already wrapped
if (!($this->storage instanceof Wrapper)) {
$this->storage = $this->loader->wrap($this, $this->storage);
}
} else {
// Update old classes to new namespace
if (strpos($storage, 'OC_Filestorage_') !== false) {
Expand Down
21 changes: 21 additions & 0 deletions tests/lib/files/mount/mountpoint.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,25 @@ public function testInvalidStorage() {
// storage wrapper never called
$this->assertFalse($called);
}

public function testWrappedStorage() {
$storage = $this->getMockBuilder('\OC\Files\Storage\Wrapper\Wrapper')
->disableOriginalConstructor()
->getMock();

$loader = $this->getMock('\OCP\Files\Storage\IStorageFactory');
$loader->expects($this->never())
->method('getInstance');
$loader->expects($this->never())
->method('wrap');

$mountPoint = new \OC\Files\Mount\MountPoint(
$storage,
'/mountpoint',
null,
$loader
);

$this->assertEquals($storage, $mountPoint->getStorage());
}
}

0 comments on commit b96796c

Please sign in to comment.