49 lines
1.1 KiB
PHP
49 lines
1.1 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Tests\Support;
|
|
|
|
final class TestFilesystem
|
|
{
|
|
public static function resetUploads(): void
|
|
{
|
|
if (!defined('QDB_TEST_UPLOADS')) {
|
|
return;
|
|
}
|
|
if (defined('QDB_PATH')) {
|
|
if (is_file(QDB_PATH)) {
|
|
@unlink(QDB_PATH);
|
|
}
|
|
if (defined('QDB_LOCK') && is_file(QDB_LOCK)) {
|
|
@unlink(QDB_LOCK);
|
|
}
|
|
}
|
|
self::rmTree(QDB_TEST_UPLOADS);
|
|
mkdir(QDB_TEST_UPLOADS, 0755, true);
|
|
}
|
|
|
|
private static function rmTree(string $dir): void
|
|
{
|
|
if (!is_dir($dir)) {
|
|
return;
|
|
}
|
|
$items = scandir($dir);
|
|
if ($items === false) {
|
|
return;
|
|
}
|
|
foreach ($items as $item) {
|
|
if ($item === '.' || $item === '..') {
|
|
continue;
|
|
}
|
|
$path = $dir . DIRECTORY_SEPARATOR . $item;
|
|
if (is_dir($path)) {
|
|
self::rmTree($path);
|
|
} else {
|
|
@unlink($path);
|
|
}
|
|
}
|
|
@rmdir($dir);
|
|
}
|
|
}
|