Skip to content

Commit 3c93e5d

Browse files
committed
FileStorage: always creates directories
1 parent 7c885a2 commit 3c93e5d

File tree

2 files changed

+5
-35
lines changed

2 files changed

+5
-35
lines changed

src/Bridges/CacheDI/CacheExtension.php

Lines changed: 2 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ public function __construct($tempDir)
2929

3030
public function loadConfiguration()
3131
{
32+
@mkdir($this->tempDir . '/cache'); // @ - directory may exists
33+
3234
$builder = $this->getContainerBuilder();
3335

3436
$builder->addDefinition($this->prefix('journal'))
@@ -45,32 +47,4 @@ public function loadConfiguration()
4547
}
4648
}
4749

48-
49-
public function afterCompile(Nette\PhpGenerator\ClassType $class)
50-
{
51-
if (!$this->checkTempDir($this->tempDir . '/cache')) {
52-
$class->getMethod('initialize')->addBody('Nette\Caching\Storages\FileStorage::$useDirectories = FALSE;');
53-
}
54-
}
55-
56-
57-
private function checkTempDir($dir)
58-
{
59-
@mkdir($dir); // @ - directory may exists
60-
61-
// checks whether directory is writable
62-
$uniq = uniqid('_', TRUE);
63-
if (!@mkdir("$dir/$uniq")) { // @ - is escalated to exception
64-
throw new Nette\InvalidStateException("Unable to write to directory '$dir'. Make this directory writable.");
65-
}
66-
67-
// checks whether subdirectory is writable
68-
$isWritable = @file_put_contents("$dir/$uniq/_", '') !== FALSE; // @ - error is expected
69-
if ($isWritable) {
70-
unlink("$dir/$uniq/_");
71-
}
72-
rmdir("$dir/$uniq");
73-
return $isWritable;
74-
}
75-
7650
}

src/Caching/Storages/FileStorage.php

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -49,15 +49,12 @@ class FileStorage implements Nette\Caching\IStorage
4949
/** @var float probability that the clean() routine is started */
5050
public static $gcProbability = 0.001;
5151

52-
/** @var bool */
52+
/** @deprecated */
5353
public static $useDirectories = TRUE;
5454

5555
/** @var string */
5656
private $dir;
5757

58-
/** @var bool */
59-
private $useDirs;
60-
6158
/** @var IJournal */
6259
private $journal;
6360

@@ -72,7 +69,6 @@ public function __construct($dir, IJournal $journal = NULL)
7269
}
7370

7471
$this->dir = $dir;
75-
$this->useDirs = (bool) static::$useDirectories;
7672
$this->journal = $journal;
7773

7874
if (mt_rand() / mt_getrandmax() < static::$gcProbability) {
@@ -142,7 +138,7 @@ private function verify(array $meta): bool
142138
public function lock(string $key)
143139
{
144140
$cacheFile = $this->getCacheFile($key);
145-
if ($this->useDirs && !is_dir($dir = dirname($cacheFile))) {
141+
if (!is_dir($dir = dirname($cacheFile))) {
146142
@mkdir($dir); // @ - directory may already exist
147143
}
148144
$handle = fopen($cacheFile, 'c+b');
@@ -356,7 +352,7 @@ protected function readData(array $meta)
356352
protected function getCacheFile(string $key): string
357353
{
358354
$file = urlencode($key);
359-
if ($this->useDirs && $a = strrpos($file, '%00')) { // %00 = urlencode(Nette\Caching\Cache::NAMESPACE_SEPARATOR)
355+
if ($a = strrpos($file, '%00')) { // %00 = urlencode(Nette\Caching\Cache::NAMESPACE_SEPARATOR)
360356
$file = substr_replace($file, '/_', $a, 3);
361357
}
362358
return $this->dir . '/_' . $file;

0 commit comments

Comments
 (0)