From cac24635a94e7762380bd4e2165717eea7d14089 Mon Sep 17 00:00:00 2001 From: plegall Date: Wed, 27 Jan 2021 19:46:53 +0100 Subject: [PATCH] fixes #1300 fall back on exec(du) instead of pure PHP to calculate cache size This algorithm does not work for Windows and when "exec" is disabled. But not having this cache size is not a major issue. What is a problem is when calculating the cache size breaks the execution, which must be avoided. --- admin/include/functions.php | 14 +++++++++----- admin/intro.php | 4 ++-- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/admin/include/functions.php b/admin/include/functions.php index f587c3028..fac387eed 100644 --- a/admin/include/functions.php +++ b/admin/include/functions.php @@ -637,13 +637,17 @@ function get_fs_directory_size($path) $bytestotal = 0; $path = realpath($path); - if ($path !== false && $path != '' && file_exists($path)) + if (!function_exists('exec')) { - foreach (new RecursiveIteratorIterator(new RecursiveDirectoryIterator($path, FilesystemIterator::SKIP_DOTS)) as $object) - { - $bytestotal += $object->getSize(); - } + return false; } + + @exec('du -sk '.$path, $returnarray); + if (is_array($returnarray) and !empty($returnarray[0]) and preg_match('/^(\d+)\s/', $returnarray[0], $matches)) + { + $bytestotal = $matches[1] * 1024; + } + return $bytestotal; } diff --git a/admin/intro.php b/admin/intro.php index 1e587d651..904e72626 100644 --- a/admin/intro.php +++ b/admin/intro.php @@ -404,8 +404,8 @@ if (isset($result[0]['SUM(filesize)'])) $data_storage['Formats'] = $result[0]['SUM(filesize)']; } -// PHP 5.5.19 is the oldest version get_fs_directory_size was tested on -if (version_compare(PHP_VERSION, '5.5.19') >= 0) +// Windows can't execute get_fs_directory_size correctly +if (strtoupper(substr(PHP_OS, 0, 3)) !== 'WIN') { if (!isset($_SESSION['cachedir_info']) or $_SESSION['cachedir_info']['calculated_on'] < strtotime('5 minutes ago')) {