Skip to content

Commit 40b423d

Browse files
author
Oleksandr Iegorov
committed
Merge branch 'MAGETWO-95853' of github.com:magento-tango/magento2ce into PR-2311
2 parents 909591d + dd4077c commit 40b423d

File tree

2 files changed

+71
-7
lines changed

2 files changed

+71
-7
lines changed

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

Lines changed: 54 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99
use Magento\Framework\Exception\FileSystemException;
1010
use Magento\Framework\Exception\ValidatorException;
1111

12+
/**
13+
* Write Interface implementation
14+
*/
1215
class Write extends Read implements WriteInterface
1316
{
1417
/**
@@ -175,6 +178,7 @@ public function createSymlink($path, $destination, WriteInterface $targetDirecto
175178
*/
176179
public function delete($path = null)
177180
{
181+
$exceptionMessages = [];
178182
$this->validatePath($path);
179183
if (!$this->isExist($path)) {
180184
return true;
@@ -183,11 +187,59 @@ public function delete($path = null)
183187
if ($this->driver->isFile($absolutePath)) {
184188
$this->driver->deleteFile($absolutePath);
185189
} else {
186-
$this->driver->deleteDirectory($absolutePath);
190+
try {
191+
$this->deleteFilesRecursively($absolutePath);
192+
} catch (FileSystemException $e) {
193+
$exceptionMessages[] = $e->getMessage();
194+
}
195+
try {
196+
$this->driver->deleteDirectory($absolutePath);
197+
} catch (FileSystemException $e) {
198+
$exceptionMessages[] = $e->getMessage();
199+
}
200+
201+
if (!empty($exceptionMessages)) {
202+
throw new FileSystemException(
203+
new \Magento\Framework\Phrase(
204+
\implode(' ', $exceptionMessages)
205+
)
206+
);
207+
}
187208
}
188209
return true;
189210
}
190211

212+
/**
213+
* Delete files recursively
214+
*
215+
* Implemented in order to delete as much files as possible and collect all exceptions
216+
*
217+
* @param string $path
218+
* @return void
219+
* @throws FileSystemException
220+
*/
221+
private function deleteFilesRecursively(string $path)
222+
{
223+
$exceptionMessages = [];
224+
$entitiesList = $this->driver->readDirectoryRecursively($path);
225+
foreach ($entitiesList as $entityPath) {
226+
if ($this->driver->isFile($entityPath)) {
227+
try {
228+
$this->driver->deleteFile($entityPath);
229+
} catch (FileSystemException $e) {
230+
$exceptionMessages[] = $e->getMessage();
231+
}
232+
}
233+
}
234+
if (!empty($exceptionMessages)) {
235+
throw new FileSystemException(
236+
new \Magento\Framework\Phrase(
237+
\implode(' ', $exceptionMessages)
238+
)
239+
);
240+
}
241+
}
242+
191243
/**
192244
* Change permissions of given path
193245
*
@@ -245,7 +297,7 @@ public function touch($path, $modificationTime = null)
245297
/**
246298
* Check if given path is writable
247299
*
248-
* @param null $path
300+
* @param string|null $path
249301
* @return bool
250302
* @throws \Magento\Framework\Exception\FileSystemException
251303
* @throws ValidatorException

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

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -400,24 +400,36 @@ public function deleteFile($path)
400400
*/
401401
public function deleteDirectory($path)
402402
{
403+
$exceptionMessages = [];
403404
$flags = \FilesystemIterator::SKIP_DOTS | \FilesystemIterator::UNIX_PATHS;
404405
$iterator = new \FilesystemIterator($path, $flags);
405406
/** @var \FilesystemIterator $entity */
406407
foreach ($iterator as $entity) {
407-
if ($entity->isDir()) {
408-
$this->deleteDirectory($entity->getPathname());
409-
} else {
410-
$this->deleteFile($entity->getPathname());
408+
try {
409+
if ($entity->isDir()) {
410+
$this->deleteDirectory($entity->getPathname());
411+
} else {
412+
$this->deleteFile($entity->getPathname());
413+
}
414+
} catch (FileSystemException $exception) {
415+
$exceptionMessages[] = $exception->getMessage();
411416
}
412417
}
413418

419+
if (!empty($exceptionMessages)) {
420+
throw new FileSystemException(
421+
new \Magento\Framework\Phrase(
422+
\implode(' ', $exceptionMessages)
423+
)
424+
);
425+
}
426+
414427
$fullPath = $this->getScheme() . $path;
415428
if (is_link($fullPath)) {
416429
$result = @unlink($fullPath);
417430
} else {
418431
$result = @rmdir($fullPath);
419432
}
420-
421433
if (!$result) {
422434
throw new FileSystemException(
423435
new \Magento\Framework\Phrase(

0 commit comments

Comments
 (0)