Skip to content

Commit

Permalink
Merge pull request #32 from chapeupreto/master
Browse files Browse the repository at this point in the history
Delete directories using FilesystemIterator
  • Loading branch information
freekmurze authored Aug 28, 2019
2 parents 8a23b99 + 6f7b74a commit 007f8e2
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 12 deletions.
9 changes: 3 additions & 6 deletions src/TemporaryDirectory.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Spatie\TemporaryDirectory;

use Exception;
use FilesystemIterator;
use InvalidArgumentException;

class TemporaryDirectory
Expand Down Expand Up @@ -150,12 +151,8 @@ protected function deleteDirectory(string $path): bool
return unlink($path);
}

foreach (scandir($path) as $item) {
if ($item == '.' || $item == '..') {
continue;
}

if (! $this->deleteDirectory($path.DIRECTORY_SEPARATOR.$item)) {
foreach (new FilesystemIterator($path) as $item) {
if (! $this->deleteDirectory($item)) {
return false;
}
}
Expand Down
9 changes: 3 additions & 6 deletions tests/TemporaryDirectoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Spatie\TemporaryDirectory\Test;

use FilesystemIterator;
use InvalidArgumentException;
use PHPUnit\Framework\TestCase;
use Spatie\TemporaryDirectory\TemporaryDirectory;
Expand Down Expand Up @@ -259,12 +260,8 @@ protected function deleteDirectory(string $path): bool
return unlink($path);
}

foreach (scandir($path) as $item) {
if ($item == '.' || $item == '..') {
continue;
}

if (! $this->deleteDirectory($path.DIRECTORY_SEPARATOR.$item)) {
foreach (new FilesystemIterator($path) as $item) {
if (! $this->deleteDirectory($item)) {
return false;
}
}
Expand Down

0 comments on commit 007f8e2

Please sign in to comment.