From 82bd7095644060cbdfdc0d517f9cccddcf6f7845 Mon Sep 17 00:00:00 2001 From: provokateurin Date: Thu, 19 Sep 2024 18:19:34 +0200 Subject: [PATCH] fix(Storage): Fix IStorage return types Signed-off-by: provokateurin --- .../Files/ObjectStore/ObjectStoreStorage.php | 43 +-- lib/private/Files/Storage/Common.php | 128 +++---- lib/private/Files/Storage/CommonTest.php | 22 +- lib/private/Files/Storage/DAV.php | 98 ++--- lib/private/Files/Storage/FailedStorage.php | 85 ++-- lib/private/Files/Storage/Home.php | 18 +- lib/private/Files/Storage/Local.php | 77 ++-- .../Files/Storage/LocalRootStorage.php | 3 +- .../Files/Storage/LocalTempFileTrait.php | 2 +- .../Files/Storage/PolyFill/CopyDirectory.php | 22 +- lib/private/Files/Storage/Storage.php | 56 +-- lib/private/Files/Storage/StorageFactory.php | 28 +- lib/private/Files/Storage/Temporary.php | 4 +- .../Files/Storage/Wrapper/Availability.php | 149 ++++--- .../Files/Storage/Wrapper/Encoding.php | 273 ++----------- .../Wrapper/EncodingDirectoryWrapper.php | 7 +- .../Files/Storage/Wrapper/Encryption.php | 140 ++----- lib/private/Files/Storage/Wrapper/Jail.php | 286 +++----------- .../Files/Storage/Wrapper/KnownMtime.php | 26 +- .../Files/Storage/Wrapper/PermissionsMask.php | 32 +- lib/private/Files/Storage/Wrapper/Quota.php | 62 +-- lib/private/Files/Storage/Wrapper/Wrapper.php | 362 +++--------------- lib/private/Files/Stream/Quota.php | 2 +- lib/private/Files/Utils/Scanner.php | 3 + .../Lockdown/Filesystem/NullStorage.php | 55 +-- 25 files changed, 527 insertions(+), 1456 deletions(-) diff --git a/lib/private/Files/ObjectStore/ObjectStoreStorage.php b/lib/private/Files/ObjectStore/ObjectStoreStorage.php index 26823f65c2f0e..7b731a4d40d82 100644 --- a/lib/private/Files/ObjectStore/ObjectStoreStorage.php +++ b/lib/private/Files/ObjectStore/ObjectStoreStorage.php @@ -17,6 +17,7 @@ use OC\Files\Storage\PolyFill\CopyDirectory; use OCP\Files\Cache\ICache; use OCP\Files\Cache\ICacheEntry; +use OCP\Files\Cache\IScanner; use OCP\Files\FileInfo; use OCP\Files\GenericFileException; use OCP\Files\NotFoundException; @@ -64,7 +65,7 @@ public function __construct($params) { $this->logger = \OCP\Server::get(LoggerInterface::class); } - public function mkdir($path, bool $force = false) { + public function mkdir($path, bool $force = false): bool { $path = $this->normalizePath($path); if (!$force && $this->file_exists($path)) { $this->logger->warning("Tried to create an object store folder that already exists: $path"); @@ -130,7 +131,7 @@ private function normalizePath($path) { * Object Stores use a NoopScanner because metadata is directly stored in * the file cache and cannot really scan the filesystem. The storage passed in is not used anywhere. */ - public function getScanner($path = '', $storage = null) { + public function getScanner($path = '', $storage = null): IScanner { if (!$storage) { $storage = $this; } @@ -141,11 +142,11 @@ public function getScanner($path = '', $storage = null) { return $this->scanner; } - public function getId() { + public function getId(): string { return $this->id; } - public function rmdir($path) { + public function rmdir($path): bool { $path = $this->normalizePath($path); $entry = $this->getCache()->get($path); @@ -175,7 +176,7 @@ private function rmObjects(ICacheEntry $entry): bool { return true; } - public function unlink($path) { + public function unlink($path): bool { $path = $this->normalizePath($path); $entry = $this->getCache()->get($path); @@ -209,7 +210,7 @@ public function rmObject(ICacheEntry $entry): bool { return true; } - public function stat($path) { + public function stat($path): array|false { $path = $this->normalizePath($path); $cacheEntry = $this->getCache()->get($path); if ($cacheEntry instanceof CacheEntry) { @@ -226,7 +227,7 @@ public function stat($path) { } } - public function getPermissions($path) { + public function getPermissions($path): int { $stat = $this->stat($path); if (is_array($stat) && isset($stat['permissions'])) { @@ -268,7 +269,7 @@ public function opendir($path) { } } - public function filetype($path) { + public function filetype($path): string|false { $path = $this->normalizePath($path); $stat = $this->stat($path); if ($stat) { @@ -373,12 +374,12 @@ public function fopen($path, $mode) { return false; } - public function file_exists($path) { + public function file_exists($path): bool { $path = $this->normalizePath($path); return (bool)$this->stat($path); } - public function rename($source, $target) { + public function rename($source, $target): bool { $source = $this->normalizePath($source); $target = $this->normalizePath($target); $this->remove($target); @@ -387,12 +388,12 @@ public function rename($source, $target) { return true; } - public function getMimeType($path) { + public function getMimeType($path): string|false { $path = $this->normalizePath($path); return parent::getMimeType($path); } - public function touch($path, $mtime = null) { + public function touch($path, $mtime = null): bool { if (is_null($mtime)) { $mtime = time(); } @@ -443,22 +444,15 @@ public function writeBack($tmpFile, $path) { $this->writeStream($path, fopen($tmpFile, 'r'), $size); } - /** - * external changes are not supported, exclusive access to the object storage is assumed - * - * @param string $path - * @param int $time - * @return false - */ - public function hasUpdated($path, $time) { + public function hasUpdated($path, $time): bool { return false; } - public function needsPartFile() { + public function needsPartFile(): bool { return false; } - public function file_put_contents($path, $data) { + public function file_put_contents($path, $data): int { $fh = fopen('php://temp', 'w+'); fwrite($fh, $data); rewind($fh); @@ -571,7 +565,7 @@ public function copyFromStorage( $sourceInternalPath, $targetInternalPath, $preserveMtime = false, - ) { + ): bool { if ($sourceStorage->instanceOfStorage(ObjectStoreStorage::class)) { /** @var ObjectStoreStorage $sourceStorage */ if ($sourceStorage->getObjectStore()->getStorageId() === $this->getObjectStore()->getStorageId()) { @@ -627,7 +621,7 @@ public function moveFromStorage(IStorage $sourceStorage, $sourceInternalPath, $t return true; } - public function copy($source, $target) { + public function copy($source, $target): bool { $source = $this->normalizePath($source); $target = $this->normalizePath($target); @@ -695,7 +689,6 @@ public function startChunkedWrite(string $targetPath): string { } /** - * * @throws GenericFileException */ public function putChunkedWritePart( diff --git a/lib/private/Files/Storage/Common.php b/lib/private/Files/Storage/Common.php index b6f14321f6141..375e0987e2580 100644 --- a/lib/private/Files/Storage/Common.php +++ b/lib/private/Files/Storage/Common.php @@ -17,6 +17,11 @@ use OC\Files\Filesystem; use OC\Files\Storage\Wrapper\Jail; use OC\Files\Storage\Wrapper\Wrapper; +use OCP\Files\Cache\ICache; +use OCP\Files\Cache\IPropagator; +use OCP\Files\Cache\IScanner; +use OCP\Files\Cache\IUpdater; +use OCP\Files\Cache\IWatcher; use OCP\Files\ForbiddenException; use OCP\Files\GenericFileException; use OCP\Files\IFilenameValidator; @@ -65,9 +70,8 @@ public function __construct($parameters) { * Remove a file or folder * * @param string $path - * @return bool */ - protected function remove($path) { + protected function remove($path): bool { if ($this->is_dir($path)) { return $this->rmdir($path); } elseif ($this->is_file($path)) { @@ -77,11 +81,11 @@ protected function remove($path) { } } - public function is_dir($path) { + public function is_dir($path): bool { return $this->filetype($path) === 'dir'; } - public function is_file($path) { + public function is_file($path): bool { return $this->filetype($path) === 'file'; } @@ -98,27 +102,27 @@ public function filesize($path): false|int|float { } } - public function isReadable($path) { + public function isReadable($path): bool { // at least check whether it exists // subclasses might want to implement this more thoroughly return $this->file_exists($path); } - public function isUpdatable($path) { + public function isUpdatable($path): bool { // at least check whether it exists // subclasses might want to implement this more thoroughly // a non-existing file/folder isn't updatable return $this->file_exists($path); } - public function isCreatable($path) { + public function isCreatable($path): bool { if ($this->is_dir($path) && $this->isUpdatable($path)) { return true; } return false; } - public function isDeletable($path) { + public function isDeletable($path): bool { if ($path === '' || $path === '/') { return $this->isUpdatable($path); } @@ -126,11 +130,11 @@ public function isDeletable($path) { return $this->isUpdatable($parent) && $this->isUpdatable($path); } - public function isSharable($path) { + public function isSharable($path): bool { return $this->isReadable($path); } - public function getPermissions($path) { + public function getPermissions($path): int { $permissions = 0; if ($this->isCreatable($path)) { $permissions |= \OCP\Constants::PERMISSION_CREATE; @@ -150,7 +154,7 @@ public function getPermissions($path) { return $permissions; } - public function filemtime($path) { + public function filemtime($path): int|false { $stat = $this->stat($path); if (isset($stat['mtime']) && $stat['mtime'] > 0) { return $stat['mtime']; @@ -159,7 +163,7 @@ public function filemtime($path) { } } - public function file_get_contents($path) { + public function file_get_contents($path): bool|string { $handle = $this->fopen($path, 'r'); if (!$handle) { return false; @@ -169,7 +173,7 @@ public function file_get_contents($path) { return $data; } - public function file_put_contents($path, $data) { + public function file_put_contents($path, $data): float|bool|int { $handle = $this->fopen($path, 'w'); if (!$handle) { return false; @@ -180,14 +184,14 @@ public function file_put_contents($path, $data) { return $count; } - public function rename($source, $target) { + public function rename($source, $target): bool { $this->remove($target); $this->removeCachedFile($source); return $this->copy($source, $target) and $this->remove($source); } - public function copy($source, $target) { + public function copy($source, $target): bool { if ($this->is_dir($source)) { $this->remove($target); $dir = $this->opendir($source); @@ -214,7 +218,7 @@ public function copy($source, $target) { } } - public function getMimeType($path) { + public function getMimeType($path): bool|string { if ($this->is_dir($path)) { return 'httpd/unix-directory'; } elseif ($this->file_exists($path)) { @@ -224,7 +228,7 @@ public function getMimeType($path) { } } - public function hash($type, $path, $raw = false) { + public function hash($type, $path, $raw = false): bool|string { $fh = $this->fopen($path, 'rb'); $ctx = hash_init($type); hash_update_stream($ctx, $fh); @@ -232,15 +236,11 @@ public function hash($type, $path, $raw = false) { return hash_final($ctx, $raw); } - public function getLocalFile($path) { + public function getLocalFile($path): bool|string { return $this->getCachedFile($path); } - /** - * @param string $path - * @param string $target - */ - private function addLocalFolder($path, $target) { + private function addLocalFolder($path, $target): void { $dh = $this->opendir($path); if (is_resource($dh)) { while (($file = readdir($dh)) !== false) { @@ -257,12 +257,7 @@ private function addLocalFolder($path, $target) { } } - /** - * @param string $query - * @param string $dir - * @return array - */ - protected function searchInDir($query, $dir = '') { + protected function searchInDir($query, $dir = ''): array { $files = []; $dh = $this->opendir($dir); if (is_resource($dh)) { @@ -283,18 +278,15 @@ protected function searchInDir($query, $dir = '') { } /** + * @inheritDoc * Check if a file or folder has been updated since $time * * The method is only used to check if the cache needs to be updated. Storage backends that don't support checking * the mtime should always return false here. As a result storage implementations that always return false expect * exclusive access to the backend and will not pick up files that have been added in a way that circumvents * Nextcloud filesystem. - * - * @param string $path - * @param int $time - * @return bool */ - public function hasUpdated($path, $time) { + public function hasUpdated($path, $time): bool { return $this->filemtime($path) > $time; } @@ -306,23 +298,18 @@ protected function getCacheDependencies(): CacheDependencies { return $dependencies; } - /** - * @return Cache - */ - public function getCache($path = '', $storage = null) { + public function getCache($path = '', $storage = null): ICache { if (!$storage) { $storage = $this; } - /** @psalm-suppress NoInterfaceProperties The isset check is safe */ + /** @var self $storage */ 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; } - public function getScanner($path = '', $storage = null) { + public function getScanner($path = '', $storage = null): IScanner { if (!$storage) { $storage = $this; } @@ -335,7 +322,7 @@ public function getScanner($path = '', $storage = null) { return $storage->scanner; } - public function getWatcher($path = '', $storage = null) { + public function getWatcher($path = '', $storage = null): IWatcher { if (!$storage) { $storage = $this; } @@ -347,7 +334,7 @@ public function getWatcher($path = '', $storage = null) { return $this->watcher; } - public function getPropagator($storage = null) { + public function getPropagator($storage = null): IPropagator { if (!$storage) { $storage = $this; } @@ -362,27 +349,24 @@ public function getPropagator($storage = 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) { + public function getUpdater($storage = null): IUpdater { if (!$storage) { $storage = $this; } if (!$storage->instanceOfStorage(self::class)) { throw new \InvalidArgumentException('Storage is not of the correct class'); } + /** @var self $storage */ if (!isset($storage->updater)) { $storage->updater = new Updater($storage); } return $storage->updater; } - public function getStorageCache($storage = null) { - return $this->getCache($storage)->getStorageCache(); + public function getStorageCache($storage = null): \OC\Files\Cache\Storage { + /** @var Cache $cache */ + $cache = $this->getCache($storage); + return $cache->getStorageCache(); } public function getOwner($path): string|false { @@ -399,7 +383,7 @@ public function getOwner($path): string|false { * @param string $path * @return string|false */ - public function getETag($path) { + public function getETag($path): bool|string { return uniqid(); } @@ -410,7 +394,7 @@ public function getETag($path) { * @param string $path The path to clean * @return string cleaned path */ - public function cleanPath($path) { + public function cleanPath($path): string { if (strlen($path) == 0 or $path[0] != '/') { $path = '/' . $path; } @@ -432,7 +416,7 @@ public function cleanPath($path) { * * @return bool */ - public function test() { + public function test(): bool { try { if ($this->stat('')) { return true; @@ -454,14 +438,14 @@ public function test() { * @param string $path * @return int|float|false */ - public function free_space($path) { + public function free_space($path): float|bool|int { return \OCP\Files\FileInfo::SPACE_UNKNOWN; } /** * {@inheritdoc} */ - public function isLocal() { + public function isLocal(): bool { // the common implementation returns a temporary file by // default, which is not local return false; @@ -473,7 +457,7 @@ public function isLocal() { * @param string $class * @return bool */ - public function instanceOfStorage($class) { + public function instanceOfStorage($class): bool { if (ltrim($class, '\\') === 'OC\Files\Storage\Shared') { // FIXME Temporary fix to keep existing checks working $class = '\OCA\Files_Sharing\SharedStorage'; @@ -489,7 +473,7 @@ public function instanceOfStorage($class) { * @param string $path * @return array|false */ - public function getDirectDownload($path) { + public function getDirectDownload($path): bool|array { return []; } @@ -497,7 +481,7 @@ public function getDirectDownload($path) { * @inheritdoc * @throws InvalidPathException */ - public function verifyPath($path, $fileName) { + public function verifyPath($path, $fileName): void { $this->getFilenameValidator() ->validateFilename($fileName); @@ -529,7 +513,7 @@ protected function getFilenameValidator(): IFilenameValidator { /** * @param array $options */ - public function setMountOptions(array $options) { + public function setMountOptions(array $options): void { $this->mountOptions = $options; } @@ -538,7 +522,7 @@ public function setMountOptions(array $options) { * @param mixed $default * @return mixed */ - public function getMountOption($name, $default = null) { + public function getMountOption($name, $default = null): mixed { return $this->mountOptions[$name] ?? $default; } @@ -549,7 +533,7 @@ public function getMountOption($name, $default = null) { * @param bool $preserveMtime * @return bool */ - public function copyFromStorage(IStorage $sourceStorage, $sourceInternalPath, $targetInternalPath, $preserveMtime = false) { + public function copyFromStorage(IStorage $sourceStorage, $sourceInternalPath, $targetInternalPath, $preserveMtime = false): bool { if ($sourceStorage === $this) { return $this->copy($sourceInternalPath, $targetInternalPath); } @@ -615,7 +599,7 @@ private function isSameStorage(IStorage $storage): bool { * @param string $targetInternalPath * @return bool */ - public function moveFromStorage(IStorage $sourceStorage, $sourceInternalPath, $targetInternalPath) { + public function moveFromStorage(IStorage $sourceStorage, $sourceInternalPath, $targetInternalPath): bool { if ($this->isSameStorage($sourceStorage)) { // resolve any jailed paths while ($sourceStorage->instanceOfStorage(Jail::class)) { @@ -644,7 +628,7 @@ public function moveFromStorage(IStorage $sourceStorage, $sourceInternalPath, $t return $result; } - public function getMetaData($path) { + public function getMetaData($path): ?array { if (Filesystem::isFileBlacklisted($path)) { throw new ForbiddenException('Invalid path: ' . $path, false); } @@ -674,7 +658,7 @@ public function getMetaData($path) { return $data; } - public function acquireLock($path, $type, ILockingProvider $provider) { + public function acquireLock($path, $type, ILockingProvider $provider): void { $logger = $this->getLockLogger(); if ($logger) { $typeString = ($type === ILockingProvider::LOCK_SHARED) ? 'shared' : 'exclusive'; @@ -701,7 +685,7 @@ public function acquireLock($path, $type, ILockingProvider $provider) { } } - public function releaseLock($path, $type, ILockingProvider $provider) { + public function releaseLock($path, $type, ILockingProvider $provider): void { $logger = $this->getLockLogger(); if ($logger) { $typeString = ($type === ILockingProvider::LOCK_SHARED) ? 'shared' : 'exclusive'; @@ -728,7 +712,7 @@ public function releaseLock($path, $type, ILockingProvider $provider) { } } - public function changeLock($path, $type, ILockingProvider $provider) { + public function changeLock($path, $type, ILockingProvider $provider): void { $logger = $this->getLockLogger(); if ($logger) { $typeString = ($type === ILockingProvider::LOCK_SHARED) ? 'shared' : 'exclusive'; @@ -766,14 +750,14 @@ private function getLockLogger(): ?LoggerInterface { /** * @return array [ available, last_checked ] */ - public function getAvailability() { + public function getAvailability(): array { return $this->getStorageCache()->getAvailability(); } /** * @param bool $isAvailable */ - public function setAvailability($isAvailable) { + public function setAvailability($isAvailable): void { $this->getStorageCache()->setAvailability($isAvailable); } @@ -793,7 +777,7 @@ public function setOwner(?string $user): void { /** * @return bool */ - public function needsPartFile() { + public function needsPartFile(): bool { return true; } diff --git a/lib/private/Files/Storage/CommonTest.php b/lib/private/Files/Storage/CommonTest.php index efdd36345785c..f49666648c2d2 100644 --- a/lib/private/Files/Storage/CommonTest.php +++ b/lib/private/Files/Storage/CommonTest.php @@ -18,43 +18,43 @@ public function __construct($params) { $this->storage = new \OC\Files\Storage\Local($params); } - public function getId() { + public function getId(): string { return 'test::' . $this->storage->getId(); } - public function mkdir($path) { + public function mkdir($path): bool { return $this->storage->mkdir($path); } - public function rmdir($path) { + public function rmdir($path): bool { return $this->storage->rmdir($path); } public function opendir($path) { return $this->storage->opendir($path); } - public function stat($path) { + public function stat($path): bool|array { return $this->storage->stat($path); } - public function filetype($path) { + public function filetype($path): bool|string { return @$this->storage->filetype($path); } - public function isReadable($path) { + public function isReadable($path): bool { return $this->storage->isReadable($path); } - public function isUpdatable($path) { + public function isUpdatable($path): bool { return $this->storage->isUpdatable($path); } - public function file_exists($path) { + public function file_exists($path): bool { return $this->storage->file_exists($path); } - public function unlink($path) { + public function unlink($path): bool { return $this->storage->unlink($path); } public function fopen($path, $mode) { return $this->storage->fopen($path, $mode); } - public function free_space($path) { + public function free_space($path): float|bool|int { return $this->storage->free_space($path); } - public function touch($path, $mtime = null) { + public function touch($path, $mtime = null): bool { return $this->storage->touch($path, $mtime); } } diff --git a/lib/private/Files/Storage/DAV.php b/lib/private/Files/Storage/DAV.php index 87aa78887b507..6164a492b09e1 100644 --- a/lib/private/Files/Storage/DAV.php +++ b/lib/private/Files/Storage/DAV.php @@ -128,7 +128,7 @@ public function __construct($params) { $this->mimeTypeDetector = \OC::$server->getMimeTypeDetector(); } - protected function init() { + protected function init(): void { if ($this->ready) { return; } @@ -177,17 +177,15 @@ protected function init() { /** * Clear the stat cache */ - public function clearStatCache() { + public function clearStatCache(): void { $this->statCache->clear(); } - /** {@inheritdoc} */ - public function getId() { + public function getId(): string { return 'webdav::' . $this->user . '@' . $this->host . '/' . $this->root; } - /** {@inheritdoc} */ - public function createBaseUri() { + public function createBaseUri(): string { $baseUri = 'http'; if ($this->secure) { $baseUri .= 's'; @@ -196,8 +194,7 @@ public function createBaseUri() { return $baseUri; } - /** {@inheritdoc} */ - public function mkdir($path) { + public function mkdir($path): bool { $this->init(); $path = $this->cleanPath($path); $result = $this->simpleResponse('MKCOL', $path, null, 201); @@ -207,8 +204,7 @@ public function mkdir($path) { return $result; } - /** {@inheritdoc} */ - public function rmdir($path) { + public function rmdir($path): bool { $this->init(); $path = $this->cleanPath($path); // FIXME: some WebDAV impl return 403 when trying to DELETE @@ -219,7 +215,6 @@ public function rmdir($path) { return $result; } - /** {@inheritdoc} */ public function opendir($path) { $this->init(); $path = $this->cleanPath($path); @@ -248,7 +243,7 @@ public function opendir($path) { * * @throws ClientHttpException */ - protected function propfind($path) { + protected function propfind($path): bool|array { $path = $this->cleanPath($path); $cachedResponse = $this->statCache->get($path); // we either don't know it, or we know it exists but need more details @@ -276,8 +271,7 @@ protected function propfind($path) { return $response; } - /** {@inheritdoc} */ - public function filetype($path) { + public function filetype($path): bool|string { try { $response = $this->propfind($path); if ($response === false) { @@ -295,8 +289,7 @@ public function filetype($path) { return false; } - /** {@inheritdoc} */ - public function file_exists($path) { + public function file_exists($path): bool { try { $path = $this->cleanPath($path); $cachedState = $this->statCache->get($path); @@ -314,8 +307,7 @@ public function file_exists($path) { return false; } - /** {@inheritdoc} */ - public function unlink($path) { + public function unlink($path): bool { $this->init(); $path = $this->cleanPath($path); $result = $this->simpleResponse('DELETE', $path, null, 204); @@ -324,7 +316,6 @@ public function unlink($path) { return $result; } - /** {@inheritdoc} */ public function fopen($path, $mode) { $this->init(); $path = $this->cleanPath($path); @@ -402,13 +393,12 @@ public function fopen($path, $mode) { /** * @param string $tmpFile */ - public function writeBack($tmpFile, $path) { + public function writeBack($tmpFile, $path): void { $this->uploadFile($tmpFile, $path); unlink($tmpFile); } - /** {@inheritdoc} */ - public function free_space($path) { + public function free_space($path): float|bool|int { $this->init(); $path = $this->cleanPath($path); try { @@ -426,8 +416,7 @@ public function free_space($path) { } } - /** {@inheritdoc} */ - public function touch($path, $mtime = null) { + public function touch($path, $mtime = null): bool { $this->init(); if (is_null($mtime)) { $mtime = time(); @@ -469,7 +458,7 @@ public function touch($path, $mtime = null) { * @param mixed $data * @return int|float|false */ - public function file_put_contents($path, $data) { + public function file_put_contents($path, $data): float|bool|int { $path = $this->cleanPath($path); $result = parent::file_put_contents($path, $data); $this->statCache->remove($path); @@ -480,7 +469,7 @@ public function file_put_contents($path, $data) { * @param string $path * @param string $target */ - protected function uploadFile($path, $target) { + protected function uploadFile($path, $target): void { $this->init(); // invalidate @@ -500,8 +489,7 @@ protected function uploadFile($path, $target) { $this->removeCachedFile($target); } - /** {@inheritdoc} */ - public function rename($source, $target) { + public function rename($source, $target): bool { $this->init(); $source = $this->cleanPath($source); $target = $this->cleanPath($target); @@ -532,8 +520,7 @@ public function rename($source, $target) { return false; } - /** {@inheritdoc} */ - public function copy($source, $target) { + public function copy($source, $target): bool { $this->init(); $source = $this->cleanPath($source); $target = $this->cleanPath($target); @@ -561,7 +548,7 @@ public function copy($source, $target) { return false; } - public function getMetaData($path) { + public function getMetaData($path): ?array { if (Filesystem::isFileBlacklisted($path)) { throw new ForbiddenException('Invalid path: ' . $path, false); } @@ -623,15 +610,13 @@ private function getMetaFromPropfind(string $path, array $response): array { ]; } - /** {@inheritdoc} */ - public function stat($path) { + public function stat($path): array|false { $meta = $this->getMetaData($path); return $meta ?: false; } - /** {@inheritdoc} */ - public function getMimeType($path) { + public function getMimeType($path): bool|string { $meta = $this->getMetaData($path); return $meta ? $meta['mimetype'] : false; } @@ -640,7 +625,7 @@ public function getMimeType($path) { * @param string $path * @return string */ - public function cleanPath($path) { + public function cleanPath($path): string { if ($path === '') { return $path; } @@ -655,7 +640,7 @@ public function cleanPath($path) { * @param string $path to encode * @return string encoded path */ - protected function encodePath($path) { + protected function encodePath($path): string { // slashes need to stay return str_replace('%2F', '/', rawurlencode($path)); } @@ -669,7 +654,7 @@ protected function encodePath($path) { * @throws StorageInvalidException * @throws StorageNotAvailableException */ - protected function simpleResponse($method, $path, $body, $expected) { + protected function simpleResponse($method, $path, $body, $expected): bool { $path = $this->cleanPath($path); try { $response = $this->client->request($method, $this->encodePath($path), $body); @@ -691,46 +676,37 @@ protected function simpleResponse($method, $path, $body, $expected) { /** * check if curl is installed */ - public static function checkDependencies() { + public static function checkDependencies(): bool { return true; } - /** {@inheritdoc} */ - public function isUpdatable($path) { + public function isUpdatable($path): bool { return (bool)($this->getPermissions($path) & Constants::PERMISSION_UPDATE); } - /** {@inheritdoc} */ - public function isCreatable($path) { + public function isCreatable($path): bool { return (bool)($this->getPermissions($path) & Constants::PERMISSION_CREATE); } - /** {@inheritdoc} */ - public function isSharable($path) { + public function isSharable($path): bool { return (bool)($this->getPermissions($path) & Constants::PERMISSION_SHARE); } - /** {@inheritdoc} */ - public function isDeletable($path) { + public function isDeletable($path): bool { return (bool)($this->getPermissions($path) & Constants::PERMISSION_DELETE); } - /** {@inheritdoc} */ - public function getPermissions($path) { + public function getPermissions($path): int { $stat = $this->getMetaData($path); return $stat ? $stat['permissions'] : 0; } - public function getETag($path) { + public function getETag($path): bool|string { $meta = $this->getMetaData($path); return $meta ? $meta['etag'] : false; } - /** - * @param string $permissionsString - * @return int - */ - protected function parsePermissions($permissionsString) { + protected function parsePermissions($permissionsString): int { $permissions = Constants::PERMISSION_READ; if (str_contains($permissionsString, 'R')) { $permissions |= Constants::PERMISSION_SHARE; @@ -748,15 +724,7 @@ protected function parsePermissions($permissionsString) { return $permissions; } - /** - * check if a file or folder has been updated since $time - * - * @param string $path - * @param int $time - * @throws \OCP\Files\StorageNotAvailableException - * @return bool - */ - public function hasUpdated($path, $time) { + public function hasUpdated($path, $time): bool { $this->init(); $path = $this->cleanPath($path); try { @@ -822,7 +790,7 @@ public function hasUpdated($path, $time) { * which might be temporary * @throws ForbiddenException if the action is not allowed */ - protected function convertException(Exception $e, $path = '') { + protected function convertException(Exception $e, $path = ''): void { Server::get(LoggerInterface::class)->debug($e->getMessage(), ['app' => 'files_external', 'exception' => $e]); if ($e instanceof ClientHttpException) { if ($e->getHttpStatus() === Http::STATUS_LOCKED) { diff --git a/lib/private/Files/Storage/FailedStorage.php b/lib/private/Files/Storage/FailedStorage.php index 87a6e7f5041e7..35c78bd326904 100644 --- a/lib/private/Files/Storage/FailedStorage.php +++ b/lib/private/Files/Storage/FailedStorage.php @@ -29,168 +29,163 @@ public function __construct($params) { } } - public function getId() { + public function getId(): string { // we can't return anything sane here return 'failedstorage'; } - public function mkdir($path) { + public function mkdir($path): never { throw new StorageNotAvailableException($this->e->getMessage(), $this->e->getCode(), $this->e); } - public function rmdir($path) { + public function rmdir($path): never { throw new StorageNotAvailableException($this->e->getMessage(), $this->e->getCode(), $this->e); } - public function opendir($path) { + public function opendir($path): never { throw new StorageNotAvailableException($this->e->getMessage(), $this->e->getCode(), $this->e); } - public function is_dir($path) { + public function is_dir($path): never { throw new StorageNotAvailableException($this->e->getMessage(), $this->e->getCode(), $this->e); } - public function is_file($path) { + public function is_file($path): never { throw new StorageNotAvailableException($this->e->getMessage(), $this->e->getCode(), $this->e); } - public function stat($path) { + public function stat($path): never { throw new StorageNotAvailableException($this->e->getMessage(), $this->e->getCode(), $this->e); } - public function filetype($path) { + public function filetype($path): never { throw new StorageNotAvailableException($this->e->getMessage(), $this->e->getCode(), $this->e); } - public function filesize($path): false|int|float { + public function filesize($path): never { throw new StorageNotAvailableException($this->e->getMessage(), $this->e->getCode(), $this->e); } - public function isCreatable($path) { + public function isCreatable($path): never { throw new StorageNotAvailableException($this->e->getMessage(), $this->e->getCode(), $this->e); } - public function isReadable($path) { + public function isReadable($path): never { throw new StorageNotAvailableException($this->e->getMessage(), $this->e->getCode(), $this->e); } - public function isUpdatable($path) { + public function isUpdatable($path): never { throw new StorageNotAvailableException($this->e->getMessage(), $this->e->getCode(), $this->e); } - public function isDeletable($path) { + public function isDeletable($path): never { throw new StorageNotAvailableException($this->e->getMessage(), $this->e->getCode(), $this->e); } - public function isSharable($path) { + public function isSharable($path): never { throw new StorageNotAvailableException($this->e->getMessage(), $this->e->getCode(), $this->e); } - public function getPermissions($path) { + public function getPermissions($path): never { throw new StorageNotAvailableException($this->e->getMessage(), $this->e->getCode(), $this->e); } - public function file_exists($path) { + public function file_exists($path): never { throw new StorageNotAvailableException($this->e->getMessage(), $this->e->getCode(), $this->e); } - public function filemtime($path) { + public function filemtime($path): never { throw new StorageNotAvailableException($this->e->getMessage(), $this->e->getCode(), $this->e); } - public function file_get_contents($path) { + public function file_get_contents($path): never { throw new StorageNotAvailableException($this->e->getMessage(), $this->e->getCode(), $this->e); } - public function file_put_contents($path, $data) { + public function file_put_contents($path, $data): never { throw new StorageNotAvailableException($this->e->getMessage(), $this->e->getCode(), $this->e); } - public function unlink($path) { + public function unlink($path): never { throw new StorageNotAvailableException($this->e->getMessage(), $this->e->getCode(), $this->e); } - public function rename($source, $target) { + public function rename($source, $target): never { throw new StorageNotAvailableException($this->e->getMessage(), $this->e->getCode(), $this->e); } - public function copy($source, $target) { + public function copy($source, $target): never { throw new StorageNotAvailableException($this->e->getMessage(), $this->e->getCode(), $this->e); } - public function fopen($path, $mode) { + public function fopen($path, $mode): never { throw new StorageNotAvailableException($this->e->getMessage(), $this->e->getCode(), $this->e); } - public function getMimeType($path) { + public function getMimeType($path): never { throw new StorageNotAvailableException($this->e->getMessage(), $this->e->getCode(), $this->e); } - public function hash($type, $path, $raw = false) { + public function hash($type, $path, $raw = false): never { throw new StorageNotAvailableException($this->e->getMessage(), $this->e->getCode(), $this->e); } - public function free_space($path) { + public function free_space($path): never { throw new StorageNotAvailableException($this->e->getMessage(), $this->e->getCode(), $this->e); } - public function search($query) { + public function touch($path, $mtime = null): never { throw new StorageNotAvailableException($this->e->getMessage(), $this->e->getCode(), $this->e); } - public function touch($path, $mtime = null) { + public function getLocalFile($path): never { throw new StorageNotAvailableException($this->e->getMessage(), $this->e->getCode(), $this->e); } - public function getLocalFile($path) { + public function hasUpdated($path, $time): never { throw new StorageNotAvailableException($this->e->getMessage(), $this->e->getCode(), $this->e); } - public function hasUpdated($path, $time) { + public function getETag($path): never { throw new StorageNotAvailableException($this->e->getMessage(), $this->e->getCode(), $this->e); } - public function getETag($path) { + public function getDirectDownload($path): never { throw new StorageNotAvailableException($this->e->getMessage(), $this->e->getCode(), $this->e); } - public function getDirectDownload($path) { - throw new StorageNotAvailableException($this->e->getMessage(), $this->e->getCode(), $this->e); - } - - public function verifyPath($path, $fileName) { - return true; + public function verifyPath($path, $fileName): void { } - public function copyFromStorage(IStorage $sourceStorage, $sourceInternalPath, $targetInternalPath, $preserveMtime = false) { + public function copyFromStorage(IStorage $sourceStorage, $sourceInternalPath, $targetInternalPath, $preserveMtime = false): never { throw new StorageNotAvailableException($this->e->getMessage(), $this->e->getCode(), $this->e); } - public function moveFromStorage(IStorage $sourceStorage, $sourceInternalPath, $targetInternalPath) { + public function moveFromStorage(IStorage $sourceStorage, $sourceInternalPath, $targetInternalPath): never { throw new StorageNotAvailableException($this->e->getMessage(), $this->e->getCode(), $this->e); } - public function acquireLock($path, $type, ILockingProvider $provider) { + public function acquireLock($path, $type, ILockingProvider $provider): never { throw new StorageNotAvailableException($this->e->getMessage(), $this->e->getCode(), $this->e); } - public function releaseLock($path, $type, ILockingProvider $provider) { + public function releaseLock($path, $type, ILockingProvider $provider): never { throw new StorageNotAvailableException($this->e->getMessage(), $this->e->getCode(), $this->e); } - public function changeLock($path, $type, ILockingProvider $provider) { + public function changeLock($path, $type, ILockingProvider $provider): never { throw new StorageNotAvailableException($this->e->getMessage(), $this->e->getCode(), $this->e); } - public function getAvailability() { + public function getAvailability(): never { throw new StorageNotAvailableException($this->e->getMessage(), $this->e->getCode(), $this->e); } - public function setAvailability($isAvailable) { + public function setAvailability($isAvailable): never { throw new StorageNotAvailableException($this->e->getMessage(), $this->e->getCode(), $this->e); } - public function getCache($path = '', $storage = null) { + public function getCache($path = '', $storage = null): FailedCache { return new FailedCache(); } } diff --git a/lib/private/Files/Storage/Home.php b/lib/private/Files/Storage/Home.php index fd1d287629fc2..6729b293860ab 100644 --- a/lib/private/Files/Storage/Home.php +++ b/lib/private/Files/Storage/Home.php @@ -8,6 +8,8 @@ namespace OC\Files\Storage; use OC\Files\Cache\HomePropagator; +use OCP\Files\Cache\ICache; +use OCP\Files\Cache\IPropagator; use OCP\IUser; /** @@ -38,41 +40,31 @@ public function __construct($arguments) { parent::__construct(['datadir' => $datadir]); } - public function getId() { + public function getId(): string { return $this->id; } - /** - * @return \OC\Files\Cache\HomeCache - */ - public function getCache($path = '', $storage = null) { + public function getCache($path = '', $storage = null): ICache { if (!$storage) { $storage = $this; } if (!isset($this->cache)) { $this->cache = new \OC\Files\Cache\HomeCache($storage, $this->getCacheDependencies()); } - /** @var \OC\Files\Cache\HomeCache */ return $this->cache; } - public function getPropagator($storage = null) { + public function getPropagator($storage = null): IPropagator { if (!$storage) { $storage = $this; } if (!isset($this->propagator)) { $this->propagator = new HomePropagator($storage, \OC::$server->getDatabaseConnection()); } - /** @var \OC\Files\Cache\Propagator */ return $this->propagator; } - /** - * Returns the owner of this home storage - * - * @return \OC\User\User owner of this home storage - */ public function getUser(): IUser { return $this->user; } diff --git a/lib/private/Files/Storage/Local.php b/lib/private/Files/Storage/Local.php index 5b1dcb623ba7a..8e7b258e14c8b 100644 --- a/lib/private/Files/Storage/Local.php +++ b/lib/private/Files/Storage/Local.php @@ -74,11 +74,11 @@ public function __construct($arguments) { public function __destruct() { } - public function getId() { + public function getId(): string { return 'local::' . $this->datadir; } - public function mkdir($path) { + public function mkdir($path): bool { $sourcePath = $this->getSourcePath($path); $oldMask = umask($this->defUMask); $result = @mkdir($sourcePath, 0777, true); @@ -86,7 +86,7 @@ public function mkdir($path) { return $result; } - public function rmdir($path) { + public function rmdir($path): bool { if (!$this->isDeletable($path)) { return false; } @@ -129,7 +129,7 @@ public function opendir($path) { return opendir($this->getSourcePath($path)); } - public function is_dir($path) { + public function is_dir($path): bool { if ($this->caseInsensitive && !$this->file_exists($path)) { return false; } @@ -139,14 +139,14 @@ public function is_dir($path) { return is_dir($this->getSourcePath($path)); } - public function is_file($path) { + public function is_file($path): bool { if ($this->caseInsensitive && !$this->file_exists($path)) { return false; } return is_file($this->getSourcePath($path)); } - public function stat($path) { + public function stat($path): array|false { $fullPath = $this->getSourcePath($path); clearstatcache(true, $fullPath); if (!file_exists($fullPath)) { @@ -164,7 +164,7 @@ public function stat($path) { return $statResult; } - public function getMetaData($path) { + public function getMetaData($path): ?array { try { $stat = $this->stat($path); } catch (ForbiddenException $e) { @@ -213,7 +213,7 @@ public function getMetaData($path) { return $data; } - public function filetype($path) { + public function filetype($path): bool|string { $filetype = filetype($this->getSourcePath($path)); if ($filetype == 'link') { $filetype = filetype(realpath($this->getSourcePath($path))); @@ -233,15 +233,15 @@ public function filesize($path): false|int|float { return filesize($fullPath); } - public function isReadable($path) { + public function isReadable($path): bool { return is_readable($this->getSourcePath($path)); } - public function isUpdatable($path) { + public function isUpdatable($path): bool { return is_writable($this->getSourcePath($path)); } - public function file_exists($path) { + public function file_exists($path): bool { if ($this->caseInsensitive) { $fullPath = $this->getSourcePath($path); $parentPath = dirname($fullPath); @@ -255,7 +255,7 @@ public function file_exists($path) { } } - public function filemtime($path) { + public function filemtime($path): false|int { $fullPath = $this->getSourcePath($path); clearstatcache(true, $fullPath); if (!$this->file_exists($path)) { @@ -268,7 +268,7 @@ public function filemtime($path) { return filemtime($fullPath); } - public function touch($path, $mtime = null) { + public function touch($path, $mtime = null): bool { // sets the modification time of the file to the given value. // If mtime is nil the current time is set. // note that the access time of the file always changes to the current time. @@ -289,11 +289,11 @@ public function touch($path, $mtime = null) { return $result; } - public function file_get_contents($path) { + public function file_get_contents($path): bool|string { return file_get_contents($this->getSourcePath($path)); } - public function file_put_contents($path, $data) { + public function file_put_contents($path, $data): float|bool|int { $oldMask = umask($this->defUMask); if ($this->unlinkOnTruncate) { $this->unlink($path); @@ -303,7 +303,7 @@ public function file_put_contents($path, $data) { return $result; } - public function unlink($path) { + public function unlink($path): bool { if ($this->is_dir($path)) { return $this->rmdir($path); } elseif ($this->is_file($path)) { @@ -313,7 +313,7 @@ public function unlink($path) { } } - private function checkTreeForForbiddenItems(string $path) { + private function checkTreeForForbiddenItems(string $path): void { $iterator = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($path)); foreach ($iterator as $file) { /** @var \SplFileInfo $file */ @@ -364,7 +364,7 @@ public function rename($source, $target): bool { return $this->copy($source, $target) && $this->unlink($source); } - public function copy($source, $target) { + public function copy($source, $target): bool { if ($this->is_dir($source)) { return parent::copy($source, $target); } else { @@ -401,7 +401,7 @@ public function hash($type, $path, $raw = false): string|false { return hash_file($type, $this->getSourcePath($path), $raw); } - public function free_space($path) { + public function free_space($path): float|bool|int { $sourcePath = $this->getSourcePath($path); // using !is_dir because $sourcePath might be a part file or // non-existing file, so we'd still want to use the parent dir @@ -417,20 +417,19 @@ public function free_space($path) { return Util::numericToNumber($space); } - public function search($query) { + public function search($query): array { return $this->searchInDir($query); } - public function getLocalFile($path) { + public function getLocalFile($path): bool|string { return $this->getSourcePath($path); } /** * @param string $query * @param string $dir - * @return array */ - protected function searchInDir($query, $dir = '') { + protected function searchInDir($query, $dir = ''): array { $files = []; $physicalDir = $this->getSourcePath($dir); foreach (scandir($physicalDir) as $item) { @@ -449,14 +448,7 @@ protected function searchInDir($query, $dir = '') { return $files; } - /** - * check if a file or folder has been updated since $time - * - * @param string $path - * @param int $time - * @return bool - */ - public function hasUpdated($path, $time) { + public function hasUpdated($path, $time): bool { if ($this->file_exists($path)) { return $this->filemtime($path) > $time; } else { @@ -468,10 +460,9 @@ public function hasUpdated($path, $time) { * Get the source path (on disk) of a given path * * @param string $path - * @return string * @throws ForbiddenException */ - public function getSourcePath($path) { + public function getSourcePath($path): string { if (Filesystem::isFileBlacklisted($path)) { throw new ForbiddenException('Invalid path: ' . $path, false); } @@ -503,14 +494,11 @@ public function getSourcePath($path) { throw new ForbiddenException('Following symlinks is not allowed', false); } - /** - * {@inheritdoc} - */ - public function isLocal() { + public function isLocal(): bool { return true; } - public function getETag($path) { + public function getETag($path): bool|string { return $this->calculateEtag($path, $this->stat($path)); } @@ -540,7 +528,7 @@ private function calculateEtag(string $path, array $stat): string|false { } } - private function canDoCrossStorageMove(IStorage $sourceStorage) { + private function canDoCrossStorageMove(IStorage $sourceStorage): bool { /** @psalm-suppress UndefinedClass */ return $sourceStorage->instanceOfStorage(Local::class) // Don't treat ACLStorageWrapper like local storage where copy can be done directly. @@ -553,14 +541,7 @@ private function canDoCrossStorageMove(IStorage $sourceStorage) { && !$sourceStorage->instanceOfStorage(Encryption::class); } - /** - * @param IStorage $sourceStorage - * @param string $sourceInternalPath - * @param string $targetInternalPath - * @param bool $preserveMtime - * @return bool - */ - public function copyFromStorage(IStorage $sourceStorage, $sourceInternalPath, $targetInternalPath, $preserveMtime = false) { + public function copyFromStorage(IStorage $sourceStorage, $sourceInternalPath, $targetInternalPath, $preserveMtime = false): bool { if ($this->canDoCrossStorageMove($sourceStorage)) { if ($sourceStorage->instanceOfStorage(Jail::class)) { /** @@ -584,7 +565,7 @@ public function copyFromStorage(IStorage $sourceStorage, $sourceInternalPath, $t * @param string $targetInternalPath * @return bool */ - public function moveFromStorage(IStorage $sourceStorage, $sourceInternalPath, $targetInternalPath) { + public function moveFromStorage(IStorage $sourceStorage, $sourceInternalPath, $targetInternalPath): bool { if ($this->canDoCrossStorageMove($sourceStorage)) { if ($sourceStorage->instanceOfStorage(Jail::class)) { /** diff --git a/lib/private/Files/Storage/LocalRootStorage.php b/lib/private/Files/Storage/LocalRootStorage.php index ae0575fe0430a..b44467964d671 100644 --- a/lib/private/Files/Storage/LocalRootStorage.php +++ b/lib/private/Files/Storage/LocalRootStorage.php @@ -9,9 +9,10 @@ namespace OC\Files\Storage; use OC\Files\Cache\LocalRootScanner; +use OCP\Files\Cache\IScanner; class LocalRootStorage extends Local { - public function getScanner($path = '', $storage = null) { + public function getScanner($path = '', $storage = null): IScanner { if (!$storage) { $storage = $this; } diff --git a/lib/private/Files/Storage/LocalTempFileTrait.php b/lib/private/Files/Storage/LocalTempFileTrait.php index 26fbcc238fd49..057970dea8f22 100644 --- a/lib/private/Files/Storage/LocalTempFileTrait.php +++ b/lib/private/Files/Storage/LocalTempFileTrait.php @@ -32,7 +32,7 @@ protected function getCachedFile(string $path): string|false { /** * @param string $path */ - protected function removeCachedFile($path) { + protected function removeCachedFile($path): void { unset($this->cachedFiles[$path]); } diff --git a/lib/private/Files/Storage/PolyFill/CopyDirectory.php b/lib/private/Files/Storage/PolyFill/CopyDirectory.php index 5fe396d97e1d1..614432f0363d3 100644 --- a/lib/private/Files/Storage/PolyFill/CopyDirectory.php +++ b/lib/private/Files/Storage/PolyFill/CopyDirectory.php @@ -12,31 +12,28 @@ trait CopyDirectory { * Check if a path is a directory * * @param string $path - * @return bool */ - abstract public function is_dir($path); + abstract public function is_dir($path): bool; /** * Check if a file or folder exists * * @param string $path - * @return bool */ - abstract public function file_exists($path); + abstract public function file_exists($path): bool; /** * Delete a file or folder * * @param string $path - * @return bool */ - abstract public function unlink($path); + abstract public function unlink($path): bool; /** * Open a directory handle for a folder * * @param string $path - * @return resource | bool + * @return resource|bool */ abstract public function opendir($path); @@ -44,11 +41,10 @@ abstract public function opendir($path); * Create a new folder * * @param string $path - * @return bool */ - abstract public function mkdir($path); + abstract public function mkdir($path): bool; - public function copy($source, $target) { + public function copy($source, $target): bool { if ($this->is_dir($source)) { if ($this->file_exists($target)) { $this->unlink($target); @@ -62,12 +58,8 @@ public function copy($source, $target) { /** * For adapters that don't support copying folders natively - * - * @param $source - * @param $target - * @return bool */ - protected function copyRecursive($source, $target) { + protected function copyRecursive($source, $target): bool { $dh = $this->opendir($source); $result = true; while (($file = readdir($dh)) !== false) { diff --git a/lib/private/Files/Storage/Storage.php b/lib/private/Files/Storage/Storage.php index d6d1d26c35a84..9cdc70aaa5969 100644 --- a/lib/private/Files/Storage/Storage.php +++ b/lib/private/Files/Storage/Storage.php @@ -8,11 +8,11 @@ namespace OC\Files\Storage; -use OC\Files\Cache\Cache; -use OC\Files\Cache\Propagator; -use OC\Files\Cache\Scanner; -use OC\Files\Cache\Updater; -use OC\Files\Cache\Watcher; +use OCP\Files\Cache\ICache; +use OCP\Files\Cache\IPropagator; +use OCP\Files\Cache\IScanner; +use OCP\Files\Cache\IUpdater; +use OCP\Files\Cache\IWatcher; use OCP\Files\Storage\ILockingStorage; use OCP\Files\Storage\IStorage; @@ -22,53 +22,23 @@ * All paths passed to the storage are relative to the storage and should NOT have a leading slash. */ interface Storage extends IStorage, ILockingStorage { - /** - * @inheritDoc - * @return Cache - */ - public function getCache($path = '', $storage = null); + public function getCache($path = '', $storage = null): ICache; - /** - * @inheritDoc - * @return Scanner - */ - public function getScanner($path = '', $storage = null); + public function getScanner($path = '', $storage = null): IScanner; - /** - * @inheritDoc - * @return Watcher - */ - public function getWatcher($path = '', $storage = null); + public function getWatcher($path = '', $storage = null): IWatcher; - /** - * @inheritDoc - * @return Propagator - */ - public function getPropagator($storage = null); + public function getPropagator($storage = null): IPropagator; - /** - * @inheritDoc - * @return Updater - */ - public function getUpdater($storage = null); + public function getUpdater($storage = null): IUpdater; - /** - * @return \OC\Files\Cache\Storage - */ - public function getStorageCache(); + public function getStorageCache(): \OC\Files\Cache\Storage; - /** - * @param string $path - * @return array|null - */ - public function getMetaData($path); + public function getMetaData($path): ?array; /** * Get the contents of a directory with metadata * - * @param string $directory - * @return \Traversable an iterator, containing file metadata - * * The metadata array will contain the following fields * * - name @@ -79,5 +49,5 @@ public function getMetaData($path); * - storage_mtime * - permissions */ - public function getDirectoryContent($directory): \Traversable; + public function getDirectoryContent($directory): \Traversable|false; } diff --git a/lib/private/Files/Storage/StorageFactory.php b/lib/private/Files/Storage/StorageFactory.php index 590425f5b641b..16fbc736535b7 100644 --- a/lib/private/Files/Storage/StorageFactory.php +++ b/lib/private/Files/Storage/StorageFactory.php @@ -17,19 +17,7 @@ class StorageFactory implements IStorageFactory { */ private $storageWrappers = []; - /** - * allow modifier storage behaviour by adding wrappers around storages - * - * $callback should be a function of type (string $mountPoint, Storage $storage) => Storage - * - * @param string $wrapperName name of the wrapper - * @param callable $callback callback - * @param int $priority wrappers with the lower priority are applied last (meaning they get called first) - * @param \OCP\Files\Mount\IMountPoint[] $existingMounts existing mount points to apply the wrapper to - * @return bool true if the wrapper was added, false if there was already a wrapper with this - * name registered - */ - public function addStorageWrapper($wrapperName, $callback, $priority = 50, $existingMounts = []) { + public function addStorageWrapper($wrapperName, $callback, $priority = 50, $existingMounts = []): bool { if (isset($this->storageWrappers[$wrapperName])) { return false; } @@ -50,26 +38,18 @@ public function addStorageWrapper($wrapperName, $callback, $priority = 50, $exis * @param string $wrapperName name of the wrapper * @internal */ - public function removeStorageWrapper($wrapperName) { + public function removeStorageWrapper($wrapperName): void { unset($this->storageWrappers[$wrapperName]); } - /** - * Create an instance of a storage and apply the registered storage wrappers - * - * @param string $class - * @param array $arguments - * @return IStorage - */ - public function getInstance(IMountPoint $mountPoint, $class, $arguments) { + public function getInstance(IMountPoint $mountPoint, $class, $arguments): IStorage { return $this->wrap($mountPoint, new $class($arguments)); } /** * @param IStorage $storage - * @return IStorage */ - public function wrap(IMountPoint $mountPoint, $storage) { + public function wrap(IMountPoint $mountPoint, $storage): IStorage { $wrappers = array_values($this->storageWrappers); usort($wrappers, function ($a, $b) { return $b['priority'] - $a['priority']; diff --git a/lib/private/Files/Storage/Temporary.php b/lib/private/Files/Storage/Temporary.php index 6c7ef4260c192..429f0fd1e92db 100644 --- a/lib/private/Files/Storage/Temporary.php +++ b/lib/private/Files/Storage/Temporary.php @@ -15,7 +15,7 @@ public function __construct($arguments = []) { parent::__construct(['datadir' => \OC::$server->getTempManager()->getTemporaryFolder()]); } - public function cleanUp() { + public function cleanUp(): void { \OC_Helper::rmdirr($this->datadir); } @@ -24,7 +24,7 @@ public function __destruct() { $this->cleanUp(); } - public function getDataDir() { + public function getDataDir(): array|string { return $this->datadir; } } diff --git a/lib/private/Files/Storage/Wrapper/Availability.php b/lib/private/Files/Storage/Wrapper/Availability.php index aaf0acdc74f7b..82a502c08f247 100644 --- a/lib/private/Files/Storage/Wrapper/Availability.php +++ b/lib/private/Files/Storage/Wrapper/Availability.php @@ -28,7 +28,7 @@ public function __construct($parameters) { parent::__construct($parameters); } - public static function shouldRecheck($availability) { + public static function shouldRecheck($availability): bool { if (!$availability['available']) { // trigger a recheck if TTL reached if ((time() - $availability['last_checked']) > self::RECHECK_TTL_SEC) { @@ -40,10 +40,8 @@ public static function shouldRecheck($availability) { /** * Only called if availability === false - * - * @return bool */ - private function updateAvailability() { + private function updateAvailability(): bool { // reset availability to false so that multiple requests don't recheck concurrently $this->setAvailability(false); try { @@ -55,10 +53,7 @@ private function updateAvailability() { return $result; } - /** - * @return bool - */ - private function isAvailable() { + private function isAvailable(): bool { $availability = $this->getAvailability(); if (self::shouldRecheck($availability)) { return $this->updateAvailability(); @@ -69,154 +64,153 @@ private function isAvailable() { /** * @throws StorageNotAvailableException */ - private function checkAvailability() { + private function checkAvailability(): void { if (!$this->isAvailable()) { throw new StorageNotAvailableException(); } } - /** {@inheritdoc} */ - public function mkdir($path) { + public function mkdir($path): bool { $this->checkAvailability(); try { return parent::mkdir($path); } catch (StorageNotAvailableException $e) { $this->setUnavailable($e); + return false; } } - /** {@inheritdoc} */ - public function rmdir($path) { + public function rmdir($path): bool { $this->checkAvailability(); try { return parent::rmdir($path); } catch (StorageNotAvailableException $e) { $this->setUnavailable($e); + return false; } } - /** {@inheritdoc} */ public function opendir($path) { $this->checkAvailability(); try { return parent::opendir($path); } catch (StorageNotAvailableException $e) { $this->setUnavailable($e); + return false; } } - /** {@inheritdoc} */ - public function is_dir($path) { + public function is_dir($path): bool { $this->checkAvailability(); try { return parent::is_dir($path); } catch (StorageNotAvailableException $e) { $this->setUnavailable($e); + return false; } } - /** {@inheritdoc} */ - public function is_file($path) { + public function is_file($path): bool { $this->checkAvailability(); try { return parent::is_file($path); } catch (StorageNotAvailableException $e) { $this->setUnavailable($e); + return false; } } - /** {@inheritdoc} */ - public function stat($path) { + public function stat($path): array|false { $this->checkAvailability(); try { return parent::stat($path); } catch (StorageNotAvailableException $e) { $this->setUnavailable($e); + return false; } } - /** {@inheritdoc} */ - public function filetype($path) { + public function filetype($path): string|false { $this->checkAvailability(); try { return parent::filetype($path); } catch (StorageNotAvailableException $e) { $this->setUnavailable($e); + return false; } } - /** {@inheritdoc} */ public function filesize($path): false|int|float { $this->checkAvailability(); try { return parent::filesize($path); } catch (StorageNotAvailableException $e) { $this->setUnavailable($e); + return false; } } - /** {@inheritdoc} */ - public function isCreatable($path) { + public function isCreatable($path): bool { $this->checkAvailability(); try { return parent::isCreatable($path); } catch (StorageNotAvailableException $e) { $this->setUnavailable($e); + return false; } } - /** {@inheritdoc} */ - public function isReadable($path) { + public function isReadable($path): bool { $this->checkAvailability(); try { return parent::isReadable($path); } catch (StorageNotAvailableException $e) { $this->setUnavailable($e); + return false; } } - /** {@inheritdoc} */ - public function isUpdatable($path) { + public function isUpdatable($path): bool { $this->checkAvailability(); try { return parent::isUpdatable($path); } catch (StorageNotAvailableException $e) { $this->setUnavailable($e); + return false; } } - /** {@inheritdoc} */ - public function isDeletable($path) { + public function isDeletable($path): bool { $this->checkAvailability(); try { return parent::isDeletable($path); } catch (StorageNotAvailableException $e) { $this->setUnavailable($e); + return false; } } - /** {@inheritdoc} */ - public function isSharable($path) { + public function isSharable($path): bool { $this->checkAvailability(); try { return parent::isSharable($path); } catch (StorageNotAvailableException $e) { $this->setUnavailable($e); + return false; } } - /** {@inheritdoc} */ - public function getPermissions($path) { + public function getPermissions($path): int { $this->checkAvailability(); try { return parent::getPermissions($path); } catch (StorageNotAvailableException $e) { $this->setUnavailable($e); + return 0; } } - /** {@inheritdoc} */ - public function file_exists($path) { + public function file_exists($path): bool { if ($path === '') { return true; } @@ -225,91 +219,91 @@ public function file_exists($path) { return parent::file_exists($path); } catch (StorageNotAvailableException $e) { $this->setUnavailable($e); + return false; } } - /** {@inheritdoc} */ - public function filemtime($path) { + public function filemtime($path): int|false { $this->checkAvailability(); try { return parent::filemtime($path); } catch (StorageNotAvailableException $e) { $this->setUnavailable($e); + return false; } } - /** {@inheritdoc} */ - public function file_get_contents($path) { + public function file_get_contents($path): string|false { $this->checkAvailability(); try { return parent::file_get_contents($path); } catch (StorageNotAvailableException $e) { $this->setUnavailable($e); + return false; } } - /** {@inheritdoc} */ - public function file_put_contents($path, $data) { + public function file_put_contents($path, $data): int|float|false { $this->checkAvailability(); try { return parent::file_put_contents($path, $data); } catch (StorageNotAvailableException $e) { $this->setUnavailable($e); + return false; } } - /** {@inheritdoc} */ - public function unlink($path) { + public function unlink($path): bool { $this->checkAvailability(); try { return parent::unlink($path); } catch (StorageNotAvailableException $e) { $this->setUnavailable($e); + return false; } } - /** {@inheritdoc} */ - public function rename($source, $target) { + public function rename($source, $target): bool { $this->checkAvailability(); try { return parent::rename($source, $target); } catch (StorageNotAvailableException $e) { $this->setUnavailable($e); + return false; } } - /** {@inheritdoc} */ - public function copy($source, $target) { + public function copy($source, $target): bool { $this->checkAvailability(); try { return parent::copy($source, $target); } catch (StorageNotAvailableException $e) { $this->setUnavailable($e); + return false; } } - /** {@inheritdoc} */ public function fopen($path, $mode) { $this->checkAvailability(); try { return parent::fopen($path, $mode); } catch (StorageNotAvailableException $e) { $this->setUnavailable($e); + return false; } } - /** {@inheritdoc} */ - public function getMimeType($path) { + public function getMimeType($path): string|false { $this->checkAvailability(); try { return parent::getMimeType($path); } catch (StorageNotAvailableException $e) { $this->setUnavailable($e); + return false; } } - /** {@inheritdoc} */ - public function hash($type, $path, $raw = false) { + public function hash($type, $path, $raw = false): string|false { $this->checkAvailability(); try { return parent::hash($type, $path, $raw); @@ -319,48 +313,37 @@ public function hash($type, $path, $raw = false) { } } - /** {@inheritdoc} */ - public function free_space($path) { + public function free_space($path): int|float|false { $this->checkAvailability(); try { return parent::free_space($path); } catch (StorageNotAvailableException $e) { $this->setUnavailable($e); + return false; } } - /** {@inheritdoc} */ - public function search($query) { - $this->checkAvailability(); - try { - return parent::search($query); - } catch (StorageNotAvailableException $e) { - $this->setUnavailable($e); - } - } - - /** {@inheritdoc} */ - public function touch($path, $mtime = null) { + public function touch($path, $mtime = null): bool { $this->checkAvailability(); try { return parent::touch($path, $mtime); } catch (StorageNotAvailableException $e) { $this->setUnavailable($e); + return false; } } - /** {@inheritdoc} */ - public function getLocalFile($path) { + public function getLocalFile($path): string|false { $this->checkAvailability(); try { return parent::getLocalFile($path); } catch (StorageNotAvailableException $e) { $this->setUnavailable($e); + return false; } } - /** {@inheritdoc} */ - public function hasUpdated($path, $time) { + public function hasUpdated($path, $time): bool { if (!$this->isAvailable()) { return false; } @@ -382,52 +365,53 @@ public function getOwner($path): string|false { } } - /** {@inheritdoc} */ - public function getETag($path) { + public function getETag($path): string|false { $this->checkAvailability(); try { return parent::getETag($path); } catch (StorageNotAvailableException $e) { $this->setUnavailable($e); + return false; } } - /** {@inheritdoc} */ - public function getDirectDownload($path) { + public function getDirectDownload($path): array|false { $this->checkAvailability(); try { return parent::getDirectDownload($path); } catch (StorageNotAvailableException $e) { $this->setUnavailable($e); + return false; } } - /** {@inheritdoc} */ - public function copyFromStorage(IStorage $sourceStorage, $sourceInternalPath, $targetInternalPath) { + public function copyFromStorage(IStorage $sourceStorage, $sourceInternalPath, $targetInternalPath): bool { $this->checkAvailability(); try { return parent::copyFromStorage($sourceStorage, $sourceInternalPath, $targetInternalPath); } catch (StorageNotAvailableException $e) { $this->setUnavailable($e); + return false; } } - /** {@inheritdoc} */ - public function moveFromStorage(IStorage $sourceStorage, $sourceInternalPath, $targetInternalPath) { + public function moveFromStorage(IStorage $sourceStorage, $sourceInternalPath, $targetInternalPath): bool { $this->checkAvailability(); try { return parent::moveFromStorage($sourceStorage, $sourceInternalPath, $targetInternalPath); } catch (StorageNotAvailableException $e) { $this->setUnavailable($e); + return false; } } - public function getMetaData($path) { + public function getMetaData($path): ?array { $this->checkAvailability(); try { return parent::getMetaData($path); } catch (StorageNotAvailableException $e) { $this->setUnavailable($e); + return null; } } @@ -454,12 +438,13 @@ protected function setUnavailable(?StorageNotAvailableException $e): void { - public function getDirectoryContent($directory): \Traversable { + public function getDirectoryContent($directory): \Traversable|false { $this->checkAvailability(); try { return parent::getDirectoryContent($directory); } catch (StorageNotAvailableException $e) { $this->setUnavailable($e); + return false; } } } diff --git a/lib/private/Files/Storage/Wrapper/Encoding.php b/lib/private/Files/Storage/Wrapper/Encoding.php index 48c6c38c8483f..26e0e3a15ddd4 100644 --- a/lib/private/Files/Storage/Wrapper/Encoding.php +++ b/lib/private/Files/Storage/Wrapper/Encoding.php @@ -9,6 +9,7 @@ use OC\Files\Filesystem; use OCP\Cache\CappedMemoryCache; +use OCP\Files\Cache\IScanner; use OCP\Files\Storage\IStorage; use OCP\ICache; @@ -36,10 +37,8 @@ public function __construct($parameters) { * Returns whether the given string is only made of ASCII characters * * @param string $str string - * - * @return bool true if the string is all ASCII, false otherwise */ - private function isAscii($str) { + private function isAscii($str): bool { return !preg_match('/[\\x80-\\xff]+/', $str); } @@ -52,7 +51,7 @@ private function isAscii($str) { * * @return string original or converted path */ - private function findPathToUse($fullPath) { + private function findPathToUse($fullPath): string { $cachedPath = $this->namesCache[$fullPath]; if ($cachedPath !== null) { return $cachedPath; @@ -81,7 +80,7 @@ private function findPathToUse($fullPath) { * * @return string|null original or converted path, or null if none of the forms was found */ - private function findPathToUseLastSection($basePath, $lastSection) { + private function findPathToUseLastSection($basePath, $lastSection): ?string { $fullPath = $basePath . $lastSection; if ($lastSection === '' || $this->isAscii($lastSection) || $this->storage->file_exists($fullPath)) { $this->namesCache[$fullPath] = $fullPath; @@ -105,13 +104,7 @@ private function findPathToUseLastSection($basePath, $lastSection) { return null; } - /** - * see https://www.php.net/manual/en/function.mkdir.php - * - * @param string $path - * @return bool - */ - public function mkdir($path) { + public function mkdir($path): bool { // note: no conversion here, method should not be called with non-NFC names! $result = $this->storage->mkdir($path); if ($result) { @@ -120,13 +113,7 @@ public function mkdir($path) { return $result; } - /** - * see https://www.php.net/manual/en/function.rmdir.php - * - * @param string $path - * @return bool - */ - public function rmdir($path) { + public function rmdir($path): bool { $result = $this->storage->rmdir($this->findPathToUse($path)); if ($result) { unset($this->namesCache[$path]); @@ -134,175 +121,72 @@ public function rmdir($path) { return $result; } - /** - * see https://www.php.net/manual/en/function.opendir.php - * - * @param string $path - * @return resource|false - */ public function opendir($path) { $handle = $this->storage->opendir($this->findPathToUse($path)); return EncodingDirectoryWrapper::wrap($handle); } - /** - * see https://www.php.net/manual/en/function.is_dir.php - * - * @param string $path - * @return bool - */ - public function is_dir($path) { + public function is_dir($path): bool { return $this->storage->is_dir($this->findPathToUse($path)); } - /** - * see https://www.php.net/manual/en/function.is_file.php - * - * @param string $path - * @return bool - */ - public function is_file($path) { + public function is_file($path): bool { return $this->storage->is_file($this->findPathToUse($path)); } - /** - * see https://www.php.net/manual/en/function.stat.php - * only the following keys are required in the result: size and mtime - * - * @param string $path - * @return array|bool - */ - public function stat($path) { + public function stat($path): array|false { return $this->storage->stat($this->findPathToUse($path)); } - /** - * see https://www.php.net/manual/en/function.filetype.php - * - * @param string $path - * @return string|bool - */ - public function filetype($path) { + public function filetype($path): string|false { return $this->storage->filetype($this->findPathToUse($path)); } - /** - * see https://www.php.net/manual/en/function.filesize.php - * The result for filesize when called on a folder is required to be 0 - */ - public function filesize($path): false|int|float { + public function filesize($path): int|float|false { return $this->storage->filesize($this->findPathToUse($path)); } - /** - * check if a file can be created in $path - * - * @param string $path - * @return bool - */ - public function isCreatable($path) { + public function isCreatable($path): bool { return $this->storage->isCreatable($this->findPathToUse($path)); } - /** - * check if a file can be read - * - * @param string $path - * @return bool - */ - public function isReadable($path) { + public function isReadable($path): bool { return $this->storage->isReadable($this->findPathToUse($path)); } - /** - * check if a file can be written to - * - * @param string $path - * @return bool - */ - public function isUpdatable($path) { + public function isUpdatable($path): bool { return $this->storage->isUpdatable($this->findPathToUse($path)); } - /** - * check if a file can be deleted - * - * @param string $path - * @return bool - */ - public function isDeletable($path) { + public function isDeletable($path): bool { return $this->storage->isDeletable($this->findPathToUse($path)); } - /** - * check if a file can be shared - * - * @param string $path - * @return bool - */ - public function isSharable($path) { + public function isSharable($path): bool { return $this->storage->isSharable($this->findPathToUse($path)); } - /** - * get the full permissions of a path. - * Should return a combination of the PERMISSION_ constants defined in lib/public/constants.php - * - * @param string $path - * @return int - */ - public function getPermissions($path) { + public function getPermissions($path): int { return $this->storage->getPermissions($this->findPathToUse($path)); } - /** - * see https://www.php.net/manual/en/function.file_exists.php - * - * @param string $path - * @return bool - */ - public function file_exists($path) { + public function file_exists($path): bool { return $this->storage->file_exists($this->findPathToUse($path)); } - /** - * see https://www.php.net/manual/en/function.filemtime.php - * - * @param string $path - * @return int|bool - */ - public function filemtime($path) { + public function filemtime($path): int|false { return $this->storage->filemtime($this->findPathToUse($path)); } - /** - * see https://www.php.net/manual/en/function.file_get_contents.php - * - * @param string $path - * @return string|false - */ - public function file_get_contents($path) { + public function file_get_contents($path): string|false { return $this->storage->file_get_contents($this->findPathToUse($path)); } - /** - * see https://www.php.net/manual/en/function.file_put_contents.php - * - * @param string $path - * @param mixed $data - * @return int|float|false - */ - public function file_put_contents($path, $data) { + public function file_put_contents($path, $data): int|float|false { return $this->storage->file_put_contents($this->findPathToUse($path), $data); } - /** - * see https://www.php.net/manual/en/function.unlink.php - * - * @param string $path - * @return bool - */ - public function unlink($path) { + public function unlink($path): bool { $result = $this->storage->unlink($this->findPathToUse($path)); if ($result) { unset($this->namesCache[$path]); @@ -310,36 +194,15 @@ public function unlink($path) { return $result; } - /** - * see https://www.php.net/manual/en/function.rename.php - * - * @param string $source - * @param string $target - * @return bool - */ - public function rename($source, $target) { + public function rename($source, $target): bool { // second name always NFC return $this->storage->rename($this->findPathToUse($source), $this->findPathToUse($target)); } - /** - * see https://www.php.net/manual/en/function.copy.php - * - * @param string $source - * @param string $target - * @return bool - */ - public function copy($source, $target) { + public function copy($source, $target): bool { return $this->storage->copy($this->findPathToUse($source), $this->findPathToUse($target)); } - /** - * see https://www.php.net/manual/en/function.fopen.php - * - * @param string $path - * @param string $mode - * @return resource|bool - */ public function fopen($path, $mode) { $result = $this->storage->fopen($this->findPathToUse($path), $mode); if ($result && $mode !== 'r' && $mode !== 'rb') { @@ -348,107 +211,49 @@ public function fopen($path, $mode) { return $result; } - /** - * get the mimetype for a file or folder - * The mimetype for a folder is required to be "httpd/unix-directory" - * - * @param string $path - * @return string|bool - */ - public function getMimeType($path) { + public function getMimeType($path): string|false { return $this->storage->getMimeType($this->findPathToUse($path)); } - /** - * see https://www.php.net/manual/en/function.hash.php - * - * @param string $type - * @param string $path - * @param bool $raw - * @return string|bool - */ - public function hash($type, $path, $raw = false) { + public function hash($type, $path, $raw = false): string|false { return $this->storage->hash($type, $this->findPathToUse($path), $raw); } - /** - * see https://www.php.net/manual/en/function.free_space.php - * - * @param string $path - * @return int|float|bool - */ - public function free_space($path) { + public function free_space($path): int|float|false { return $this->storage->free_space($this->findPathToUse($path)); } - /** - * see https://www.php.net/manual/en/function.touch.php - * If the backend does not support the operation, false should be returned - * - * @param string $path - * @param int $mtime - * @return bool - */ - public function touch($path, $mtime = null) { + public function touch($path, $mtime = null): bool { return $this->storage->touch($this->findPathToUse($path), $mtime); } - /** - * get the path to a local version of the file. - * The local version of the file can be temporary and doesn't have to be persistent across requests - * - * @param string $path - * @return string|false - */ - public function getLocalFile($path) { + public function getLocalFile($path): string|false { return $this->storage->getLocalFile($this->findPathToUse($path)); } - /** - * check if a file or folder has been updated since $time - * - * @param string $path - * @param int $time - * @return bool - * - * hasUpdated for folders should return at least true if a file inside the folder is add, removed or renamed. - * returning true for other changes in the folder is optional - */ - public function hasUpdated($path, $time) { + public function hasUpdated($path, $time): bool { return $this->storage->hasUpdated($this->findPathToUse($path), $time); } - public function getCache($path = '', $storage = null) { + public function getCache($path = '', $storage = null): \OCP\Files\Cache\ICache { if (!$storage) { $storage = $this; } return $this->storage->getCache($this->findPathToUse($path), $storage); } - public function getScanner($path = '', $storage = null) { + public function getScanner($path = '', $storage = null): IScanner { if (!$storage) { $storage = $this; } return $this->storage->getScanner($this->findPathToUse($path), $storage); } - /** - * get the ETag for a file or folder - * - * @param string $path - * @return string|false - */ - public function getETag($path) { + public function getETag($path): string|false { return $this->storage->getETag($this->findPathToUse($path)); } - /** - * @param IStorage $sourceStorage - * @param string $sourceInternalPath - * @param string $targetInternalPath - * @return bool - */ - public function copyFromStorage(IStorage $sourceStorage, $sourceInternalPath, $targetInternalPath) { + public function copyFromStorage(IStorage $sourceStorage, $sourceInternalPath, $targetInternalPath): bool { if ($sourceStorage === $this) { return $this->copy($sourceInternalPath, $this->findPathToUse($targetInternalPath)); } @@ -460,13 +265,7 @@ public function copyFromStorage(IStorage $sourceStorage, $sourceInternalPath, $t return $result; } - /** - * @param IStorage $sourceStorage - * @param string $sourceInternalPath - * @param string $targetInternalPath - * @return bool - */ - public function moveFromStorage(IStorage $sourceStorage, $sourceInternalPath, $targetInternalPath) { + public function moveFromStorage(IStorage $sourceStorage, $sourceInternalPath, $targetInternalPath): bool { if ($sourceStorage === $this) { $result = $this->rename($sourceInternalPath, $this->findPathToUse($targetInternalPath)); if ($result) { @@ -484,7 +283,7 @@ public function moveFromStorage(IStorage $sourceStorage, $sourceInternalPath, $t return $result; } - public function getMetaData($path) { + public function getMetaData($path): ?array { $entry = $this->storage->getMetaData($this->findPathToUse($path)); $entry['name'] = trim(Filesystem::normalizePath($entry['name']), '/'); return $entry; diff --git a/lib/private/Files/Storage/Wrapper/EncodingDirectoryWrapper.php b/lib/private/Files/Storage/Wrapper/EncodingDirectoryWrapper.php index 26b32d9aa6285..0a90b49f0f153 100644 --- a/lib/private/Files/Storage/Wrapper/EncodingDirectoryWrapper.php +++ b/lib/private/Files/Storage/Wrapper/EncodingDirectoryWrapper.php @@ -13,11 +13,7 @@ * Normalize file names while reading directory entries */ class EncodingDirectoryWrapper extends DirectoryWrapper { - /** - * @psalm-suppress ImplementedReturnTypeMismatch Until return type is fixed upstream - * @return string|false - */ - public function dir_readdir() { + public function dir_readdir(): string|false { $file = readdir($this->source); if ($file !== false && $file !== '.' && $file !== '..') { $file = trim(Filesystem::normalizePath($file), '/'); @@ -28,7 +24,6 @@ public function dir_readdir() { /** * @param resource $source - * @param callable $filter * @return resource|false */ public static function wrap($source) { diff --git a/lib/private/Files/Storage/Wrapper/Encryption.php b/lib/private/Files/Storage/Wrapper/Encryption.php index 3b45e996f5de5..728e9c46413c6 100644 --- a/lib/private/Files/Storage/Wrapper/Encryption.php +++ b/lib/private/Files/Storage/Wrapper/Encryption.php @@ -18,7 +18,6 @@ use OC\Files\Storage\LocalTempFileTrait; use OC\Memcache\ArrayCache; use OCP\Cache\CappedMemoryCache; -use OCP\Encryption\Exceptions\GenericEncryptionException; use OCP\Encryption\IFile; use OCP\Encryption\IManager; use OCP\Encryption\Keys\IStorage; @@ -104,10 +103,6 @@ public function __construct( parent::__construct($parameters); } - /** - * see https://www.php.net/manual/en/function.filesize.php - * The result for filesize when called on a folder is required to be 0 - */ public function filesize($path): false|int|float { $fullPath = $this->getFullPath($path); @@ -179,7 +174,7 @@ private function modifyMetaData(string $path, array $data): array { return $data; } - public function getMetaData($path) { + public function getMetaData($path): ?array { $data = $this->storage->getMetaData($path); if (is_null($data)) { return null; @@ -194,13 +189,7 @@ public function getDirectoryContent($directory): \Traversable { } } - /** - * see https://www.php.net/manual/en/function.file_get_contents.php - * - * @param string $path - * @return string|false - */ - public function file_get_contents($path) { + public function file_get_contents($path): false|string { $encryptionModule = $this->getEncryptionModule($path); if ($encryptionModule) { @@ -215,14 +204,7 @@ public function file_get_contents($path) { return $this->storage->file_get_contents($path); } - /** - * see https://www.php.net/manual/en/function.file_put_contents.php - * - * @param string $path - * @param mixed $data - * @return int|false - */ - public function file_put_contents($path, $data) { + public function file_put_contents($path, $data): float|false|int { // file put content will always be translated to a stream write $handle = $this->fopen($path, 'w'); if (is_resource($handle)) { @@ -234,13 +216,7 @@ public function file_put_contents($path, $data) { return false; } - /** - * see https://www.php.net/manual/en/function.unlink.php - * - * @param string $path - * @return bool - */ - public function unlink($path) { + public function unlink($path): bool { $fullPath = $this->getFullPath($path); if ($this->util->isExcluded($fullPath)) { return $this->storage->unlink($path); @@ -254,14 +230,7 @@ public function unlink($path) { return $this->storage->unlink($path); } - /** - * see https://www.php.net/manual/en/function.rename.php - * - * @param string $source - * @param string $target - * @return bool - */ - public function rename($source, $target) { + public function rename($source, $target): bool { $result = $this->storage->rename($source, $target); if ($result && @@ -286,13 +255,7 @@ public function rename($source, $target) { return $result; } - /** - * see https://www.php.net/manual/en/function.rmdir.php - * - * @param string $path - * @return bool - */ - public function rmdir($path) { + public function rmdir($path): bool { $result = $this->storage->rmdir($path); $fullPath = $this->getFullPath($path); if ($result && @@ -305,13 +268,7 @@ public function rmdir($path) { return $result; } - /** - * check if a file can be read - * - * @param string $path - * @return bool - */ - public function isReadable($path) { + public function isReadable($path): bool { $isReadable = true; $metaData = $this->getMetaData($path); @@ -328,12 +285,6 @@ public function isReadable($path) { return $this->storage->isReadable($path) && $isReadable; } - /** - * see https://www.php.net/manual/en/function.copy.php - * - * @param string $source - * @param string $target - */ public function copy($source, $target): bool { $sourcePath = $this->getFullPath($source); @@ -347,15 +298,6 @@ public function copy($source, $target): bool { return $this->copyFromStorage($this, $source, $target); } - /** - * see https://www.php.net/manual/en/function.fopen.php - * - * @param string $path - * @param string $mode - * @return resource|bool - * @throws GenericEncryptionException - * @throws ModuleDoesNotExistsException - */ public function fopen($path, $mode) { // check if the file is stored in the array cache, this means that we // copy a file over to the versions folder, in this case we don't want to @@ -409,10 +351,8 @@ public function fopen($path, $mode) { // if we update a encrypted file with a un-encrypted one we change the db flag if ($targetIsEncrypted && $encryptionEnabled === false) { $cache = $this->storage->getCache(); - if ($cache) { - $entry = $cache->get($path); - $cache->update($entry->getId(), ['encrypted' => 0]); - } + $entry = $cache->get($path); + $cache->update($entry->getId(), ['encrypted' => 0]); } if ($encryptionEnabled) { // if $encryptionModuleId is empty, the default module will be used @@ -511,7 +451,7 @@ protected function verifyUnencryptedSize(string $path, int $unencryptedSize): in * * @return int calculated unencrypted size */ - protected function fixUnencryptedSize(string $path, int $size, int $unencryptedSize): int { + protected function fixUnencryptedSize(string $path, int $size, int $unencryptedSize): float|int { $headerSize = $this->getHeaderSize($path); $header = $this->getHeader($path); $encryptionModule = $this->getEncryptionModule($path); @@ -580,12 +520,10 @@ protected function fixUnencryptedSize(string $path, int $size, int $unencryptedS // write to cache if applicable $cache = $this->storage->getCache(); - if ($cache) { - $entry = $cache->get($path); - $cache->update($entry['fileid'], [ - 'unencrypted_size' => $newUnencryptedSize - ]); - } + $entry = $cache->get($path); + $cache->update($entry['fileid'], [ + 'unencrypted_size' => $newUnencryptedSize + ]); return $newUnencryptedSize; } @@ -617,19 +555,12 @@ private function fread_block($handle, int $blockSize): string { return $data; } - /** - * @param Storage\IStorage $sourceStorage - * @param string $sourceInternalPath - * @param string $targetInternalPath - * @param bool $preserveMtime - * @return bool - */ public function moveFromStorage( Storage\IStorage $sourceStorage, $sourceInternalPath, $targetInternalPath, $preserveMtime = true, - ) { + ): bool { if ($sourceStorage === $this) { return $this->rename($sourceInternalPath, $targetInternalPath); } @@ -655,22 +586,13 @@ public function moveFromStorage( return $result; } - - /** - * @param Storage\IStorage $sourceStorage - * @param string $sourceInternalPath - * @param string $targetInternalPath - * @param bool $preserveMtime - * @param bool $isRename - * @return bool - */ public function copyFromStorage( Storage\IStorage $sourceStorage, $sourceInternalPath, $targetInternalPath, $preserveMtime = false, $isRename = false, - ) { + ): bool { // TODO clean this up once the underlying moveFromStorage in OC\Files\Storage\Wrapper\Common is fixed: // - call $this->storage->copyFromStorage() instead of $this->copyBetweenStorage // - copy the file cache update from $this->copyBetweenStorage to this method @@ -695,7 +617,7 @@ private function updateEncryptedVersion( $targetInternalPath, $isRename, $keepEncryptionVersion, - ) { + ): void { $isEncrypted = $this->encryptionManager->isEnabled() && $this->shouldEncrypt($targetInternalPath); $cacheInformation = [ 'encrypted' => $isEncrypted, @@ -750,7 +672,7 @@ private function copyBetweenStorage( $targetInternalPath, $preserveMtime, $isRename, - ) { + ): bool { // for versions we have nothing to do, because versions should always use the // key from the original file. Just create a 1:1 copy and done if ($this->isVersion($targetInternalPath) || @@ -828,7 +750,7 @@ private function copyBetweenStorage( return (bool)$result; } - public function getLocalFile($path) { + public function getLocalFile($path): string|false { if ($this->encryptionManager->isEnabled()) { $cachedFile = $this->getCachedFile($path); if (is_string($cachedFile)) { @@ -838,14 +760,14 @@ public function getLocalFile($path) { return $this->storage->getLocalFile($path); } - public function isLocal() { + public function isLocal(): bool { if ($this->encryptionManager->isEnabled()) { return false; } return $this->storage->isLocal(); } - public function stat($path) { + public function stat($path): array|false { $stat = $this->storage->stat($path); if (!$stat) { return false; @@ -857,7 +779,7 @@ public function stat($path) { return $stat; } - public function hash($type, $path, $raw = false) { + public function hash($type, $path, $raw = false): false|string { $fh = $this->fopen($path, 'rb'); $ctx = hash_init($type); hash_update_stream($ctx, $fh); @@ -871,7 +793,7 @@ public function hash($type, $path, $raw = false) { * @param string $path relative to mount point * @return string full path including mount point */ - protected function getFullPath($path) { + protected function getFullPath($path): string { return Filesystem::normalizePath($this->mountPoint . '/' . $path); } @@ -882,7 +804,7 @@ protected function getFullPath($path) { * @param string $path * @return string */ - protected function readFirstBlock($path) { + protected function readFirstBlock($path): string { $firstBlock = ''; if ($this->storage->is_file($path)) { $handle = $this->storage->fopen($path, 'r'); @@ -898,7 +820,7 @@ protected function readFirstBlock($path) { * @param string $path * @return int */ - protected function getHeaderSize($path) { + protected function getHeaderSize($path): int { $headerSize = 0; $realFile = $this->util->stripPartialFileExtension($path); if ($this->storage->is_file($realFile)) { @@ -919,7 +841,7 @@ protected function getHeaderSize($path) { * @param string $path * @return array */ - protected function getHeader($path) { + protected function getHeader($path): array { $realFile = $this->util->stripPartialFileExtension($path); $exists = $this->storage->is_file($realFile); if ($exists) { @@ -956,7 +878,7 @@ protected function getHeader($path) { * @throws ModuleDoesNotExistsException * @throws \Exception */ - protected function getEncryptionModule($path) { + protected function getEncryptionModule($path): ?\OCP\Encryption\IEncryptionModule { $encryptionModule = null; $header = $this->getHeader($path); $encryptionModuleId = $this->util->getEncryptionModuleId($header); @@ -976,7 +898,7 @@ protected function getEncryptionModule($path) { * @param string $path * @param int $unencryptedSize */ - public function updateUnencryptedSize($path, $unencryptedSize) { + public function updateUnencryptedSize($path, $unencryptedSize): void { $this->unencryptedSize[$path] = $unencryptedSize; } @@ -987,7 +909,7 @@ public function updateUnencryptedSize($path, $unencryptedSize) { * @param string $target path relative to data/ * @return bool */ - protected function copyKeys($source, $target) { + protected function copyKeys($source, $target): bool { if (!$this->util->isExcluded($source)) { return $this->keyStorage->copyKeys($source, $target); } @@ -1001,7 +923,7 @@ protected function copyKeys($source, $target) { * @param $path * @return bool */ - protected function isVersion($path) { + protected function isVersion($path): bool { $normalized = Filesystem::normalizePath($path); return substr($normalized, 0, strlen('/files_versions/')) === '/files_versions/'; } @@ -1012,7 +934,7 @@ protected function isVersion($path) { * @param $path * @return bool */ - protected function shouldEncrypt($path) { + protected function shouldEncrypt($path): bool { $fullPath = $this->getFullPath($path); $mountPointConfig = $this->mount->getOption('encrypt', true); if ($mountPointConfig === false) { diff --git a/lib/private/Files/Storage/Wrapper/Jail.php b/lib/private/Files/Storage/Wrapper/Jail.php index e61ded4bc380f..894908291c026 100644 --- a/lib/private/Files/Storage/Wrapper/Jail.php +++ b/lib/private/Files/Storage/Wrapper/Jail.php @@ -11,6 +11,9 @@ use OC\Files\Cache\Wrapper\JailPropagator; use OC\Files\Cache\Wrapper\JailWatcher; use OC\Files\Filesystem; +use OCP\Files\Cache\ICache; +use OCP\Files\Cache\IPropagator; +use OCP\Files\Cache\IWatcher; use OCP\Files\Storage\IStorage; use OCP\Files\Storage\IWriteStreamStorage; use OCP\Lock\ILockingProvider; @@ -37,19 +40,19 @@ public function __construct($arguments) { $this->rootPath = $arguments['root']; } - public function getUnjailedPath($path) { + public function getUnjailedPath($path): string { return trim(Filesystem::normalizePath($this->rootPath . '/' . $path), '/'); } /** * This is separate from Wrapper::getWrapperStorage so we can get the jailed storage consistently even if the jail is inside another wrapper */ - public function getUnjailedStorage() { + public function getUnjailedStorage(): IStorage { return $this->storage; } - public function getJailedPath($path) { + public function getJailedPath($path): ?string { $root = rtrim($this->rootPath, '/') . '/'; if ($path !== $this->rootPath && !str_starts_with($path, $root)) { @@ -60,305 +63,123 @@ public function getJailedPath($path) { } } - public function getId() { + public function getId(): string { return parent::getId(); } - /** - * see https://www.php.net/manual/en/function.mkdir.php - * - * @param string $path - * @return bool - */ - public function mkdir($path) { + public function mkdir($path): bool { return $this->getWrapperStorage()->mkdir($this->getUnjailedPath($path)); } - /** - * see https://www.php.net/manual/en/function.rmdir.php - * - * @param string $path - * @return bool - */ - public function rmdir($path) { + public function rmdir($path): bool { return $this->getWrapperStorage()->rmdir($this->getUnjailedPath($path)); } - /** - * see https://www.php.net/manual/en/function.opendir.php - * - * @param string $path - * @return resource|false - */ public function opendir($path) { return $this->getWrapperStorage()->opendir($this->getUnjailedPath($path)); } - /** - * see https://www.php.net/manual/en/function.is_dir.php - * - * @param string $path - * @return bool - */ - public function is_dir($path) { + public function is_dir($path): bool { return $this->getWrapperStorage()->is_dir($this->getUnjailedPath($path)); } - /** - * see https://www.php.net/manual/en/function.is_file.php - * - * @param string $path - * @return bool - */ - public function is_file($path) { + public function is_file($path): bool { return $this->getWrapperStorage()->is_file($this->getUnjailedPath($path)); } - /** - * see https://www.php.net/manual/en/function.stat.php - * only the following keys are required in the result: size and mtime - * - * @param string $path - * @return array|bool - */ - public function stat($path) { + public function stat($path): array|false { return $this->getWrapperStorage()->stat($this->getUnjailedPath($path)); } - /** - * see https://www.php.net/manual/en/function.filetype.php - * - * @param string $path - * @return bool - */ - public function filetype($path) { + public function filetype($path): false|string { return $this->getWrapperStorage()->filetype($this->getUnjailedPath($path)); } - /** - * see https://www.php.net/manual/en/function.filesize.php - * The result for filesize when called on a folder is required to be 0 - */ public function filesize($path): false|int|float { return $this->getWrapperStorage()->filesize($this->getUnjailedPath($path)); } - /** - * check if a file can be created in $path - * - * @param string $path - * @return bool - */ - public function isCreatable($path) { + public function isCreatable($path): bool { return $this->getWrapperStorage()->isCreatable($this->getUnjailedPath($path)); } - /** - * check if a file can be read - * - * @param string $path - * @return bool - */ - public function isReadable($path) { + public function isReadable($path): bool { return $this->getWrapperStorage()->isReadable($this->getUnjailedPath($path)); } - /** - * check if a file can be written to - * - * @param string $path - * @return bool - */ - public function isUpdatable($path) { + public function isUpdatable($path): bool { return $this->getWrapperStorage()->isUpdatable($this->getUnjailedPath($path)); } - /** - * check if a file can be deleted - * - * @param string $path - * @return bool - */ - public function isDeletable($path) { + public function isDeletable($path): bool { return $this->getWrapperStorage()->isDeletable($this->getUnjailedPath($path)); } - /** - * check if a file can be shared - * - * @param string $path - * @return bool - */ - public function isSharable($path) { + public function isSharable($path): bool { return $this->getWrapperStorage()->isSharable($this->getUnjailedPath($path)); } - /** - * get the full permissions of a path. - * Should return a combination of the PERMISSION_ constants defined in lib/public/constants.php - * - * @param string $path - * @return int - */ - public function getPermissions($path) { + public function getPermissions($path): int { return $this->getWrapperStorage()->getPermissions($this->getUnjailedPath($path)); } - /** - * see https://www.php.net/manual/en/function.file_exists.php - * - * @param string $path - * @return bool - */ - public function file_exists($path) { + public function file_exists($path): bool { return $this->getWrapperStorage()->file_exists($this->getUnjailedPath($path)); } - /** - * see https://www.php.net/manual/en/function.filemtime.php - * - * @param string $path - * @return int|bool - */ - public function filemtime($path) { + public function filemtime($path): false|int { return $this->getWrapperStorage()->filemtime($this->getUnjailedPath($path)); } - /** - * see https://www.php.net/manual/en/function.file_get_contents.php - * - * @param string $path - * @return string|false - */ - public function file_get_contents($path) { + public function file_get_contents($path): false|string { return $this->getWrapperStorage()->file_get_contents($this->getUnjailedPath($path)); } - /** - * see https://www.php.net/manual/en/function.file_put_contents.php - * - * @param string $path - * @param mixed $data - * @return int|float|false - */ - public function file_put_contents($path, $data) { + public function file_put_contents($path, $data): float|false|int { return $this->getWrapperStorage()->file_put_contents($this->getUnjailedPath($path), $data); } - /** - * see https://www.php.net/manual/en/function.unlink.php - * - * @param string $path - * @return bool - */ - public function unlink($path) { + public function unlink($path): bool { return $this->getWrapperStorage()->unlink($this->getUnjailedPath($path)); } - /** - * see https://www.php.net/manual/en/function.rename.php - * - * @param string $source - * @param string $target - * @return bool - */ - public function rename($source, $target) { + public function rename($source, $target): bool { return $this->getWrapperStorage()->rename($this->getUnjailedPath($source), $this->getUnjailedPath($target)); } - /** - * see https://www.php.net/manual/en/function.copy.php - * - * @param string $source - * @param string $target - * @return bool - */ - public function copy($source, $target) { + public function copy($source, $target): bool { return $this->getWrapperStorage()->copy($this->getUnjailedPath($source), $this->getUnjailedPath($target)); } - /** - * see https://www.php.net/manual/en/function.fopen.php - * - * @param string $path - * @param string $mode - * @return resource|bool - */ public function fopen($path, $mode) { return $this->getWrapperStorage()->fopen($this->getUnjailedPath($path), $mode); } - /** - * get the mimetype for a file or folder - * The mimetype for a folder is required to be "httpd/unix-directory" - * - * @param string $path - * @return string|bool - */ - public function getMimeType($path) { + public function getMimeType($path): false|string { return $this->getWrapperStorage()->getMimeType($this->getUnjailedPath($path)); } - /** - * see https://www.php.net/manual/en/function.hash.php - * - * @param string $type - * @param string $path - * @param bool $raw - * @return string|bool - */ - public function hash($type, $path, $raw = false) { + public function hash($type, $path, $raw = false): false|string { return $this->getWrapperStorage()->hash($type, $this->getUnjailedPath($path), $raw); } - /** - * see https://www.php.net/manual/en/function.free_space.php - * - * @param string $path - * @return int|float|bool - */ - public function free_space($path) { + public function free_space($path): float|false|int { return $this->getWrapperStorage()->free_space($this->getUnjailedPath($path)); } - /** - * see https://www.php.net/manual/en/function.touch.php - * If the backend does not support the operation, false should be returned - * - * @param string $path - * @param int $mtime - * @return bool - */ - public function touch($path, $mtime = null) { + public function touch($path, $mtime = null): bool { return $this->getWrapperStorage()->touch($this->getUnjailedPath($path), $mtime); } - /** - * get the path to a local version of the file. - * The local version of the file can be temporary and doesn't have to be persistent across requests - * - * @param string $path - * @return string|false - */ - public function getLocalFile($path) { + public function getLocalFile($path): false|string { return $this->getWrapperStorage()->getLocalFile($this->getUnjailedPath($path)); } - /** - * check if a file or folder has been updated since $time - * - * @param string $path - * @param int $time - * @return bool - * - * hasUpdated for folders should return at least true if a file inside the folder is add, removed or renamed. - * returning true for other changes in the folder is optional - */ - public function hasUpdated($path, $time) { + public function hasUpdated($path, $time): bool { return $this->getWrapperStorage()->hasUpdated($this->getUnjailedPath($path), $time); } - public function getCache($path = '', $storage = null) { + public function getCache($path = '', $storage = null): ICache { $sourceCache = $this->getWrapperStorage()->getCache($this->getUnjailedPath($path)); return new CacheJail($sourceCache, $this->rootPath); } @@ -367,34 +188,28 @@ public function getOwner($path): string|false { return $this->getWrapperStorage()->getOwner($this->getUnjailedPath($path)); } - public function getWatcher($path = '', $storage = null) { + public function getWatcher($path = '', $storage = null): IWatcher { $sourceWatcher = $this->getWrapperStorage()->getWatcher($this->getUnjailedPath($path), $this->getWrapperStorage()); return new JailWatcher($sourceWatcher, $this->rootPath); } - /** - * get the ETag for a file or folder - * - * @param string $path - * @return string|false - */ - public function getETag($path) { + public function getETag($path): false|string { return $this->getWrapperStorage()->getETag($this->getUnjailedPath($path)); } - public function getMetaData($path) { + public function getMetaData($path): ?array { return $this->getWrapperStorage()->getMetaData($this->getUnjailedPath($path)); } - public function acquireLock($path, $type, ILockingProvider $provider) { + public function acquireLock($path, $type, ILockingProvider $provider): void { $this->getWrapperStorage()->acquireLock($this->getUnjailedPath($path), $type, $provider); } - public function releaseLock($path, $type, ILockingProvider $provider) { + public function releaseLock($path, $type, ILockingProvider $provider): void { $this->getWrapperStorage()->releaseLock($this->getUnjailedPath($path), $type, $provider); } - public function changeLock($path, $type, ILockingProvider $provider) { + public function changeLock($path, $type, ILockingProvider $provider): void { $this->getWrapperStorage()->changeLock($this->getUnjailedPath($path), $type, $provider); } @@ -402,39 +217,26 @@ public function changeLock($path, $type, ILockingProvider $provider) { * Resolve the path for the source of the share * * @param string $path - * @return array */ - public function resolvePath($path) { + public function resolvePath($path): array { return [$this->getWrapperStorage(), $this->getUnjailedPath($path)]; } - /** - * @param IStorage $sourceStorage - * @param string $sourceInternalPath - * @param string $targetInternalPath - * @return bool - */ - public function copyFromStorage(IStorage $sourceStorage, $sourceInternalPath, $targetInternalPath) { + public function copyFromStorage(IStorage $sourceStorage, $sourceInternalPath, $targetInternalPath): bool { if ($sourceStorage === $this) { return $this->copy($sourceInternalPath, $targetInternalPath); } return $this->getWrapperStorage()->copyFromStorage($sourceStorage, $sourceInternalPath, $this->getUnjailedPath($targetInternalPath)); } - /** - * @param IStorage $sourceStorage - * @param string $sourceInternalPath - * @param string $targetInternalPath - * @return bool - */ - public function moveFromStorage(IStorage $sourceStorage, $sourceInternalPath, $targetInternalPath) { + public function moveFromStorage(IStorage $sourceStorage, $sourceInternalPath, $targetInternalPath): bool { if ($sourceStorage === $this) { return $this->rename($sourceInternalPath, $targetInternalPath); } return $this->getWrapperStorage()->moveFromStorage($sourceStorage, $sourceInternalPath, $this->getUnjailedPath($targetInternalPath)); } - public function getPropagator($storage = null) { + public function getPropagator($storage = null): IPropagator { if (isset($this->propagator)) { return $this->propagator; } @@ -460,7 +262,7 @@ public function writeStream(string $path, $stream, ?int $size = null): int { } } - public function getDirectoryContent($directory): \Traversable { + public function getDirectoryContent($directory): \Traversable|false { return $this->getWrapperStorage()->getDirectoryContent($this->getUnjailedPath($directory)); } } diff --git a/lib/private/Files/Storage/Wrapper/KnownMtime.php b/lib/private/Files/Storage/Wrapper/KnownMtime.php index a7360ae134680..d5a3fbc3764d0 100644 --- a/lib/private/Files/Storage/Wrapper/KnownMtime.php +++ b/lib/private/Files/Storage/Wrapper/KnownMtime.php @@ -26,7 +26,7 @@ public function __construct($arguments) { $this->clock = $arguments['clock']; } - public function file_put_contents($path, $data) { + public function file_put_contents($path, $data): float|false|int { $result = parent::file_put_contents($path, $data); if ($result) { $now = $this->clock->now()->getTimestamp(); @@ -35,7 +35,7 @@ public function file_put_contents($path, $data) { return $result; } - public function stat($path) { + public function stat($path): array|false { $stat = parent::stat($path); if ($stat) { $this->applyKnownMtime($path, $stat); @@ -43,7 +43,7 @@ public function stat($path) { return $stat; } - public function getMetaData($path) { + public function getMetaData($path): ?array { $stat = parent::getMetaData($path); if ($stat) { $this->applyKnownMtime($path, $stat); @@ -51,19 +51,19 @@ public function getMetaData($path) { return $stat; } - private function applyKnownMtime(string $path, array &$stat) { + private function applyKnownMtime(string $path, array &$stat): void { if (isset($stat['mtime'])) { $knownMtime = $this->knowMtimes->get($path) ?? 0; $stat['mtime'] = max($stat['mtime'], $knownMtime); } } - public function filemtime($path) { + public function filemtime($path): false|int { $knownMtime = $this->knowMtimes->get($path) ?? 0; return max(parent::filemtime($path), $knownMtime); } - public function mkdir($path) { + public function mkdir($path): bool { $result = parent::mkdir($path); if ($result) { $this->knowMtimes->set($path, $this->clock->now()->getTimestamp()); @@ -71,7 +71,7 @@ public function mkdir($path) { return $result; } - public function rmdir($path) { + public function rmdir($path): bool { $result = parent::rmdir($path); if ($result) { $this->knowMtimes->set($path, $this->clock->now()->getTimestamp()); @@ -79,7 +79,7 @@ public function rmdir($path) { return $result; } - public function unlink($path) { + public function unlink($path): bool { $result = parent::unlink($path); if ($result) { $this->knowMtimes->set($path, $this->clock->now()->getTimestamp()); @@ -87,7 +87,7 @@ public function unlink($path) { return $result; } - public function rename($source, $target) { + public function rename($source, $target): bool { $result = parent::rename($source, $target); if ($result) { $this->knowMtimes->set($target, $this->clock->now()->getTimestamp()); @@ -96,7 +96,7 @@ public function rename($source, $target) { return $result; } - public function copy($source, $target) { + public function copy($source, $target): bool { $result = parent::copy($source, $target); if ($result) { $this->knowMtimes->set($target, $this->clock->now()->getTimestamp()); @@ -112,7 +112,7 @@ public function fopen($path, $mode) { return $result; } - public function touch($path, $mtime = null) { + public function touch($path, $mtime = null): bool { $result = parent::touch($path, $mtime); if ($result) { $this->knowMtimes->set($path, $mtime ?? $this->clock->now()->getTimestamp()); @@ -120,7 +120,7 @@ public function touch($path, $mtime = null) { return $result; } - public function copyFromStorage(IStorage $sourceStorage, $sourceInternalPath, $targetInternalPath) { + public function copyFromStorage(IStorage $sourceStorage, $sourceInternalPath, $targetInternalPath): bool { $result = parent::copyFromStorage($sourceStorage, $sourceInternalPath, $targetInternalPath); if ($result) { $this->knowMtimes->set($targetInternalPath, $this->clock->now()->getTimestamp()); @@ -128,7 +128,7 @@ public function copyFromStorage(IStorage $sourceStorage, $sourceInternalPath, $t return $result; } - public function moveFromStorage(IStorage $sourceStorage, $sourceInternalPath, $targetInternalPath) { + public function moveFromStorage(IStorage $sourceStorage, $sourceInternalPath, $targetInternalPath): bool { $result = parent::moveFromStorage($sourceStorage, $sourceInternalPath, $targetInternalPath); if ($result) { $this->knowMtimes->set($targetInternalPath, $this->clock->now()->getTimestamp()); diff --git a/lib/private/Files/Storage/Wrapper/PermissionsMask.php b/lib/private/Files/Storage/Wrapper/PermissionsMask.php index d6b745c0d3119..0afe7a87415fe 100644 --- a/lib/private/Files/Storage/Wrapper/PermissionsMask.php +++ b/lib/private/Files/Storage/Wrapper/PermissionsMask.php @@ -34,31 +34,31 @@ public function __construct($arguments) { $this->mask = $arguments['mask']; } - private function checkMask($permissions) { + private function checkMask($permissions): bool { return ($this->mask & $permissions) === $permissions; } - public function isUpdatable($path) { + public function isUpdatable($path): bool { return $this->checkMask(Constants::PERMISSION_UPDATE) and parent::isUpdatable($path); } - public function isCreatable($path) { + public function isCreatable($path): bool { return $this->checkMask(Constants::PERMISSION_CREATE) and parent::isCreatable($path); } - public function isDeletable($path) { + public function isDeletable($path): bool { return $this->checkMask(Constants::PERMISSION_DELETE) and parent::isDeletable($path); } - public function isSharable($path) { + public function isSharable($path): bool { return $this->checkMask(Constants::PERMISSION_SHARE) and parent::isSharable($path); } - public function getPermissions($path) { + public function getPermissions($path): int { return $this->storage->getPermissions($path) & $this->mask; } - public function rename($source, $target) { + public function rename($source, $target): bool { //This is a rename of the transfer file to the original file if (dirname($source) === dirname($target) && strpos($source, '.ocTransferId') > 0) { return $this->checkMask(Constants::PERMISSION_CREATE) and parent::rename($source, $target); @@ -66,28 +66,28 @@ public function rename($source, $target) { return $this->checkMask(Constants::PERMISSION_UPDATE) and parent::rename($source, $target); } - public function copy($source, $target) { + public function copy($source, $target): bool { return $this->checkMask(Constants::PERMISSION_CREATE) and parent::copy($source, $target); } - public function touch($path, $mtime = null) { + public function touch($path, $mtime = null): bool { $permissions = $this->file_exists($path) ? Constants::PERMISSION_UPDATE : Constants::PERMISSION_CREATE; return $this->checkMask($permissions) and parent::touch($path, $mtime); } - public function mkdir($path) { + public function mkdir($path): bool { return $this->checkMask(Constants::PERMISSION_CREATE) and parent::mkdir($path); } - public function rmdir($path) { + public function rmdir($path): bool { return $this->checkMask(Constants::PERMISSION_DELETE) and parent::rmdir($path); } - public function unlink($path) { + public function unlink($path): bool { return $this->checkMask(Constants::PERMISSION_DELETE) and parent::unlink($path); } - public function file_put_contents($path, $data) { + public function file_put_contents($path, $data): float|false|int { $permissions = $this->file_exists($path) ? Constants::PERMISSION_UPDATE : Constants::PERMISSION_CREATE; return $this->checkMask($permissions) ? parent::file_put_contents($path, $data) : false; } @@ -101,7 +101,7 @@ public function fopen($path, $mode) { } } - public function getCache($path = '', $storage = null) { + public function getCache($path = '', $storage = null): \OCP\Files\Cache\ICache { if (!$storage) { $storage = $this; } @@ -109,7 +109,7 @@ public function getCache($path = '', $storage = null) { return new CachePermissionsMask($sourceCache, $this->mask); } - public function getMetaData($path) { + public function getMetaData($path): ?array { $data = parent::getMetaData($path); if ($data && isset($data['permissions'])) { @@ -119,7 +119,7 @@ public function getMetaData($path) { return $data; } - public function getScanner($path = '', $storage = null) { + public function getScanner($path = '', $storage = null): \OCP\Files\Cache\IScanner { if (!$storage) { $storage = $this->storage; } diff --git a/lib/private/Files/Storage/Wrapper/Quota.php b/lib/private/Files/Storage/Wrapper/Quota.php index b642c438266d8..b6cb29d36cea4 100644 --- a/lib/private/Files/Storage/Wrapper/Quota.php +++ b/lib/private/Files/Storage/Wrapper/Quota.php @@ -33,9 +33,6 @@ public function __construct($parameters) { $this->quotaIncludeExternalStorage = $parameters['include_external_storage'] ?? false; } - /** - * @return int|float quota value - */ public function getQuota(): int|float { if ($this->quota === null) { $quotaCallback = $this->quotaCallback; @@ -55,9 +52,8 @@ private function hasQuota(): bool { /** * @param string $path * @param IStorage $storage - * @return int|float */ - protected function getSize($path, $storage = null) { + protected function getSize($path, $storage = null): float|int { if ($this->quotaIncludeExternalStorage) { $rootInfo = Filesystem::getFileInfo('', 'ext'); if ($rootInfo) { @@ -75,13 +71,7 @@ protected function getSize($path, $storage = null) { } } - /** - * Get free space as limited by the quota - * - * @param string $path - * @return int|float|bool - */ - public function free_space($path) { + public function free_space($path): float|false|int { if (!$this->hasQuota()) { return $this->storage->free_space($path); } @@ -101,14 +91,7 @@ public function free_space($path) { } } - /** - * see https://www.php.net/manual/en/function.file_put_contents.php - * - * @param string $path - * @param mixed $data - * @return int|float|false - */ - public function file_put_contents($path, $data) { + public function file_put_contents($path, $data): float|false|int { if (!$this->hasQuota()) { return $this->storage->file_put_contents($path, $data); } @@ -120,14 +103,7 @@ public function file_put_contents($path, $data) { } } - /** - * see https://www.php.net/manual/en/function.copy.php - * - * @param string $source - * @param string $target - * @return bool - */ - public function copy($source, $target) { + public function copy($source, $target): bool { if (!$this->hasQuota()) { return $this->storage->copy($source, $target); } @@ -139,13 +115,6 @@ public function copy($source, $target) { } } - /** - * see https://www.php.net/manual/en/function.fopen.php - * - * @param string $path - * @param string $mode - * @return resource|bool - */ public function fopen($path, $mode) { if (!$this->hasQuota()) { return $this->storage->fopen($path, $mode); @@ -170,10 +139,9 @@ public function fopen($path, $mode) { * Checks whether the given path is a part file * * @param string $path Path that may identify a .part file - * @return bool * @note this is needed for reusing keys */ - private function isPartFile($path) { + private function isPartFile($path): bool { $extension = pathinfo($path, PATHINFO_EXTENSION); return ($extension === 'part'); @@ -186,13 +154,7 @@ private function shouldApplyQuota(string $path): bool { return str_starts_with(ltrim($path, '/'), 'files/'); } - /** - * @param IStorage $sourceStorage - * @param string $sourceInternalPath - * @param string $targetInternalPath - * @return bool - */ - public function copyFromStorage(IStorage $sourceStorage, $sourceInternalPath, $targetInternalPath) { + public function copyFromStorage(IStorage $sourceStorage, $sourceInternalPath, $targetInternalPath): bool { if (!$this->hasQuota()) { return $this->storage->copyFromStorage($sourceStorage, $sourceInternalPath, $targetInternalPath); } @@ -204,13 +166,7 @@ public function copyFromStorage(IStorage $sourceStorage, $sourceInternalPath, $t } } - /** - * @param IStorage $sourceStorage - * @param string $sourceInternalPath - * @param string $targetInternalPath - * @return bool - */ - public function moveFromStorage(IStorage $sourceStorage, $sourceInternalPath, $targetInternalPath) { + public function moveFromStorage(IStorage $sourceStorage, $sourceInternalPath, $targetInternalPath): bool { if (!$this->hasQuota()) { return $this->storage->moveFromStorage($sourceStorage, $sourceInternalPath, $targetInternalPath); } @@ -222,7 +178,7 @@ public function moveFromStorage(IStorage $sourceStorage, $sourceInternalPath, $t } } - public function mkdir($path) { + public function mkdir($path): bool { if (!$this->hasQuota()) { return $this->storage->mkdir($path); } @@ -234,7 +190,7 @@ public function mkdir($path) { return parent::mkdir($path); } - public function touch($path, $mtime = null) { + public function touch($path, $mtime = null): bool { if (!$this->hasQuota()) { return $this->storage->touch($path, $mtime); } diff --git a/lib/private/Files/Storage/Wrapper/Wrapper.php b/lib/private/Files/Storage/Wrapper/Wrapper.php index 93dcacdfb42f0..a387609c0ec61 100644 --- a/lib/private/Files/Storage/Wrapper/Wrapper.php +++ b/lib/private/Files/Storage/Wrapper/Wrapper.php @@ -8,7 +8,12 @@ namespace OC\Files\Storage\Wrapper; use OC\Files\Storage\FailedStorage; -use OCP\Files\InvalidPathException; +use OC\Files\Storage\Storage; +use OCP\Files\Cache\ICache; +use OCP\Files\Cache\IPropagator; +use OCP\Files\Cache\IScanner; +use OCP\Files\Cache\IUpdater; +use OCP\Files\Cache\IWatcher; use OCP\Files\Storage\ILockingStorage; use OCP\Files\Storage\IStorage; use OCP\Files\Storage\IWriteStreamStorage; @@ -35,10 +40,7 @@ public function __construct($parameters) { $this->storage = $parameters['storage']; } - /** - * @return \OC\Files\Storage\Storage - */ - public function getWrapperStorage() { + public function getWrapperStorage(): Storage { if (!$this->storage) { $message = 'storage wrapper ' . get_class($this) . " doesn't have a wrapped storage set"; $logger = Server::get(LoggerInterface::class); @@ -48,319 +50,130 @@ public function getWrapperStorage() { return $this->storage; } - /** - * Get the identifier for the storage, - * the returned id should be the same for every storage object that is created with the same parameters - * and two storage objects with the same id should refer to two storages that display the same files. - * - * @return string - */ - public function getId() { + public function getId(): string { return $this->getWrapperStorage()->getId(); } - /** - * see https://www.php.net/manual/en/function.mkdir.php - * - * @param string $path - * @return bool - */ - public function mkdir($path) { + public function mkdir($path): bool { return $this->getWrapperStorage()->mkdir($path); } - /** - * see https://www.php.net/manual/en/function.rmdir.php - * - * @param string $path - * @return bool - */ - public function rmdir($path) { + public function rmdir($path): bool { return $this->getWrapperStorage()->rmdir($path); } - /** - * see https://www.php.net/manual/en/function.opendir.php - * - * @param string $path - * @return resource|false - */ public function opendir($path) { return $this->getWrapperStorage()->opendir($path); } - /** - * see https://www.php.net/manual/en/function.is_dir.php - * - * @param string $path - * @return bool - */ - public function is_dir($path) { + public function is_dir($path): bool { return $this->getWrapperStorage()->is_dir($path); } - /** - * see https://www.php.net/manual/en/function.is_file.php - * - * @param string $path - * @return bool - */ - public function is_file($path) { + public function is_file($path): bool { return $this->getWrapperStorage()->is_file($path); } - /** - * see https://www.php.net/manual/en/function.stat.php - * only the following keys are required in the result: size and mtime - * - * @param string $path - * @return array|bool - */ - public function stat($path) { + public function stat($path): array|false { return $this->getWrapperStorage()->stat($path); } - /** - * see https://www.php.net/manual/en/function.filetype.php - * - * @param string $path - * @return string|bool - */ - public function filetype($path) { + public function filetype($path): string|false { return $this->getWrapperStorage()->filetype($path); } - /** - * see https://www.php.net/manual/en/function.filesize.php - * The result for filesize when called on a folder is required to be 0 - */ public function filesize($path): false|int|float { return $this->getWrapperStorage()->filesize($path); } - /** - * check if a file can be created in $path - * - * @param string $path - * @return bool - */ - public function isCreatable($path) { + public function isCreatable($path): bool { return $this->getWrapperStorage()->isCreatable($path); } - /** - * check if a file can be read - * - * @param string $path - * @return bool - */ - public function isReadable($path) { + public function isReadable($path): bool { return $this->getWrapperStorage()->isReadable($path); } - /** - * check if a file can be written to - * - * @param string $path - * @return bool - */ - public function isUpdatable($path) { + public function isUpdatable($path): bool { return $this->getWrapperStorage()->isUpdatable($path); } - /** - * check if a file can be deleted - * - * @param string $path - * @return bool - */ - public function isDeletable($path) { + public function isDeletable($path): bool { return $this->getWrapperStorage()->isDeletable($path); } - /** - * check if a file can be shared - * - * @param string $path - * @return bool - */ - public function isSharable($path) { + public function isSharable($path): bool { return $this->getWrapperStorage()->isSharable($path); } - /** - * get the full permissions of a path. - * Should return a combination of the PERMISSION_ constants defined in lib/public/constants.php - * - * @param string $path - * @return int - */ - public function getPermissions($path) { + public function getPermissions($path): int { return $this->getWrapperStorage()->getPermissions($path); } - /** - * see https://www.php.net/manual/en/function.file_exists.php - * - * @param string $path - * @return bool - */ - public function file_exists($path) { + public function file_exists($path): bool { return $this->getWrapperStorage()->file_exists($path); } - /** - * see https://www.php.net/manual/en/function.filemtime.php - * - * @param string $path - * @return int|bool - */ - public function filemtime($path) { + public function filemtime($path): int|false { return $this->getWrapperStorage()->filemtime($path); } - /** - * see https://www.php.net/manual/en/function.file_get_contents.php - * - * @param string $path - * @return string|false - */ - public function file_get_contents($path) { + public function file_get_contents($path): string|false { return $this->getWrapperStorage()->file_get_contents($path); } - /** - * see https://www.php.net/manual/en/function.file_put_contents.php - * - * @param string $path - * @param mixed $data - * @return int|float|false - */ - public function file_put_contents($path, $data) { + public function file_put_contents($path, $data): int|float|false { return $this->getWrapperStorage()->file_put_contents($path, $data); } - /** - * see https://www.php.net/manual/en/function.unlink.php - * - * @param string $path - * @return bool - */ - public function unlink($path) { + public function unlink($path): bool { return $this->getWrapperStorage()->unlink($path); } - /** - * see https://www.php.net/manual/en/function.rename.php - * - * @param string $source - * @param string $target - * @return bool - */ - public function rename($source, $target) { + public function rename($source, $target): bool { return $this->getWrapperStorage()->rename($source, $target); } - /** - * see https://www.php.net/manual/en/function.copy.php - * - * @param string $source - * @param string $target - * @return bool - */ - public function copy($source, $target) { + public function copy($source, $target): bool { return $this->getWrapperStorage()->copy($source, $target); } - /** - * see https://www.php.net/manual/en/function.fopen.php - * - * @param string $path - * @param string $mode - * @return resource|bool - */ public function fopen($path, $mode) { return $this->getWrapperStorage()->fopen($path, $mode); } - /** - * get the mimetype for a file or folder - * The mimetype for a folder is required to be "httpd/unix-directory" - * - * @param string $path - * @return string|bool - */ - public function getMimeType($path) { + public function getMimeType($path): string|false { return $this->getWrapperStorage()->getMimeType($path); } - /** - * see https://www.php.net/manual/en/function.hash.php - * - * @param string $type - * @param string $path - * @param bool $raw - * @return string|bool - */ - public function hash($type, $path, $raw = false) { + public function hash($type, $path, $raw = false): string|false { return $this->getWrapperStorage()->hash($type, $path, $raw); } - /** - * see https://www.php.net/manual/en/function.free_space.php - * - * @param string $path - * @return int|float|bool - */ - public function free_space($path) { + public function free_space($path): int|float|false { return $this->getWrapperStorage()->free_space($path); } - /** - * see https://www.php.net/manual/en/function.touch.php - * If the backend does not support the operation, false should be returned - * - * @param string $path - * @param int $mtime - * @return bool - */ - public function touch($path, $mtime = null) { + public function touch($path, $mtime = null): bool { return $this->getWrapperStorage()->touch($path, $mtime); } - /** - * get the path to a local version of the file. - * The local version of the file can be temporary and doesn't have to be persistent across requests - * - * @param string $path - * @return string|false - */ - public function getLocalFile($path) { + public function getLocalFile($path): string|false { return $this->getWrapperStorage()->getLocalFile($path); } - /** - * check if a file or folder has been updated since $time - * - * @param string $path - * @param int $time - * @return bool - * - * hasUpdated for folders should return at least true if a file inside the folder is add, removed or renamed. - * returning true for other changes in the folder is optional - */ - public function hasUpdated($path, $time) { + public function hasUpdated($path, $time): bool { return $this->getWrapperStorage()->hasUpdated($path, $time); } - public function getCache($path = '', $storage = null) { + public function getCache($path = '', $storage = null): ICache { if (!$storage) { $storage = $this; } return $this->getWrapperStorage()->getCache($path, $storage); } - public function getScanner($path = '', $storage = null) { + public function getScanner($path = '', $storage = null): IScanner { if (!$storage) { $storage = $this; } @@ -371,66 +184,44 @@ public function getOwner($path): string|false { return $this->getWrapperStorage()->getOwner($path); } - public function getWatcher($path = '', $storage = null) { + public function getWatcher($path = '', $storage = null): IWatcher { if (!$storage) { $storage = $this; } return $this->getWrapperStorage()->getWatcher($path, $storage); } - public function getPropagator($storage = null) { + public function getPropagator($storage = null): IPropagator { if (!$storage) { $storage = $this; } return $this->getWrapperStorage()->getPropagator($storage); } - public function getUpdater($storage = null) { + public function getUpdater($storage = null): IUpdater { if (!$storage) { $storage = $this; } return $this->getWrapperStorage()->getUpdater($storage); } - public function getStorageCache() { + public function getStorageCache(): \OC\Files\Cache\Storage { return $this->getWrapperStorage()->getStorageCache(); } - /** - * get the ETag for a file or folder - * - * @param string $path - * @return string|false - */ - public function getETag($path) { + public function getETag($path): string|false { return $this->getWrapperStorage()->getETag($path); } - /** - * Returns true - * - * @return true - */ - public function test() { + public function test(): bool { return $this->getWrapperStorage()->test(); } - /** - * Returns the wrapped storage's value for isLocal() - * - * @return bool wrapped storage's isLocal() value - */ - public function isLocal() { + public function isLocal(): bool { return $this->getWrapperStorage()->isLocal(); } - /** - * Check if the storage is an instance of $class or is a wrapper for a storage that is an instance of $class - * - * @param class-string $class - * @return bool - */ - public function instanceOfStorage($class) { + public function instanceOfStorage($class): bool { if (ltrim($class, '\\') === 'OC\Files\Storage\Shared') { // FIXME Temporary fix to keep existing checks working $class = '\OCA\Files_Sharing\SharedStorage'; @@ -443,7 +234,7 @@ public function instanceOfStorage($class) { * @psalm-param class-string $class * @psalm-return T|null */ - public function getInstanceOfStorage(string $class) { + public function getInstanceOfStorage(string $class): ?IStorage { $storage = $this; while ($storage instanceof Wrapper) { if ($storage instanceof $class) { @@ -468,53 +259,23 @@ public function __call($method, $args) { return call_user_func_array([$this->getWrapperStorage(), $method], $args); } - /** - * 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 - */ - public function getDirectDownload($path) { + public function getDirectDownload($path): array|false { return $this->getWrapperStorage()->getDirectDownload($path); } - /** - * Get availability of the storage - * - * @return array [ available, last_checked ] - */ - public function getAvailability() { + public function getAvailability(): array { return $this->getWrapperStorage()->getAvailability(); } - /** - * Set availability of the storage - * - * @param bool $isAvailable - */ - public function setAvailability($isAvailable) { + public function setAvailability($isAvailable): void { $this->getWrapperStorage()->setAvailability($isAvailable); } - /** - * @param string $path the path of the target folder - * @param string $fileName the name of the file itself - * @return void - * @throws InvalidPathException - */ - public function verifyPath($path, $fileName) { + public function verifyPath($path, $fileName): void { $this->getWrapperStorage()->verifyPath($path, $fileName); } - /** - * @param IStorage $sourceStorage - * @param string $sourceInternalPath - * @param string $targetInternalPath - * @return bool - */ - public function copyFromStorage(IStorage $sourceStorage, $sourceInternalPath, $targetInternalPath) { + public function copyFromStorage(IStorage $sourceStorage, $sourceInternalPath, $targetInternalPath): bool { if ($sourceStorage === $this) { return $this->copy($sourceInternalPath, $targetInternalPath); } @@ -522,13 +283,7 @@ public function copyFromStorage(IStorage $sourceStorage, $sourceInternalPath, $t return $this->getWrapperStorage()->copyFromStorage($sourceStorage, $sourceInternalPath, $targetInternalPath); } - /** - * @param IStorage $sourceStorage - * @param string $sourceInternalPath - * @param string $targetInternalPath - * @return bool - */ - public function moveFromStorage(IStorage $sourceStorage, $sourceInternalPath, $targetInternalPath) { + public function moveFromStorage(IStorage $sourceStorage, $sourceInternalPath, $targetInternalPath): bool { if ($sourceStorage === $this) { return $this->rename($sourceInternalPath, $targetInternalPath); } @@ -536,32 +291,29 @@ public function moveFromStorage(IStorage $sourceStorage, $sourceInternalPath, $t return $this->getWrapperStorage()->moveFromStorage($sourceStorage, $sourceInternalPath, $targetInternalPath); } - public function getMetaData($path) { + public function getMetaData($path): ?array { return $this->getWrapperStorage()->getMetaData($path); } - public function acquireLock($path, $type, ILockingProvider $provider) { + public function acquireLock($path, $type, ILockingProvider $provider): void { if ($this->getWrapperStorage()->instanceOfStorage('\OCP\Files\Storage\ILockingStorage')) { $this->getWrapperStorage()->acquireLock($path, $type, $provider); } } - public function releaseLock($path, $type, ILockingProvider $provider) { + public function releaseLock($path, $type, ILockingProvider $provider): void { if ($this->getWrapperStorage()->instanceOfStorage('\OCP\Files\Storage\ILockingStorage')) { $this->getWrapperStorage()->releaseLock($path, $type, $provider); } } - public function changeLock($path, $type, ILockingProvider $provider) { + public function changeLock($path, $type, ILockingProvider $provider): void { if ($this->getWrapperStorage()->instanceOfStorage('\OCP\Files\Storage\ILockingStorage')) { $this->getWrapperStorage()->changeLock($path, $type, $provider); } } - /** - * @return bool - */ - public function needsPartFile() { + public function needsPartFile(): bool { return $this->getWrapperStorage()->needsPartFile(); } @@ -579,11 +331,11 @@ public function writeStream(string $path, $stream, ?int $size = null): int { } } - public function getDirectoryContent($directory): \Traversable { + public function getDirectoryContent($directory): \Traversable|false { return $this->getWrapperStorage()->getDirectoryContent($directory); } - public function isWrapperOf(IStorage $storage) { + public function isWrapperOf(IStorage $storage): bool { $wrapped = $this->getWrapperStorage(); if ($wrapped === $storage) { return true; diff --git a/lib/private/Files/Stream/Quota.php b/lib/private/Files/Stream/Quota.php index d8e7ae6dff08f..cc737910fd8dc 100644 --- a/lib/private/Files/Stream/Quota.php +++ b/lib/private/Files/Stream/Quota.php @@ -23,7 +23,7 @@ class Quota extends Wrapper { /** * @param resource $stream * @param int $limit - * @return bool|resource + * @return resource|false */ public static function wrap($stream, $limit) { $context = stream_context_create([ diff --git a/lib/private/Files/Utils/Scanner.php b/lib/private/Files/Utils/Scanner.php index bcc54dea0dcb1..40201d10b9925 100644 --- a/lib/private/Files/Utils/Scanner.php +++ b/lib/private/Files/Utils/Scanner.php @@ -106,6 +106,7 @@ protected function getMounts($dir) { * @param \OC\Files\Mount\MountPoint $mount */ protected function attachListener($mount) { + /** @var \OC\Files\Cache\Scanner $scanner */ $scanner = $mount->getStorage()->getScanner(); $scanner->listen('\OC\Files\Cache\Scanner', 'scanFile', function ($path) use ($mount) { $this->emit('\OC\Files\Utils\Scanner', 'scanFile', [$mount->getMountPoint() . $path]); @@ -145,6 +146,7 @@ public function backgroundScan($dir) { continue; } + /** @var \OC\Files\Cache\Scanner $scanner */ $scanner = $storage->getScanner(); $this->attachListener($mount); @@ -221,6 +223,7 @@ public function scan($dir = '', $recursive = \OC\Files\Cache\Scanner::SCAN_RECUR continue; } $relativePath = $mount->getInternalPath($dir); + /** @var \OC\Files\Cache\Scanner $scanner */ $scanner = $storage->getScanner(); $scanner->setUseTransactions(false); $this->attachListener($mount); diff --git a/lib/private/Lockdown/Filesystem/NullStorage.php b/lib/private/Lockdown/Filesystem/NullStorage.php index 00124877e9d59..242ffe5bec87a 100644 --- a/lib/private/Lockdown/Filesystem/NullStorage.php +++ b/lib/private/Lockdown/Filesystem/NullStorage.php @@ -8,6 +8,7 @@ use Icewind\Streams\IteratorDirectory; use OC\Files\FileInfo; use OC\Files\Storage\Common; +use OCP\Files\Cache\ICache; use OCP\Files\Storage\IStorage; class NullStorage extends Common { @@ -31,15 +32,15 @@ public function opendir($path) { return new IteratorDirectory([]); } - public function is_dir($path) { + public function is_dir($path): bool { return $path === ''; } - public function is_file($path) { + public function is_file($path): bool { return false; } - public function stat($path) { + public function stat($path): never { throw new \OC\ForbiddenException('This request is not allowed to access the filesystem'); } @@ -51,43 +52,43 @@ public function filesize($path): false|int|float { throw new \OC\ForbiddenException('This request is not allowed to access the filesystem'); } - public function isCreatable($path) { + public function isCreatable($path): bool { return false; } - public function isReadable($path) { + public function isReadable($path): bool { return $path === ''; } - public function isUpdatable($path) { + public function isUpdatable($path): bool { return false; } - public function isDeletable($path) { + public function isDeletable($path): bool { return false; } - public function isSharable($path) { + public function isSharable($path): bool { return false; } - public function getPermissions($path) { - return null; + public function getPermissions($path): int { + return 0; } public function file_exists($path) { return $path === ''; } - public function filemtime($path) { + public function filemtime($path): false|int { return ($path === '') ? time() : false; } - public function file_get_contents($path) { + public function file_get_contents($path): bool|string { throw new \OC\ForbiddenException('This request is not allowed to access the filesystem'); } - public function file_put_contents($path, $data) { + public function file_put_contents($path, $data): float|bool|int { throw new \OC\ForbiddenException('This request is not allowed to access the filesystem'); } @@ -95,11 +96,11 @@ public function unlink($path) { throw new \OC\ForbiddenException('This request is not allowed to access the filesystem'); } - public function rename($source, $target) { + public function rename($source, $target): bool { throw new \OC\ForbiddenException('This request is not allowed to access the filesystem'); } - public function copy($source, $target) { + public function copy($source, $target): bool { throw new \OC\ForbiddenException('This request is not allowed to access the filesystem'); } @@ -107,15 +108,15 @@ public function fopen($path, $mode) { throw new \OC\ForbiddenException('This request is not allowed to access the filesystem'); } - public function getMimeType($path) { + public function getMimeType($path): bool|string { throw new \OC\ForbiddenException('This request is not allowed to access the filesystem'); } - public function hash($type, $path, $raw = false) { + public function hash($type, $path, $raw = false): bool|string { throw new \OC\ForbiddenException('This request is not allowed to access the filesystem'); } - public function free_space($path) { + public function free_space($path): float|bool|int { return FileInfo::SPACE_UNKNOWN; } @@ -123,35 +124,35 @@ public function touch($path, $mtime = null) { throw new \OC\ForbiddenException('This request is not allowed to access the filesystem'); } - public function getLocalFile($path) { + public function getLocalFile($path): bool|string { return false; } - public function hasUpdated($path, $time) { + public function hasUpdated($path, $time): bool { return false; } - public function getETag($path) { + public function getETag($path): bool|string { return ''; } - public function isLocal() { + public function isLocal(): bool { return false; } - public function getDirectDownload($path) { + public function getDirectDownload($path): bool|array { return false; } - public function copyFromStorage(IStorage $sourceStorage, $sourceInternalPath, $targetInternalPath, $preserveMtime = false) { + public function copyFromStorage(IStorage $sourceStorage, $sourceInternalPath, $targetInternalPath, $preserveMtime = false): bool { throw new \OC\ForbiddenException('This request is not allowed to access the filesystem'); } - public function moveFromStorage(IStorage $sourceStorage, $sourceInternalPath, $targetInternalPath) { + public function moveFromStorage(IStorage $sourceStorage, $sourceInternalPath, $targetInternalPath): bool { throw new \OC\ForbiddenException('This request is not allowed to access the filesystem'); } - public function test() { + public function test(): bool { return true; } @@ -159,7 +160,7 @@ public function getOwner($path): string|false { return false; } - public function getCache($path = '', $storage = null) { + public function getCache($path = '', $storage = null): ICache { return new NullCache(); } }