using mkdir() in copyThenRemove() leads to errors if the target exists or not a dir, use ensureDirectoryExists() instead
parent
b333d7a485
commit
dd4db91ae7
|
@ -129,15 +129,12 @@ class Filesystem
|
||||||
{
|
{
|
||||||
$it = new RecursiveDirectoryIterator($source, RecursiveDirectoryIterator::SKIP_DOTS);
|
$it = new RecursiveDirectoryIterator($source, RecursiveDirectoryIterator::SKIP_DOTS);
|
||||||
$ri = new RecursiveIteratorIterator($it, RecursiveIteratorIterator::SELF_FIRST);
|
$ri = new RecursiveIteratorIterator($it, RecursiveIteratorIterator::SELF_FIRST);
|
||||||
|
$this->ensureDirectoryExists($target);
|
||||||
if (!file_exists($target)) {
|
|
||||||
mkdir($target, 0777, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach ($ri as $file) {
|
foreach ($ri as $file) {
|
||||||
$targetPath = $target . DIRECTORY_SEPARATOR . $ri->getSubPathName();
|
$targetPath = $target . DIRECTORY_SEPARATOR . $ri->getSubPathName();
|
||||||
if ($file->isDir()) {
|
if ($file->isDir()) {
|
||||||
mkdir($targetPath);
|
$this->ensureDirectoryExists($targetPath);
|
||||||
} else {
|
} else {
|
||||||
copy($file->getPathname(), $targetPath);
|
copy($file->getPathname(), $targetPath);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue