diff options
author | Toon Claes <toon@gitlab.com> | 2024-01-19 17:55:32 +0300 |
---|---|---|
committer | GitLab <noreply@gitlab.com> | 2024-01-19 17:55:32 +0300 |
commit | c15c9d250a7e80fe868fe037bfd58e1f7b5f7584 (patch) | |
tree | 3d8edca0b3853dab14e78365b9f3561e216e0566 | |
parent | dde45bd7b851b9f33e201ccc9519c78efa75caf6 (diff) | |
parent | 396352f28151ef868a8088c9496af7caa971abf5 (diff) |
Merge branch 'jliu-fix-restore-order' into 'master'
backup: Check for backup before deleting repo
See merge request https://gitlab.com/gitlab-org/gitaly/-/merge_requests/6620
Merged-by: Toon Claes <toon@gitlab.com>
Approved-by: Toon Claes <toon@gitlab.com>
Approved-by: Sami Hiltunen <shiltunen@gitlab.com>
Co-authored-by: James Liu <jliu@gitlab.com>
-rw-r--r-- | internal/backup/backup.go | 8 | ||||
-rw-r--r-- | internal/backup/backup_test.go | 1 |
2 files changed, 5 insertions, 4 deletions
diff --git a/internal/backup/backup.go b/internal/backup/backup.go index a15f47abe..bc54cbaf0 100644 --- a/internal/backup/backup.go +++ b/internal/backup/backup.go @@ -335,10 +335,6 @@ func (mgr *Manager) Restore(ctx context.Context, req *RestoreRequest) error { return fmt.Errorf("manager: %w", err) } - if err := repo.Remove(ctx); err != nil { - return fmt.Errorf("manager: %w", err) - } - var backup *Backup if req.BackupID == "" { backup, err = mgr.locator.FindLatest(ctx, req.VanityRepository) @@ -359,6 +355,10 @@ func (mgr *Manager) Restore(ctx context.Context, req *RestoreRequest) error { defaultBranch, defaultBranchKnown := git.ReferenceName(backup.HeadReference).Branch() + if err := repo.Remove(ctx); err != nil { + return fmt.Errorf("manager: %w", err) + } + if err := repo.Create(ctx, hash, defaultBranch); err != nil { return fmt.Errorf("manager: %w", err) } diff --git a/internal/backup/backup_test.go b/internal/backup/backup_test.go index 81e87a33a..96a06fba3 100644 --- a/internal/backup/backup_test.go +++ b/internal/backup/backup_test.go @@ -977,6 +977,7 @@ func TestManager_Restore_specific(t *testing.T) { return repo, nil }, expectedErrAs: backup.ErrSkipped, + expectExists: true, }, { desc: "single incremental", |