diff options
Diffstat (limited to 'lib/public')
-rw-r--r-- | lib/public/Color.php | 2 | ||||
-rw-r--r-- | lib/public/Files.php | 38 | ||||
-rw-r--r-- | lib/public/Template.php | 4 | ||||
-rw-r--r-- | lib/public/Util.php | 44 |
4 files changed, 76 insertions, 12 deletions
diff --git a/lib/public/Color.php b/lib/public/Color.php index c8ba3a1ff15..5523dbd94cb 100644 --- a/lib/public/Color.php +++ b/lib/public/Color.php @@ -125,7 +125,7 @@ class Color { * Calculate steps between two Colors * @param int $steps start color * @param Color[] $ends end color - * @return array{0: int, 1: int, 2: int} [r,g,b] steps for each color to go from $steps to $ends + * @return array{0: float, 1: float, 2: float} [r,g,b] steps for each color to go from $steps to $ends * @since 25.0.0 */ private static function stepCalc(int $steps, array $ends): array { diff --git a/lib/public/Files.php b/lib/public/Files.php index b12aa463f1a..3df3152b0ef 100644 --- a/lib/public/Files.php +++ b/lib/public/Files.php @@ -85,15 +85,45 @@ class Files { /** * Copy the contents of one stream to another + * + * @template T of null|true * @param resource $source * @param resource $target - * @return int the number of bytes copied + * @param T $includeResult + * @return int|array + * @psalm-return (T is true ? array{0: int, 1: bool} : int) * @since 5.0.0 + * @since 32.0.0 added $includeResult parameter * @deprecated 14.0.0 */ - public static function streamCopy($source, $target) { - [$count, ] = \OC_Helper::streamCopy($source, $target); - return $count; + public static function streamCopy($source, $target, ?bool $includeResult = null) { + if (!$source or !$target) { + return $includeResult ? [0, false] : 0; + } + + $bufSize = 8192; + $count = 0; + $result = true; + while (!feof($source)) { + $buf = fread($source, $bufSize); + if ($buf === false) { + $result = false; + break; + } + + $bytesWritten = fwrite($target, $buf); + if ($bytesWritten !== false) { + $count += $bytesWritten; + } + + if ($bytesWritten === false + || ($bytesWritten < $bufSize && $bytesWritten < strlen($buf)) + ) { + $result = false; + break; + } + } + return $includeResult ? [$count, $result] : $count; } /** diff --git a/lib/public/Template.php b/lib/public/Template.php index 715115bc635..c29de52db4f 100644 --- a/lib/public/Template.php +++ b/lib/public/Template.php @@ -23,7 +23,7 @@ require_once __DIR__ . '/../private/Template/functions.php'; */ class Template extends \OC_Template implements ITemplate { /** - * Make OC_Helper::imagePath available as a simple function + * Make \OCP\IURLGenerator::imagePath available as a simple function * * @see \OCP\IURLGenerator::imagePath * @@ -39,7 +39,7 @@ class Template extends \OC_Template implements ITemplate { /** - * Make OC_Helper::mimetypeIcon available as a simple function + * Make IMimeTypeDetector->mimeTypeIcon available as a simple function * * @param string $mimetype * @return string to the image of this file type. diff --git a/lib/public/Util.php b/lib/public/Util.php index 979e7abe609..b3111c54fc7 100644 --- a/lib/public/Util.php +++ b/lib/public/Util.php @@ -491,7 +491,12 @@ class Util { * @since 4.5.0 */ public static function mb_array_change_key_case($input, $case = MB_CASE_LOWER, $encoding = 'UTF-8') { - return \OC_Helper::mb_array_change_key_case($input, $case, $encoding); + $case = ($case != MB_CASE_UPPER) ? MB_CASE_LOWER : MB_CASE_UPPER; + $ret = []; + foreach ($input as $k => $v) { + $ret[mb_convert_case($k, $case, $encoding)] = $v; + } + return $ret; } /** @@ -505,7 +510,18 @@ class Util { * @deprecated 15.0.0 */ public static function recursiveArraySearch($haystack, $needle, $index = null) { - return \OC_Helper::recursiveArraySearch($haystack, $needle, $index); + $aIt = new \RecursiveArrayIterator($haystack); + $it = new \RecursiveIteratorIterator($aIt); + + while ($it->valid()) { + if (((isset($index) and ($it->key() == $index)) or !isset($index)) and ($it->current() == $needle)) { + return $aIt->key(); + } + + $it->next(); + } + + return false; } /** @@ -517,7 +533,10 @@ class Util { * @since 5.0.0 */ public static function maxUploadFilesize(string $dir, int|float|null $free = null): int|float { - return \OC_Helper::maxUploadFilesize($dir, $free); + if (is_null($free) || $free < 0) { + $free = self::freeSpace($dir); + } + return min($free, self::uploadLimit()); } /** @@ -527,7 +546,13 @@ class Util { * @since 7.0.0 */ public static function freeSpace(string $dir): int|float { - return \OC_Helper::freeSpace($dir); + $freeSpace = \OC\Files\Filesystem::free_space($dir); + if ($freeSpace < \OCP\Files\FileInfo::SPACE_UNLIMITED) { + $freeSpace = max($freeSpace, 0); + return $freeSpace; + } else { + return (INF > 0)? INF: PHP_INT_MAX; // work around https://bugs.php.net/bug.php?id=69188 + } } /** @@ -537,7 +562,16 @@ class Util { * @since 7.0.0 */ public static function uploadLimit(): int|float { - return \OC_Helper::uploadLimit(); + $ini = Server::get(IniGetWrapper::class); + $upload_max_filesize = self::computerFileSize($ini->get('upload_max_filesize')) ?: 0; + $post_max_size = self::computerFileSize($ini->get('post_max_size')) ?: 0; + if ($upload_max_filesize === 0 && $post_max_size === 0) { + return INF; + } elseif ($upload_max_filesize === 0 || $post_max_size === 0) { + return max($upload_max_filesize, $post_max_size); //only the non 0 value counts + } else { + return min($upload_max_filesize, $post_max_size); + } } /** |