diff options
author | provokateurin <kate@provokateurin.de> | 2024-09-19 18:18:39 +0200 |
---|---|---|
committer | provokateurin <kate@provokateurin.de> | 2024-09-26 17:29:47 +0200 |
commit | 376d5665bb56d9bdf04825c174381ad116d91727 (patch) | |
tree | 5a3b4c433444f65f79324cb6dddbf53ea204fa3b /apps | |
parent | 0356e9e82f8a16057dffd78a3436c5a2558533bc (diff) | |
download | nextcloud-server-376d5665bb56d9bdf04825c174381ad116d91727.tar.gz nextcloud-server-376d5665bb56d9bdf04825c174381ad116d91727.zip |
fix(files_sharing): Fix all IStorage return types
Signed-off-by: provokateurin <kate@provokateurin.de>
Diffstat (limited to 'apps')
-rw-r--r-- | apps/files_sharing/lib/External/Storage.php | 34 | ||||
-rw-r--r-- | apps/files_sharing/lib/SharedStorage.php | 63 | ||||
-rw-r--r-- | apps/files_sharing/tests/ExternalStorageTest.php | 7 |
3 files changed, 34 insertions, 70 deletions
diff --git a/apps/files_sharing/lib/External/Storage.php b/apps/files_sharing/lib/External/Storage.php index 6e5e219ae69..718afbf7499 100644 --- a/apps/files_sharing/lib/External/Storage.php +++ b/apps/files_sharing/lib/External/Storage.php @@ -18,6 +18,9 @@ use OCA\Files_Sharing\ISharedStorage; use OCP\AppFramework\Http; use OCP\Constants; use OCP\Federation\ICloudId; +use OCP\Files\Cache\ICache; +use OCP\Files\Cache\IScanner; +use OCP\Files\Cache\IWatcher; use OCP\Files\NotFoundException; use OCP\Files\Storage\IDisableEncryptionStorage; use OCP\Files\Storage\IReliableEtagStorage; @@ -91,7 +94,7 @@ class Storage extends DAV implements ISharedStorage, IDisableEncryptionStorage, ); } - public function getWatcher($path = '', $storage = null) { + public function getWatcher($path = '', $storage = null): IWatcher { if (!$storage) { $storage = $this; } @@ -122,22 +125,18 @@ class Storage extends DAV implements ISharedStorage, IDisableEncryptionStorage, return $this->password; } - /** - * Get id of the mount point. - * @return string - */ - public function getId() { + public function getId(): string { return 'shared::' . md5($this->token . '@' . $this->getRemote()); } - public function getCache($path = '', $storage = null) { + public function getCache($path = '', $storage = null): ICache { if (is_null($this->cache)) { $this->cache = new Cache($this, $this->cloudId); } return $this->cache; } - public function getScanner($path = '', $storage = null) { + public function getScanner($path = '', $storage = null): IScanner { if (!$storage) { $storage = $this; } @@ -148,16 +147,7 @@ class Storage extends DAV implements ISharedStorage, IDisableEncryptionStorage, return $this->scanner; } - /** - * Check if a file or folder has been updated since $time - * - * @param string $path - * @param int $time - * @throws \OCP\Files\StorageNotAvailableException - * @throws \OCP\Files\StorageInvalidException - * @return bool - */ - public function hasUpdated($path, $time) { + public function hasUpdated($path, $time): bool { // since for owncloud webdav servers we can rely on etag propagation we only need to check the root of the storage // because of that we only do one check for the entire storage per request if ($this->updateChecked) { @@ -177,7 +167,7 @@ class Storage extends DAV implements ISharedStorage, IDisableEncryptionStorage, } } - public function test() { + public function test(): bool { try { return parent::test(); } catch (StorageInvalidException $e) { @@ -227,7 +217,7 @@ class Storage extends DAV implements ISharedStorage, IDisableEncryptionStorage, } } - public function file_exists($path) { + public function file_exists($path): bool { if ($path === '') { return true; } else { @@ -368,7 +358,7 @@ class Storage extends DAV implements ISharedStorage, IDisableEncryptionStorage, return $permissions; } - public function needsPartFile() { + public function needsPartFile(): bool { return false; } @@ -418,7 +408,7 @@ class Storage extends DAV implements ISharedStorage, IDisableEncryptionStorage, return $permissions; } - public function free_space($path) { + public function free_space($path): int|float|false { return parent::free_space(''); } diff --git a/apps/files_sharing/lib/SharedStorage.php b/apps/files_sharing/lib/SharedStorage.php index 0a6a068c441..7addc9f0a91 100644 --- a/apps/files_sharing/lib/SharedStorage.php +++ b/apps/files_sharing/lib/SharedStorage.php @@ -9,18 +9,21 @@ namespace OCA\Files_Sharing; use OC\Files\Cache\CacheDependencies; use OC\Files\Cache\FailedCache; use OC\Files\Cache\NullWatcher; -use OC\Files\Cache\Watcher; use OC\Files\ObjectStore\HomeObjectStoreStorage; use OC\Files\Storage\Common; use OC\Files\Storage\FailedStorage; use OC\Files\Storage\Home; +use OC\Files\Storage\Storage; use OC\Files\Storage\Wrapper\PermissionsMask; use OC\Files\Storage\Wrapper\Wrapper; use OC\User\NoUserException; use OCA\Files_External\Config\ConfigAdapter; use OCA\Files_Sharing\ISharedStorage as LegacyISharedStorage; use OCP\Constants; +use OCP\Files\Cache\ICache; use OCP\Files\Cache\ICacheEntry; +use OCP\Files\Cache\IScanner; +use OCP\Files\Cache\IWatcher; use OCP\Files\Config\IUserMountCache; use OCP\Files\Folder; use OCP\Files\IHomeStorage; @@ -78,7 +81,7 @@ class SharedStorage extends \OC\Files\Storage\Wrapper\Jail implements LegacyISha /** * @psalm-suppress NonInvariantDocblockPropertyType - * @var ?\OC\Files\Storage\Storage $storage + * @var ?Storage $storage */ protected $storage; @@ -118,7 +121,7 @@ class SharedStorage extends \OC\Files\Storage\Wrapper\Jail implements LegacyISha } /** - * @psalm-assert \OC\Files\Storage\Storage $this->storage + * @psalm-assert Storage $this->storage */ private function init() { if ($this->initialized) { @@ -199,9 +202,6 @@ class SharedStorage extends \OC\Files\Storage\Wrapper\Jail implements LegacyISha self::$initDepth--; } - /** - * @inheritdoc - */ public function instanceOfStorage($class): bool { if ($class === '\OC\Files\Storage\Common' || $class == Common::class) { return true; @@ -230,21 +230,10 @@ class SharedStorage extends \OC\Files\Storage\Wrapper\Jail implements LegacyISha return $this->getSourceRootInfo() && ($this->getSourceRootInfo()->getPermissions() & Constants::PERMISSION_SHARE) === Constants::PERMISSION_SHARE; } - /** - * get id of the mount point - * - * @return string - */ public function getId(): string { return 'shared::' . $this->getMountPoint(); } - /** - * Get the permissions granted for a shared file - * - * @param string $path Shared target file path - * @return int CRUDS permissions granted - */ public function getPermissions($path = ''): int { if (!$this->isValid()) { return 0; @@ -347,13 +336,6 @@ class SharedStorage extends \OC\Files\Storage\Wrapper\Jail implements LegacyISha return $this->nonMaskedStorage->fopen($this->getUnjailedPath($path), $mode); } - /** - * see https://www.php.net/manual/en/function.rename.php - * - * @param string $source - * @param string $target - * @return bool - */ public function rename($source, $target): bool { $this->init(); $isPartFile = pathinfo($source, PATHINFO_EXTENSION) === 'part'; @@ -402,9 +384,6 @@ class SharedStorage extends \OC\Files\Storage\Wrapper\Jail implements LegacyISha return $this->superShare->getShareOwner(); } - /** - * @return \OCP\Share\IShare - */ public function getShare(): IShare { return $this->superShare; } @@ -418,7 +397,7 @@ class SharedStorage extends \OC\Files\Storage\Wrapper\Jail implements LegacyISha return $this->superShare->getNodeType(); } - public function getCache($path = '', $storage = null) { + public function getCache($path = '', $storage = null): ICache { if ($this->cache) { return $this->cache; } @@ -439,7 +418,7 @@ class SharedStorage extends \OC\Files\Storage\Wrapper\Jail implements LegacyISha return $this->cache; } - public function getScanner($path = '', $storage = null) { + public function getScanner($path = '', $storage = null): IScanner { if (!$storage) { $storage = $this; } @@ -450,7 +429,7 @@ class SharedStorage extends \OC\Files\Storage\Wrapper\Jail implements LegacyISha return $this->superShare->getShareOwner(); } - public function getWatcher($path = '', $storage = null): Watcher { + public function getWatcher($path = '', $storage = null): IWatcher { if ($this->watcher) { return $this->watcher; } @@ -488,7 +467,7 @@ class SharedStorage extends \OC\Files\Storage\Wrapper\Jail implements LegacyISha return true; } - public function acquireLock($path, $type, ILockingProvider $provider) { + public function acquireLock($path, $type, ILockingProvider $provider): void { /** @var ILockingStorage $targetStorage */ [$targetStorage, $targetInternalPath] = $this->resolvePath($path); $targetStorage->acquireLock($targetInternalPath, $type, $provider); @@ -499,7 +478,7 @@ class SharedStorage extends \OC\Files\Storage\Wrapper\Jail implements LegacyISha } } - public function releaseLock($path, $type, ILockingProvider $provider) { + public function releaseLock($path, $type, ILockingProvider $provider): void { /** @var ILockingStorage $targetStorage */ [$targetStorage, $targetInternalPath] = $this->resolvePath($path); $targetStorage->releaseLock($targetInternalPath, $type, $provider); @@ -510,16 +489,13 @@ class SharedStorage extends \OC\Files\Storage\Wrapper\Jail implements LegacyISha } } - public function changeLock($path, $type, ILockingProvider $provider) { + public function changeLock($path, $type, ILockingProvider $provider): void { /** @var ILockingStorage $targetStorage */ [$targetStorage, $targetInternalPath] = $this->resolvePath($path); $targetStorage->changeLock($targetInternalPath, $type, $provider); } - /** - * @return array [ available, last_checked ] - */ - public function getAvailability() { + public function getAvailability(): array { // shares do not participate in availability logic return [ 'available' => true, @@ -527,10 +503,7 @@ class SharedStorage extends \OC\Files\Storage\Wrapper\Jail implements LegacyISha ]; } - /** - * @param bool $isAvailable - */ - public function setAvailability($isAvailable) { + public function setAvailability($isAvailable): void { // shares do not participate in availability logic } @@ -539,7 +512,7 @@ class SharedStorage extends \OC\Files\Storage\Wrapper\Jail implements LegacyISha return $this->nonMaskedStorage; } - public function getWrapperStorage() { + public function getWrapperStorage(): Storage { $this->init(); /** @@ -554,7 +527,7 @@ class SharedStorage extends \OC\Files\Storage\Wrapper\Jail implements LegacyISha return $this->storage; } - public function file_get_contents($path) { + public function file_get_contents($path): string|false { $info = [ 'target' => $this->getMountPoint() . '/' . $path, 'source' => $this->getUnjailedPath($path), @@ -563,7 +536,7 @@ class SharedStorage extends \OC\Files\Storage\Wrapper\Jail implements LegacyISha return parent::file_get_contents($path); } - public function file_put_contents($path, $data) { + public function file_put_contents($path, $data): int|float|false { $info = [ 'target' => $this->getMountPoint() . '/' . $path, 'source' => $this->getUnjailedPath($path), @@ -580,7 +553,7 @@ class SharedStorage extends \OC\Files\Storage\Wrapper\Jail implements LegacyISha $this->mountOptions = $options; } - public function getUnjailedPath($path) { + public function getUnjailedPath($path): string { $this->init(); return parent::getUnjailedPath($path); } diff --git a/apps/files_sharing/tests/ExternalStorageTest.php b/apps/files_sharing/tests/ExternalStorageTest.php index 56a1f320030..90aad4dca6e 100644 --- a/apps/files_sharing/tests/ExternalStorageTest.php +++ b/apps/files_sharing/tests/ExternalStorageTest.php @@ -95,7 +95,8 @@ class ExternalStorageTest extends \Test\TestCase { } public function testIfTestReturnsTheValue(): void { - $result = $this->getTestStorage('https://remoteserver')->test(); + $storage = $this->getTestStorage('https://remoteserver'); + $result = $storage->test(); $this->assertSame(true, $result); } } @@ -108,9 +109,9 @@ class TestSharingExternalStorage extends \OCA\Files_Sharing\External\Storage { return $this->createBaseUri(); } - public function stat($path) { + public function stat($path): array|false { if ($path === '') { - return true; + return ['key' => 'value']; } return parent::stat($path); } |