Skip to content

Commit 5cc4d14

Browse files
committed
Fix 32bits bigint support in Util/OC_Helper
Signed-off-by: Côme Chilliet <[email protected]>
1 parent 2e8e20a commit 5cc4d14

3 files changed

Lines changed: 19 additions & 20 deletions

File tree

lib/private/legacy/OC_Helper.php

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
use OCP\ICacheFactory;
5050
use OCP\IBinaryFinder;
5151
use OCP\IUser;
52+
use OCP\Util;
5253
use Psr\Log\LoggerInterface;
5354

5455
/**
@@ -59,12 +60,12 @@ class OC_Helper {
5960

6061
/**
6162
* Make a human file size
62-
* @param int $bytes file size in bytes
63+
* @param int|float $bytes file size in bytes
6364
* @return string a human readable file size
6465
*
6566
* Makes 2048 to 2 kB.
6667
*/
67-
public static function humanFileSize($bytes) {
68+
public static function humanFileSize(int|float $bytes): string {
6869
if ($bytes < 0) {
6970
return "?";
7071
}
@@ -126,9 +127,7 @@ public static function computerFileSize(string $str): false|int|float {
126127
return false;
127128
}
128129

129-
$bytes = round($bytes);
130-
131-
return $bytes;
130+
return Util::numericToNumber(round($bytes));
132131
}
133132

134133
/**
@@ -384,8 +383,8 @@ public static function recursiveArraySearch($haystack, $needle, $index = null) {
384383
* calculates the maximum upload size respecting system settings, free space and user quota
385384
*
386385
* @param string $dir the current folder where the user currently operates
387-
* @param int $freeSpace the number of bytes free on the storage holding $dir, if not set this will be received from the storage directly
388-
* @return int number of bytes representing
386+
* @param int|float $freeSpace the number of bytes free on the storage holding $dir, if not set this will be received from the storage directly
387+
* @return int|float number of bytes representing
389388
*/
390389
public static function maxUploadFilesize($dir, $freeSpace = null) {
391390
if (is_null($freeSpace) || $freeSpace < 0) {
@@ -398,7 +397,7 @@ public static function maxUploadFilesize($dir, $freeSpace = null) {
398397
* Calculate free space left within user quota
399398
*
400399
* @param string $dir the current folder where the user currently operates
401-
* @return int number of bytes representing
400+
* @return int|float number of bytes representing
402401
*/
403402
public static function freeSpace($dir) {
404403
$freeSpace = \OC\Files\Filesystem::free_space($dir);
@@ -413,12 +412,12 @@ public static function freeSpace($dir) {
413412
/**
414413
* Calculate PHP upload limit
415414
*
416-
* @return int PHP upload file size limit
415+
* @return int|float PHP upload file size limit
417416
*/
418417
public static function uploadLimit() {
419418
$ini = \OC::$server->get(IniGetWrapper::class);
420-
$upload_max_filesize = (int)OCP\Util::computerFileSize($ini->get('upload_max_filesize'));
421-
$post_max_size = (int)OCP\Util::computerFileSize($ini->get('post_max_size'));
419+
$upload_max_filesize = Util::computerFileSize($ini->get('upload_max_filesize'));
420+
$post_max_size = Util::computerFileSize($ini->get('post_max_size'));
422421
if ($upload_max_filesize === 0 && $post_max_size === 0) {
423422
return INF;
424423
} elseif ($upload_max_filesize === 0 || $post_max_size === 0) {
@@ -579,8 +578,8 @@ public static function getStorageInfo($path, $rootInfo = null, $includeMountPoin
579578
/**
580579
* Get storage info including all mount points and quota
581580
*/
582-
private static function getGlobalStorageInfo(int $quota, IUser $user, IMountPoint $mount): array {
583-
$rootInfo = \OC\Files\Filesystem::getFileInfo('', 'ext');
581+
private static function getGlobalStorageInfo(int|float $quota, IUser $user, IMountPoint $mount): array {
582+
$rootInfo = \OC\Files\Filesystem::getFileInfo('', true);
584583
$used = $rootInfo['size'];
585584
if ($used < 0) {
586585
$used = 0;

lib/private/legacy/OC_Util.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ public static function isSharingDisabledForUser(IConfig $config, IGroupManager $
146146
/**
147147
* check if share API enforces a default expire date
148148
*
149-
* @return boolean
149+
* @return bool
150150
* @suppress PhanDeprecatedFunction
151151
*/
152152
public static function isDefaultExpireDateEnforced() {
@@ -159,7 +159,7 @@ public static function isDefaultExpireDateEnforced() {
159159
* Get the quota of a user
160160
*
161161
* @param IUser|null $user
162-
* @return int|\OCP\Files\FileInfo::SPACE_UNLIMITED|false Quota bytes
162+
* @return int|\OCP\Files\FileInfo::SPACE_UNLIMITED|false|float Quota bytes
163163
*/
164164
public static function getUserQuota(?IUser $user) {
165165
if (is_null($user)) {

lib/public/Util.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -341,22 +341,22 @@ public static function getDefaultEmailAddress(string $user_part): string {
341341

342342
/**
343343
* Converts string to int of float depending if it fits an int
344-
* @param numeric-string $number numeric string
344+
* @param numeric-string|float|int $number numeric string
345345
* @return int|float int if it fits, float if it is too big
346346
* @since 26.0.0
347347
*/
348-
public static function numericToNumber(string $number): int|float {
348+
public static function numericToNumber(string|float|int $number): int|float {
349349
/* This is a hack to cast to (int|float) */
350350
return 0 + $number;
351351
}
352352

353353
/**
354354
* Make a human file size (2048 to 2 kB)
355-
* @param int $bytes file size in bytes
355+
* @param int|float $bytes file size in bytes
356356
* @return string a human readable file size
357357
* @since 4.0.0
358358
*/
359-
public static function humanFileSize($bytes) {
359+
public static function humanFileSize(int|float $bytes): string {
360360
return \OC_Helper::humanFileSize($bytes);
361361
}
362362

@@ -368,7 +368,7 @@ public static function humanFileSize($bytes) {
368368
* Inspired by: https://www.php.net/manual/en/function.filesize.php#92418
369369
* @since 4.0.0
370370
*/
371-
public static function computerFileSize($str) {
371+
public static function computerFileSize(string $str): false|int|float {
372372
return \OC_Helper::computerFileSize($str);
373373
}
374374

0 commit comments

Comments
 (0)