feat(vikon): cleanup _old/_new artifacts after successful sync

This commit is contained in:
F4ilji
2026-07-05 13:58:00 +05:00
parent 416403b6ce
commit b0ff3bf397
3 changed files with 63 additions and 2 deletions
@@ -28,6 +28,7 @@ class UpdateCoreAction
$this->downloadCore($moduleId, $modulePath, $tempPath, $accessToken);
$this->syncFromFM($moduleId, $modulePath, $accessToken);
$this->cleanupPostSync($modulePath);
File::put($modulePath . '/.vikon', date('Y-m-d H:i:s'));
@@ -302,4 +303,34 @@ class UpdateCoreAction
}
}
}
private function cleanupPostSync(string $modulePath): void
{
if (!File::isDirectory($modulePath)) {
return;
}
$removed = 0;
// Remove _old and _new directories/files left after successful atomic swap
foreach (File::directories($modulePath) as $dir) {
$name = basename($dir);
if (str_ends_with($name, '_old') || str_ends_with($name, '_new')) {
File::deleteDirectory($dir);
$removed++;
}
}
foreach (File::files($modulePath) as $file) {
$name = $file->getFilename();
if (str_ends_with($name, '_old') || str_ends_with($name, '_new')) {
File::delete($file->getPathname());
$removed++;
}
}
if ($removed > 0) {
Log::info('Vikon: cleaned up post-sync', ['removed' => $removed]);
}
}
}
@@ -93,8 +93,9 @@ class UpdatePartAction
// Step 5: Apply
$syncedCount = $this->applyPart($part, $tempPath, $modulePath, $moduleId, $config);
} finally {
// Step 6: Clean temp
// Step 6: Clean temp and post-sync artifacts
File::deleteDirectory($tempPath);
$this->cleanupPostSync($modulePath);
}
Log::info('Vikon: part update complete', ['module' => $moduleId, 'part' => $part, 'synced' => $syncedCount]);
@@ -195,4 +196,33 @@ class UpdatePartAction
return $synced;
}
private function cleanupPostSync(string $modulePath): void
{
if (!File::isDirectory($modulePath)) {
return;
}
$removed = 0;
foreach (File::directories($modulePath) as $dir) {
$name = basename($dir);
if (str_ends_with($name, '_old') || str_ends_with($name, '_new')) {
File::deleteDirectory($dir);
$removed++;
}
}
foreach (File::files($modulePath) as $file) {
$name = $file->getFilename();
if (str_ends_with($name, '_old') || str_ends_with($name, '_new')) {
File::delete($file->getPathname());
$removed++;
}
}
if ($removed > 0) {
Log::info('Vikon: cleaned up post-sync', ['removed' => $removed, 'path' => $modulePath]);
}
}
}