Skip to content

Commit

Permalink
fix(updater): make clean-up job more robust / easier to debug
Browse files Browse the repository at this point in the history
Signed-off-by: Josh <josh.t.richards@gmail.com>
  • Loading branch information
joshtrichards authored Oct 12, 2024
1 parent 03d553f commit 1c90467
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions core/BackgroundJobs/BackgroundCleanupUpdaterBackupsJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,20 @@ public function __construct(
* @param array $argument
*/
public function run($argument): void {
$this->log->info("Running background job to clean-up outdated updater backups");

$updateDir = $this->config->getSystemValue('updatedirectory', null) ?? $this->config->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data');
$instanceId = $this->config->getSystemValue('instanceid', null);

if (!is_string($instanceId) || empty($instanceId)) {
$this->log->error("Skipping updater backup clean-up - instanceId is missing!");
return;
}

$updaterFolderPath = $updateDir . '/updater-' . $instanceId;
$backupFolderPath = $updaterFolderPath . '/backups';
if (file_exists($backupFolderPath)) {
$this->log->info("$backupFolderPath exists - start to clean it up");
$this->log->debug("Updater backup folder detected: $backupFolderPath");

$dirList = [];
$dirs = new \DirectoryIterator($backupFolderPath);
Expand All @@ -52,6 +55,8 @@ public function run($argument): void {
$realPath = $dir->getRealPath();

if ($realPath === false) {
$pathName = $dir->getPathname();
$this->log->warn("Skipping updater backup folder $pathname (not found)");

Check failure on line 59 in core/BackgroundJobs/BackgroundCleanupUpdaterBackupsJob.php

View workflow job for this annotation

GitHub Actions / static-code-analysis

UndefinedInterfaceMethod

core/BackgroundJobs/BackgroundCleanupUpdaterBackupsJob.php:59:18: UndefinedInterfaceMethod: Method Psr\Log\LoggerInterface::warn does not exist (see https://psalm.dev/181)

Check failure on line 59 in core/BackgroundJobs/BackgroundCleanupUpdaterBackupsJob.php

View workflow job for this annotation

GitHub Actions / static-code-analysis

UndefinedVariable

core/BackgroundJobs/BackgroundCleanupUpdaterBackupsJob.php:59:55: UndefinedVariable: Cannot find referenced variable $pathname (see https://psalm.dev/024)
continue;
}

Expand All @@ -61,15 +66,18 @@ public function run($argument): void {
ksort($dirList);
// drop the newest 3 directories
$dirList = array_slice($dirList, 0, -3);
$this->log->info('List of all directories that will be deleted: ' . json_encode($dirList));
$this->log->debug('Updater backup folders that will be deleted: ' . json_encode($dirList));

foreach ($dirList as $dir) {
$this->log->info("Removing $dir ...");
\OC_Helper::rmdirr($dir);
$result = \OC_Helper::rmdirr($dir);
if (!$result) {
$this->log->error('Could not remove updater backup folder $dir');
}
}
$this->log->info('Cleanup finished');
$this->log->info('Background job to clean-up updater backups has finished');
} else {
$this->log->info("Could not find updater directory $backupFolderPath - cleanup step not needed");
$this->log->warn("Skipping updater backup clean-up - could not find updater backup folder $backupFolderPath");

Check failure on line 80 in core/BackgroundJobs/BackgroundCleanupUpdaterBackupsJob.php

View workflow job for this annotation

GitHub Actions / static-code-analysis

UndefinedInterfaceMethod

core/BackgroundJobs/BackgroundCleanupUpdaterBackupsJob.php:80:16: UndefinedInterfaceMethod: Method Psr\Log\LoggerInterface::warn does not exist (see https://psalm.dev/181)
}
}
}

0 comments on commit 1c90467

Please sign in to comment.