fix: improve handling of unavailable storages

Signed-off-by: Robin Appelman <robin@icewind.nl>
This commit is contained in:
Robin Appelman 2025-12-18 19:31:49 +01:00
parent 73e84f9bf5
commit 9dffca2f07
No known key found for this signature in database
GPG key ID: 42B69D8A64526EFB
3 changed files with 23 additions and 8 deletions

View file

@ -440,4 +440,9 @@ class StorageConfig implements \JsonSerializable {
public function getMountPointForUser(IUser $user): string {
return '/' . $user->getUID() . '/files/' . trim($this->mountPoint, '/') . '/';
}
public function __clone(): void {
$this->backend = clone $this->backend;
$this->authMechanism = clone $this->authMechanism;
}
}

View file

@ -9,6 +9,7 @@ declare(strict_types=1);
namespace OCA\Files_External\Service;
use OC\Files\Cache\CacheEntry;
use OC\Files\Storage\FailedStorage;
use OC\User\LazyUser;
use OCA\Files_External\Config\ConfigAdapter;
use OCA\Files_External\Event\StorageCreatedEvent;
@ -17,7 +18,6 @@ use OCA\Files_External\Event\StorageUpdatedEvent;
use OCA\Files_External\Lib\StorageConfig;
use OCP\Cache\CappedMemoryCache;
use OCP\EventDispatcher\Event;
use OCP\EventDispatcher\Event as T;
use OCP\EventDispatcher\IEventListener;
use OCP\Files\Cache\ICacheEntry;
use OCP\Files\Config\IUserMountCache;
@ -133,16 +133,21 @@ class MountCacheService implements IEventListener {
}
private function getCacheEntryForRoot(IUser $user, StorageConfig $storage): ICacheEntry {
$storage = $this->configAdapter->constructStorageForUser($user, $storage);
try {
$userStorage = $this->configAdapter->constructStorageForUser($user, clone $storage);
} catch (\Exception $e) {
$userStorage = new FailedStorage(['exception' => $e]);
}
if ($cachedEntry = $this->storageRootCache->get($storage->getId())) {
$cachedEntry = $this->storageRootCache->get($userStorage->getId());
if ($cachedEntry !== null) {
return $cachedEntry;
}
$cache = $storage->getCache();
$cache = $userStorage->getCache();
$entry = $cache->get('');
if ($entry) {
$this->storageRootCache->set($storage->getId(), $entry);
if ($entry && $entry->getId() !== -1) {
$this->storageRootCache->set($userStorage->getId(), $entry);
return $entry;
}
@ -164,10 +169,14 @@ class MountCacheService implements IEventListener {
'encrypted' => 0,
'checksum' => '',
];
$data['fileid'] = $cache->insert('', $data);
if ($cache->getNumericStorageId() !== -1) {
$data['fileid'] = $cache->insert('', $data);
} else {
$data['fileid'] = -1;
}
$entry = new CacheEntry($data);
$this->storageRootCache->set($storage->getId(), $entry);
$this->storageRootCache->set($userStorage->getId(), $entry);
return $entry;
}

View file

@ -542,6 +542,7 @@ class UserMountCache implements IUserMountCache {
'root_id' => $query->createNamedParameter($rootCacheEntry->getId()),
'user_id' => $query->createNamedParameter($user->getUID()),
'mount_point' => $query->createNamedParameter($mountPoint),
'mount_point_hash' => $query->createNamedParameter(hash('xxh128', $mountPoint)),
'mount_id' => $query->createNamedParameter($mountId),
'mount_provider_class' => $query->createNamedParameter($mountProvider)
]);