-
-
Notifications
You must be signed in to change notification settings - Fork 4.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #27205 from nextcloud/backport/26936/stable21
[stable21] better cleanup of filecache when deleting an external storage
- Loading branch information
Showing
5 changed files
with
77 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -40,7 +40,11 @@ | |
use OCA\Files_External\Service\DBConfigService; | ||
use OCA\Files_External\Service\StoragesService; | ||
use OCP\AppFramework\IAppContainer; | ||
use OCP\Files\Cache\ICache; | ||
use OCP\Files\Config\IUserMountCache; | ||
use OCP\Files\Mount\IMountPoint; | ||
use OCP\Files\Storage\IStorage; | ||
use OCP\IUser; | ||
|
||
class CleaningDBConfig extends DBConfigService { | ||
private $mountIds = []; | ||
|
@@ -279,27 +283,24 @@ public function deleteStorageDataProvider() { | |
'password' => 'testPassword', | ||
'root' => 'someroot', | ||
], | ||
'webdav::[email protected]//someroot/', | ||
0 | ||
'webdav::[email protected]//someroot/' | ||
], | ||
// special case with $user vars, cannot auto-remove the oc_storages entry | ||
[ | ||
[ | ||
'host' => 'example.com', | ||
'user' => '$user', | ||
'password' => 'testPassword', | ||
'root' => 'someroot', | ||
], | ||
'webdav::[email protected]//someroot/', | ||
1 | ||
'webdav::[email protected]//someroot/' | ||
], | ||
]; | ||
} | ||
|
||
/** | ||
* @dataProvider deleteStorageDataProvider | ||
*/ | ||
public function testDeleteStorage($backendOptions, $rustyStorageId, $expectedCountAfterDeletion) { | ||
public function testDeleteStorage($backendOptions, $rustyStorageId) { | ||
$backend = $this->backendService->getBackend('identifier:\OCA\Files_External\Lib\Backend\DAV'); | ||
$authMechanism = $this->backendService->getAuthMechanism('identifier:\Auth\Mechanism'); | ||
$storage = new StorageConfig(255); | ||
|
@@ -315,6 +316,31 @@ public function testDeleteStorage($backendOptions, $rustyStorageId, $expectedCou | |
// access, which isn't possible within this test | ||
$storageCache = new \OC\Files\Cache\Storage($rustyStorageId); | ||
|
||
/** @var IUserMountCache $mountCache */ | ||
$mountCache = \OC::$server->get(IUserMountCache::class); | ||
$mountCache->clear(); | ||
$user = $this->createMock(IUser::class); | ||
$user->method('getUID')->willReturn('test'); | ||
$cache = $this->createMock(ICache::class); | ||
$storage = $this->createMock(IStorage::class); | ||
$storage->method('getCache')->willReturn($cache); | ||
$mount = $this->createMock(IMountPoint::class); | ||
$mount->method('getStorage') | ||
->willReturn($storage); | ||
$mount->method('getStorageId') | ||
->willReturn($rustyStorageId); | ||
$mount->method('getNumericStorageId') | ||
->willReturn($storageCache->getNumericId()); | ||
$mount->method('getStorageRootId') | ||
->willReturn(1); | ||
$mount->method('getMountPoint') | ||
->willReturn('dummy'); | ||
$mount->method('getMountId') | ||
->willReturn($id); | ||
$mountCache->registerMounts($user, [ | ||
$mount | ||
]); | ||
|
||
// get numeric id for later check | ||
$numericId = $storageCache->getNumericId(); | ||
|
||
|
@@ -338,7 +364,7 @@ public function testDeleteStorage($backendOptions, $rustyStorageId, $expectedCou | |
$result = $storageCheckQuery->execute(); | ||
$storages = $result->fetchAll(); | ||
$result->closeCursor(); | ||
$this->assertCount($expectedCountAfterDeletion, $storages, "expected $expectedCountAfterDeletion storages, got " . json_encode($storages)); | ||
$this->assertCount(0, $storages, "expected 0 storages, got " . json_encode($storages)); | ||
} | ||
|
||
protected function actualDeletedUnexistingStorageTest() { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters