From ab696963433b93b75443d1d5bce7e9e847b60cad Mon Sep 17 00:00:00 2001 From: wayblink Date: Thu, 12 Sep 2024 10:04:57 +0800 Subject: [PATCH] fix getBackup panic if pass a invalid backup ID (#424) Signed-off-by: wayblink --- core/backup_context.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/core/backup_context.go b/core/backup_context.go index cb450ec..7c76e95 100644 --- a/core/backup_context.go +++ b/core/backup_context.go @@ -647,13 +647,13 @@ func (b *BackupContext) GetRestore(ctx context.Context, request *backuppb.GetRes } task := b.meta.GetRestoreTask(request.GetId()) - progress := int32(float32(task.GetRestoredSize()) * 100 / float32(task.GetToRestoreSize())) - // don't return zero - if progress == 0 { - progress = 1 - } - task.Progress = progress if task != nil { + progress := int32(float32(task.GetRestoredSize()) * 100 / float32(task.GetToRestoreSize())) + // don't return zero + if progress == 0 { + progress = 1 + } + task.Progress = progress resp.Code = backuppb.ResponseCode_Success resp.Msg = "success" resp.Data = task