handle invalid storages in LazyStorageMountInfo

This commit is contained in:
Robin Appelman 2016-06-13 13:31:45 +02:00
parent f7c41fa4e6
commit 338cd4033a
2 changed files with 16 additions and 8 deletions

View File

@ -28,7 +28,7 @@ use OCP\Files\Node;
use OCP\IUser;
class LazyStorageMountInfo extends CachedMountInfo {
/** @var IMountPoint */
/** @var IMountPoint */
private $mount;
/**
@ -47,7 +47,11 @@ class LazyStorageMountInfo extends CachedMountInfo {
*/
public function getStorageId() {
if (!$this->storageId) {
$this->storageId = $this->mount->getStorage()->getStorageCache()->getNumericId();
$storage = $this->mount->getStorage();
if (!$storage) {
return -1;
}
$this->storageId = $storage->getStorageCache()->getNumericId();
}
return parent::getStorageId();
}

View File

@ -124,12 +124,16 @@ class UserMountCache implements IUserMountCache {
}
private function addToCache(ICachedMountInfo $mount) {
$this->connection->insertIfNotExist('*PREFIX*mounts', [
'storage_id' => $mount->getStorageId(),
'root_id' => $mount->getRootId(),
'user_id' => $mount->getUser()->getUID(),
'mount_point' => $mount->getMountPoint()
], ['root_id', 'user_id']);
if ($mount->getStorageId() !== -1) {
$this->connection->insertIfNotExist('*PREFIX*mounts', [
'storage_id' => $mount->getStorageId(),
'root_id' => $mount->getRootId(),
'user_id' => $mount->getUser()->getUID(),
'mount_point' => $mount->getMountPoint()
], ['root_id', 'user_id']);
} else {
$this->logger->error('Error getting storage info for mount at ' . $mount->getMountPoint());
}
}
private function setMountPoint(ICachedMountInfo $mount) {