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

[Cache] clean tags folder on invalidation #33930

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 9, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
[Cache] clean tags folder on invalidation
  • Loading branch information
nicolas-grekas committed Oct 9, 2019
commit b377e41a2c7c11d2bf4e2a077b78b781d542af71
36 changes: 26 additions & 10 deletions 36 src/Symfony/Component/Cache/Adapter/FilesystemTagAwareAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@

namespace Symfony\Component\Cache\Adapter;

use Symfony\Component\Cache\Exception\LogicException;
use Symfony\Component\Cache\Marshaller\DefaultMarshaller;
use Symfony\Component\Cache\Marshaller\MarshallerInterface;
use Symfony\Component\Cache\PruneableInterface;
Expand Down Expand Up @@ -115,22 +114,39 @@ protected function doDelete(array $ids, array $tagData = []): bool
protected function doInvalidate(array $tagIds): bool
{
foreach ($tagIds as $tagId) {
$tagsFolder = $this->getTagFolder($tagId);
if (!file_exists($tagsFolder)) {
if (!file_exists($tagsFolder = $this->getTagFolder($tagId))) {
continue;
}

foreach (new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($tagsFolder, \FilesystemIterator::SKIP_DOTS)) as $itemLink) {
if (!$itemLink->isLink()) {
throw new LogicException('Expected a (sym)link when iterating over tag folder, non link found: '.$itemLink);
set_error_handler(static function () {});

try {
if (rename($tagsFolder, $renamed = substr_replace($tagsFolder, bin2hex(random_bytes(4)), -1))) {
$tagsFolder = $renamed.\DIRECTORY_SEPARATOR;
} else {
$renamed = null;
}

foreach (new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($tagsFolder, \FilesystemIterator::SKIP_DOTS | \FilesystemIterator::CURRENT_AS_PATHNAME)) as $itemLink) {
unlink(realpath($itemLink) ?: $itemLink);
unlink($itemLink);
}

$valueFile = $itemLink->getRealPath();
if ($valueFile && file_exists($valueFile)) {
@unlink($valueFile);
if (null === $renamed) {
continue;
}

@unlink((string) $itemLink);
$chars = '+-ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';

for ($i = 0; $i < 38; ++$i) {
for ($j = 0; $j < 38; ++$j) {
rmdir($tagsFolder.$chars[$i].\DIRECTORY_SEPARATOR.$chars[$j]);
}
rmdir($tagsFolder.$chars[$i]);
}
rmdir($renamed);
} finally {
restore_error_handler();
}
}

Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.