diff --git a/src/includes/closures/Plugin/CacheDirStatUtils.php b/src/includes/closures/Plugin/CacheDirStatUtils.php index e679216b..6840b632 100644 --- a/src/includes/closures/Plugin/CacheDirStatUtils.php +++ b/src/includes/closures/Plugin/CacheDirStatUtils.php @@ -7,10 +7,12 @@ * * @since 15xxxx Adding cache directory statistics. * + * @param boolean $include_paths Include array of all scanned file paths? + * * @return array Cache directory stats. */ -$self->statsForCacheDir = function () use ($self) { - return $self->getDirRegexStats($self->cacheDir()); +$self->statsForCacheDir = function ($include_paths = false) use ($self) { + return $self->getDirRegexStats($self->cacheDir(), '', $include_paths); }; /* @@ -18,9 +20,11 @@ * * @since 15xxxx Adding cache directory statistics. * + * @param boolean $include_paths Include array of all scanned file paths? + * * @return array HTML compressor cache directory stats. */ -$self->statsForHtmlCCacheDirs = function () use ($self) { +$self->statsForHtmlCCacheDirs = function ($include_paths = false) use ($self) { $stats = array(); // Initialize the stats array. $htmlc_cache_dirs = array(); // Initialize array directories. @@ -30,7 +34,7 @@ foreach (array_unique($htmlc_cache_dirs) as $_htmlc_cache_dir) { $_check_disk_stats = $stats ? false : true; - foreach ($self->getDirRegexStats($_htmlc_cache_dir, '', $_check_disk_stats) as $_key => $_value) { + foreach ($self->getDirRegexStats($_htmlc_cache_dir, '', $include_paths, $_check_disk_stats) as $_key => $_value) { $stats[$_key] = isset($stats[$_key]) ? $stats[$_key] + $_value : $_value; } unset($_key, $_value); // Housekeeping. @@ -75,7 +79,7 @@ $_host_cache_dir = $self->nDirSeps($cache_dir.'/'.$_host_cache_path); // Normalize. $_check_disk_stats = $stats || $___considering_domain_mapping ? false : true; - foreach ($self->getDirRegexStats($_host_cache_dir, '', $_check_disk_stats) as $_key => $_value) { + foreach ($self->getDirRegexStats($_host_cache_dir, '', false, $_check_disk_stats) as $_key => $_value) { $stats[$_key] = isset($stats[$_key]) ? $stats[$_key] + $_value : $_value; } unset($_key, $_value); // Housekeeping. @@ -150,7 +154,7 @@ foreach (array_unique($htmlc_cache_dirs) as $_htmlc_cache_dir) { $_check_disk_stats = $stats ? false : true; - foreach ($self->getDirRegexStats($_htmlc_cache_dir, '', $_check_disk_stats) as $_key => $_value) { + foreach ($self->getDirRegexStats($_htmlc_cache_dir, '', false, $_check_disk_stats) as $_key => $_value) { $stats[$_key] = isset($stats[$_key]) ? $stats[$_key] + $_value : $_value; } unset($_key, $_value); // Housekeeping. diff --git a/src/includes/closures/Shared/FsUtils.php b/src/includes/closures/Shared/FsUtils.php index f6db1c34..a0508311 100644 --- a/src/includes/closures/Shared/FsUtils.php +++ b/src/includes/closures/Shared/FsUtils.php @@ -172,40 +172,59 @@ * * @param string $dir An absolute server directory path. * @param string $regex A regex pattern; compares to each full file path. + * @param boolean $include_paths Include array of all scanned file paths? * @param boolean $check_disk Also check disk statistics? - * @param boolean $reconsider Bypass cached statistics? * - * @return array `total_size`, `total_links`, `total_files`, `total_dirs`, `disk_free_space`, `disk_total_space`. + * @return array Directory stats. */ -$self->getDirRegexStats = function ($dir, $regex = '', $check_disk = true, $reconsider = false) use ($self) { - if (!is_null($stats = &$self->staticKey('getDirStats', array($dir, $regex, $check_disk))) && !$reconsider) { - return $stats; // Already cached this. - } +$self->getDirRegexStats = function ($dir, $regex = '', $include_paths = false, $check_disk = true) use ($self) { + $dir = (string) $dir; // Force string. + $stats = array( - 'total_size' => 0, - 'total_links' => 0, - 'total_files' => 0, - 'total_dirs' => 0, + 'dir' => $dir, + 'total_size' => 0, + + 'total_links' => 0, + 'link_subpaths' => array(), + + 'total_files' => 0, + 'file_subpaths' => array(), + + 'total_dirs' => 0, + 'dir_subpaths' => array(), + 'disk_free_space' => 0, 'disk_total_space' => 0, ); - if (!is_dir($dir = (string) $dir)) { + if (!$dir || !is_dir($dir)) { return $stats; // Not possible. } foreach ($self->dirRegexIteration($dir, $regex) as $_resource) { switch ($_resource->getType()) { // `link`, `file`, `dir`. case 'link': // Symbolic links. + if ($include_paths) { + $stats['link_subpaths'][] = $_resource->getSubpathname(); + } ++$stats['total_links']; // Counter. + break; // Break switch handler. case 'file': // Regular files; i.e., not symlinks. + if ($include_paths) { + $stats['file_subpaths'][] = $_resource->getSubpathname(); + } $stats['total_size'] += $_resource->getSize(); ++$stats['total_files']; // Counter. + break; // Break switch. case 'dir': // Regular dirs; i.e., not symlinks. + if ($include_paths) { + $stats['dir_subpaths'][] = $_resource->getSubpathname(); + } ++$stats['total_dirs']; // Counter. + break; // Break switch. } }