From e0f6f7e6ac9fbb956318c47e2b173fbafa7347c0 Mon Sep 17 00:00:00 2001 From: Vincent Petry Date: Mon, 12 Dec 2022 10:25:53 +0100 Subject: Remove quota value type for 32-bit systems Signed-off-by: Vincent Petry --- lib/private/Files/Storage/Wrapper/Quota.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'lib') diff --git a/lib/private/Files/Storage/Wrapper/Quota.php b/lib/private/Files/Storage/Wrapper/Quota.php index 5c542361c36..e28df24111e 100644 --- a/lib/private/Files/Storage/Wrapper/Quota.php +++ b/lib/private/Files/Storage/Wrapper/Quota.php @@ -57,9 +57,9 @@ class Quota extends Wrapper { } /** - * @return int quota value + * @return quota value */ - public function getQuota(): int { + public function getQuota() { if ($this->quota === null) { $quotaCallback = $this->quotaCallback; if ($quotaCallback === null) { -- cgit v1.2.3 From 79922e2f86097385fbac11c43cae04ebcf414eda Mon Sep 17 00:00:00 2001 From: Côme Chilliet Date: Mon, 19 Dec 2022 13:54:23 +0100 Subject: Make it clear that file sizes may be float on 32bits MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Côme Chilliet --- lib/private/Files/Storage/Wrapper/Quota.php | 16 +++++++++------- lib/private/Files/Storage/Wrapper/Wrapper.php | 6 +++--- lib/public/Files/Storage.php | 6 +++--- lib/public/Files/Storage/IStorage.php | 6 +++--- 4 files changed, 18 insertions(+), 16 deletions(-) (limited to 'lib') diff --git a/lib/private/Files/Storage/Wrapper/Quota.php b/lib/private/Files/Storage/Wrapper/Quota.php index e28df24111e..5b702890675 100644 --- a/lib/private/Files/Storage/Wrapper/Quota.php +++ b/lib/private/Files/Storage/Wrapper/Quota.php @@ -41,7 +41,8 @@ use OCP\Files\Storage\IStorage; class Quota extends Wrapper { /** @var callable|null */ protected $quotaCallback; - protected ?int $quota; + /** @var int|float|null int on 64bits, float on 32bits for bigint */ + protected $quota; protected string $sizeRoot; private SystemConfig $config; @@ -57,7 +58,7 @@ class Quota extends Wrapper { } /** - * @return quota value + * @return int|float quota value */ public function getQuota() { if ($this->quota === null) { @@ -77,7 +78,8 @@ class Quota extends Wrapper { /** * @param string $path - * @param \OC\Files\Storage\Storage $storage + * @param IStorage $storage + * @return int|float */ protected function getSize($path, $storage = null) { if ($this->config->getValue('quota_include_external_storage', false)) { @@ -101,7 +103,7 @@ class Quota extends Wrapper { * Get free space as limited by the quota * * @param string $path - * @return int|bool + * @return int|float|bool */ public function free_space($path) { if (!$this->hasQuota()) { @@ -128,7 +130,7 @@ class Quota extends Wrapper { * * @param string $path * @param mixed $data - * @return int|false + * @return int|float|false */ public function file_put_contents($path, $data) { if (!$this->hasQuota()) { @@ -177,7 +179,7 @@ class Quota extends Wrapper { // don't apply quota for part files if (!$this->isPartFile($path)) { $free = $this->free_space($path); - if ($source && is_int($free) && $free >= 0 && $mode !== 'r' && $mode !== 'rb') { + if ($source && (is_int($free) || is_float($free)) && $free >= 0 && $mode !== 'r' && $mode !== 'rb') { // only apply quota for files, not metadata, trash or others if ($this->shouldApplyQuota($path)) { return \OC\Files\Stream\Quota::wrap($source, $free); @@ -192,7 +194,7 @@ class Quota extends Wrapper { * Checks whether the given path is a part file * * @param string $path Path that may identify a .part file - * @return string File path without .part extension + * @return bool * @note this is needed for reusing keys */ private function isPartFile($path) { diff --git a/lib/private/Files/Storage/Wrapper/Wrapper.php b/lib/private/Files/Storage/Wrapper/Wrapper.php index 6bc66bf9c89..5a3fc7567c2 100644 --- a/lib/private/Files/Storage/Wrapper/Wrapper.php +++ b/lib/private/Files/Storage/Wrapper/Wrapper.php @@ -150,7 +150,7 @@ class Wrapper implements \OC\Files\Storage\Storage, ILockingStorage, IWriteStrea * The result for filesize when called on a folder is required to be 0 * * @param string $path - * @return int|bool + * @return int|float|bool */ public function filesize($path) { return $this->getWrapperStorage()->filesize($path); @@ -252,7 +252,7 @@ class Wrapper implements \OC\Files\Storage\Storage, ILockingStorage, IWriteStrea * * @param string $path * @param mixed $data - * @return int|false + * @return int|float|false */ public function file_put_contents($path, $data) { return $this->getWrapperStorage()->file_put_contents($path, $data); @@ -328,7 +328,7 @@ class Wrapper implements \OC\Files\Storage\Storage, ILockingStorage, IWriteStrea * see https://www.php.net/manual/en/function.free_space.php * * @param string $path - * @return int|bool + * @return int|float|bool */ public function free_space($path) { return $this->getWrapperStorage()->free_space($path); diff --git a/lib/public/Files/Storage.php b/lib/public/Files/Storage.php index 0a1a504b137..827ff962da8 100644 --- a/lib/public/Files/Storage.php +++ b/lib/public/Files/Storage.php @@ -135,7 +135,7 @@ interface Storage extends IStorage { * The result for filesize when called on a folder is required to be 0 * * @param string $path - * @return int|bool + * @return int|float|bool * @since 6.0.0 */ public function filesize($path); @@ -227,7 +227,7 @@ interface Storage extends IStorage { * * @param string $path * @param mixed $data - * @return int|false + * @return int|float|false * @since 6.0.0 */ public function file_put_contents($path, $data); @@ -296,7 +296,7 @@ interface Storage extends IStorage { * see https://www.php.net/manual/en/function.free_space.php * * @param string $path - * @return int|bool + * @return int|float|bool * @since 6.0.0 */ public function free_space($path); diff --git a/lib/public/Files/Storage/IStorage.php b/lib/public/Files/Storage/IStorage.php index f42eb81bfec..8dacd4358ee 100644 --- a/lib/public/Files/Storage/IStorage.php +++ b/lib/public/Files/Storage/IStorage.php @@ -132,7 +132,7 @@ interface IStorage { * The result for filesize when called on a folder is required to be 0 * * @param string $path - * @return int|bool + * @return int|float|bool * @since 9.0.0 */ public function filesize($path); @@ -224,7 +224,7 @@ interface IStorage { * * @param string $path * @param mixed $data - * @return int|false + * @return int|float|false * @since 9.0.0 */ public function file_put_contents($path, $data); @@ -293,7 +293,7 @@ interface IStorage { * see https://www.php.net/manual/en/function.free_space.php * * @param string $path - * @return int|bool + * @return int|float|bool * @since 9.0.0 */ public function free_space($path); -- cgit v1.2.3 From ad999e552108f18cef72ac663faeb0b80ecdc987 Mon Sep 17 00:00:00 2001 From: Côme Chilliet Date: Mon, 19 Dec 2022 14:03:09 +0100 Subject: Adapt types of subclasses MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Côme Chilliet --- lib/private/Files/Storage/Common.php | 3 +-- lib/private/Files/Storage/DAV.php | 2 +- lib/private/Files/Storage/Wrapper/Encoding.php | 7 +++---- lib/private/Files/Storage/Wrapper/Jail.php | 6 +++--- lib/private/LargeFileHelper.php | 2 +- 5 files changed, 9 insertions(+), 11 deletions(-) (limited to 'lib') diff --git a/lib/private/Files/Storage/Common.php b/lib/private/Files/Storage/Common.php index a7bc44e10e2..36281d74cf5 100644 --- a/lib/private/Files/Storage/Common.php +++ b/lib/private/Files/Storage/Common.php @@ -477,7 +477,7 @@ abstract class Common implements Storage, ILockingStorage, IWriteStreamStorage { * get the free space in the storage * * @param string $path - * @return int|false + * @return int|float|false */ public function free_space($path) { return \OCP\Files\FileInfo::SPACE_UNKNOWN; @@ -523,7 +523,6 @@ abstract class Common implements Storage, ILockingStorage, IWriteStreamStorage { * @throws InvalidPathException */ public function verifyPath($path, $fileName) { - // verify empty and dot files $trimmed = trim($fileName); if ($trimmed === '') { diff --git a/lib/private/Files/Storage/DAV.php b/lib/private/Files/Storage/DAV.php index 132e3d257aa..a3cd187e7b2 100644 --- a/lib/private/Files/Storage/DAV.php +++ b/lib/private/Files/Storage/DAV.php @@ -486,7 +486,7 @@ class DAV extends Common { /** * @param string $path * @param mixed $data - * @return int|false + * @return int|float|false */ public function file_put_contents($path, $data) { $path = $this->cleanPath($path); diff --git a/lib/private/Files/Storage/Wrapper/Encoding.php b/lib/private/Files/Storage/Wrapper/Encoding.php index ac9cc248ce6..65c52d3b793 100644 --- a/lib/private/Files/Storage/Wrapper/Encoding.php +++ b/lib/private/Files/Storage/Wrapper/Encoding.php @@ -40,7 +40,6 @@ use OCP\ICache; * the actual given name and then try its NFD form. */ class Encoding extends Wrapper { - /** * @var ICache */ @@ -213,7 +212,7 @@ class Encoding extends Wrapper { * The result for filesize when called on a folder is required to be 0 * * @param string $path - * @return int|bool + * @return int|float|bool */ public function filesize($path) { return $this->storage->filesize($this->findPathToUse($path)); @@ -315,7 +314,7 @@ class Encoding extends Wrapper { * * @param string $path * @param mixed $data - * @return int|false + * @return int|float|false */ public function file_put_contents($path, $data) { return $this->storage->file_put_contents($this->findPathToUse($path), $data); @@ -400,7 +399,7 @@ class Encoding extends Wrapper { * see https://www.php.net/manual/en/function.free_space.php * * @param string $path - * @return int|bool + * @return int|float|bool */ public function free_space($path) { return $this->storage->free_space($this->findPathToUse($path)); diff --git a/lib/private/Files/Storage/Wrapper/Jail.php b/lib/private/Files/Storage/Wrapper/Jail.php index 65ee6f1181a..b817073d2e0 100644 --- a/lib/private/Files/Storage/Wrapper/Jail.php +++ b/lib/private/Files/Storage/Wrapper/Jail.php @@ -160,7 +160,7 @@ class Jail extends Wrapper { * The result for filesize when called on a folder is required to be 0 * * @param string $path - * @return int|bool + * @return int|float|bool */ public function filesize($path) { return $this->getWrapperStorage()->filesize($this->getUnjailedPath($path)); @@ -262,7 +262,7 @@ class Jail extends Wrapper { * * @param string $path * @param mixed $data - * @return int|false + * @return int|float|false */ public function file_put_contents($path, $data) { return $this->getWrapperStorage()->file_put_contents($this->getUnjailedPath($path), $data); @@ -338,7 +338,7 @@ class Jail extends Wrapper { * see https://www.php.net/manual/en/function.free_space.php * * @param string $path - * @return int|bool + * @return int|float|bool */ public function free_space($path) { return $this->getWrapperStorage()->free_space($this->getUnjailedPath($path)); diff --git a/lib/private/LargeFileHelper.php b/lib/private/LargeFileHelper.php index 82b3c5ae760..6db79a795fe 100755 --- a/lib/private/LargeFileHelper.php +++ b/lib/private/LargeFileHelper.php @@ -95,7 +95,7 @@ class LargeFileHelper { * * @param string $filename Path to the file. * - * @return null|int|float Number of bytes as number (float or int) or + * @return int|float Number of bytes as number (float or int) or * null on failure. */ public function getFileSize($filename) { -- cgit v1.2.3 From 77f2f9776f7862b0e48835d3e38b9aa895119ecb Mon Sep 17 00:00:00 2001 From: Côme Chilliet Date: Mon, 19 Dec 2022 14:13:11 +0100 Subject: Silence a warning from psalm with explanation MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Côme Chilliet --- lib/private/Files/Storage/Local.php | 1 + 1 file changed, 1 insertion(+) (limited to 'lib') diff --git a/lib/private/Files/Storage/Local.php b/lib/private/Files/Storage/Local.php index 62a04292e23..0e118e76c5f 100644 --- a/lib/private/Files/Storage/Local.php +++ b/lib/private/Files/Storage/Local.php @@ -609,6 +609,7 @@ class Local extends \OC\Files\Storage\Common { } public function writeStream(string $path, $stream, int $size = null): int { + /** @var int|false $result We consider here that returned size will never be a float because we write less than 4GB */ $result = $this->file_put_contents($path, $stream); if (is_resource($stream)) { fclose($stream); -- cgit v1.2.3