force-set absolute path for local cache if CACHE_DIR config value is relative

This commit is contained in:
Andrew Dolgov 2024-04-13 00:39:37 +03:00
parent 435c321caa
commit ae5e7568f5
No known key found for this signature in database
GPG Key ID: 1A56B4FA25D4AF2A
1 changed files with 8 additions and 1 deletions

View File

@ -11,7 +11,14 @@ class Cache_Local implements Cache_Adapter {
}
public function set_dir(string $dir) : void {
$this->dir = Config::get(Config::CACHE_DIR) . "/" . basename(clean($dir));
$cache_dir = Config::get(Config::CACHE_DIR);
// use absolute path local to current dir if CACHE_DIR is relative
// TODO: maybe add a special method to Config() for this?
if ($cache_dir[0] != '/')
$cache_dir = dirname(__DIR__) . "/$cache_dir";
$this->dir = $cache_dir . "/" . basename(clean($dir));
$this->make_dir();
}