Fix deleting a backup that is locked and failed; closes #3404

This commit is contained in:
Dane Everitt 2021-06-13 10:26:47 -07:00
parent 725fc82657
commit d049839ffc
No known key found for this signature in database
GPG key ID: EEA66103B3D71F53
4 changed files with 141 additions and 11 deletions

View file

@ -12,17 +12,11 @@ use League\Flysystem\AwsS3v3\AwsS3Adapter;
use Pterodactyl\Exceptions\DisplayException;
use Pterodactyl\Http\Controllers\Controller;
use Pterodactyl\Extensions\Backups\BackupManager;
use Pterodactyl\Repositories\Eloquent\BackupRepository;
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
use Pterodactyl\Http\Requests\Api\Remote\ReportBackupCompleteRequest;
class BackupStatusController extends Controller
{
/**
* @var \Pterodactyl\Repositories\Eloquent\BackupRepository
*/
private $repository;
/**
* @var \Pterodactyl\Extensions\Backups\BackupManager
*/
@ -31,9 +25,8 @@ class BackupStatusController extends Controller
/**
* BackupStatusController constructor.
*/
public function __construct(BackupRepository $repository, BackupManager $backupManager)
public function __construct(BackupManager $backupManager)
{
$this->repository = $repository;
$this->backupManager = $backupManager;
}
@ -64,6 +57,10 @@ class BackupStatusController extends Controller
$successful = $request->input('successful') ? true : false;
$model->fill([
'is_successful' => $successful,
// Change the lock state to unlocked if this was a failed backup so that it can be
// deleted easily. Also does not make sense to have a locked backup on the system
// that is failed.
'is_locked' => $successful ? $model->is_locked : false,
'checksum' => $successful ? ($request->input('checksum_type') . ':' . $request->input('checksum')) : null,
'bytes' => $successful ? $request->input('size') : 0,
'completed_at' => CarbonImmutable::now(),

View file

@ -50,13 +50,20 @@ class DeleteBackupService
}
/**
* Deletes a backup from the system.
* Deletes a backup from the system. If the backup is stored in S3 a request
* will be made to delete that backup from the disk as well.
*
* @throws \Throwable
*/
public function handle(Backup $backup)
{
if ($backup->is_locked) {
// If the backup is marked as failed it can still be deleted, even if locked
// since the UI doesn't allow you to unlock a failed backup in the first place.
//
// I also don't really see any reason you'd have a locked, failed backup to keep
// around. The logic that updates the backup to the failed state will also remove
// the lock, so this condition should really never happen.
if ($backup->is_locked && ($backup->completed_at && $backup->is_successful)) {
throw new BackupLockedException();
}