Commit 653b0d67 authored by Rolf Forst's avatar Rolf Forst
Browse files

Add getCacheOldDir(); update removeDir();

parent b824f1cf
......@@ -314,9 +314,10 @@ final class File
* Recursively deletes a directory tree.
* @param string $folder The directory path.
* @param bool $keepRootFolder Whether to keep the top-level folder.
* @param int $maxFiles The max. number of files to delete
* @return bool TRUE on success, otherwise FALSE.
*/
protected static function removeDir(string $folder, bool $keepRootFolder = false): bool
public static function removeDir(string $folder, bool $keepRootFolder = false, int $maxFiles = 0): bool
{
// Handle arguments.
if (empty($folder) || !file_exists($folder)) {
......@@ -332,16 +333,20 @@ final class File
);
// Delete all children.
$i = 1;
$maxFiles = absint($maxFiles);
foreach ($files as $fileinfo) {
$action = ($fileinfo->isDir() ? 'rmdir' : 'unlink');
if (!@$action($fileinfo->getRealPath())) {
return false; // Abort due to the failure.
}
$i++;
if($maxFiles && $i > $maxFiles) {
return false;
}
}
clearstatcache();
return (!$keepRootFolder ? @rmdir($folder) : true);
return ((!$keepRootFolder && !$maxFiles) ? @rmdir($folder) : true);
}
/**
......@@ -362,6 +367,15 @@ final class File
return self::$cacheDir;
}
/**
* [getCacheOldDir description]
* @return string [description]
*/
public static function getCacheOldDir(): string
{
return self::$cacheOldDir;
}
/**
* [getTimeoutFile description]
* @return string [description]
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment