diff --git a/index.php b/index.php index f1708c94..66a0a2a0 100644 --- a/index.php +++ b/index.php @@ -997,20 +997,36 @@ private function moveWithExclusions(string $dataLocation, array $excludedElement throw new \Exception('Could not mkdir ' . $this->baseDir . '/../' . dirname($fileName)); } } - $state = rename($path, $this->baseDir . '/../' . $fileName); + $state = copy($path, $this->baseDir . '/../' . $fileName); if ($state === false) { throw new \Exception( sprintf( - 'Could not rename %s to %s', + 'Could not copy %s to %s', $path, $this->baseDir . '/../' . $fileName ) ); } } - if ($fileInfo->isDir()) { - $this->recursiveDelete($path); + } + + // Cleanup (delete $path) + foreach ($this->getRecursiveDirectoryIterator($dataLocation) as $path => $fileInfo) { + $fileName = explode($dataLocation, $path)[1]; + $folderStructure = explode('/', $fileName, -1); + + // Exclude the exclusions + if (isset($folderStructure[0])) { + if (array_search($folderStructure[0], $excludedElements) !== false) { + continue; + } + } else { + if (array_search($fileName, $excludedElements) !== false) { + continue; + } } + + $this->recursiveDelete($path); } } diff --git a/lib/Updater.php b/lib/Updater.php index d944fb7f..7437c017 100644 --- a/lib/Updater.php +++ b/lib/Updater.php @@ -958,20 +958,36 @@ private function moveWithExclusions(string $dataLocation, array $excludedElement throw new \Exception('Could not mkdir ' . $this->baseDir . '/../' . dirname($fileName)); } } - $state = rename($path, $this->baseDir . '/../' . $fileName); + $state = copy($path, $this->baseDir . '/../' . $fileName); if ($state === false) { throw new \Exception( sprintf( - 'Could not rename %s to %s', + 'Could not copy %s to %s', $path, $this->baseDir . '/../' . $fileName ) ); } } - if ($fileInfo->isDir()) { - $this->recursiveDelete($path); + } + + // Cleanup (delete $path) + foreach ($this->getRecursiveDirectoryIterator($dataLocation) as $path => $fileInfo) { + $fileName = explode($dataLocation, $path)[1]; + $folderStructure = explode('/', $fileName, -1); + + // Exclude the exclusions + if (isset($folderStructure[0])) { + if (array_search($folderStructure[0], $excludedElements) !== false) { + continue; + } + } else { + if (array_search($fileName, $excludedElements) !== false) { + continue; + } } + + $this->recursiveDelete($path); } }