Skip to content

Commit b5afb64

Browse files
committed
fix: improve handling of unavailable storages
Signed-off-by: Robin Appelman <[email protected]>
1 parent f166766 commit b5afb64

File tree

3 files changed

+32
-8
lines changed

3 files changed

+32
-8
lines changed

apps/files_external/lib/Lib/StorageConfig.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -440,4 +440,19 @@ protected function formatStorageForUI(): void {
440440
public function getMountPointForUser(IUser $user): string {
441441
return '/' . $user->getUID() . '/files/' . trim($this->mountPoint, '/') . '/';
442442
}
443+
444+
public function __clone() {
445+
$clone = new StorageConfig($this->getId());
446+
$clone->setBackend(clone $this->getBackend());
447+
$clone->setAuthMechanism(clone $this->getAuthMechanism());
448+
$clone->setBackendOptions($this->getBackendOptions());
449+
$clone->setMountPoint($this->getMountPoint());
450+
$clone->setStatus($this->getStatus(), $this->getStatusMessage());
451+
$clone->setPriority($this->getPriority());
452+
$clone->setApplicableUsers($this->getApplicableUsers());
453+
$clone->setApplicableGroups($this->getApplicableGroups());
454+
$clone->setMountOptions($this->getMountOptions());
455+
$clone->setType($this->getType());
456+
return $clone;
457+
}
443458
}

apps/files_external/lib/Service/MountCacheService.php

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
namespace OCA\Files_External\Service;
1010

1111
use OC\Files\Cache\CacheEntry;
12+
use OC\Files\Storage\FailedStorage;
1213
use OC\User\LazyUser;
1314
use OCA\Files_External\Config\ConfigAdapter;
1415
use OCA\Files_External\Event\StorageCreatedEvent;
@@ -17,7 +18,6 @@
1718
use OCA\Files_External\Lib\StorageConfig;
1819
use OCP\Cache\CappedMemoryCache;
1920
use OCP\EventDispatcher\Event;
20-
use OCP\EventDispatcher\Event as T;
2121
use OCP\EventDispatcher\IEventListener;
2222
use OCP\Files\Cache\ICacheEntry;
2323
use OCP\Files\Config\IUserMountCache;
@@ -132,16 +132,20 @@ public function registerUpdatedStorage(StorageConfig $oldStorage, StorageConfig
132132
}
133133

134134
private function getCacheEntryForRoot(IUser $user, StorageConfig $storage): ICacheEntry {
135-
$storage = $this->configAdapter->constructStorageForUser($user, $storage);
135+
try {
136+
$userStorage = $this->configAdapter->constructStorageForUser($user, clone $storage);
137+
} catch (\Exception $e) {
138+
$userStorage = new FailedStorage(['exception' => $e]);
139+
}
136140

137-
if ($cachedEntry = $this->storageRootCache->get($storage->getId())) {
141+
if ($cachedEntry = $this->storageRootCache->get($userStorage->getId())) {
138142
return $cachedEntry;
139143
}
140144

141-
$cache = $storage->getCache();
145+
$cache = $userStorage->getCache();
142146
$entry = $cache->get('');
143-
if ($entry) {
144-
$this->storageRootCache->set($storage->getId(), $entry);
147+
if ($entry && $entry->getId() !== -1) {
148+
$this->storageRootCache->set($userStorage->getId(), $entry);
145149
return $entry;
146150
}
147151

@@ -163,10 +167,14 @@ private function getCacheEntryForRoot(IUser $user, StorageConfig $storage): ICac
163167
'encrypted' => 0,
164168
'checksum' => '',
165169
];
166-
$data['fileid'] = $cache->insert('', $data);
170+
if ($cache->getNumericStorageId() !== -1) {
171+
$data['fileid'] = $cache->insert('', $data);
172+
} else {
173+
$data['fileid'] = -1;
174+
}
167175

168176
$entry = new CacheEntry($data);
169-
$this->storageRootCache->set($storage->getId(), $entry);
177+
$this->storageRootCache->set($userStorage->getId(), $entry);
170178
return $entry;
171179
}
172180

lib/private/Files/Config/UserMountCache.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -542,6 +542,7 @@ public function addMount(IUser $user, string $mountPoint, ICacheEntry $rootCache
542542
'root_id' => $query->createNamedParameter($rootCacheEntry->getId()),
543543
'user_id' => $query->createNamedParameter($user->getUID()),
544544
'mount_point' => $query->createNamedParameter($mountPoint),
545+
'mount_point_hash' => $query->createNamedParameter(hash('xxh128', $mountPoint)),
545546
'mount_id' => $query->createNamedParameter($mountId),
546547
'mount_provider_class' => $query->createNamedParameter($mountProvider)
547548
]);

0 commit comments

Comments
 (0)