(cp ab81e77) fixes #1290 avoid calling external command to calculate directory size

+ add a 5 minutes cache to avoid calculating cache size too often
* tested with anold PHP 5.5 (could work with earlier versions, but I prefer to not take the risk)
This commit is contained in:
plegall
2021-01-21 10:43:47 +01:00
parent 0e7531515c
commit d7cb303258
2 changed files with 37 additions and 8 deletions

View File

@@ -625,6 +625,28 @@ function get_fs_directories($path, $recursive = true)
return $dirs;
}
/**
* returns the size (in bytes) of a filesystem directory
*
* @since 11
* @param string path
* @return int
*/
function get_fs_directory_size($path)
{
$bytestotal = 0;
$path = realpath($path);
if ($path !== false && $path != '' && file_exists($path))
{
foreach (new RecursiveIteratorIterator(new RecursiveDirectoryIterator($path, FilesystemIterator::SKIP_DOTS)) as $object)
{
$bytestotal += $object->getSize();
}
}
return $bytestotal;
}
/**
* save the rank depending on given categories order
*