11
11
12
12
namespace Symfony \Component \Cache \Adapter ;
13
13
14
- use Symfony \Component \Cache \Exception \LogicException ;
15
14
use Symfony \Component \Cache \Marshaller \DefaultMarshaller ;
16
15
use Symfony \Component \Cache \Marshaller \MarshallerInterface ;
17
16
use Symfony \Component \Cache \PruneableInterface ;
@@ -115,22 +114,39 @@ protected function doDelete(array $ids, array $tagData = []): bool
115
114
protected function doInvalidate (array $ tagIds ): bool
116
115
{
117
116
foreach ($ tagIds as $ tagId ) {
118
- $ tagsFolder = $ this ->getTagFolder ($ tagId );
119
- if (!file_exists ($ tagsFolder )) {
117
+ if (!file_exists ($ tagsFolder = $ this ->getTagFolder ($ tagId ))) {
120
118
continue ;
121
119
}
122
120
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 );
126
133
}
127
134
128
- $ valueFile = $ itemLink ->getRealPath ();
129
- if ($ valueFile && file_exists ($ valueFile )) {
130
- @unlink ($ valueFile );
135
+ if (null === $ renamed ) {
136
+ continue ;
131
137
}
132
138
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 ();
134
150
}
135
151
}
136
152
0 commit comments