Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix: Improve variable names
Signed-off-by: Côme Chilliet <[email protected]>
  • Loading branch information
come-nc committed Feb 6, 2025
commit f37bf9380d2867945389f8ca820bd2b5f03d3a18
20 changes: 10 additions & 10 deletions lib/Updater.php
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,6 @@ private function getRecursiveDirectoryIterator(string $folder, array $excludedPa
yield $path => new \SplFileInfo($path);
}


closedir($handle);
}

Expand Down Expand Up @@ -408,25 +407,26 @@ public function createBackup(): void {
throw new \Exception('Could not create backup folder location');
}

foreach ($this->getRecursiveDirectoryIterator($this->nextcloudDir, $excludedElements) as $path => $fileInfo) {
$fileName = explode($this->nextcloudDir, $path)[1];
foreach ($this->getRecursiveDirectoryIterator($this->nextcloudDir, $excludedElements) as $absolutePath => $fileInfo) {
$relativePath = explode($this->nextcloudDir, $absolutePath)[1];
$relativeDirectory = dirname($relativePath);

// Create folder if it doesn't exist
if (!file_exists($backupFolderLocation . '/' . dirname($fileName))) {
$state = mkdir($backupFolderLocation . '/' . dirname($fileName), 0750, true);
if (!file_exists($backupFolderLocation . '/' . $relativeDirectory)) {
$state = mkdir($backupFolderLocation . '/' . $relativeDirectory, 0750, true);
if ($state === false) {
throw new \Exception('Could not create folder: '.$backupFolderLocation.'/'.dirname($fileName));
throw new \Exception('Could not create folder: '.$backupFolderLocation.'/'.$relativeDirectory);
}
}

// If it is a file copy it
if ($fileInfo->isFile()) {
$state = copy($fileInfo->getRealPath(), $backupFolderLocation . $fileName);
$state = copy($fileInfo->getRealPath(), $backupFolderLocation . $relativePath);
if ($state === false) {
$message = sprintf(
'Could not copy "%s" to "%s"',
$fileInfo->getRealPath(),
$backupFolderLocation . $fileName
$backupFolderLocation . $relativePath
);

if (is_readable($fileInfo->getRealPath()) === false) {
Expand All @@ -437,11 +437,11 @@ public function createBackup(): void {
);
}

if (is_writable($backupFolderLocation . $fileName) === false) {
if (is_writable($backupFolderLocation . $relativePath) === false) {
$message = sprintf(
'%s. Destination %s is not writable',
$message,
$backupFolderLocation . $fileName
$backupFolderLocation . $relativePath
);
}

Expand Down