Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit b377e41

Browse filesBrowse files
[Cache] clean tags folder on invalidation
1 parent 0d49141 commit b377e41
Copy full SHA for b377e41

File tree

1 file changed

+26
-10
lines changed
Filter options

1 file changed

+26
-10
lines changed

‎src/Symfony/Component/Cache/Adapter/FilesystemTagAwareAdapter.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Cache/Adapter/FilesystemTagAwareAdapter.php
+26-10Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111

1212
namespace Symfony\Component\Cache\Adapter;
1313

14-
use Symfony\Component\Cache\Exception\LogicException;
1514
use Symfony\Component\Cache\Marshaller\DefaultMarshaller;
1615
use Symfony\Component\Cache\Marshaller\MarshallerInterface;
1716
use Symfony\Component\Cache\PruneableInterface;
@@ -115,22 +114,39 @@ protected function doDelete(array $ids, array $tagData = []): bool
115114
protected function doInvalidate(array $tagIds): bool
116115
{
117116
foreach ($tagIds as $tagId) {
118-
$tagsFolder = $this->getTagFolder($tagId);
119-
if (!file_exists($tagsFolder)) {
117+
if (!file_exists($tagsFolder = $this->getTagFolder($tagId))) {
120118
continue;
121119
}
122120

123-
foreach (new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($tagsFolder, \FilesystemIterator::SKIP_DOTS)) as $itemLink) {
124-
if (!$itemLink->isLink()) {
125-
throw new LogicException('Expected a (sym)link when iterating over tag folder, non link found: '.$itemLink);
121+
set_error_handler(static function () {});
122+
123+
try {
124+
if (rename($tagsFolder, $renamed = substr_replace($tagsFolder, bin2hex(random_bytes(4)), -1))) {
125+
$tagsFolder = $renamed.\DIRECTORY_SEPARATOR;
126+
} else {
127+
$renamed = null;
128+
}
129+
130+
foreach (new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($tagsFolder, \FilesystemIterator::SKIP_DOTS | \FilesystemIterator::CURRENT_AS_PATHNAME)) as $itemLink) {
131+
unlink(realpath($itemLink) ?: $itemLink);
132+
unlink($itemLink);
126133
}
127134

128-
$valueFile = $itemLink->getRealPath();
129-
if ($valueFile && file_exists($valueFile)) {
130-
@unlink($valueFile);
135+
if (null === $renamed) {
136+
continue;
131137
}
132138

133-
@unlink((string) $itemLink);
139+
$chars = '+-ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
140+
141+
for ($i = 0; $i < 38; ++$i) {
142+
for ($j = 0; $j < 38; ++$j) {
143+
rmdir($tagsFolder.$chars[$i].\DIRECTORY_SEPARATOR.$chars[$j]);
144+
}
145+
rmdir($tagsFolder.$chars[$i]);
146+
}
147+
rmdir($renamed);
148+
} finally {
149+
restore_error_handler();
134150
}
135151
}
136152

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.