Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion apps/files_external/lib/Service/StoragesService.php
Original file line number Diff line number Diff line change
Expand Up @@ -424,12 +424,14 @@ public function removeStorage(int $id): void {
$this->dbConfig->removeMount($id);

$deletedStorage = $this->getStorageConfigFromDBMount($existingMount);
$this->eventDispatcher->dispatchTyped(new StorageDeletedEvent($deletedStorage));
$this->triggerHooks($deletedStorage, Filesystem::signal_delete_mount);

// delete oc_storages entries and oc_filecache
Storage::cleanByMountId($id);

// listeners remove the oc_mounts rows that cleanByMountId() uses to find the storages
$this->eventDispatcher->dispatchTyped(new StorageDeletedEvent($deletedStorage));

$this->updateOverwriteHomeFolders();
}

Expand Down
33 changes: 33 additions & 0 deletions apps/files_external/tests/Service/StoragesServiceTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

use OC\Files\Cache\Storage;
use OC\Files\Filesystem;
use OCA\Files_External\Event\StorageDeletedEvent;
use OCA\Files_External\Lib\Auth\AuthMechanism;
use OCA\Files_External\Lib\Auth\InvalidAuth;
use OCA\Files_External\Lib\Auth\NullMechanism;
Expand All @@ -22,6 +23,8 @@
use OCA\Files_External\Service\BackendService;
use OCA\Files_External\Service\DBConfigService;
use OCA\Files_External\Service\StoragesService;
use OCP\DB\QueryBuilder\IQueryBuilder;
use OCP\EventDispatcher\Event;
use OCP\EventDispatcher\IEventDispatcher;
use OCP\Files\Cache\ICache;
use OCP\Files\Config\IUserMountCache;
Expand Down Expand Up @@ -284,6 +287,26 @@ public function testDeleteStorage(array $backendOptions, string $rustyStorageId)
// get numeric id for later check
$numericId = $storageCache->getNumericId();

$path = $this->getUniqueID('file');
$qb = Server::get(IDBConnection::class)->getQueryBuilder();
$qb->insert('filecache')
->values([
'storage' => $qb->createNamedParameter($numericId, IQueryBuilder::PARAM_INT),
'path' => $qb->createNamedParameter($path),
'path_hash' => $qb->createNamedParameter(md5($path)),
'parent' => $qb->createNamedParameter(-1, IQueryBuilder::PARAM_INT),
'name' => $qb->createNamedParameter($path),
])
->executeStatement();

// listeners of StorageDeletedEvent clear the mount cache, like MountCacheService does
$this->eventDispatcher->method('dispatchTyped')
->willReturnCallback(function (Event $event) use ($mountCache, $user): void {
if ($event instanceof StorageDeletedEvent) {
$mountCache->removeMount('dummy', $user);
}
});

$this->service->removeStorage($id);

$caught = false;
Expand All @@ -305,6 +328,16 @@ public function testDeleteStorage(array $backendOptions, string $rustyStorageId)
$storages = $result->fetchAll();
$result->closeCursor();
$this->assertCount(0, $storages, 'expected 0 storages, got ' . json_encode($storages));

// filecache entries of the storage were removed
$qb = Server::get(IDBConnection::class)->getQueryBuilder();
$result = $qb->select('fileid')
->from('filecache')
->where($qb->expr()->eq('storage', $qb->createNamedParameter($numericId, IQueryBuilder::PARAM_INT)))
->executeQuery();
$fileIds = $result->fetchFirstColumn();
$result->closeCursor();
$this->assertCount(0, $fileIds, 'expected 0 filecache entries, got ' . json_encode($fileIds));
}

protected function actualDeletedUnexistingStorageTest() {
Expand Down
Loading