-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
[stable9] Backport lazy init of shared storage/mount #26912
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
<?php | ||
/** | ||
* @author Robin Appelman <icewind@owncloud.com> | ||
* | ||
* @copyright Copyright (c) 2016, ownCloud, Inc. | ||
* @license AGPL-3.0 | ||
* | ||
* This code is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License, version 3, | ||
* as published by the Free Software Foundation. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License, version 3, | ||
* along with this program. If not, see <http://www.gnu.org/licenses/> | ||
* | ||
*/ | ||
|
||
namespace OC\Files\Config; | ||
|
||
use OC\Files\Filesystem; | ||
use OCP\Files\Config\ICachedMountInfo; | ||
use OCP\Files\Mount\IMountPoint; | ||
use OCP\Files\Node; | ||
use OCP\IUser; | ||
|
||
class LazyStorageMountInfo extends CachedMountInfo { | ||
/** @var IMountPoint */ | ||
private $mount; | ||
|
||
/** | ||
* CachedMountInfo constructor. | ||
* | ||
* @param IUser $user | ||
* @param IMountPoint $mount | ||
*/ | ||
public function __construct(IUser $user, IMountPoint $mount) { | ||
$this->user = $user; | ||
$this->mount = $mount; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we have to call the parent constructor. The parent might not be properly initialized otherwise and could cause issues. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This was backported from 9.1 which didn't call the parent either (not my code), I hope it had a good reason |
||
} | ||
|
||
/** | ||
* @return int the numeric storage id of the mount | ||
*/ | ||
public function getStorageId() { | ||
if (!$this->storageId) { | ||
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(); | ||
} | ||
} | ||
return parent::getStorageId(); | ||
} | ||
|
||
/** | ||
* @return int the fileid of the root of the mount | ||
*/ | ||
public function getRootId() { | ||
if (!$this->rootId) { | ||
$this->rootId = $this->mount->getStorageRootId(); | ||
} | ||
return parent::getRootId(); | ||
} | ||
|
||
/** | ||
* @return string the mount point of the mount for the user | ||
*/ | ||
public function getMountPoint() { | ||
if (!$this->mountPoint) { | ||
$this->mountPoint = $this->mount->getMountPoint(); | ||
} | ||
return parent::getMountPoint(); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -91,18 +91,18 @@ public function registerMounts(IUser $user, array $mounts) { | |
}); | ||
/** @var ICachedMountInfo[] $newMounts */ | ||
$newMounts = array_map(function (IMountPoint $mount) use ($user) { | ||
$storage = $mount->getStorage(); | ||
if ($storage->instanceOfStorage('\OC\Files\Storage\Shared')) { | ||
$rootId = (int)$storage->getShare()['file_source']; | ||
// note: SharedMount goes there | ||
if (method_exists($mount, 'getStorageRootId')) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why is this necessary? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah, i didn't think about that! Makes sense then! |
||
$rootId = $mount->getStorageRootId(); | ||
} else { | ||
$storage = $mount->getStorage(); | ||
$rootId = (int)$storage->getCache()->getId(''); | ||
} | ||
$storageId = (int)$storage->getStorageCache()->getNumericId(); | ||
// filter out any storages which aren't scanned yet since we aren't interested in files from those storages (yet) | ||
if ($rootId === -1) { | ||
return null; | ||
} else { | ||
return new CachedMountInfo($user, $storageId, $rootId, $mount->getMountPoint()); | ||
return new LazyStorageMountInfo($user, $mount); | ||
} | ||
}, $mounts); | ||
$newMounts = array_values(array_filter($newMounts)); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -58,6 +58,7 @@ | |
use OCP\IUser; | ||
use OCP\Lock\ILockingProvider; | ||
use OCP\Lock\LockedException; | ||
use OCA\Files_Sharing\SharedMount; | ||
|
||
/** | ||
* Class to provide access to ownCloud filesystem via a "view", and methods for | ||
|
@@ -1648,10 +1649,11 @@ public function getETag($path) { | |
* Note that the resulting path is not guarantied to be unique for the id, multiple paths can point to the same file | ||
* | ||
* @param int $id | ||
* @param bool $includeShares whether to recurse into shared mounts | ||
* @throws NotFoundException | ||
* @return string | ||
*/ | ||
public function getPath($id) { | ||
public function getPath($id, $includeShares = true) { | ||
$id = (int)$id; | ||
$manager = Filesystem::getMountManager(); | ||
$mounts = $manager->findIn($this->fakeRoot); | ||
|
@@ -1663,6 +1665,11 @@ public function getPath($id) { | |
/** | ||
* @var \OC\Files\Mount\MountPoint $mount | ||
*/ | ||
if (!$includeShares && $mount instanceof SharedMount) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure if this will be enough to prevent the infinite loop There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This was enough on 9.1, at least for known cases |
||
// prevent potential infinite loop when instantiating shared storages | ||
// recursively | ||
continue; | ||
} | ||
if ($mount->getStorage()) { | ||
$cache = $mount->getStorage()->getCache(); | ||
$internalPath = $cache->getPathById($id); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should check if the "share" key is present and throw an error otherwise.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed