clear mount cache when deleting user

This commit is contained in:
Robin Appelman 2015-12-03 14:10:05 +01:00
parent 99415a9f7f
commit be380accb9
4 changed files with 101 additions and 18 deletions

View File

@ -195,4 +195,17 @@ class UserMountCache implements IUserMountCache {
return array_map([$this, 'dbRowToMountInfo'], $rows);
}
/**
* Remove all cached mounts for a user
*
* @param IUser $user
*/
public function removeUserMounts(IUser $user) {
$builder = $this->connection->getQueryBuilder();
$query = $builder->delete('mounts')
->where($builder->expr()->eq('user_id', $builder->createNamedParameter($user->getUID())));
$query->execute();
}
}

View File

@ -0,0 +1,48 @@
<?php
/**
* @author Robin Appelman <icewind@owncloud.com>
*
* @copyright Copyright (c) 2015, 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\User\Manager;
use OCP\Files\Config\IUserMountCache;
/**
* Listen to hooks and update the mount cache as needed
*/
class UserMountCacheListener {
/**
* @var IUserMountCache
*/
private $userMountCache;
/**
* UserMountCacheListener constructor.
*
* @param IUserMountCache $userMountCache
*/
public function __construct(IUserMountCache $userMountCache) {
$this->userMountCache = $userMountCache;
}
public function listen(Manager $manager) {
$manager->listen('\OC\User', 'postDelete', [$this->userMountCache, 'removeUserMounts']);
}
}

View File

