8000 [Cache] Remove exception false-positive from FilesystemAdapterTrait · symfony/symfony@b462fba · GitHub
[go: up one dir, main page]

Skip to content

Commit b462fba

Browse files
[Cache] Remove exception false-positive from FilesystemAdapterTrait
1 parent d41a3a5 commit b462fba

File tree

1 file changed

+9
-10
lines changed

1 file changed

+9
-10
lines changed

src/Symfony/Component/Cache/Adapter/FilesystemAdapterTrait.php

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,27 +23,26 @@ trait FilesystemAdapterTrait
2323
private $directory;
2424
private $tmp;
2525

26-
private function init($namespace, $directory)
26+
private function init($namespace, $dir)
2727
{
28-
if (!isset($directory[0])) {
29-
$directory = sys_get_temp_dir().'/symfony-cache';
28+
if (!isset($dir[0])) {
29+
$dir = sys_get_temp_dir().'/symfony-cache';
30+
} else {
31+
$dir = realpath($dir) ?: $dir;
3032
}
3133
if (isset($namespace[0])) {
3234
if (preg_match('#[^-+_.A-Za-z0-9]#', $namespace, $match)) {
3335
throw new InvalidArgumentException(sprintf('Namespace contains "%s" but only characters in [-+_.A-Za-z0-9] are allowed.', $match[0]));
3436
}
35-
$directory .= '/'.$namespace;
37+
$dir .= DIRECTORY_SEPARATOR.$namespace;
3638
}
37-
if (!file_exists($dir = $directory.'/.')) {
38-
@mkdir($directory, 0777, true);
39-
}
40-
if (false === $dir = realpath($dir) ?: (file_exists($dir) ? $dir : false)) {
41-
throw new InvalidArgumentException(sprintf('Cache directory does not exist (%s)', $directory));
39+
if (!file_exists($dir)) {
40+
@mkdir($dir, 0777, true);
4241
}
4342
$dir .= DIRECTORY_SEPARATOR;
4443
// On Windows the whole path is limited to 258 chars
4544
if ('\\' === DIRECTORY_SEPARATOR && strlen($dir) > 234) {
46-
throw new InvalidArgumentException(sprintf('Cache directory too long (%s)', $directory));
45+
throw new InvalidArgumentException(sprintf('Cache directory too long (%s)', $dir));
4746
}
4847

4948
$this->directory = $dir;

0 commit comments

Comments
 (0)
0