From 9dffca2f07e6e5800e5cf1e269813c5087d9af76 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Thu, 18 Dec 2025 19:31:49 +0100 Subject: [PATCH] fix: improve handling of unavailable storages Signed-off-by: Robin Appelman --- apps/files_external/lib/Lib/StorageConfig.php | 5 ++++ .../lib/Service/MountCacheService.php | 25 +++++++++++++------ lib/private/Files/Config/UserMountCache.php | 1 + 3 files changed, 23 insertions(+), 8 deletions(-) diff --git a/apps/files_external/lib/Lib/StorageConfig.php b/apps/files_external/lib/Lib/StorageConfig.php index 3111456ac36..3f8a318b280 100644 --- a/apps/files_external/lib/Lib/StorageConfig.php +++ b/apps/files_external/lib/Lib/StorageConfig.php @@ -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; + } } diff --git a/apps/files_external/lib/Service/MountCacheService.php b/apps/files_external/lib/Service/MountCacheService.php index 56c2b392590..e284bf156d1 100644 --- a/apps/files_external/lib/Service/MountCacheService.php +++ b/apps/files_external/lib/Service/MountCacheService.php @@ -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; } diff --git a/lib/private/Files/Config/UserMountCache.php b/lib/private/Files/Config/UserMountCache.php index 2a78491a378..238ee959a0d 100644 --- a/lib/private/Files/Config/UserMountCache.php +++ b/lib/private/Files/Config/UserMountCache.php @@ -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) ]);