From 22822d5e9b29e7c49a524bf2e6e60291c244ff09 Mon Sep 17 00:00:00 2001 From: =?utf8?q?C=C3=B4me=20Chilliet?= Date: Sun, 15 Sep 2024 15:38:25 +0200 Subject: [PATCH] fix: Fix other uses of removed Storage interface MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 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 00f757d4734..62f5880294c 100644 --- a/apps/files_sharing/lib/SharedStorage.php +++ b/apps/files_sharing/lib/SharedStorage.php @@ -27,6 +27,7 @@ use OCP\Files\IHomeStorage; 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 @@ class SharedStorage extends \OC\Files\Storage\Wrapper\Jail implements LegacyISha * @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 @@ class SharedStorage extends \OC\Files\Storage\Wrapper\Jail implements LegacyISha * @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 @@ class SharedStorage extends \OC\Files\Storage\Wrapper\Jail implements LegacyISha * @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 5f907ad8de3..49ff97c053a 100644 --- a/apps/files_sharing/tests/SharedStorageTest.php +++ b/apps/files_sharing/tests/SharedStorageTest.php @@ -416,9 +416,6 @@ class SharedStorageTest extends TestCase { $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 @@ class SharedStorageTest extends TestCase { $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 44b1a52cfc0..8f37daaf613 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 @@ interface Storage extends \OCP\Files\Storage { */ 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 612592e2d3a..590425f5b64 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 @@ class StorageFactory implements IStorageFactory { /** * 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 @@ class StorageFactory implements IStorageFactory { }, $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 e18d6768346..90767005239 100644 --- a/lib/public/Files/Storage/IStorage.php +++ b/lib/public/Files/Storage/IStorage.php @@ -279,6 +279,15 @@ interface IStorage { */ 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 @@ interface IStorage { */ 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 5b0bbf2f95b..36d70965848 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 @@ abstract class Storage extends \Test\TestCase { } 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 66f2a2af9a6..d1e8d927dc9 100644 --- a/tests/lib/Files/Storage/StorageFactoryTest.php +++ b/tests/lib/Files/Storage/StorageFactoryTest.php @@ -10,7 +10,7 @@ namespace Test\Files\Storage; 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 { -- 2.39.5