Skip to content

Commit 7f46e72

Browse files
committed
FileStorage: always creates directories
1 parent 7da6cc6 commit 7f46e72

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
@@ -27,6 +27,8 @@ public function __construct($tempDir)
2727

2828
public function loadConfiguration()
2929
{
30+
@mkdir($this->tempDir . '/cache'); // @ - directory may exists
31+
3032
$builder = $this->getContainerBuilder();
3133

3234
$builder->addDefinition($this->prefix('journal'))
@@ -43,32 +45,4 @@ public function loadConfiguration()
4345
}
4446
}
4547

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

src/Caching/Storages/FileStorage.php

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

50-
/** @var bool */
50+
/** @deprecated */
5151
public static $useDirectories = TRUE;
5252

5353
/** @var string */
5454
private $dir;
5555

56-
/** @var bool */
57-
private $useDirs;
58-
5956
/** @var IJournal */
6057
private $journal;
6158

@@ -70,7 +67,6 @@ public function __construct($dir, IJournal $journal = NULL)
7067
}
7168

7269
$this->dir = $dir;
73-
$this->useDirs = (bool) static::$useDirectories;
7470
$this->journal = $journal;
7571

7672
if (mt_rand() / mt_getrandmax() < static::$gcProbability) {
@@ -144,7 +140,7 @@ private function verify($meta)
144140
public function lock($key)
145141
{
146142
$cacheFile = $this->getCacheFile($key);
147-
if ($this->useDirs && !is_dir($dir = dirname($cacheFile))) {
143+
if (!is_dir($dir = dirname($cacheFile))) {
148144
@mkdir($dir); // @ - directory may already exist
149145
}
150146
$handle = fopen($cacheFile, 'c+b');
@@ -366,7 +362,7 @@ protected function readData($meta)
366362
protected function getCacheFile($key)
367363
{
368364
$file = urlencode($key);
369-
if ($this->useDirs && $a = strrpos($file, '%00')) { // %00 = urlencode(Nette\Caching\Cache::NAMESPACE_SEPARATOR)
365+
if ($a = strrpos($file, '%00')) { // %00 = urlencode(Nette\Caching\Cache::NAMESPACE_SEPARATOR)
370366
$file = substr_replace($file, '/_', $a, 3);
371367
}
372368
return $this->dir . '/_' . $file;

0 commit comments

Comments
 (0)