Skip to content

Commit

Permalink
Merge pull request #25799 from owncloud/fix-sharedstorage-recursion-hell
Browse files Browse the repository at this point in the history
Fix sharedstorage recursion hell
  • Loading branch information
Vincent Petry authored Aug 16, 2016
2 parents ee44683 + 40e66cc commit 9975240
Show file tree
Hide file tree
Showing 6 changed files with 146 additions and 108 deletions.
9 changes: 9 additions & 0 deletions apps/files_sharing/lib/SharedMount.php
Original file line number Diff line number Diff line change
Expand Up @@ -234,4 +234,13 @@ public function getShare() {
public function getStorageRootId() {
return $this->getShare()->getNodeId();
}

public function getStorageNumericId() {
$query = \OC::$server->getDatabaseConnection()->getQueryBuilder();
$query->select('storage')
->from('filecache')
->where($query->expr()->eq('fileid', $query->createNamedParameter($this->getStorageRootId())));

return $query->execute()->fetchColumn();
}
}
23 changes: 15 additions & 8 deletions apps/files_sharing/lib/sharedstorage.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
use OCP\Files\Cache\ICacheEntry;
use OCP\Files\Storage\IStorage;
use OCP\Lock\ILockingProvider;
use OC\Files\Storage\FailedStorage;

/**
* Convert target path to source path and pass the function call to the correct storage provider
Expand Down Expand Up @@ -82,13 +83,9 @@ public function __construct($arguments) {

$this->user = $arguments['user'];

Filesystem::initMountPoints($this->superShare->getShareOwner());
$sourcePath = $this->ownerView->getPath($this->superShare->getNodeId());
list($storage, $internalPath) = $this->ownerView->resolvePath($sourcePath);

parent::__construct([
'storage' => $storage,
'root' => $internalPath,
'storage' => null, // init later
'root' => null, // init later
]);
}

Expand All @@ -99,12 +96,17 @@ private function init() {
$this->initialized = true;
try {
Filesystem::initMountPoints($this->superShare->getShareOwner());
$sourcePath = $this->ownerView->getPath($this->superShare->getNodeId());
$sourcePath = $this->ownerView->getPath($this->superShare->getNodeId(), false);
list($this->sourceStorage, $sourceInternalPath) = $this->ownerView->resolvePath($sourcePath);
$this->sourceRootInfo = $this->sourceStorage->getCache()->get($sourceInternalPath);
// adjust jail
$this->rootPath = $sourceInternalPath;

} catch (\Exception $e) {
$this->sourceStorage = new FailedStorage(['exception' => $e]);
$this->logger->logException($e);
}
$this->storage = $this->sourceStorage;
}

/**
Expand Down Expand Up @@ -311,7 +313,7 @@ public function getItemType() {

public function getCache($path = '', $storage = null) {
$this->init();
if (is_null($this->sourceStorage)) {
if (is_null($this->sourceStorage) || $this->sourceStorage instanceof FailedStorage) {
return new FailedCache(false);
}
if (!$storage) {
Expand Down Expand Up @@ -439,4 +441,9 @@ public function file_put_contents($path, $data) {
return parent::file_put_contents($path, $data);
}

public function getWrapperStorage() {
$this->init();

return $this->sourceStorage;
}
}
12 changes: 8 additions & 4 deletions lib/private/Files/Config/LazyStorageMountInfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,15 @@ public function __construct(IUser $user, IMountPoint $mount) {
*/
public function getStorageId() {
if (!$this->storageId) {
$storage = $this->mount->getStorage();
if (!$storage) {
return -1;
if (method_exists($this->mount, 'getStorageNumericId')) {
$this->storageId = $this->mount->getStorageNumericId();
} else {
$storage = $this->mount->getStorage();
if (!$storage) {
return -1;
}
$this->storageId = $storage->getStorageCache()->getNumericId();
}
$this->storageId = $storage->getStorageCache()->getNumericId();
}
return parent::getStorageId();
}
Expand Down
Loading

0 comments on commit 9975240

Please sign in to comment.