Skip to content

Commit bca09e4

Browse files
committed
bug #22374 [Cache] Remove exception false-positive from FilesystemAdapterTrait (nicolas-grekas)
This PR was merged into the 3.2 branch. Discussion ---------- [Cache] Remove exception false-positive from FilesystemAdapterTrait | Q | A | ------------- | --- | Branch? | 3.2 | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #20517 | License | MIT | Doc PR | - As reported in the linked issue, there seem to be a race condition in FilesystemAdapterTrait (maybe related to realpath cache?). Let's remove that exception: if the mkdir really fails, the error will be logged later on when a cache entry will be written (or succeed if the race is over.) Commits ------- a756db7 [Cache] Remove exception false-positive from FilesystemAdapterTrait
2 parents 8d34959 + a756db7 commit bca09e4

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed

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

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,26 +27,25 @@ private function init($namespace, $directory)
2727
{
2828
if (!isset($directory[0])) {
2929
$directory = sys_get_temp_dir().'/symfony-cache';
30+
} else {
31+
$directory = realpath($directory) ?: $directory;
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+
$directory .= DIRECTORY_SEPARATOR.$namespace;
3638
}
37-
if (!file_exists($dir = $directory.'/.')) {
39+
if (!file_exists($directory)) {
3840
@mkdir($directory, 0777, true);
3941
}
40-
if (false === $dir = realpath($dir) ?: (file_exists($dir) ? $dir : false)) {
41-
throw new InvalidArgumentException(sprintf('Cache directory does not exist (%s)', $directory));
42-
}
43-
$dir .= DIRECTORY_SEPARATOR;
42+
$directory .= DIRECTORY_SEPARATOR;
4443
// On Windows the whole path is limited to 258 chars
45-
if ('\\' === DIRECTORY_SEPARATOR && strlen($dir) > 234) {
44+
if ('\\' === DIRECTORY_SEPARATOR && strlen($directory) > 234) {
4645
throw new InvalidArgumentException(sprintf('Cache directory too long (%s)', $directory));
4746
}
4847

49-
$this->directory = $dir;
48+
$this->directory = $directory;
5049
}
5150

5251
/**

0 commit comments

Comments
 (0)