From 801733e5232620932dca14452b3b84dbdad14ed7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=B4me=20Chilliet?= Date: Sun, 15 Sep 2024 14:13:29 +0200 Subject: [PATCH 1/9] fix: Remove OCP\Files\Storage interface deprecated since version 9 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Côme Chilliet --- apps/dav/lib/Connector/Sabre/File.php | 14 +- .../tests/unit/Connector/Sabre/FileTest.php | 6 +- .../tests/unit/Connector/Sabre/NodeTest.php | 8 +- .../tests/Crypto/EncryptionTest.php | 8 +- apps/encryption/tests/KeyManagerTest.php | 4 +- apps/encryption/tests/UtilTest.php | 4 +- .../lib/Config/ConfigAdapter.php | 20 +- .../Lib/Auth/Password/SessionCredentials.php | 4 +- .../lib/Lib/StorageModifierTrait.php | 12 +- .../Controller/ShareAPIControllerTest.php | 32 +- lib/public/Files/Storage.php | 445 ------------------ lib/public/Files/Storage/IStorageFactory.php | 4 +- tests/lib/Encryption/DecryptAllTest.php | 6 +- .../lib/Encryption/EncryptionWrapperTest.php | 4 +- tests/lib/Files/Mount/MountPointTest.php | 4 +- tests/lib/Files/Node/FolderTest.php | 18 +- tests/lib/Files/Node/NodeTest.php | 4 +- .../Lockdown/Filesystem/NullStorageTest.php | 6 +- tests/lib/Share20/ManagerTest.php | 26 +- 19 files changed, 90 insertions(+), 539 deletions(-) delete mode 100644 lib/public/Files/Storage.php diff --git a/apps/dav/lib/Connector/Sabre/File.php b/apps/dav/lib/Connector/Sabre/File.php index 0b9199492fe0c..34cc2b77b37da 100644 --- a/apps/dav/lib/Connector/Sabre/File.php +++ b/apps/dav/lib/Connector/Sabre/File.php @@ -28,7 +28,7 @@ use OCP\Files\LockNotAcquiredException; use OCP\Files\NotFoundException; use OCP\Files\NotPermittedException; -use OCP\Files\Storage; +use OCP\Files\Storage\IWriteStreamStorage; use OCP\Files\StorageNotAvailableException; use OCP\IL10N; use OCP\IRequest; @@ -117,8 +117,10 @@ public function put($data) { // verify path of the target $this->verifyPath(); - /** @var Storage $partStorage */ [$partStorage] = $this->fileView->resolvePath($this->path); + if ($partStorage === null) { + throw new ServiceUnavailable($this->l10n->t('Failed to get storage for file')); + } $needsPartFile = $partStorage->needsPartFile() && (strlen($this->path) > 1); $view = \OC\Files\Filesystem::getView(); @@ -141,10 +143,11 @@ public function put($data) { } // the part file and target file might be on a different storage in case of a single file storage (e.g. single file share) - /** @var \OC\Files\Storage\Storage $partStorage */ [$partStorage, $internalPartPath] = $this->fileView->resolvePath($partFilePath); - /** @var \OC\Files\Storage\Storage $storage */ [$storage, $internalPath] = $this->fileView->resolvePath($this->path); + if ($partStorage === null || $storage === null) { + throw new ServiceUnavailable($this->l10n->t('Failed to get storage for file')); + } try { if (!$needsPartFile) { try { @@ -196,7 +199,7 @@ public function put($data) { } } - if ($partStorage->instanceOfStorage(Storage\IWriteStreamStorage::class)) { + if ($partStorage->instanceOfStorage(IWriteStreamStorage::class)) { $isEOF = false; $wrappedData = CallbackWrapper::wrap($data, null, null, null, null, function ($stream) use (&$isEOF) { $isEOF = feof($stream); @@ -535,7 +538,6 @@ public function getDirectDownload() { if (\OCP\Server::get(\OCP\App\IAppManager::class)->isEnabledForUser('encryption')) { return []; } - /** @var \OCP\Files\Storage $storage */ [$storage, $internalPath] = $this->fileView->resolvePath($this->path); if (is_null($storage)) { return []; diff --git a/apps/dav/tests/unit/Connector/Sabre/FileTest.php b/apps/dav/tests/unit/Connector/Sabre/FileTest.php index 6f9a214fab9f3..07128a1c7af76 100644 --- a/apps/dav/tests/unit/Connector/Sabre/FileTest.php +++ b/apps/dav/tests/unit/Connector/Sabre/FileTest.php @@ -17,7 +17,7 @@ use OCP\Constants; use OCP\Files\FileInfo; use OCP\Files\ForbiddenException; -use OCP\Files\Storage; +use OCP\Files\Storage\IStorage; use OCP\IConfig; use OCP\IRequestId; use OCP\ITempManager; @@ -73,10 +73,10 @@ protected function tearDown(): void { } /** - * @return MockObject|Storage + * @return MockObject|IStorage */ private function getMockStorage() { - $storage = $this->getMockBuilder(Storage::class) + $storage = $this->getMockBuilder(IStorage::class) ->disableOriginalConstructor() ->getMock(); $storage->method('getId') diff --git a/apps/dav/tests/unit/Connector/Sabre/NodeTest.php b/apps/dav/tests/unit/Connector/Sabre/NodeTest.php index 83f4139a2d9ef..c5e2b03d8b481 100644 --- a/apps/dav/tests/unit/Connector/Sabre/NodeTest.php +++ b/apps/dav/tests/unit/Connector/Sabre/NodeTest.php @@ -18,7 +18,7 @@ use OCP\Constants; use OCP\Files\Cache\ICacheEntry; use OCP\Files\Mount\IMountPoint; -use OCP\Files\Storage; +use OCP\Files\Storage\IStorage; use OCP\ICache; use OCP\Share\IManager; use OCP\Share\IShare; @@ -75,7 +75,7 @@ public function testDavPermissions($permissions, $type, $shared, $shareRootPermi return $this->createMock(MountPoint::class); } }); - $storage = $this->createMock(Storage\IStorage::class); + $storage = $this->createMock(IStorage::class); if ($shared) { $storage->method('instanceOfStorage') ->willReturn(true); @@ -145,7 +145,7 @@ public function sharePermissionsProvider() { * @dataProvider sharePermissionsProvider */ public function testSharePermissions($type, $user, $permissions, $expected): void { - $storage = $this->getMockBuilder(Storage::class) + $storage = $this->getMockBuilder(IStorage::class) ->disableOriginalConstructor() ->getMock(); $storage->method('getPermissions')->willReturn($permissions); @@ -223,7 +223,7 @@ public function testShareAttributes(): void { } public function testShareAttributesNonShare(): void { - $storage = $this->getMockBuilder(Storage::class) + $storage = $this->getMockBuilder(IStorage::class) ->disableOriginalConstructor() ->getMock(); diff --git a/apps/encryption/tests/Crypto/EncryptionTest.php b/apps/encryption/tests/Crypto/EncryptionTest.php index b07bd0a6b256c..10f85f7e74ed0 100644 --- a/apps/encryption/tests/Crypto/EncryptionTest.php +++ b/apps/encryption/tests/Crypto/EncryptionTest.php @@ -15,8 +15,9 @@ use OCA\Encryption\KeyManager; use OCA\Encryption\Session; use OCA\Encryption\Util; -use OCP\Files\Storage; +use OCP\Files\Storage\IStorage; use OCP\IL10N; +use PHPUnit\Framework\MockObject\MockObject; use Psr\Log\LoggerInterface; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; @@ -50,13 +51,12 @@ class EncryptionTest extends TestCase { /** @var \OCP\IL10N|\PHPUnit\Framework\MockObject\MockObject */ private $l10nMock; - /** @var \OCP\Files\Storage|\PHPUnit\Framework\MockObject\MockObject */ - private $storageMock; + private IStorage&MockObject $storageMock; protected function setUp(): void { parent::setUp(); - $this->storageMock = $this->getMockBuilder(Storage::class) + $this->storageMock = $this->getMockBuilder(IStorage::class) ->disableOriginalConstructor()->getMock(); $this->cryptMock = $this->getMockBuilder(Crypt::class) ->disableOriginalConstructor() diff --git a/apps/encryption/tests/KeyManagerTest.php b/apps/encryption/tests/KeyManagerTest.php index a9919e8eab4e5..869e5e2cf96b5 100644 --- a/apps/encryption/tests/KeyManagerTest.php +++ b/apps/encryption/tests/KeyManagerTest.php @@ -15,7 +15,7 @@ use OCA\Encryption\Util; use OCP\Encryption\Keys\IStorage; use OCP\Files\Cache\ICache; -use OCP\Files\Storage; +use OCP\Files\Storage\IStorage as FilesIStorage; use OCP\IConfig; use OCP\IUserSession; use OCP\Lock\ILockingProvider; @@ -687,7 +687,7 @@ public function testSetVersionWithFileInfo(): void { $cache->expects($this->once()) ->method('update') ->with(123, ['encrypted' => 5, 'encryptedVersion' => 5]); - $storage = $this->getMockBuilder(Storage::class) + $storage = $this->getMockBuilder(FilesIStorage::class) ->disableOriginalConstructor()->getMock(); $storage->expects($this->once()) ->method('getCache') diff --git a/apps/encryption/tests/UtilTest.php b/apps/encryption/tests/UtilTest.php index 6f2eec1ebf400..f2e6f406c3507 100644 --- a/apps/encryption/tests/UtilTest.php +++ b/apps/encryption/tests/UtilTest.php @@ -11,7 +11,7 @@ use OCA\Encryption\Crypto\Crypt; use OCA\Encryption\Util; use OCP\Files\Mount\IMountPoint; -use OCP\Files\Storage; +use OCP\Files\Storage\IStorage; use OCP\IConfig; use OCP\IUser; use OCP\IUserManager; @@ -181,7 +181,7 @@ public function dataTestSetEncryptHomeStorage() { } public function testGetStorage(): void { - $return = $this->getMockBuilder(Storage::class) + $return = $this->getMockBuilder(IStorage::class) ->disableOriginalConstructor() ->getMock(); diff --git a/apps/files_external/lib/Config/ConfigAdapter.php b/apps/files_external/lib/Config/ConfigAdapter.php index 97bc4f78142e8..d0437432427ac 100644 --- a/apps/files_external/lib/Config/ConfigAdapter.php +++ b/apps/files_external/lib/Config/ConfigAdapter.php @@ -14,7 +14,8 @@ use OCA\Files_External\Service\UserGlobalStoragesService; use OCA\Files_External\Service\UserStoragesService; use OCP\Files\Config\IMountProvider; -use OCP\Files\Storage; +use OCP\Files\ObjectStore\IObjectStore; +use OCP\Files\Storage\IStorage; use OCP\Files\Storage\IStorageFactory; use OCP\Files\StorageNotAvailableException; use OCP\IUser; @@ -34,11 +35,9 @@ public function __construct( /** * Process storage ready for mounting * - * @param StorageConfig $storage - * @param IUser $user * @throws \OCP\AppFramework\QueryException */ - private function prepareStorageConfig(StorageConfig &$storage, IUser $user) { + private function prepareStorageConfig(StorageConfig &$storage, IUser $user): void { foreach ($storage->getBackendOptions() as $option => $value) { $storage->setBackendOption($option, \OCA\Files_External\MountConfig::substitutePlaceholdersInConfig($value, $user->getUID())); } @@ -46,7 +45,7 @@ private function prepareStorageConfig(StorageConfig &$storage, IUser $user) { $objectStore = $storage->getBackendOption('objectstore'); if ($objectStore) { $objectClass = $objectStore['class']; - if (!is_subclass_of($objectClass, '\OCP\Files\ObjectStore\IObjectStore')) { + if (!is_subclass_of($objectClass, IObjectStore::class)) { throw new \InvalidArgumentException('Invalid object store'); } $storage->setBackendOption('objectstore', new $objectClass($objectStore)); @@ -60,9 +59,8 @@ private function prepareStorageConfig(StorageConfig &$storage, IUser $user) { * Construct the storage implementation * * @param StorageConfig $storageConfig - * @return Storage */ - private function constructStorage(StorageConfig $storageConfig) { + private function constructStorage(StorageConfig $storageConfig): IStorage { $class = $storageConfig->getBackend()->getStorageClass(); $storage = new $class($storageConfig->getBackendOptions()); @@ -76,8 +74,6 @@ private function constructStorage(StorageConfig $storageConfig) { /** * Get all mountpoints applicable for the user * - * @param \OCP\IUser $user - * @param \OCP\Files\Storage\IStorageFactory $loader * @return \OCP\Files\Mount\IMountPoint[] */ public function getMountsForUser(IUser $user, IStorageFactory $loader) { @@ -97,11 +93,11 @@ public function getMountsForUser(IUser $user, IStorageFactory $loader) { }, $storageConfigs); - \OC\Files\Cache\Storage::getGlobalCache()->loadForStorageIds(array_map(function (Storage\IStorage $storage) { + \OC\Files\Cache\Storage::getGlobalCache()->loadForStorageIds(array_map(function (IStorage $storage) { return $storage->getId(); }, $storages)); - $availableStorages = array_map(function (Storage\IStorage $storage, StorageConfig $storageConfig) { + $availableStorages = array_map(function (IStorage $storage, StorageConfig $storageConfig): IStorage { try { $availability = $storage->getAvailability(); if (!$availability['available'] && !Availability::shouldRecheck($availability)) { @@ -116,7 +112,7 @@ public function getMountsForUser(IUser $user, IStorageFactory $loader) { return $storage; }, $storages, $storageConfigs); - $mounts = array_map(function (StorageConfig $storageConfig, Storage\IStorage $storage) use ($user, $loader) { + $mounts = array_map(function (StorageConfig $storageConfig, IStorage $storage) use ($user, $loader) { $storage->setOwner($user->getUID()); if ($storageConfig->getType() === StorageConfig::MOUNT_TYPE_PERSONAL) { return new PersonalMount( diff --git a/apps/files_external/lib/Lib/Auth/Password/SessionCredentials.php b/apps/files_external/lib/Lib/Auth/Password/SessionCredentials.php index d81c73ca13f1d..314ab82385ee8 100644 --- a/apps/files_external/lib/Lib/Auth/Password/SessionCredentials.php +++ b/apps/files_external/lib/Lib/Auth/Password/SessionCredentials.php @@ -12,7 +12,7 @@ use OCA\Files_External\Lib\StorageConfig; use OCP\Authentication\Exceptions\CredentialsUnavailableException; use OCP\Authentication\LoginCredentials\IStore as CredentialsStore; -use OCP\Files\Storage; +use OCP\Files\Storage\IStorage; use OCP\Files\StorageAuthException; use OCP\IL10N; use OCP\IUser; @@ -56,7 +56,7 @@ public function manipulateStorageConfig(StorageConfig &$storage, ?IUser $user = $storage->setBackendOption('password', $credentials->getPassword()); } - public function wrapStorage(Storage $storage) { + public function wrapStorage(IStorage $storage): IStorage { return new SessionStorageWrapper(['storage' => $storage]); } } diff --git a/apps/files_external/lib/Lib/StorageModifierTrait.php b/apps/files_external/lib/Lib/StorageModifierTrait.php index 7cc7a15605ccb..4b9264f4223d0 100644 --- a/apps/files_external/lib/Lib/StorageModifierTrait.php +++ b/apps/files_external/lib/Lib/StorageModifierTrait.php @@ -6,7 +6,7 @@ */ namespace OCA\Files_External\Lib; -use OCP\Files\Storage; +use OCP\Files\Storage\IStorage; use OCP\Files\StorageNotAvailableException; use OCP\IUser; @@ -28,8 +28,8 @@ trait StorageModifierTrait { /** * Modify a StorageConfig parameters * - * @param StorageConfig $storage - * @param IUser $user User the storage is being used as + * @param StorageConfig &$storage + * @param ?IUser $user User the storage is being used as * @return void * @throws InsufficientDataForMeaningfulAnswerException * @throws StorageNotAvailableException @@ -38,14 +38,12 @@ public function manipulateStorageConfig(StorageConfig &$storage, ?IUser $user = } /** - * Wrap a Storage if necessary + * Wrap a storage if necessary * - * @param Storage $storage - * @return Storage * @throws InsufficientDataForMeaningfulAnswerException * @throws StorageNotAvailableException */ - public function wrapStorage(Storage $storage) { + public function wrapStorage(IStorage $storage): IStorage { return $storage; } } diff --git a/apps/files_sharing/tests/Controller/ShareAPIControllerTest.php b/apps/files_sharing/tests/Controller/ShareAPIControllerTest.php index f28302b4ccd00..36ac04714b7ed 100644 --- a/apps/files_sharing/tests/Controller/ShareAPIControllerTest.php +++ b/apps/files_sharing/tests/Controller/ShareAPIControllerTest.php @@ -16,7 +16,7 @@ use OCP\Files\IRootFolder; use OCP\Files\Mount\IMountPoint; use OCP\Files\NotFoundException; -use OCP\Files\Storage; +use OCP\Files\Storage\IStorage; use OCP\IConfig; use OCP\IDateTimeZone; use OCP\IGroup; @@ -526,7 +526,7 @@ public function dataGetShare() { ->getMock(); $cache->method('getNumericStorageId')->willReturn(101); - $storage = $this->getMockBuilder(Storage::class) + $storage = $this->getMockBuilder(IStorage::class) ->disableOriginalConstructor() ->getMock(); $storage->method('getId')->willReturn('STORAGE'); @@ -1923,7 +1923,7 @@ public function testCreateShareLinkNoLinksAllowed(): void { $path = $this->getMockBuilder(Folder::class)->getMock(); $path->method('getId')->willReturn(42); - $storage = $this->createMock(Storage::class); + $storage = $this->createMock(IStorage::class); $storage->method('instanceOfStorage') ->willReturnMap([ ['OCA\Files_Sharing\External\Storage', false], @@ -1947,7 +1947,7 @@ public function testCreateShareLinkNoPublicUpload(): void { $path = $this->getMockBuilder(Folder::class)->getMock(); $path->method('getId')->willReturn(42); - $storage = $this->createMock(Storage::class); + $storage = $this->createMock(IStorage::class); $storage->method('instanceOfStorage') ->willReturnMap([ ['OCA\Files_Sharing\External\Storage', false], @@ -1972,7 +1972,7 @@ public function testCreateShareLinkPublicUploadFile(): void { $path = $this->getMockBuilder(File::class)->getMock(); $path->method('getId')->willReturn(42); - $storage = $this->createMock(Storage::class); + $storage = $this->createMock(IStorage::class); $storage->method('instanceOfStorage') ->willReturnMap([ ['OCA\Files_Sharing\External\Storage', false], @@ -1996,7 +1996,7 @@ public function testCreateShareLinkPublicUploadFolder(): void { $path = $this->getMockBuilder(Folder::class)->getMock(); $path->method('getId')->willReturn(1); - $storage = $this->createMock(Storage::class); + $storage = $this->createMock(IStorage::class); $storage->method('instanceOfStorage') ->willReturnMap([ ['OCA\Files_Sharing\External\Storage', false], @@ -2035,7 +2035,7 @@ public function testCreateShareLinkPassword(): void { $path = $this->getMockBuilder(Folder::class)->getMock(); $path->method('getId')->willReturn(42); - $storage = $this->createMock(Storage::class); + $storage = $this->createMock(IStorage::class); $storage->method('instanceOfStorage') ->willReturnMap([ ['OCA\Files_Sharing\External\Storage', false], @@ -2074,7 +2074,7 @@ public function testCreateShareLinkSendPasswordByTalk(): void { $path = $this->getMockBuilder(Folder::class)->getMock(); $path->method('getId')->willReturn(42); - $storage = $this->createMock(Storage::class); + $storage = $this->createMock(IStorage::class); $storage->method('instanceOfStorage') ->willReturnMap([ ['OCA\Files_Sharing\External\Storage', false], @@ -2120,7 +2120,7 @@ public function testCreateShareLinkSendPasswordByTalkWithTalkDisabled(): void { $path = $this->getMockBuilder(Folder::class)->getMock(); $path->method('getId')->willReturn(42); - $storage = $this->createMock(Storage::class); + $storage = $this->createMock(IStorage::class); $storage->method('instanceOfStorage') ->willReturnMap([ ['OCA\Files_Sharing\External\Storage', false], @@ -2159,7 +2159,7 @@ public function testCreateShareValidExpireDate(): void { $path = $this->getMockBuilder(Folder::class)->getMock(); $path->method('getId')->willReturn(42); - $storage = $this->createMock(Storage::class); + $storage = $this->createMock(IStorage::class); $storage->method('instanceOfStorage') ->willReturnMap([ ['OCA\Files_Sharing\External\Storage', false], @@ -2205,7 +2205,7 @@ public function testCreateShareInvalidExpireDate(): void { $path = $this->getMockBuilder(Folder::class)->getMock(); $path->method('getId')->willReturn(42); - $storage = $this->createMock(Storage::class); + $storage = $this->createMock(IStorage::class); $storage->method('instanceOfStorage') ->willReturnMap([ ['OCA\Files_Sharing\External\Storage', false], @@ -2574,7 +2574,7 @@ public function testCreateReshareOfFederatedMountNoDeletePermissions(): void { $path = $this->getMockBuilder(Folder::class)->getMock(); $path->method('getId')->willReturn(42); - $storage = $this->createMock(Storage::class); + $storage = $this->createMock(IStorage::class); $storage->method('instanceOfStorage') ->willReturnMap([ ['OCA\Files_Sharing\External\Storage', true], @@ -3762,7 +3762,7 @@ public function dataFormatShare() { $cache = $this->getMockBuilder('OCP\Files\Cache\ICache')->getMock(); $cache->method('getNumericStorageId')->willReturn(100); - $storage = $this->createMock(Storage::class); + $storage = $this->createMock(IStorage::class); $storage->method('getId')->willReturn('storageId'); $storage->method('getCache')->willReturn($cache); @@ -4759,7 +4759,7 @@ public function dataFormatRoomShare() { $cache = $this->getMockBuilder('OCP\Files\Cache\ICache')->getMock(); $cache->method('getNumericStorageId')->willReturn(100); - $storage = $this->createMock(Storage::class); + $storage = $this->createMock(IStorage::class); $storage->method('getId')->willReturn('storageId'); $storage->method('getCache')->willReturn($cache); @@ -4923,7 +4923,7 @@ public function testFormatRoomShare(array $expects, \OCP\Share\IShare $share, bo private function getNonSharedUserFolder(): array { $node = $this->getMockBuilder(Folder::class)->getMock(); $userFolder = $this->getMockBuilder(Folder::class)->getMock(); - $storage = $this->createMock(Storage::class); + $storage = $this->createMock(IStorage::class); $storage->method('instanceOfStorage') ->willReturnMap([ ['OCA\Files_Sharing\External\Storage', false], @@ -4938,7 +4938,7 @@ private function getNonSharedUserFolder(): array { private function getNonSharedUserFile(): array { $node = $this->getMockBuilder(File::class)->getMock(); $userFolder = $this->getMockBuilder(Folder::class)->getMock(); - $storage = $this->createMock(Storage::class); + $storage = $this->createMock(IStorage::class); $storage->method('instanceOfStorage') ->willReturnMap([ ['OCA\Files_Sharing\External\Storage', false], diff --git a/lib/public/Files/Storage.php b/lib/public/Files/Storage.php deleted file mode 100644 index 049841075ca69..0000000000000 --- a/lib/public/Files/Storage.php +++ /dev/null @@ -1,445 +0,0 @@ - $class - * @return bool - * @since 7.0.0 - * @psalm-assert-if-true T $this - */ - public function instanceOfStorage($class); - - /** - * A custom storage implementation can return an url for direct download of a give file. - * - * For now the returned array can hold the parameter url - in future more attributes might follow. - * - * @param string $path - * @return array|bool - * @since 8.0.0 - */ - public function getDirectDownload($path); - - /** - * @param string $path the path of the target folder - * @param string $fileName the name of the file itself - * @return void - * @throws InvalidPathException - * @since 8.1.0 - */ - public function verifyPath($path, $fileName); - - /** - * @param IStorage $sourceStorage - * @param string $sourceInternalPath - * @param string $targetInternalPath - * @return bool - * @since 8.1.0 - */ - public function copyFromStorage(IStorage $sourceStorage, $sourceInternalPath, $targetInternalPath); - - /** - * @param IStorage $sourceStorage - * @param string $sourceInternalPath - * @param string $targetInternalPath - * @return bool - * @since 8.1.0 - */ - public function moveFromStorage(IStorage $sourceStorage, $sourceInternalPath, $targetInternalPath); - - /** - * @param string $path The path of the file to acquire the lock for - * @param int $type \OCP\Lock\ILockingProvider::LOCK_SHARED or \OCP\Lock\ILockingProvider::LOCK_EXCLUSIVE - * @param \OCP\Lock\ILockingProvider $provider - * @throws \OCP\Lock\LockedException - * @since 8.1.0 - */ - public function acquireLock($path, $type, ILockingProvider $provider); - - /** - * @param string $path The path of the file to acquire the lock for - * @param int $type \OCP\Lock\ILockingProvider::LOCK_SHARED or \OCP\Lock\ILockingProvider::LOCK_EXCLUSIVE - * @param \OCP\Lock\ILockingProvider $provider - * @throws \OCP\Lock\LockedException - * @since 8.1.0 - */ - public function releaseLock($path, $type, ILockingProvider $provider); - - /** - * @param string $path The path of the file to change the lock for - * @param int $type \OCP\Lock\ILockingProvider::LOCK_SHARED or \OCP\Lock\ILockingProvider::LOCK_EXCLUSIVE - * @param \OCP\Lock\ILockingProvider $provider - * @throws \OCP\Lock\LockedException - * @since 8.1.0 - */ - public function changeLock($path, $type, ILockingProvider $provider); - - /** - * Test a storage for availability - * - * @since 8.2.0 - * @return bool - */ - public function test(); - - /** - * @since 8.2.0 - * @return array [ available, last_checked ] - */ - public function getAvailability(); - - /** - * @since 8.2.0 - * @param bool $isAvailable - */ - public function setAvailability($isAvailable); - - /** - * @since 12.0.0 - * @return mixed - */ - public function needsPartFile(); -} diff --git a/lib/public/Files/Storage/IStorageFactory.php b/lib/public/Files/Storage/IStorageFactory.php index e0ec31288769c..6d44b39274ec9 100644 --- a/lib/public/Files/Storage/IStorageFactory.php +++ b/lib/public/Files/Storage/IStorageFactory.php @@ -28,10 +28,10 @@ interface IStorageFactory { public function addStorageWrapper($wrapperName, $callback); /** - * @param \OCP\Files\Mount\IMountPoint $mountPoint + * @param IMountPoint $mountPoint * @param string $class * @param array $arguments - * @return \OCP\Files\Storage + * @return IStorage * @since 8.0.0 */ public function getInstance(IMountPoint $mountPoint, $class, $arguments); diff --git a/tests/lib/Encryption/DecryptAllTest.php b/tests/lib/Encryption/DecryptAllTest.php index d073efc82354a..6a8453bcaf8b8 100644 --- a/tests/lib/Encryption/DecryptAllTest.php +++ b/tests/lib/Encryption/DecryptAllTest.php @@ -12,7 +12,7 @@ use OC\Encryption\Manager; use OC\Files\FileInfo; use OC\Files\View; -use OCP\Files\Storage; +use OCP\Files\Storage\IStorage; use OCP\IUserManager; use OCP\UserInterface; use Symfony\Component\Console\Formatter\OutputFormatterInterface; @@ -246,11 +246,11 @@ public function testDecryptUsersFiles(): void { ->setMethods(['decryptFile']) ->getMock(); - $storage = $this->getMockBuilder(Storage::class) + $storage = $this->getMockBuilder(IStorage::class) ->disableOriginalConstructor()->getMock(); - $sharedStorage = $this->getMockBuilder(Storage::class) + $sharedStorage = $this->getMockBuilder(IStorage::class) ->disableOriginalConstructor()->getMock(); $sharedStorage->expects($this->once())->method('instanceOfStorage') diff --git a/tests/lib/Encryption/EncryptionWrapperTest.php b/tests/lib/Encryption/EncryptionWrapperTest.php index 1ecb9dc89c737..bda8597a9c4ff 100644 --- a/tests/lib/Encryption/EncryptionWrapperTest.php +++ b/tests/lib/Encryption/EncryptionWrapperTest.php @@ -10,7 +10,7 @@ use OC\Encryption\EncryptionWrapper; use OC\Encryption\Manager; use OC\Memcache\ArrayCache; -use OCP\Files\Storage; +use OCP\Files\Storage\IStorage; use Psr\Log\LoggerInterface; use Test\TestCase; @@ -42,7 +42,7 @@ protected function setUp(): void { * @dataProvider provideWrapStorage */ public function testWrapStorage($expectedWrapped, $wrappedStorages): void { - $storage = $this->getMockBuilder(Storage::class) + $storage = $this->getMockBuilder(IStorage::class) ->disableOriginalConstructor() ->getMock(); diff --git a/tests/lib/Files/Mount/MountPointTest.php b/tests/lib/Files/Mount/MountPointTest.php index eda61feb24946..3de54e315a169 100644 --- a/tests/lib/Files/Mount/MountPointTest.php +++ b/tests/lib/Files/Mount/MountPointTest.php @@ -8,14 +8,14 @@ namespace Test\Files\Mount; use OC\Files\Storage\StorageFactory; -use OCP\Files\Storage; +use OCP\Files\Storage\IStorage; class DummyStorage { } class MountPointTest extends \Test\TestCase { public function testGetStorage(): void { - $storage = $this->createMock(Storage::class); + $storage = $this->createMock(IStorage::class); $storage->expects($this->once()) ->method('getId') ->willReturn(123); diff --git a/tests/lib/Files/Node/FolderTest.php b/tests/lib/Files/Node/FolderTest.php index 2e3b6e369d3c0..5af409a1a93ce 100644 --- a/tests/lib/Files/Node/FolderTest.php +++ b/tests/lib/Files/Node/FolderTest.php @@ -28,7 +28,7 @@ use OCP\Files\NotFoundException; use OCP\Files\Search\ISearchComparison; use OCP\Files\Search\ISearchOrder; -use OCP\Files\Storage; +use OCP\Files\Storage\IStorage; use PHPUnit\Framework\MockObject\MockObject; /** @@ -292,7 +292,7 @@ public function testSearch(): void { $root->method('getUser') ->willReturn($this->user); /** @var Storage\IStorage&MockObject $storage */ - $storage = $this->createMock(Storage\IStorage::class); + $storage = $this->createMock(IStorage::class); $storage->method('getId')->willReturn('test::1'); $cache = new Cache($storage); @@ -341,7 +341,7 @@ public function testSearchInRoot(): void { ->method('getUser') ->willReturn($this->user); /** @var \PHPUnit\Framework\MockObject\MockObject|Storage $storage */ - $storage = $this->createMock(Storage::class); + $storage = $this->createMock(IStorage::class); $storage->method('getId')->willReturn('test::2'); $cache = new Cache($storage); @@ -379,7 +379,7 @@ public function testSearchInStorageRoot(): void { ->getMock(); $root->method('getUser') ->willReturn($this->user); - $storage = $this->createMock(Storage::class); + $storage = $this->createMock(IStorage::class); $storage->method('getId')->willReturn('test::1'); $cache = new Cache($storage); @@ -420,10 +420,10 @@ public function testSearchSubStorages(): void { $root->expects($this->any()) ->method('getUser') ->willReturn($this->user); - $storage = $this->createMock(Storage::class); + $storage = $this->createMock(IStorage::class); $storage->method('getId')->willReturn('test::1'); $cache = new Cache($storage); - $subStorage = $this->createMock(Storage::class); + $subStorage = $this->createMock(IStorage::class); $subStorage->method('getId')->willReturn('test::2'); $subCache = new Cache($subStorage); $subMount = $this->getMockBuilder(MountPoint::class)->setConstructorArgs([Temporary::class, ''])->getMock(); @@ -922,14 +922,14 @@ public function testSearchSubStoragesLimitOffset(int $offset, int $limit, array $root->expects($this->any()) ->method('getUser') ->willReturn($this->user); - $storage = $this->createMock(Storage::class); + $storage = $this->createMock(IStorage::class); $storage->method('getId')->willReturn('test::1'); $cache = new Cache($storage); - $subStorage1 = $this->createMock(Storage::class); + $subStorage1 = $this->createMock(IStorage::class); $subStorage1->method('getId')->willReturn('test::2'); $subCache1 = new Cache($subStorage1); $subMount1 = $this->getMockBuilder(MountPoint::class)->setConstructorArgs([Temporary::class, ''])->getMock(); - $subStorage2 = $this->createMock(Storage::class); + $subStorage2 = $this->createMock(IStorage::class); $subStorage2->method('getId')->willReturn('test::3'); $subCache2 = new Cache($subStorage2); $subMount2 = $this->getMockBuilder(MountPoint::class)->setConstructorArgs([Temporary::class, ''])->getMock(); diff --git a/tests/lib/Files/Node/NodeTest.php b/tests/lib/Files/Node/NodeTest.php index d12448a248180..db87aa925d3b3 100644 --- a/tests/lib/Files/Node/NodeTest.php +++ b/tests/lib/Files/Node/NodeTest.php @@ -16,7 +16,7 @@ use OCP\Files\Mount\IMountPoint; use OCP\Files\Node; use OCP\Files\NotFoundException; -use OCP\Files\Storage; +use OCP\Files\Storage\IStorage; use OCP\ICacheFactory; use OCP\IUser; use OCP\IUserManager; @@ -111,7 +111,7 @@ abstract protected function getNonExistingNodeClass(); abstract protected function getViewDeleteMethod(); protected function getMockStorage() { - $storage = $this->getMockBuilder(Storage::class) + $storage = $this->getMockBuilder(IStorage::class) ->disableOriginalConstructor() ->getMock(); $storage->expects($this->any()) diff --git a/tests/lib/Lockdown/Filesystem/NullStorageTest.php b/tests/lib/Lockdown/Filesystem/NullStorageTest.php index 331adeb8a544f..cc65221d0a3a7 100644 --- a/tests/lib/Lockdown/Filesystem/NullStorageTest.php +++ b/tests/lib/Lockdown/Filesystem/NullStorageTest.php @@ -11,7 +11,7 @@ use OC\ForbiddenException; use OC\Lockdown\Filesystem\NullCache; use OC\Lockdown\Filesystem\NullStorage; -use OCP\Files\Storage; +use OCP\Files\Storage\IStorage; use Test\TestCase; class NullStorageTest extends TestCase { @@ -196,7 +196,7 @@ public function testGetDirectDownload(): void { } public function testCopyFromStorage(): void { - $sourceStorage = $this->createMock(Storage::class); + $sourceStorage = $this->createMock(IStorage::class); $this->expectException(ForbiddenException::class); $this->expectExceptionMessage('This request is not allowed to access the filesystem'); @@ -205,7 +205,7 @@ public function testCopyFromStorage(): void { } public function testMoveFromStorage(): void { - $sourceStorage = $this->createMock(Storage::class); + $sourceStorage = $this->createMock(IStorage::class); $this->expectException(ForbiddenException::class); $this->expectExceptionMessage('This request is not allowed to access the filesystem'); diff --git a/tests/lib/Share20/ManagerTest.php b/tests/lib/Share20/ManagerTest.php index 2250e28bd131b..d0c43b2862c53 100644 --- a/tests/lib/Share20/ManagerTest.php +++ b/tests/lib/Share20/ManagerTest.php @@ -23,7 +23,7 @@ use OCP\Files\Mount\IMountManager; use OCP\Files\Mount\IMountPoint; use OCP\Files\Node; -use OCP\Files\Storage; +use OCP\Files\Storage\IStorage; use OCP\HintException; use OCP\IConfig; use OCP\IDateTimeZone; @@ -631,7 +631,7 @@ public function dataGeneralChecks() { $file = $this->createMock(File::class); $node = $this->createMock(Node::class); - $storage = $this->createMock(Storage\IStorage::class); + $storage = $this->createMock(IStorage::class); $storage->method('instanceOfStorage') ->with('\OCA\Files_Sharing\External\Storage') ->willReturn(false); @@ -706,7 +706,7 @@ public function dataGeneralChecks() { $data[] = [$this->createShare(null, IShare::TYPE_GROUP, $limitedPermssions, $group0, $user0, $user0, 17, null, null), 'Cannot increase permissions of path', true]; $data[] = [$this->createShare(null, IShare::TYPE_LINK, $limitedPermssions, null, $user0, $user0, 3, null, null), 'Cannot increase permissions of path', true]; - $nonMovableStorage = $this->createMock(Storage\IStorage::class); + $nonMovableStorage = $this->createMock(IStorage::class); $nonMovableStorage->method('instanceOfStorage') ->with('\OCA\Files_Sharing\External\Storage') ->willReturn(false); @@ -752,7 +752,7 @@ public function dataGeneralChecks() { $data[] = [$this->createShare(null, IShare::TYPE_LINK, $allPermssions, null, $user0, $user0, 17, null, null), null, false]; - $remoteStorage = $this->createMock(Storage\IStorage::class); + $remoteStorage = $this->createMock(IStorage::class); $remoteStorage->method('instanceOfStorage') ->with('\OCA\Files_Sharing\External\Storage') ->willReturn(true); @@ -2059,7 +2059,7 @@ public function testPathCreateChecksContainsSharedMount(): void { $path->method('getPath')->willReturn('path'); $mount = $this->createMock(IMountPoint::class); - $storage = $this->createMock(Storage::class); + $storage = $this->createMock(IStorage::class); $mount->method('getStorage')->willReturn($storage); $storage->method('instanceOfStorage')->with('\OCA\Files_Sharing\ISharedStorage')->willReturn(true); @@ -2073,7 +2073,7 @@ public function testPathCreateChecksContainsNoSharedMount(): void { $path->method('getPath')->willReturn('path'); $mount = $this->createMock(IMountPoint::class); - $storage = $this->createMock(Storage::class); + $storage = $this->createMock(IStorage::class); $mount->method('getStorage')->willReturn($storage); $storage->method('instanceOfStorage')->with('\OCA\Files_Sharing\ISharedStorage')->willReturn(false); @@ -2221,7 +2221,7 @@ public function testCreateShareUser(): void { $shareOwner = $this->createMock(IUser::class); $shareOwner->method('getUID')->willReturn('shareOwner'); - $storage = $this->createMock(Storage::class); + $storage = $this->createMock(IStorage::class); $path = $this->createMock(File::class); $path->method('getOwner')->willReturn($shareOwner); $path->method('getName')->willReturn('target'); @@ -2276,7 +2276,7 @@ public function testCreateShareGroup(): void { $shareOwner = $this->createMock(IUser::class); $shareOwner->method('getUID')->willReturn('shareOwner'); - $storage = $this->createMock(Storage::class); + $storage = $this->createMock(IStorage::class); $path = $this->createMock(File::class); $path->method('getOwner')->willReturn($shareOwner); $path->method('getName')->willReturn('target'); @@ -2339,7 +2339,7 @@ public function testCreateShareLink(): void { $shareOwner = $this->createMock(IUser::class); $shareOwner->method('getUID')->willReturn('shareOwner'); - $storage = $this->createMock(Storage::class); + $storage = $this->createMock(IStorage::class); $path = $this->createMock(File::class); $path->method('getOwner')->willReturn($shareOwner); $path->method('getName')->willReturn('target'); @@ -2459,7 +2459,7 @@ public function testCreateShareMail(): void { $shareOwner = $this->createMock(IUser::class); $shareOwner->method('getUID')->willReturn('shareOwner'); - $storage = $this->createMock(Storage::class); + $storage = $this->createMock(IStorage::class); $path = $this->createMock(File::class); $path->method('getOwner')->willReturn($shareOwner); $path->method('getName')->willReturn('target'); @@ -2563,7 +2563,7 @@ public function testCreateShareHookError(): void { $shareOwner = $this->createMock(IUser::class); $shareOwner->method('getUID')->willReturn('shareOwner'); - $storage = $this->createMock(Storage::class); + $storage = $this->createMock(IStorage::class); $path = $this->createMock(File::class); $path->method('getOwner')->willReturn($shareOwner); $path->method('getName')->willReturn('target'); @@ -2623,12 +2623,12 @@ public function testCreateShareOfIncomingFederatedShare(): void { $shareOwner = $this->createMock(IUser::class); $shareOwner->method('getUID')->willReturn('shareOwner'); - $storage = $this->createMock(Storage::class); + $storage = $this->createMock(IStorage::class); $storage->method('instanceOfStorage') ->with('OCA\Files_Sharing\External\Storage') ->willReturn(true); - $storage2 = $this->createMock(Storage::class); + $storage2 = $this->createMock(IStorage::class); $storage2->method('instanceOfStorage') ->with('OCA\Files_Sharing\External\Storage') ->willReturn(false); From 22822d5e9b29e7c49a524bf2e6e60291c244ff09 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=B4me=20Chilliet?= Date: Sun, 15 Sep 2024 15:38:25 +0200 Subject: [PATCH 2/9] fix: Fix other uses of removed Storage interface MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Côme Chilliet --- apps/files_sharing/lib/SharedStorage.php | 7 +- .../files_sharing/tests/SharedStorageTest.php | 6 -- lib/private/Files/Storage/Storage.php | 81 +------------------ lib/private/Files/Storage/StorageFactory.php | 11 ++- lib/public/Files/Storage/IStorage.php | 15 ++++ tests/lib/Files/Storage/Storage.php | 3 +- .../lib/Files/Storage/StorageFactoryTest.php | 2 +- 7 files changed, 30 insertions(+), 95 deletions(-) diff --git a/apps/files_sharing/lib/SharedStorage.php b/apps/files_sharing/lib/SharedStorage.php index 00f757d473440..62f5880294cf1 100644 --- a/apps/files_sharing/lib/SharedStorage.php +++ b/apps/files_sharing/lib/SharedStorage.php @@ -27,6 +27,7 @@ use OCP\Files\IRootFolder; use OCP\Files\NotFoundException; use OCP\Files\Storage\IDisableEncryptionStorage; +use OCP\Files\Storage\ILockingStorage; use OCP\Files\Storage\ISharedStorage; use OCP\Files\Storage\IStorage; use OCP\Lock\ILockingProvider; @@ -494,7 +495,7 @@ public function unshareStorage(): bool { * @throws \OCP\Lock\LockedException */ public function acquireLock($path, $type, ILockingProvider $provider) { - /** @var \OCP\Files\Storage $targetStorage */ + /** @var ILockingStorage $targetStorage */ [$targetStorage, $targetInternalPath] = $this->resolvePath($path); $targetStorage->acquireLock($targetInternalPath, $type, $provider); // lock the parent folders of the owner when locking the share as recipient @@ -510,7 +511,7 @@ public function acquireLock($path, $type, ILockingProvider $provider) { * @param \OCP\Lock\ILockingProvider $provider */ public function releaseLock($path, $type, ILockingProvider $provider) { - /** @var \OCP\Files\Storage $targetStorage */ + /** @var ILockingStorage $targetStorage */ [$targetStorage, $targetInternalPath] = $this->resolvePath($path); $targetStorage->releaseLock($targetInternalPath, $type, $provider); // unlock the parent folders of the owner when unlocking the share as recipient @@ -526,7 +527,7 @@ public function releaseLock($path, $type, ILockingProvider $provider) { * @param \OCP\Lock\ILockingProvider $provider */ public function changeLock($path, $type, ILockingProvider $provider) { - /** @var \OCP\Files\Storage $targetStorage */ + /** @var ILockingStorage $targetStorage */ [$targetStorage, $targetInternalPath] = $this->resolvePath($path); $targetStorage->changeLock($targetInternalPath, $type, $provider); } diff --git a/apps/files_sharing/tests/SharedStorageTest.php b/apps/files_sharing/tests/SharedStorageTest.php index 5f907ad8de37a..49ff97c053a92 100644 --- a/apps/files_sharing/tests/SharedStorageTest.php +++ b/apps/files_sharing/tests/SharedStorageTest.php @@ -416,9 +416,6 @@ public function testCopyFromStorage(): void { $view = new \OC\Files\View('/' . self::TEST_FILES_SHARING_API_USER2 . '/files'); $this->assertTrue($view->file_exists($this->folder)); - /** - * @var \OCP\Files\Storage $sharedStorage - */ [$sharedStorage,] = $view->resolvePath($this->folder); $this->assertTrue($sharedStorage->instanceOfStorage('OCA\Files_Sharing\ISharedStorage')); @@ -449,9 +446,6 @@ public function testMoveFromStorage(): void { $view = new \OC\Files\View('/' . self::TEST_FILES_SHARING_API_USER2 . '/files'); $this->assertTrue($view->file_exists($this->folder)); - /** - * @var \OCP\Files\Storage $sharedStorage - */ [$sharedStorage,] = $view->resolvePath($this->folder); $this->assertTrue($sharedStorage->instanceOfStorage('OCA\Files_Sharing\ISharedStorage')); diff --git a/lib/private/Files/Storage/Storage.php b/lib/private/Files/Storage/Storage.php index 44b1a52cfc0b3..8f37daaf61326 100644 --- a/lib/private/Files/Storage/Storage.php +++ b/lib/private/Files/Storage/Storage.php @@ -5,68 +5,17 @@ * SPDX-FileCopyrightText: 2016 ownCloud, Inc. * SPDX-License-Identifier: AGPL-3.0-only */ + namespace OC\Files\Storage; -use OCP\Lock\ILockingProvider; +use OCP\Files\Storage\IStorage; /** * Provide a common interface to all different storage options * * All paths passed to the storage are relative to the storage and should NOT have a leading slash. */ -interface Storage extends \OCP\Files\Storage { - /** - * get a cache instance for the storage - * - * @param string $path - * @param \OC\Files\Storage\Storage|null (optional) the storage to pass to the cache - * @return \OC\Files\Cache\Cache - */ - public function getCache($path = '', $storage = null); - - /** - * get a scanner instance for the storage - * - * @param string $path - * @param \OC\Files\Storage\Storage (optional) the storage to pass to the scanner - * @return \OC\Files\Cache\Scanner - */ - public function getScanner($path = '', $storage = null); - - - /** - * get the user id of the owner of a file or folder - * - * @param string $path - * @return string - */ - public function getOwner($path); - - /** - * get a watcher instance for the cache - * - * @param string $path - * @param \OC\Files\Storage\Storage (optional) the storage to pass to the watcher - * @return \OC\Files\Cache\Watcher - */ - public function getWatcher($path = '', $storage = null); - - /** - * get a propagator instance for the cache - * - * @param \OC\Files\Storage\Storage (optional) the storage to pass to the watcher - * @return \OC\Files\Cache\Propagator - */ - public function getPropagator($storage = null); - - /** - * get a updater instance for the cache - * - * @param \OC\Files\Storage\Storage (optional) the storage to pass to the watcher - * @return \OC\Files\Cache\Updater - */ - public function getUpdater($storage = null); - +interface Storage extends IStorage { /** * @return \OC\Files\Cache\Storage */ @@ -78,30 +27,6 @@ public function getStorageCache(); */ public function getMetaData($path); - /** - * @param string $path The path of the file to acquire the lock for - * @param int $type \OCP\Lock\ILockingProvider::LOCK_SHARED or \OCP\Lock\ILockingProvider::LOCK_EXCLUSIVE - * @param \OCP\Lock\ILockingProvider $provider - * @throws \OCP\Lock\LockedException - */ - public function acquireLock($path, $type, ILockingProvider $provider); - - /** - * @param string $path The path of the file to release the lock for - * @param int $type \OCP\Lock\ILockingProvider::LOCK_SHARED or \OCP\Lock\ILockingProvider::LOCK_EXCLUSIVE - * @param \OCP\Lock\ILockingProvider $provider - * @throws \OCP\Lock\LockedException - */ - public function releaseLock($path, $type, ILockingProvider $provider); - - /** - * @param string $path The path of the file to change the lock for - * @param int $type \OCP\Lock\ILockingProvider::LOCK_SHARED or \OCP\Lock\ILockingProvider::LOCK_EXCLUSIVE - * @param \OCP\Lock\ILockingProvider $provider - * @throws \OCP\Lock\LockedException - */ - public function changeLock($path, $type, ILockingProvider $provider); - /** * Get the contents of a directory with metadata * diff --git a/lib/private/Files/Storage/StorageFactory.php b/lib/private/Files/Storage/StorageFactory.php index 612592e2d3ae0..590425f5b641b 100644 --- a/lib/private/Files/Storage/StorageFactory.php +++ b/lib/private/Files/Storage/StorageFactory.php @@ -8,6 +8,7 @@ namespace OC\Files\Storage; use OCP\Files\Mount\IMountPoint; +use OCP\Files\Storage\IStorage; use OCP\Files\Storage\IStorageFactory; class StorageFactory implements IStorageFactory { @@ -56,19 +57,17 @@ public function removeStorageWrapper($wrapperName) { /** * Create an instance of a storage and apply the registered storage wrappers * - * @param \OCP\Files\Mount\IMountPoint $mountPoint * @param string $class * @param array $arguments - * @return \OCP\Files\Storage + * @return IStorage */ public function getInstance(IMountPoint $mountPoint, $class, $arguments) { return $this->wrap($mountPoint, new $class($arguments)); } /** - * @param \OCP\Files\Mount\IMountPoint $mountPoint - * @param \OCP\Files\Storage $storage - * @return \OCP\Files\Storage + * @param IStorage $storage + * @return IStorage */ public function wrap(IMountPoint $mountPoint, $storage) { $wrappers = array_values($this->storageWrappers); @@ -81,7 +80,7 @@ public function wrap(IMountPoint $mountPoint, $storage) { }, $wrappers); foreach ($wrappers as $wrapper) { $storage = $wrapper($mountPoint->getMountPoint(), $storage, $mountPoint); - if (!($storage instanceof \OCP\Files\Storage)) { + if (!($storage instanceof IStorage)) { throw new \Exception('Invalid result from storage wrapper'); } } diff --git a/lib/public/Files/Storage/IStorage.php b/lib/public/Files/Storage/IStorage.php index e18d676834680..907670052392f 100644 --- a/lib/public/Files/Storage/IStorage.php +++ b/lib/public/Files/Storage/IStorage.php @@ -279,6 +279,15 @@ public function hash($type, $path, $raw = false); */ public function free_space($path); + /** + * search for occurrences of $query in file names + * + * @param string $query + * @return array|bool + * @since 6.0.0 + */ + public function search($query); + /** * see https://www.php.net/manual/en/function.touch.php * If the backend does not support the operation, false should be returned @@ -404,6 +413,12 @@ public function getAvailability(); */ public function setAvailability($isAvailable); + /** + * @since 12.0.0 + * @return mixed + */ + public function needsPartFile(); + /** * @param string $path path for which to retrieve the owner * @since 9.0.0 diff --git a/tests/lib/Files/Storage/Storage.php b/tests/lib/Files/Storage/Storage.php index 5b0bbf2f95bf1..36d709658484f 100644 --- a/tests/lib/Files/Storage/Storage.php +++ b/tests/lib/Files/Storage/Storage.php @@ -8,6 +8,7 @@ namespace Test\Files\Storage; use OC\Files\Cache\Watcher; +use OCP\Files\Storage\IStorage; use OCP\Files\Storage\IWriteStreamStorage; abstract class Storage extends \Test\TestCase { @@ -572,7 +573,7 @@ public function testCopyOverWriteDirectoryOverFile(): void { } public function testInstanceOfStorage(): void { - $this->assertTrue($this->instance->instanceOfStorage('\OCP\Files\Storage')); + $this->assertTrue($this->instance->instanceOfStorage(IStorage::class)); $this->assertTrue($this->instance->instanceOfStorage(get_class($this->instance))); $this->assertFalse($this->instance->instanceOfStorage('\OC')); } diff --git a/tests/lib/Files/Storage/StorageFactoryTest.php b/tests/lib/Files/Storage/StorageFactoryTest.php index 66f2a2af9a6e7..d1e8d927dc930 100644 --- a/tests/lib/Files/Storage/StorageFactoryTest.php +++ b/tests/lib/Files/Storage/StorageFactoryTest.php @@ -10,7 +10,7 @@ use OC\Files\Mount\MountPoint; use OC\Files\Storage\Wrapper\Wrapper; use OCP\Files\Mount\IMountPoint; -use OCP\Files\Storage as IStorage; +use OCP\Files\Storage\IStorage; use Test\TestCase; class DummyWrapper extends Wrapper { From a165d8f978ba0551ffa0905e63d820c39befbd83 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=B4me=20Chilliet?= Date: Sun, 15 Sep 2024 16:12:28 +0200 Subject: [PATCH 3/9] chore: Fix encryption test use statement MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Côme Chilliet --- tests/lib/Encryption/EncryptionWrapperTest.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/lib/Encryption/EncryptionWrapperTest.php b/tests/lib/Encryption/EncryptionWrapperTest.php index bda8597a9c4ff..1ac7342a3d86e 100644 --- a/tests/lib/Encryption/EncryptionWrapperTest.php +++ b/tests/lib/Encryption/EncryptionWrapperTest.php @@ -10,6 +10,7 @@ use OC\Encryption\EncryptionWrapper; use OC\Encryption\Manager; use OC\Memcache\ArrayCache; +use OCP\Files\Storage\IDisableEncryptionStorage; use OCP\Files\Storage\IStorage; use Psr\Log\LoggerInterface; use Test\TestCase; @@ -74,7 +75,7 @@ public function provideWrapStorage() { [true, ['OCA\Files_Trashbin\Storage']], // Do not wrap shared storages - [false, [Storage\IDisableEncryptionStorage::class]], + [false, [IDisableEncryptionStorage::class]], ]; } } From f80eda439857e4dca769f77425b6fad2da8a4765 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=B4me=20Chilliet?= Date: Sun, 15 Sep 2024 16:16:18 +0200 Subject: [PATCH 4/9] chore: fix autoloaders MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Côme Chilliet --- lib/composer/composer/autoload_classmap.php | 1 - lib/composer/composer/autoload_static.php | 1 - 2 files changed, 2 deletions(-) diff --git a/lib/composer/composer/autoload_classmap.php b/lib/composer/composer/autoload_classmap.php index 5510143197ac8..78aca5fe883a1 100644 --- a/lib/composer/composer/autoload_classmap.php +++ b/lib/composer/composer/autoload_classmap.php @@ -421,7 +421,6 @@ 'OCP\\Files\\SimpleFS\\ISimpleFolder' => $baseDir . '/lib/public/Files/SimpleFS/ISimpleFolder.php', 'OCP\\Files\\SimpleFS\\ISimpleRoot' => $baseDir . '/lib/public/Files/SimpleFS/ISimpleRoot.php', 'OCP\\Files\\SimpleFS\\InMemoryFile' => $baseDir . '/lib/public/Files/SimpleFS/InMemoryFile.php', - 'OCP\\Files\\Storage' => $baseDir . '/lib/public/Files/Storage.php', 'OCP\\Files\\StorageAuthException' => $baseDir . '/lib/public/Files/StorageAuthException.php', 'OCP\\Files\\StorageBadConfigException' => $baseDir . '/lib/public/Files/StorageBadConfigException.php', 'OCP\\Files\\StorageConnectionException' => $baseDir . '/lib/public/Files/StorageConnectionException.php', diff --git a/lib/composer/composer/autoload_static.php b/lib/composer/composer/autoload_static.php index 7b8584b543826..6a17bc4ff31fd 100644 --- a/lib/composer/composer/autoload_static.php +++ b/lib/composer/composer/autoload_static.php @@ -454,7 +454,6 @@ class ComposerStaticInit749170dad3f5e7f9ca158f5a9f04f6a2 'OCP\\Files\\SimpleFS\\ISimpleFolder' => __DIR__ . '/../../..' . '/lib/public/Files/SimpleFS/ISimpleFolder.php', 'OCP\\Files\\SimpleFS\\ISimpleRoot' => __DIR__ . '/../../..' . '/lib/public/Files/SimpleFS/ISimpleRoot.php', 'OCP\\Files\\SimpleFS\\InMemoryFile' => __DIR__ . '/../../..' . '/lib/public/Files/SimpleFS/InMemoryFile.php', - 'OCP\\Files\\Storage' => __DIR__ . '/../../..' . '/lib/public/Files/Storage.php', 'OCP\\Files\\StorageAuthException' => __DIR__ . '/../../..' . '/lib/public/Files/StorageAuthException.php', 'OCP\\Files\\StorageBadConfigException' => __DIR__ . '/../../..' . '/lib/public/Files/StorageBadConfigException.php', 'OCP\\Files\\StorageConnectionException' => __DIR__ . '/../../..' . '/lib/public/Files/StorageConnectionException.php', From 492e6997d8ed5077c2dd36b690a10eef4beb9324 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=B4me=20Chilliet?= Date: Sun, 15 Sep 2024 17:14:37 +0200 Subject: [PATCH 5/9] chore: Fix psalm issues, put back private versions of getter in private Storage interface MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Côme Chilliet --- apps/files_sharing/lib/External/Storage.php | 1 + apps/files_trashbin/lib/Trashbin.php | 7 +-- lib/private/Files/Cache/Scanner.php | 13 +++--- .../Files/ObjectStore/ObjectStoreStorage.php | 1 + lib/private/Files/Storage/Common.php | 20 +++++--- lib/private/Files/Storage/Home.php | 4 +- lib/private/Files/Storage/Storage.php | 46 ++++++++++++++++++- lib/private/Files/Storage/Temporary.php | 2 +- lib/public/Files/Storage/IStorage.php | 2 + 9 files changed, 78 insertions(+), 18 deletions(-) diff --git a/apps/files_sharing/lib/External/Storage.php b/apps/files_sharing/lib/External/Storage.php index 36f4c0b885992..169054fd1d964 100644 --- a/apps/files_sharing/lib/External/Storage.php +++ b/apps/files_sharing/lib/External/Storage.php @@ -149,6 +149,7 @@ public function getScanner($path = '', $storage = null) { if (!isset($this->scanner)) { $this->scanner = new Scanner($storage); } + /** @var \OCA\Files_Sharing\External\Scanner */ return $this->scanner; } diff --git a/apps/files_trashbin/lib/Trashbin.php b/apps/files_trashbin/lib/Trashbin.php index c9863241045f6..b83a81972e1ed 100644 --- a/apps/files_trashbin/lib/Trashbin.php +++ b/apps/files_trashbin/lib/Trashbin.php @@ -29,6 +29,7 @@ use OCP\Files\Node; use OCP\Files\NotFoundException; use OCP\Files\NotPermittedException; +use OCP\Files\Storage\ILockingStorage; use OCP\FilesMetadata\IFilesMetadataManager; use OCP\IConfig; use OCP\IDBConnection; @@ -118,7 +119,7 @@ public static function getExtraData($user) { * @param string $user * @param string $filename * @param string $timestamp - * @return string original location + * @return string|false original location */ public static function getLocation($user, $filename, $timestamp) { $query = \OC::$server->getDatabaseConnection()->getQueryBuilder(); @@ -139,7 +140,7 @@ public static function getLocation($user, $filename, $timestamp) { } } - private static function setUpTrash($user) { + private static function setUpTrash($user): void { $view = new View('/' . $user); if (!$view->is_dir('files_trashbin')) { $view->mkdir('files_trashbin'); @@ -256,7 +257,7 @@ public static function move2trash($file_path, $ownerOnly = false) { while (!$gotLock) { try { - /** @var \OC\Files\Storage\Storage $trashStorage */ + /** @var ILockingStorage $trashStorage */ [$trashStorage, $trashInternalPath] = $ownerView->resolvePath($trashPath); $trashStorage->acquireLock($trashInternalPath, ILockingProvider::LOCK_EXCLUSIVE, $lockingProvider); diff --git a/lib/private/Files/Cache/Scanner.php b/lib/private/Files/Cache/Scanner.php index c85104ac4b99e..6e1c86eed4737 100644 --- a/lib/private/Files/Cache/Scanner.php +++ b/lib/private/Files/Cache/Scanner.php @@ -15,6 +15,7 @@ use OCP\Files\Cache\IScanner; use OCP\Files\ForbiddenException; use OCP\Files\NotFoundException; +use OCP\Files\Storage\ILockingStorage; use OCP\Files\Storage\IReliableEtagStorage; use OCP\IDBConnection; use OCP\Lock\ILockingProvider; @@ -125,7 +126,7 @@ public function scanFile($file, $reuseExisting = 0, $parentId = -1, $cacheData = if (!self::isPartialFile($file)) { // acquire a lock if ($lock) { - if ($this->storage->instanceOfStorage('\OCP\Files\Storage\ILockingStorage')) { + if ($this->storage->instanceOfStorage(ILockingStorage::class)) { $this->storage->acquireLock($file, ILockingProvider::LOCK_SHARED, $this->lockingProvider); } } @@ -134,7 +135,7 @@ public function scanFile($file, $reuseExisting = 0, $parentId = -1, $cacheData = $data = $data ?? $this->getData($file); } catch (ForbiddenException $e) { if ($lock) { - if ($this->storage->instanceOfStorage('\OCP\Files\Storage\ILockingStorage')) { + if ($this->storage->instanceOfStorage(ILockingStorage::class)) { $this->storage->releaseLock($file, ILockingProvider::LOCK_SHARED, $this->lockingProvider); } } @@ -233,7 +234,7 @@ public function scanFile($file, $reuseExisting = 0, $parentId = -1, $cacheData = } } catch (\Exception $e) { if ($lock) { - if ($this->storage->instanceOfStorage('\OCP\Files\Storage\ILockingStorage')) { + if ($this->storage->instanceOfStorage(ILockingStorage::class)) { $this->storage->releaseLock($file, ILockingProvider::LOCK_SHARED, $this->lockingProvider); } } @@ -242,7 +243,7 @@ public function scanFile($file, $reuseExisting = 0, $parentId = -1, $cacheData = // release the acquired lock if ($lock) { - if ($this->storage->instanceOfStorage('\OCP\Files\Storage\ILockingStorage')) { + if ($this->storage->instanceOfStorage(ILockingStorage::class)) { $this->storage->releaseLock($file, ILockingProvider::LOCK_SHARED, $this->lockingProvider); } } @@ -319,7 +320,7 @@ public function scan($path, $recursive = self::SCAN_RECURSIVE, $reuse = -1, $loc $reuse = ($recursive === self::SCAN_SHALLOW) ? self::REUSE_ETAG | self::REUSE_SIZE : self::REUSE_ETAG; } if ($lock) { - if ($this->storage->instanceOfStorage('\OCP\Files\Storage\ILockingStorage')) { + if ($this->storage->instanceOfStorage(ILockingStorage::class)) { $this->storage->acquireLock('scanner::' . $path, ILockingProvider::LOCK_EXCLUSIVE, $this->lockingProvider); $this->storage->acquireLock($path, ILockingProvider::LOCK_SHARED, $this->lockingProvider); } @@ -337,7 +338,7 @@ public function scan($path, $recursive = self::SCAN_RECURSIVE, $reuse = -1, $loc } } finally { if ($lock) { - if ($this->storage->instanceOfStorage('\OCP\Files\Storage\ILockingStorage')) { + if ($this->storage->instanceOfStorage(ILockingStorage::class)) { $this->storage->releaseLock($path, ILockingProvider::LOCK_SHARED, $this->lockingProvider); $this->storage->releaseLock('scanner::' . $path, ILockingProvider::LOCK_EXCLUSIVE, $this->lockingProvider); } diff --git a/lib/private/Files/ObjectStore/ObjectStoreStorage.php b/lib/private/Files/ObjectStore/ObjectStoreStorage.php index 228fc51667744..663041ed92c82 100644 --- a/lib/private/Files/ObjectStore/ObjectStoreStorage.php +++ b/lib/private/Files/ObjectStore/ObjectStoreStorage.php @@ -141,6 +141,7 @@ public function getScanner($path = '', $storage = null) { if (!isset($this->scanner)) { $this->scanner = new ObjectStoreScanner($storage); } + /** @var \OC\Files\ObjectStore\ObjectStoreScanner */ return $this->scanner; } diff --git a/lib/private/Files/Storage/Common.php b/lib/private/Files/Storage/Common.php index cefba66683bce..01b33648ac0ed 100644 --- a/lib/private/Files/Storage/Common.php +++ b/lib/private/Files/Storage/Common.php @@ -44,14 +44,14 @@ abstract class Common implements Storage, ILockingStorage, IWriteStreamStorage { use LocalTempFileTrait; - protected $cache; - protected $scanner; - protected $watcher; - protected $propagator; + protected ?Cache $cache = null; + protected ?Scanner $scanner = null; + protected ?Watcher $watcher = null; + protected ?Propagator $propagator = null; protected $storageCache; - protected $updater; + protected ?Updater $updater = null; - protected $mountOptions = []; + protected array $mountOptions = []; protected $owner = null; private ?bool $shouldLogLocks = null; @@ -310,13 +310,19 @@ protected function getCacheDependencies(): CacheDependencies { return $dependencies; } + /** + * @return Cache + */ public function getCache($path = '', $storage = null) { if (!$storage) { $storage = $this; } + /** @psalm-suppress NoInterfaceProperties The isset check is safe */ if (!isset($storage->cache)) { $storage->cache = new Cache($storage, $this->getCacheDependencies()); } + /** @psalm-suppress NullableReturnStatement False-positive, as the if above avoids this being null */ + /** @psalm-suppress NoInterfaceProperties Legacy */ return $storage->cache; } @@ -324,9 +330,11 @@ public function getScanner($path = '', $storage = null) { if (!$storage) { $storage = $this; } + /** @psalm-suppress NoInterfaceProperties The isset check is safe */ if (!isset($storage->scanner)) { $storage->scanner = new Scanner($storage); } + /** @psalm-suppress NoInterfaceProperties Legacy stuff */ return $storage->scanner; } diff --git a/lib/private/Files/Storage/Home.php b/lib/private/Files/Storage/Home.php index a8d1f82b98718..0e53e7b28d431 100644 --- a/lib/private/Files/Storage/Home.php +++ b/lib/private/Files/Storage/Home.php @@ -52,13 +52,14 @@ public function getCache($path = '', $storage = null) { if (!isset($this->cache)) { $this->cache = new \OC\Files\Cache\HomeCache($storage, $this->getCacheDependencies()); } + /** @var \OC\Files\Cache\HomeCache */ return $this->cache; } /** * get a propagator instance for the cache * - * @param \OC\Files\Storage\Storage (optional) the storage to pass to the watcher + * @param \OC\Files\Storage\Storage $storage (optional) the storage to pass to the watcher * @return \OC\Files\Cache\Propagator */ public function getPropagator($storage = null) { @@ -68,6 +69,7 @@ public function getPropagator($storage = null) { if (!isset($this->propagator)) { $this->propagator = new HomePropagator($storage, \OC::$server->getDatabaseConnection()); } + /** @var \OC\Files\Cache\Propagator */ return $this->propagator; } diff --git a/lib/private/Files/Storage/Storage.php b/lib/private/Files/Storage/Storage.php index 8f37daaf61326..aff914ee12afe 100644 --- a/lib/private/Files/Storage/Storage.php +++ b/lib/private/Files/Storage/Storage.php @@ -8,6 +8,7 @@ namespace OC\Files\Storage; +use OCP\Files\Storage\ILockingStorage; use OCP\Files\Storage\IStorage; /** @@ -15,7 +16,50 @@ * * All paths passed to the storage are relative to the storage and should NOT have a leading slash. */ -interface Storage extends IStorage { +interface Storage extends IStorage, ILockingStorage { + /** + * get a cache instance for the storage + * + * @param string $path + * @param \OC\Files\Storage\Storage|null (optional) the storage to pass to the cache + * @return \OC\Files\Cache\Cache + */ + public function getCache($path = '', $storage = null); + + /** + * get a scanner instance for the storage + * + * @param string $path + * @param \OC\Files\Storage\Storage (optional) the storage to pass to the scanner + * @return \OC\Files\Cache\Scanner + */ + public function getScanner($path = '', $storage = null); + + /** + * get a watcher instance for the cache + * + * @param string $path + * @param \OC\Files\Storage\Storage (optional) the storage to pass to the watcher + * @return \OC\Files\Cache\Watcher + */ + public function getWatcher($path = '', $storage = null); + + /** + * get a propagator instance for the cache + * + * @param \OC\Files\Storage\Storage (optional) the storage to pass to the watcher + * @return \OC\Files\Cache\Propagator + */ + public function getPropagator($storage = null); + + /** + * get a updater instance for the cache + * + * @param \OC\Files\Storage\Storage (optional) the storage to pass to the watcher + * @return \OC\Files\Cache\Updater + */ + public function getUpdater($storage = null); + /** * @return \OC\Files\Cache\Storage */ diff --git a/lib/private/Files/Storage/Temporary.php b/lib/private/Files/Storage/Temporary.php index 95ae84cb7d9b4..6c7ef4260c192 100644 --- a/lib/private/Files/Storage/Temporary.php +++ b/lib/private/Files/Storage/Temporary.php @@ -11,7 +11,7 @@ * local storage backend in temporary folder for testing purpose */ class Temporary extends Local { - public function __construct($arguments = null) { + public function __construct($arguments = []) { parent::__construct(['datadir' => \OC::$server->getTempManager()->getTemporaryFolder()]); } diff --git a/lib/public/Files/Storage/IStorage.php b/lib/public/Files/Storage/IStorage.php index 907670052392f..08e58be542222 100644 --- a/lib/public/Files/Storage/IStorage.php +++ b/lib/public/Files/Storage/IStorage.php @@ -410,6 +410,7 @@ public function getAvailability(); /** * @since 9.0.0 * @param bool $isAvailable + * @return void */ public function setAvailability($isAvailable); @@ -421,6 +422,7 @@ public function needsPartFile(); /** * @param string $path path for which to retrieve the owner + * @return string * @since 9.0.0 */ public function getOwner($path); From 5d01e0a73c9e27cdec7e51e22ed32707ffca7170 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=B4me=20Chilliet?= Date: Sun, 15 Sep 2024 18:04:39 +0200 Subject: [PATCH 6/9] chore: psalm-suppress legacy code weirdness MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Côme Chilliet --- lib/private/Files/Storage/Common.php | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/lib/private/Files/Storage/Common.php b/lib/private/Files/Storage/Common.php index 01b33648ac0ed..fa8521790f3e2 100644 --- a/lib/private/Files/Storage/Common.php +++ b/lib/private/Files/Storage/Common.php @@ -353,27 +353,37 @@ public function getWatcher($path = '', $storage = null) { /** * get a propagator instance for the cache * - * @param \OC\Files\Storage\Storage (optional) the storage to pass to the watcher - * @return \OC\Files\Cache\Propagator + * @param \OC\Files\Storage\Storage $storage (optional) the storage to pass to the watcher + * @return Propagator */ public function getPropagator($storage = null) { if (!$storage) { $storage = $this; } + /** @psalm-suppress NoInterfaceProperties The isset check is safe */ if (!isset($storage->propagator)) { $config = \OC::$server->getSystemConfig(); $storage->propagator = new Propagator($storage, \OC::$server->getDatabaseConnection(), ['appdata_' . $config->getValue('instanceid')]); } + /** @psalm-suppress NullableReturnStatement False-positive, as the if above avoids this being null */ return $storage->propagator; } + /** + * get a propagator instance for the cache + * + * @param \OC\Files\Storage\Storage $storage (optional) the storage to pass to the watcher + * @return Updater + */ public function getUpdater($storage = null) { if (!$storage) { $storage = $this; } + /** @psalm-suppress NoInterfaceProperties The isset check is safe */ if (!isset($storage->updater)) { $storage->updater = new Updater($storage); } + /** @psalm-suppress NullableReturnStatement False-positive, as the if above avoids this being null */ return $storage->updater; } From ed0ac284e3e56e77f68594b834e4f04abe7ad846 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=B4me=20Chilliet?= Date: Mon, 16 Sep 2024 18:00:47 +0200 Subject: [PATCH 7/9] chore: Remove deprecated Storage::search method instead of moving it to IStorage MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Côme Chilliet --- lib/private/Files/Storage/Common.php | 4 ---- lib/private/Files/Storage/Wrapper/Encoding.php | 10 ---------- lib/private/Files/Storage/Wrapper/Jail.php | 10 ---------- lib/private/Files/Storage/Wrapper/Wrapper.php | 10 ---------- lib/public/Files/Storage/IStorage.php | 9 --------- 5 files changed, 43 deletions(-) diff --git a/lib/private/Files/Storage/Common.php b/lib/private/Files/Storage/Common.php index fa8521790f3e2..80e39fa9b933a 100644 --- a/lib/private/Files/Storage/Common.php +++ b/lib/private/Files/Storage/Common.php @@ -232,10 +232,6 @@ public function hash($type, $path, $raw = false) { return hash_final($ctx, $raw); } - public function search($query) { - return $this->searchInDir($query); - } - public function getLocalFile($path) { return $this->getCachedFile($path); } diff --git a/lib/private/Files/Storage/Wrapper/Encoding.php b/lib/private/Files/Storage/Wrapper/Encoding.php index 11f21eb828e42..a696a3e48026e 100644 --- a/lib/private/Files/Storage/Wrapper/Encoding.php +++ b/lib/private/Files/Storage/Wrapper/Encoding.php @@ -381,16 +381,6 @@ public function free_space($path) { return $this->storage->free_space($this->findPathToUse($path)); } - /** - * search for occurrences of $query in file names - * - * @param string $query - * @return array|bool - */ - public function search($query) { - return $this->storage->search($query); - } - /** * see https://www.php.net/manual/en/function.touch.php * If the backend does not support the operation, false should be returned diff --git a/lib/private/Files/Storage/Wrapper/Jail.php b/lib/private/Files/Storage/Wrapper/Jail.php index 2e8306dc70596..5673caf834ad8 100644 --- a/lib/private/Files/Storage/Wrapper/Jail.php +++ b/lib/private/Files/Storage/Wrapper/Jail.php @@ -321,16 +321,6 @@ public function free_space($path) { return $this->getWrapperStorage()->free_space($this->getUnjailedPath($path)); } - /** - * search for occurrences of $query in file names - * - * @param string $query - * @return array|bool - */ - public function search($query) { - return $this->getWrapperStorage()->search($query); - } - /** * see https://www.php.net/manual/en/function.touch.php * If the backend does not support the operation, false should be returned diff --git a/lib/private/Files/Storage/Wrapper/Wrapper.php b/lib/private/Files/Storage/Wrapper/Wrapper.php index f8aa9d963dcc0..f0420f4f16a4d 100644 --- a/lib/private/Files/Storage/Wrapper/Wrapper.php +++ b/lib/private/Files/Storage/Wrapper/Wrapper.php @@ -316,16 +316,6 @@ public function free_space($path) { return $this->getWrapperStorage()->free_space($path); } - /** - * search for occurrences of $query in file names - * - * @param string $query - * @return array|bool - */ - public function search($query) { - return $this->getWrapperStorage()->search($query); - } - /** * see https://www.php.net/manual/en/function.touch.php * If the backend does not support the operation, false should be returned diff --git a/lib/public/Files/Storage/IStorage.php b/lib/public/Files/Storage/IStorage.php index 08e58be542222..e009f2b6fae13 100644 --- a/lib/public/Files/Storage/IStorage.php +++ b/lib/public/Files/Storage/IStorage.php @@ -279,15 +279,6 @@ public function hash($type, $path, $raw = false); */ public function free_space($path); - /** - * search for occurrences of $query in file names - * - * @param string $query - * @return array|bool - * @since 6.0.0 - */ - public function search($query); - /** * see https://www.php.net/manual/en/function.touch.php * If the backend does not support the operation, false should be returned From e7ac9bb2d8a14ccbf3305de4af851ed1476b205e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=B4me=20Chilliet?= Date: Mon, 16 Sep 2024 18:07:03 +0200 Subject: [PATCH 8/9] chore: Check storage is an instance of the correct class instead of psalm-suppress MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Côme Chilliet --- lib/private/Files/Storage/Common.php | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/lib/private/Files/Storage/Common.php b/lib/private/Files/Storage/Common.php index 80e39fa9b933a..eb93ab89bc7e8 100644 --- a/lib/private/Files/Storage/Common.php +++ b/lib/private/Files/Storage/Common.php @@ -326,11 +326,12 @@ public function getScanner($path = '', $storage = null) { if (!$storage) { $storage = $this; } - /** @psalm-suppress NoInterfaceProperties The isset check is safe */ + if (!$storage->instanceOfStorage(self::class)) { + throw new \InvalidArgumentException('Storage is not of the correct class'); + } if (!isset($storage->scanner)) { $storage->scanner = new Scanner($storage); } - /** @psalm-suppress NoInterfaceProperties Legacy stuff */ return $storage->scanner; } @@ -356,12 +357,13 @@ public function getPropagator($storage = null) { if (!$storage) { $storage = $this; } - /** @psalm-suppress NoInterfaceProperties The isset check is safe */ + if (!$storage->instanceOfStorage(self::class)) { + throw new \InvalidArgumentException('Storage is not of the correct class'); + } if (!isset($storage->propagator)) { $config = \OC::$server->getSystemConfig(); $storage->propagator = new Propagator($storage, \OC::$server->getDatabaseConnection(), ['appdata_' . $config->getValue('instanceid')]); } - /** @psalm-suppress NullableReturnStatement False-positive, as the if above avoids this being null */ return $storage->propagator; } @@ -375,11 +377,12 @@ public function getUpdater($storage = null) { if (!$storage) { $storage = $this; } - /** @psalm-suppress NoInterfaceProperties The isset check is safe */ + if (!$storage->instanceOfStorage(self::class)) { + throw new \InvalidArgumentException('Storage is not of the correct class'); + } if (!isset($storage->updater)) { $storage->updater = new Updater($storage); } - /** @psalm-suppress NullableReturnStatement False-positive, as the if above avoids this being null */ return $storage->updater; } From 03b969fb9597ae86564ad5f8a83d6fd64bd1d65a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=B4me=20Chilliet?= Date: Mon, 16 Sep 2024 20:29:48 +0200 Subject: [PATCH 9/9] chore: Improve typing and phpdoc comments MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Côme Chilliet --- apps/dav/tests/unit/Connector/Sabre/FileTest.php | 10 ++-------- apps/files_trashbin/lib/Trashbin.php | 5 +++-- lib/public/Files/Storage/IStorage.php | 3 ++- 3 files changed, 7 insertions(+), 11 deletions(-) diff --git a/apps/dav/tests/unit/Connector/Sabre/FileTest.php b/apps/dav/tests/unit/Connector/Sabre/FileTest.php index 07128a1c7af76..55a6783225d8e 100644 --- a/apps/dav/tests/unit/Connector/Sabre/FileTest.php +++ b/apps/dav/tests/unit/Connector/Sabre/FileTest.php @@ -72,10 +72,7 @@ protected function tearDown(): void { parent::tearDown(); } - /** - * @return MockObject|IStorage - */ - private function getMockStorage() { + private function getMockStorage(): MockObject&IStorage { $storage = $this->getMockBuilder(IStorage::class) ->disableOriginalConstructor() ->getMock(); @@ -84,10 +81,7 @@ private function getMockStorage() { return $storage; } - /** - * @param string $string - */ - private function getStream($string) { + private function getStream(string $string) { $stream = fopen('php://temp', 'r+'); fwrite($stream, $string); fseek($stream, 0); diff --git a/apps/files_trashbin/lib/Trashbin.php b/apps/files_trashbin/lib/Trashbin.php index b83a81972e1ed..544bc877d70a6 100644 --- a/apps/files_trashbin/lib/Trashbin.php +++ b/apps/files_trashbin/lib/Trashbin.php @@ -140,6 +140,7 @@ public static function getLocation($user, $filename, $timestamp) { } } + /** @param string $user */ private static function setUpTrash($user): void { $view = new View('/' . $user); if (!$view->is_dir('files_trashbin')) { @@ -163,10 +164,10 @@ private static function setUpTrash($user): void { * @param string $sourcePath * @param string $owner * @param string $targetPath - * @param $user + * @param string $user * @param int $timestamp */ - private static function copyFilesToUser($sourcePath, $owner, $targetPath, $user, $timestamp) { + private static function copyFilesToUser($sourcePath, $owner, $targetPath, $user, $timestamp): void { self::setUpTrash($owner); $targetFilename = basename($targetPath); diff --git a/lib/public/Files/Storage/IStorage.php b/lib/public/Files/Storage/IStorage.php index e009f2b6fae13..d2fd3b7555302 100644 --- a/lib/public/Files/Storage/IStorage.php +++ b/lib/public/Files/Storage/IStorage.php @@ -407,7 +407,8 @@ public function setAvailability($isAvailable); /** * @since 12.0.0 - * @return mixed + * @since 31.0.0 moved from Storage to IStorage + * @return bool */ public function needsPartFile();