4949use OCP \ICacheFactory ;
5050use OCP \IBinaryFinder ;
5151use OCP \IUser ;
52+ use OCP \Util ;
5253use 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 ;
0 commit comments