Skip to content

Commit 415aeeb

Browse files
committed
refactor: Call IStorageFactory::addStorageFactory directly
Remove call to deprecated Filesystem api and allow to reuse instead of the mounts points between addStorageFactory. Signed-off-by: Carl Schwan <carlschwan@kde.org>
1 parent d6cf529 commit 415aeeb

16 files changed

Lines changed: 100 additions & 59 deletions

File tree

apps/dav/appinfo/v1/publicwebdav.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
use OCP\EventDispatcher\IEventDispatcher;
2222
use OCP\Files\IRootFolder;
2323
use OCP\Files\Mount\IMountManager;
24+
use OCP\Files\Storage\IStorage;
2425
use OCP\IConfig;
2526
use OCP\IDBConnection;
2627
use OCP\IPreview;
@@ -109,14 +110,14 @@ function (\Sabre\DAV\Server $server) use (
109110

110111
// FIXME: should not add storage wrappers outside of preSetup, need to find a better way
111112
$previousLog = Filesystem::logWarningWhenAddingStorageWrapper(false);
112-
Filesystem::addStorageWrapper('sharePermissions', function ($mountPoint, $storage) use ($share) {
113+
Filesystem::addStorageWrapper('sharePermissions', function (string $mountPoint, IStorage $storage) use ($share) {
113114
return new DirPermissionsMask([
114115
'storage' => $storage,
115116
'mask' => $share->getPermissions() | Constants::PERMISSION_SHARE,
116117
'path' => 'files'
117118
]);
118119
});
119-
Filesystem::addStorageWrapper('shareOwner', function ($mountPoint, $storage) use ($share) {
120+
Filesystem::addStorageWrapper('shareOwner', function (string $mountPoint, IStorage $storage) use ($share) {
120121
return new PublicOwnerWrapper(['storage' => $storage, 'owner' => $share->getShareOwner()]);
121122
});
122123
Filesystem::logWarningWhenAddingStorageWrapper($previousLog);

apps/dav/appinfo/v2/publicremote.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
use OCP\Files\IHomeStorage;
2727
use OCP\Files\IRootFolder;
2828
use OCP\Files\Mount\IMountManager;
29+
use OCP\Files\Storage\IStorage;
2930
use OCP\ICacheFactory;
3031
use OCP\IConfig;
3132
use OCP\IDBConnection;
@@ -120,7 +121,7 @@
120121
$previousLog = Filesystem::logWarningWhenAddingStorageWrapper(false);
121122

122123
/** @psalm-suppress MissingClosureParamType */
123-
Filesystem::addStorageWrapper('sharePermissions', function ($mountPoint, $storage) use ($requestUri, $baseuri, $share) {
124+
Filesystem::addStorageWrapper('sharePermissions', function (string $mountPoint, IStorage $storage) use ($requestUri, $baseuri, $share) {
124125
$mask = $share->getPermissions() | Constants::PERMISSION_SHARE;
125126

126127
// For chunked uploads it is necessary to have read and delete permission,
@@ -141,13 +142,13 @@
141142
});
142143

143144
/** @psalm-suppress MissingClosureParamType */
144-
Filesystem::addStorageWrapper('shareOwner', function ($mountPoint, $storage) use ($share) {
145+
Filesystem::addStorageWrapper('shareOwner', function (string $mountPoint, IStorage $storage) use ($share) {
145146
return new PublicOwnerWrapper(['storage' => $storage, 'owner' => $share->getShareOwner()]);
146147
});
147148

148149
// Ensure that also private shares have the `getShare` method
149150
/** @psalm-suppress MissingClosureParamType */
150-
Filesystem::addStorageWrapper('getShare', function ($mountPoint, $storage) use ($share) {
151+
Filesystem::addStorageWrapper('getShare', function (string $mountPoint, IStorage $storage) use ($share) {
151152
return new PublicShareWrapper(['storage' => $storage, 'share' => $share]);
152153
}, 0);
153154

apps/files_sharing/tests/DeleteOrphanedSharesJobTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
use OC\Files\Filesystem;
1212
use OC\SystemConfig;
1313
use OCA\Files_Sharing\DeleteOrphanedSharesJob;
14+
use OCA\Files_Trashbin\Storage;
1415
use OCP\App\IAppManager;
1516
use OCP\Constants;
1617
use OCP\IDBConnection;
@@ -60,7 +61,7 @@ public static function setUpBeforeClass(): void {
6061
$appManager->disableApp('files_trashbin');
6162

6263
// just in case...
63-
Filesystem::getLoader()->removeStorageWrapper('oc_trashbin');
64+
Filesystem::getLoader()->removeStorageWrapper(Storage::class);
6465
}
6566

6667
public static function tearDownAfterClass(): void {

apps/files_sharing/tests/UpdaterTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
use OC\Files\View;
1414
use OCA\Files_Sharing\Helper;
1515
use OCA\Files_Trashbin\AppInfo\Application;
16+
use OCA\Files_Trashbin\Storage;
1617
use OCP\App\IAppManager;
1718
use OCP\AppFramework\Bootstrap\IBootContext;
1819
use OCP\Constants;
@@ -121,7 +122,7 @@ public function testDeleteParentFolder(): void {
121122
$appManager->disableApp('files_trashbin');
122123
}
123124

124-
Filesystem::getLoader()->removeStorageWrapper('oc_trashbin');
125+
Filesystem::getLoader()->removeStorageWrapper(Storage::class);
125126
}
126127

127128
public static function shareFolderProvider() {

apps/files_trashbin/lib/Listener/EventListener.php

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,24 +10,33 @@
1010
namespace OCA\Files_Trashbin\Listener;
1111

1212
use OCA\Files_Trashbin\Storage;
13+
use OCA\Files_Trashbin\Trash\ITrashManager;
1314
use OCA\Files_Trashbin\Trashbin;
1415
use OCP\EventDispatcher\Event;
16+
use OCP\EventDispatcher\IEventDispatcher;
1517
use OCP\EventDispatcher\IEventListener;
1618
use OCP\Files\Events\BeforeFileSystemSetupEvent;
1719
use OCP\Files\Events\Node\NodeWrittenEvent;
1820
use OCP\Files\Folder;
1921
use OCP\Files\IRootFolder;
2022
use OCP\Files\NotFoundException;
2123
use OCP\Files\NotPermittedException;
24+
use OCP\Files\Storage\IStorage;
25+
use OCP\IRequest;
2226
use OCP\IUserManager;
2327
use OCP\User\Events\BeforeUserDeletedEvent;
28+
use Psr\Log\LoggerInterface;
2429

2530
/** @template-implements IEventListener<NodeWrittenEvent|BeforeUserDeletedEvent|BeforeFileSystemSetupEvent> */
2631
class EventListener implements IEventListener {
2732
public function __construct(
28-
private IUserManager $userManager,
29-
private IRootFolder $rootFolder,
30-
private ?string $userId = null,
33+
private readonly IUserManager $userManager,
34+
private readonly IRootFolder $rootFolder,
35+
private readonly IRequest $request,
36+
private readonly IEventDispatcher $eventDispatcher,
37+
private readonly LoggerInterface $logger,
38+
private readonly ITrashManager $trashManager,
39+
private readonly ?string $userId = null,
3140
) {
3241
}
3342

@@ -57,7 +66,20 @@ public function handle(Event $event): void {
5766
}
5867

5968
if ($event instanceof BeforeFileSystemSetupEvent) {
60-
Storage::setupStorage();
69+
$event->addStorageWrapper(
70+
Storage::class,
71+
function (string $mountPoint, IStorage $storage): Storage {
72+
return new Storage(
73+
['storage' => $storage, 'mountPoint' => $mountPoint],
74+
$this->trashManager,
75+
$this->userManager,
76+
$this->logger,
77+
$this->eventDispatcher,
78+
$this->rootFolder,
79+
$this->request,
80+
);
81+
},
82+
1);
6183
}
6284
}
6385
}

apps/files_trashbin/lib/Storage.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ public static function setupStorage(): void {
159159
$rootFolder = Server::get(IRootFolder::class);
160160
$request = Server::get(IRequest::class);
161161
Filesystem::addStorageWrapper(
162-
'oc_trashbin',
162+
Storage::class,
163163
function (string $mountPoint, IStorage $storage) use ($trashManager, $userManager, $logger, $eventDispatcher, $rootFolder, $request) {
164164
return new Storage(
165165
['storage' => $storage, 'mountPoint' => $mountPoint],

apps/files_trashbin/tests/StorageTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ protected function setUp(): void {
9696
}
9797

9898
protected function tearDown(): void {
99-
Filesystem::getLoader()->removeStorageWrapper('oc_trashbin');
99+
Filesystem::getLoader()->removeStorageWrapper(Storage::class);
100100
$this->logout();
101101
$user = Server::get(IUserManager::class)->get($this->user);
102102
if ($user !== null) {
@@ -502,7 +502,7 @@ public function testKeepFileAndVersionsWhenMovingFileBetweenStorages(): void {
502502
$storage2 = new Temporary([]);
503503
Filesystem::mount($storage2, [], $this->user . '/files/substorage');
504504

505-
// trigger a version (multiple would not work because of the expire logic)
505+
// trigger a version (multiple would not work because of the expiration logic)
506506
$this->userView->file_put_contents('test.txt', 'v1');
507507

508508
$results = $this->rootView->getDirectoryContent($this->user . '/files_trashbin/files');

apps/files_trashbin/tests/TrashbinTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
use OCA\Files_Trashbin\AppInfo\Application as TrashbinApplication;
2020
use OCA\Files_Trashbin\Expiration;
2121
use OCA\Files_Trashbin\Helper;
22+
use OCA\Files_Trashbin\Storage;
2223
use OCA\Files_Trashbin\Trashbin;
2324
use OCP\App\IAppManager;
2425
use OCP\AppFramework\Utility\ITimeFactory;
@@ -96,7 +97,7 @@ public static function tearDownAfterClass(): void {
9697

9798
\OC_Hook::clear();
9899

99-
Filesystem::getLoader()->removeStorageWrapper('oc_trashbin');
100+
Filesystem::getLoader()->removeStorageWrapper(Storage::class);
100101

101102
if (self::$trashBinStatus) {
102103
Server::get(IAppManager::class)->enableApp('files_trashbin');

lib/private/Encryption/Manager.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -203,11 +203,11 @@ public function getDefaultEncryptionModuleId() {
203203
/**
204204
* Add storage wrapper
205205
*/
206-
public function setupStorage() {
206+
public function setupStorage(): void {
207207
// If encryption is disabled and there are no loaded modules it makes no sense to load the wrapper
208208
if (!empty($this->encryptionModules) || $this->isEnabled()) {
209209
$encryptionWrapper = new EncryptionWrapper($this->arrayCache, $this, $this->logger);
210-
Filesystem::addStorageWrapper('oc_encryption', [$encryptionWrapper, 'wrapStorage'], 2);
210+
Filesystem::addStorageWrapper('oc_encryption', $encryptionWrapper->wrapStorage(...), 2);
211211
}
212212
}
213213

lib/private/Files/Mount/Manager.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -207,9 +207,6 @@ public function findByStorageId(string $id): array {
207207
return $result;
208208
}
209209

210-
/**
211-
* @return IMountPoint[]
212-
*/
213210
#[\Override]
214211
public function getAll(): array {
215212
return $this->mounts;

0 commit comments

Comments
 (0)