diff --git a/index.php b/index.php index 240b773c..89277b0e 100644 --- a/index.php +++ b/index.php @@ -502,7 +502,10 @@ public function createBackup(): void { } foreach ($this->getRecursiveDirectoryIterator($this->nextcloudDir, $excludedElements) as $absolutePath => $fileInfo) { - $relativePath = explode($this->nextcloudDir, $absolutePath)[1]; + $relativePath = explode($this->nextcloudDir, $absolutePath, 2)[1] ?? null; + if ($relativePath === null) { + throw new \Exception($absolutePath . ' is not in ' . $this->nextcloudDir); + } $relativeDirectory = dirname($relativePath); // Create folder if it doesn't exist @@ -1136,7 +1139,10 @@ private function moveWithExclusions(string $dataLocation, array $excludedElement } - $fileName = explode($dataLocation, $path)[1]; + $fileName = explode($dataLocation, $path, 2)[1] ?? null; + if ($fileName === null) { + throw new \Exception('Could not move ' . $path . ' as it’s not in ' . $dataLocation); + } if ($fileInfo->isFile()) { if (!file_exists($this->nextcloudDir . '/' . dirname($fileName))) { diff --git a/lib/Updater.php b/lib/Updater.php index d1f523c5..4e74be7e 100644 --- a/lib/Updater.php +++ b/lib/Updater.php @@ -486,7 +486,10 @@ public function createBackup(): void { } foreach ($this->getRecursiveDirectoryIterator($this->nextcloudDir, $excludedElements) as $absolutePath => $fileInfo) { - $relativePath = explode($this->nextcloudDir, $absolutePath)[1]; + $relativePath = explode($this->nextcloudDir, $absolutePath, 2)[1] ?? null; + if ($relativePath === null) { + throw new \Exception($absolutePath . ' is not in ' . $this->nextcloudDir); + } $relativeDirectory = dirname($relativePath); // Create folder if it doesn't exist @@ -1120,7 +1123,10 @@ private function moveWithExclusions(string $dataLocation, array $excludedElement } - $fileName = explode($dataLocation, $path)[1]; + $fileName = explode($dataLocation, $path, 2)[1] ?? null; + if ($fileName === null) { + throw new \Exception('Could not move ' . $path . ' as it’s not in ' . $dataLocation); + } if ($fileInfo->isFile()) { if (!file_exists($this->nextcloudDir . '/' . dirname($fileName))) { diff --git a/tests/checkSameCodeBase.php b/tests/checkSameCodeBase.php index bd1d2c8a..fb106b60 100644 --- a/tests/checkSameCodeBase.php +++ b/tests/checkSameCodeBase.php @@ -56,7 +56,7 @@ function findDiffPos($original, $copy) { * @var SplFileInfo $fileInfo */ foreach ($iterator as $path => $fileInfo) { - $fileName = explode($libDir, $path)[1]; + $fileName = explode($libDir, $path, 2)[1]; if (in_array($fileName, $excludedFiles)) { continue; diff --git a/updater.phar b/updater.phar index 70abbee7..b08cc626 100755 Binary files a/updater.phar and b/updater.phar differ