Skip to content

Commit 308ac7e

Browse files
author
Oleksandr Iegorov
committed
MAGETWO-95853: Can't flush Images cache in admin
1 parent c515b40 commit 308ac7e

File tree

2 files changed

+58
-2
lines changed

2 files changed

+58
-2
lines changed

lib/internal/Magento/Framework/Filesystem/Directory/Write.php

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,7 @@ public function createSymlink($path, $destination, WriteInterface $targetDirecto
175175
*/
176176
public function delete($path = null)
177177
{
178+
$exceptionMessages = [];
178179
$this->validatePath($path);
179180
if (!$this->isExist($path)) {
180181
return true;
@@ -183,11 +184,54 @@ public function delete($path = null)
183184
if ($this->driver->isFile($absolutePath)) {
184185
$this->driver->deleteFile($absolutePath);
185186
} else {
186-
$this->driver->deleteDirectory($absolutePath);
187+
try {
188+
$this->deleteFilesRecursively($absolutePath);
189+
$this->driver->deleteDirectory($absolutePath);
190+
} catch (FileSystemException $e) {
191+
$exceptionMessages[] = $e->getMessage();
192+
}
193+
}
194+
if (!empty($exceptionMessages)) {
195+
throw new FileSystemException(
196+
new \Magento\Framework\Phrase(
197+
\implode(' ', $exceptionMessages)
198+
)
199+
);
187200
}
188201
return true;
189202
}
190203

204+
/**
205+
* Delete files recursively
206+
*
207+
* Implemented in order to delete as much files as possible and collect all exceptions
208+
*
209+
* @param string $path
210+
* @return void
211+
* @throws FileSystemException
212+
*/
213+
private function deleteFilesRecursively(string $path)
214+
{
215+
$exceptionMessages = [];
216+
$entitiesList = $this->driver->readDirectoryRecursively($path);
217+
foreach ($entitiesList as $entityPath) {
218+
if (!$this->driver->isDirectory($entityPath)) {
219+
try {
220+
$this->driver->deleteFile($entityPath);
221+
} catch (FileSystemException $e) {
222+
$exceptionMessages[] = $e->getMessage();
223+
}
224+
}
225+
}
226+
if (!empty($exceptionMessages)) {
227+
throw new FileSystemException(
228+
new \Magento\Framework\Phrase(
229+
\implode(' ', $exceptionMessages)
230+
)
231+
);
232+
}
233+
}
234+
191235
/**
192236
* Change permissions of given path
193237
*

lib/internal/Magento/Framework/Filesystem/Driver/File.php

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -399,16 +399,28 @@ public function deleteFile($path)
399399
*/
400400
public function deleteDirectory($path)
401401
{
402+
$exceptionMessages = [];
402403
$flags = \FilesystemIterator::SKIP_DOTS | \FilesystemIterator::UNIX_PATHS;
403404
$iterator = new \FilesystemIterator($path, $flags);
404405
/** @var \FilesystemIterator $entity */
405406
foreach ($iterator as $entity) {
406407
if ($entity->isDir()) {
407-
$this->deleteDirectory($entity->getPathname());
408+
try {
409+
$this->deleteDirectory($entity->getPathname());
410+
} catch (FileSystemException $exception) {
411+
$exceptionMessages[] = $exception->getMessage();
412+
}
408413
} else {
409414
$this->deleteFile($entity->getPathname());
410415
}
411416
}
417+
if (!empty($exceptionMessages)) {
418+
throw new FileSystemException(
419+
new \Magento\Framework\Phrase(
420+
\implode(' ', $exceptionMessages)
421+
)
422+
);
423+
}
412424
$result = @rmdir($this->getScheme() . $path);
413425
if (!$result) {
414426
throw new FileSystemException(

0 commit comments

Comments
 (0)