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

Fix sharedstorage recursion hell #25799

Merged
merged 4 commits into from
Aug 16, 2016
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
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