fix: hackily handle locked backups during server deletion

This commit is contained in:
Elizabeth
2025-07-21 00:02:05 -05:00
parent b7d36971c5
commit aedac4dad2

View File

@@ -10,6 +10,7 @@ use Pterodactyl\Repositories\Wings\DaemonServerRepository;
use Pterodactyl\Services\Databases\DatabaseManagementService;
use Pterodactyl\Services\Backups\DeleteBackupService;
use Pterodactyl\Exceptions\Http\Connection\DaemonConnectionException;
use Pterodactyl\Exceptions\Service\Backup\BackupLockedException;
class ServerDeletionService
{
@@ -63,6 +64,28 @@ class ServerDeletionService
foreach ($server->backups as $backup) {
try {
$this->deleteBackupService->handle($backup);
} catch (BackupLockedException $exception) {
// If the backup is locked, unlock it and try again since we're deleting the entire server
$backup->update(['is_locked' => false]);
try {
$this->deleteBackupService->handle($backup);
} catch (\Exception $retryException) {
if (!$this->force) {
throw $retryException;
}
// If we still can't delete the backup from storage, at least remove the database record
// to prevent orphaned backup entries
$backup->delete();
Log::warning('Failed to delete unlocked backup during server deletion', [
'backup_id' => $backup->id,
'backup_uuid' => $backup->uuid,
'server_id' => $server->id,
'exception' => $retryException->getMessage(),
]);
}
} catch (\Exception $exception) {
if (!$this->force) {
throw $exception;