Skip to content

Commit ec73e13

Browse files
committed
CacheExtension, FileStorage: checks whether directory is absolute
1 parent d3e75f6 commit ec73e13

File tree

3 files changed

+11
-10
lines changed

3 files changed

+11
-10
lines changed

src/Bridges/CacheDI/CacheExtension.php

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,26 +10,27 @@
1010
namespace Nette\Bridges\CacheDI;
1111

1212
use Nette;
13+
use Nette\Utils\FileSystem;
1314

1415

1516
/**
1617
* Cache extension for Nette DI.
1718
*/
1819
final class CacheExtension extends Nette\DI\CompilerExtension
1920
{
20-
private string $tempDir;
21-
22-
23-
public function __construct(string $tempDir)
24-
{
25-
$this->tempDir = $tempDir;
21+
public function __construct(
22+
private string $tempDir,
23+
) {
2624
}
2725

2826

2927
public function loadConfiguration(): void
3028
{
29+
if (!FileSystem::isAbsolute($this->tempDir)) {
30+
throw new Nette\InvalidArgumentException("Cache directory must be absolute, '$this->tempDir' given.");
31+
}
3132
$dir = $this->tempDir . '/cache';
32-
Nette\Utils\FileSystem::createDir($dir);
33+
FileSystem::createDir($dir);
3334
if (!is_writable($dir)) {
3435
throw new Nette\InvalidStateException("Make directory '$dir' writable.");
3536
}

src/Caching/Storages/FileStorage.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,8 @@ class FileStorage implements Nette\Caching\Storage
5555

5656
public function __construct(string $dir, ?Journal $journal = null)
5757
{
58-
if (!is_dir($dir)) {
59-
throw new Nette\DirectoryNotFoundException("Directory '$dir' not found.");
58+
if (!is_dir($dir) || !Nette\Utils\FileSystem::isAbsolute($dir)) {
59+
throw new Nette\DirectoryNotFoundException("Directory '$dir' not found or is not absolute.");
6060
}
6161

6262
$this->dir = $dir;

tests/Storages/FileStorage.exceptions.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ require __DIR__ . '/../bootstrap.php';
1717
Assert::exception(
1818
fn() => new FileStorage(getTempDir() . '/missing'),
1919
Nette\DirectoryNotFoundException::class,
20-
"Directory '%a%' not found.",
20+
"Directory '%a%' not found or is not absolute.",
2121
);
2222

2323

0 commit comments

Comments
 (0)