]> source.dussan.org Git - nextcloud-server.git/commitdiff
fix(files_sharing): Fix all IStorage return types
authorprovokateurin <kate@provokateurin.de>
Thu, 19 Sep 2024 16:18:39 +0000 (18:18 +0200)
committerprovokateurin <kate@provokateurin.de>
Thu, 26 Sep 2024 15:29:47 +0000 (17:29 +0200)
Signed-off-by: provokateurin <kate@provokateurin.de>
apps/files_sharing/lib/External/Storage.php
apps/files_sharing/lib/SharedStorage.php
apps/files_sharing/tests/ExternalStorageTest.php

index 6e5e219ae697033561daa22b807c6a83a27469da..718afbf7499a01e76bdf80e91b56104966152546 100644 (file)
@@ -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('');
        }
 
index 0a6a068c4415675d774198a4a39d71a79c639efc..7addc9f0a912a7f36f74a4bf7985967e75ec6857 100644 (file)
@@ -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);
        }
index 56a1f3200308cee05ff4f57b64d39008bfd58d23..90aad4dca6eb0a1f5881fd490daf681bb153c12a 100644 (file)
@@ -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);
        }