@ -48,6 +48,7 @@ use OC\Diagnostics\NullEventLogger;
use OC\Diagnostics\NullQueryLogger;
use OC\Diagnostics\QueryLogger;
use OC\Files\Config\UserMountCache;
use OC\Files\Config\UserMountCacheListener;
use OC\Files\Node\HookConnector;
use OC\Files\Node\Root;
use OC\Files\View;
@ -137,7 +138,7 @@ class Server extends ServerContainer implements IServerContainer {
return new Encryption\Keys\Storage($view, $util);
});
$this->registerService('TagMapper', function(Server $c) {
$this->registerService('TagMapper', function (Server $c) {
return new TagMapper($c->getDatabaseConnection());
});
$this->registerService('TagManager', function (Server $c) {
@ -266,13 +267,13 @@ class Server extends ServerContainer implements IServerContainer {
$this->registerService('MemCacheFactory', function (Server $c) {
$config = $c->getConfig();
if($config->getSystemValue('installed', false) && !(defined('PHPUNIT_RUN') && PHPUNIT_RUN)) {
if ($config->getSystemValue('installed', false) && !(defined('PHPUNIT_RUN') && PHPUNIT_RUN)) {
$v = \OC_App::getAppVersions();
$v['core'] = md5(file_get_contents(\OC::$SERVERROOT . '/version.php'));
$version = implode(',', $v);
$instanceId = \OC_Util::getInstanceId();
$path = \OC::$SERVERROOT;
$prefix = md5($instanceId.'-'.$version.'-'.$path);
$prefix = md5($instanceId . '-' . $version . '-' . $path);
return new \OC\Memcache\Factory($prefix, $c->getLogger(),
$config->getSystemValue('memcache.local', null),
$config->getSystemValue('memcache.distributed', null),
@ -383,7 +384,7 @@ class Server extends ServerContainer implements IServerContainer {
$c->getConfig()
);
});
$this->registerService('AppManager', function(Server $c) {
$this->registerService('AppManager', function (Server $c) {
return new \OC\App\AppManager(
$c->getUserSession(),
$c->getAppConfig(),
@ -391,13 +392,13 @@ class Server extends ServerContainer implements IServerContainer {
$c->getMemCacheFactory()
);
});
$this->registerService('DateTimeZone', function(Server $c) {
$this->registerService('DateTimeZone', function (Server $c) {
return new DateTimeZone(
$c->getConfig(),
$c->getSession()
);
});
$this->registerService('DateTimeFormatter', function(Server $c) {
$this->registerService('DateTimeFormatter', function (Server $c) {
$language = $c->getConfig()->getUserValue($c->getSession()->get('user_id'), 'core', 'lang', null);
return new DateTimeFormatter(
@ -405,9 +406,15 @@ class Server extends ServerContainer implements IServerContainer {
$c->getL10N('lib', $language)
);
});
$this->registerService('UserMountCache', function (Server $c) {
$mountCache = new UserMountCache($c->getDatabaseConnection(), $c->getUserManager(), $c->getLogger());
$listener = new UserMountCacheListener($mountCache);
$listener->listen($c->getUserManager());
return $mountCache;
});
$this->registerService('MountConfigManager', function (Server $c) {
$loader = \OC\Files\Filesystem::getLoader();
$mountCache = new UserMountCache($c->getDatabaseConnection(), $c->getUserManager(), $c->getLogger());
$mountCache = $c->query('UserMountCache');
return new \OC\Files\Config\MountProviderCollection($loader, $mountCache);
});
$this->registerService('IniWrapper', function ($c) {
@ -480,14 +487,14 @@ class Server extends ServerContainer implements IServerContainer {
$stream
);
});
$this->registerService('Mailer', function(Server $c) {
$this->registerService('Mailer', function (Server $c) {
return new Mailer(
$c->getConfig(),
$c->getLogger(),
new \OC_Defaults()
);
});
$this->registerService('OcsClient', function(Server $c) {
$this->registerService('OcsClient', function (Server $c) {
return new OCSClient(
$this->getHTTPClientService(),
$this->getConfig(),
@ -509,24 +516,24 @@ class Server extends ServerContainer implements IServerContainer {
$this->registerService('MountManager', function () {
return new \OC\Files\Mount\Manager();
});
$this->registerService('MimeTypeDetector', function(Server $c) {
$this->registerService('MimeTypeDetector', function (Server $c) {
return new \OC\Files\Type\Detection(
$c->getURLGenerator(),
\OC::$SERVERROOT . '/config/',
\OC::$SERVERROOT . '/resources/config/'
);
);
});
$this->registerService('MimeTypeLoader', function(Server $c) {
$this->registerService('MimeTypeLoader', function (Server $c) {
return new \OC\Files\Type\Loader(
$c->getDatabaseConnection()
);
});
$this->registerService('NotificationManager', function() {
$this->registerService('NotificationManager', function () {
return new Manager();
});
$this->registerService('CapabilitiesManager', function (Server $c) {
$manager = new \OC\CapabilitiesManager();
$manager->registerCapability(function() use ($c) {
$manager->registerCapability(function () use ($c) {
return new \OC\OCS\CoreCapabilities($c->getConfig());
});
return $manager;
@ -538,7 +545,7 @@ class Server extends ServerContainer implements IServerContainer {
$factory = new $factoryClass();
return $factory->getManager();
});
$this->registerService('EventDispatcher', function() {
$this->registerService('EventDispatcher', function () {
return new EventDispatcher();
});
$this->registerService('CryptoWrapper', function (Server $c) {
@ -923,6 +930,7 @@ class Server extends ServerContainer implements IServerContainer {
/**
* Returns an instance of the db facade
*
* @deprecated use getDatabaseConnection, will be removed in ownCloud 10
* @return \OCP\IDb
*/
@ -932,6 +940,7 @@ class Server extends ServerContainer implements IServerContainer {
/**
* Returns an instance of the HTTP helper class
*
* @deprecated Use getHTTPClientService()
* @return \OC\HTTPHelper
*/
@ -1057,7 +1066,7 @@ class Server extends ServerContainer implements IServerContainer {
/**
* @return \OCP\Files\Config\IMountProviderCollection
*/
public function getMountProviderCollection(){
public function getMountProviderCollection() {
return $this->query('MountConfigManager');
}
@ -1073,7 +1082,7 @@ class Server extends ServerContainer implements IServerContainer {
/**
* @return \OCP\Command\IBus
*/
public function getCommandBus(){
public function getCommandBus() {
return $this->query('AsyncCommandBus');
}
@ -1173,6 +1182,7 @@ class Server extends ServerContainer implements IServerContainer {
/**
* Not a public API as of 8.2, wait for 9.0
*
* @return \OCA\Files_External\Service\BackendService
*/
public function getStoragesBackendService() {
@ -1181,6 +1191,7 @@ class Server extends ServerContainer implements IServerContainer {
/**
* Not a public API as of 8.2, wait for 9.0
*
* @return \OCA\Files_External\Service\GlobalStoragesService
*/
public function getGlobalStoragesService() {
@ -1189,6 +1200,7 @@ class Server extends ServerContainer implements IServerContainer {
/**
* Not a public API as of 8.2, wait for 9.0
*
* @return \OCA\Files_External\Service\UserGlobalStoragesService
*/
public function getUserGlobalStoragesService() {
@ -1197,6 +1209,7 @@ class Server extends ServerContainer implements IServerContainer {
/**
* Not a public API as of 8.2, wait for 9.0
*
* @return \OCA\Files_External\Service\UserStoragesService
*/
public function getUserStoragesService() {
@ -1210,4 +1223,5 @@ class Server extends ServerContainer implements IServerContainer {
public function getShareManager() {
return $this->query('ShareManager');
}
}

View File

@ -31,7 +31,7 @@ use OCP\IUser;
*/
interface IUserMountCache {
/**
* Register a mount for a user to the cache
* Register mounts for a user to the cache
*
* @param IUser $user
* @param IMountPoint[] $mounts
@ -59,4 +59,12 @@ interface IUserMountCache {
* @since 9.0.0
*/
public function getMountsForRootId($rootFileId);
/**
* Remove all cached mounts for a user
*
* @param IUser $user
* @since 9.0.0
*/
public function removeUserMounts(IUser $user);
}