handle changed mount points

This commit is contained in:
Robin Appelman 2016-01-11 13:06:10 +01:00
parent be380accb9
commit bc7bd0cd05
1 changed files with 23 additions and 1 deletions

View File

@ -96,6 +96,14 @@ class UserMountCache implements IUserMountCache {
/** @var ICachedMountInfo[] $removedMounts */
$removedMounts = array_udiff($cachedMounts, $newMounts, $mountDiff);
$changedMounts = array_uintersect($newMounts, $cachedMounts, function (ICachedMountInfo $mount1, ICachedMountInfo $mount2) {
// filter mounts with the same root id and different mountpoints
if ($mount1->getRootId() !== $mount2->getRootId()) {
return -1;
}
return ($mount1->getMountPoint() !== $mount2->getMountPoint()) ? 0 : 1;
});
foreach ($addedMounts as $mount) {
$this->addToCache($mount);
$this->mountsForUsers[$user->getUID()][] = $mount;
@ -105,6 +113,9 @@ class UserMountCache implements IUserMountCache {
$index = array_search($mount, $this->mountsForUsers[$user->getUID()]);
unset($this->mountsForUsers[$user->getUID()][$index]);
}
foreach ($changedMounts as $mount) {
$this->setMountPoint($mount);
}
}
private function addToCache(ICachedMountInfo $mount) {
@ -134,6 +145,17 @@ class UserMountCache implements IUserMountCache {
}
}
private function setMountPoint(ICachedMountInfo $mount) {
$builder = $this->connection->getQueryBuilder();
$query = $builder->update('mounts')
->set('mount_point', $builder->createNamedParameter($mount->getMountPoint()))
->where($builder->expr()->eq('user_id', $builder->createNamedParameter($mount->getUser()->getUID())))
->andWhere($builder->expr()->eq('root_id', $builder->createNamedParameter($mount->getRootId(), \PDO::PARAM_INT)));
$query->execute();
}
private function removeFromCache(ICachedMountInfo $mount) {
$builder = $this->connection->getQueryBuilder();
@ -205,7 +227,7 @@ class UserMountCache implements IUserMountCache {
$builder = $this->connection->getQueryBuilder();
$query = $builder->delete('mounts')
->where($builder->expr()->eq('user_id', $builder->createNamedParameter($user->getUID())));
->where($builder->expr()->eq('user_id', $builder->createNamedParameter($user->getUID())));
$query->execute();
}
}