Ensure some cache folders & index.html exists

This commit is contained in:
slawkens
2025-11-02 12:21:29 +01:00
parent fd729242ff
commit 730a0f2912
5 changed files with 29 additions and 1 deletions

View File

@@ -1177,7 +1177,8 @@ function getTopPlayers($limit = 5, $skill = 'level') {
});
}
function deleteDirectory($dir, $ignore = array(), $contentOnly = false) {
function deleteDirectory($dir, $ignore = array(), $contentOnly = false): bool
{
if(!file_exists($dir)) {
return true;
}
@@ -1203,6 +1204,21 @@ function deleteDirectory($dir, $ignore = array(), $contentOnly = false) {
return rmdir($dir);
}
function ensureFolderExists($dir): void
{
if (!file_exists($dir)) {
mkdir($dir, 0777, true);
}
}
function ensureIndexExists($dir): void
{
$dir = rtrim($dir, '/');
if (!file_exists($file = $dir . '/index.html')) {
touch($file);
}
}
function config($key) {
global $config;
if (is_array($key)) {

View File

@@ -18,6 +18,9 @@ use MyAAC\Settings;
defined('MYAAC') or die('Direct access not allowed!');
ensureIndexExists(CACHE);
ensureIndexExists(CACHE . 'twig/');
global $config;
if(!isset($config['installed']) || !$config['installed']) {
throw new RuntimeException('MyAAC has not been installed yet or there was error during installation. Please install again.');

View File

@@ -27,6 +27,9 @@ class PHP
{
$var = var_export($var, true);
ensureFolderExists($this->dir);
ensureIndexExists($this->dir);
// Write to temp file first to ensure atomicity
$tmp = $this->dir . "tmp_$key." . uniqid('', true) . '.tmp';
file_put_contents($tmp, '<?php $var = ' . $var . ';', LOCK_EX);

View File

@@ -513,6 +513,9 @@ class Plugins {
return false;
}
ensureFolderExists($cachePlugins = CACHE . 'plugins');
ensureIndexExists($cachePlugins);
self::$error = 'There was a problem with extracting zip archive.';
$file_name = $plugin_temp_dir . $json_file;
if(!file_exists($file_name)) {

View File

@@ -53,6 +53,9 @@
exit;
}
ensureFolderExists(SIGNATURES_CACHE);
ensureIndexExists(SIGNATURES_CACHE);
$cached = SIGNATURES_CACHE.$player->getId() . '.png';
if(file_exists($cached) && (time() < (filemtime($cached) + (60 * setting('core.signature_cache_time')))))
{