diff options
author | Toon Claes <toon@gitlab.com> | 2023-08-11 09:59:34 +0300 |
---|---|---|
committer | Toon Claes <toon@gitlab.com> | 2023-08-11 09:59:34 +0300 |
commit | d470be9b9ba6ec43785e74d34084ddb4ac7ec49a (patch) | |
tree | a11fe5929e63db614f29e8d74fc32532b02c556b | |
parent | a025b6b8dfc436a8e6f295bad13de12eb896f33f (diff) | |
parent | 6f877d7c8c085d577ebd50c09c2b41a687fcb91e (diff) |
Merge branch 'pks-revert-empty-repository-restores' into 'master'
Revert differentiated repository restores
See merge request https://gitlab.com/gitlab-org/gitaly/-/merge_requests/6208
Merged-by: Toon Claes <toon@gitlab.com>
Approved-by: Toon Claes <toon@gitlab.com>
Approved-by: Quang-Minh Nguyen <qmnguyen@gitlab.com>
Co-authored-by: Patrick Steinhardt <psteinhardt@gitlab.com>
-rw-r--r-- | cmd/gitaly-backup/restore_test.go | 12 | ||||
-rw-r--r-- | internal/backup/backup.go | 73 | ||||
-rw-r--r-- | internal/backup/backup_test.go | 131 | ||||
-rw-r--r-- | internal/backup/locator.go | 7 | ||||
-rw-r--r-- | internal/backup/locator_test.go | 21 | ||||
-rw-r--r-- | internal/backup/server_side_test.go | 4 | ||||
-rw-r--r-- | internal/gitaly/service/repository/restore_repository_test.go | 2 | ||||
-rw-r--r-- | internal/testhelper/testhelper.go | 33 |
8 files changed, 93 insertions, 190 deletions
diff --git a/cmd/gitaly-backup/restore_test.go b/cmd/gitaly-backup/restore_test.go index 069fbf6d0..7a15daeff 100644 --- a/cmd/gitaly-backup/restore_test.go +++ b/cmd/gitaly-backup/restore_test.go @@ -8,7 +8,6 @@ import ( "flag" "fmt" "io" - "os" "path/filepath" "testing" @@ -17,7 +16,6 @@ import ( "gitlab.com/gitlab-org/gitaly/v16/internal/git" "gitlab.com/gitlab-org/gitaly/v16/internal/git/gittest" "gitlab.com/gitlab-org/gitaly/v16/internal/gitaly/service/setup" - "gitlab.com/gitlab-org/gitaly/v16/internal/helper/perm" "gitlab.com/gitlab-org/gitaly/v16/internal/testhelper" "gitlab.com/gitlab-org/gitaly/v16/internal/testhelper/testcfg" "gitlab.com/gitlab-org/gitaly/v16/internal/testhelper/testserver" @@ -40,18 +38,13 @@ func TestRestoreSubcommand(t *testing.T) { path := testhelper.TempDir(t) existingRepoBundlePath := filepath.Join(path, existingRepo.RelativePath+".bundle") - existingRepoRefPath := filepath.Join(path, existingRepo.RelativePath+".refs") - gittest.Exec(t, cfg, "-C", existRepoPath, "bundle", "create", existingRepoBundlePath, "--all") - require.NoError(t, os.WriteFile(existingRepoRefPath, gittest.Exec(t, cfg, "-C", existRepoPath, "show-ref"), perm.SharedFile)) var repos []*gitalypb.Repository for i := 0; i < 2; i++ { repo := gittest.InitRepoDir(t, cfg.Storages[0].Path, fmt.Sprintf("repo-%d", i)) repoBundlePath := filepath.Join(path, repo.RelativePath+".bundle") - repoRefPath := filepath.Join(path, repo.RelativePath+".refs") testhelper.CopyFile(t, existingRepoBundlePath, repoBundlePath) - testhelper.CopyFile(t, existingRepoRefPath, repoRefPath) repos = append(repos, repo) } @@ -123,18 +116,13 @@ func TestRestoreSubcommand_serverSide(t *testing.T) { gittest.WriteCommit(t, cfg, existRepoPath, gittest.WithBranch(git.DefaultBranch)) existingRepoBundlePath := filepath.Join(path, existingRepo.RelativePath+".bundle") - existingRepoRefPath := filepath.Join(path, existingRepo.RelativePath+".refs") - gittest.Exec(t, cfg, "-C", existRepoPath, "bundle", "create", existingRepoBundlePath, "--all") - require.NoError(t, os.WriteFile(existingRepoRefPath, gittest.Exec(t, cfg, "-C", existRepoPath, "show-ref"), perm.SharedFile)) var repos []*gitalypb.Repository for i := 0; i < 2; i++ { repo := gittest.InitRepoDir(t, cfg.Storages[0].Path, fmt.Sprintf("repo-%d", i)) repoBundlePath := filepath.Join(path, repo.RelativePath+".bundle") - repoRefPath := filepath.Join(path, repo.RelativePath+".refs") testhelper.CopyFile(t, existingRepoBundlePath, repoBundlePath) - testhelper.CopyFile(t, existingRepoRefPath, repoRefPath) repos = append(repos, repo) } diff --git a/internal/backup/backup.go b/internal/backup/backup.go index fd308abd2..b2a594992 100644 --- a/internal/backup/backup.go +++ b/internal/backup/backup.go @@ -49,6 +49,10 @@ type Backup struct { type Step struct { // BundlePath is the path of the bundle BundlePath string + // SkippableOnNotFound defines if the bundle can be skipped when it does + // not exist. This allows us to maintain legacy behaviour where we always + // check a specific location for a bundle without knowing if it exists. + SkippableOnNotFound bool // RefPath is the path of the ref file RefPath string // PreviousRefPath is the path of the previous ref file @@ -270,33 +274,23 @@ func (mgr *Manager) Restore(ctx context.Context, req *RestoreRequest) error { } for _, step := range backup.Steps { - refs, err := mgr.readRefs(ctx, step.RefPath) - switch { - case errors.Is(err, ErrDoesntExist): - // For compatibility with existing backups we need to make sure the - // repository exists even if there's no bundle for project - // repositories (not wiki or snippet repositories). Gitaly does - // not know which repository is which type so here we accept a - // parameter to tell us to employ this behaviour. Since the - // repository has already been created, we simply skip cleaning up. - if req.AlwaysCreate { - return nil - } - - if err := repo.Remove(ctx); err != nil { - return fmt.Errorf("manager: remove on skipped: %w", err) - } - - return fmt.Errorf("manager: %w: %s", ErrSkipped, err.Error()) - case err != nil: - return fmt.Errorf("manager: %w", err) - } - - // Git bundles can not be created for empty repositories. Since empty - // repository backups do not contain a bundle, skip bundle restoration. - if len(refs) > 0 { - if err := mgr.restoreBundle(ctx, repo, step.BundlePath); err != nil { - return fmt.Errorf("manager: %w", err) + if err := mgr.restoreBundle(ctx, repo, step.BundlePath); err != nil { + if step.SkippableOnNotFound && errors.Is(err, ErrDoesntExist) { + // For compatibility with existing backups we need to make sure the + // repository exists even if there's no bundle for project + // repositories (not wiki or snippet repositories). Gitaly does + // not know which repository is which type so here we accept a + // parameter to tell us to employ this behaviour. Since the + // repository has already been created, we simply skip cleaning up. + if req.AlwaysCreate { + return nil + } + + if err := repo.Remove(ctx); err != nil { + return fmt.Errorf("manager: remove on skipped: %w", err) + } + + return fmt.Errorf("manager: %w: %s", ErrSkipped, err.Error()) } } if err := mgr.restoreCustomHooks(ctx, repo, step.CustomHooksPath); err != nil { @@ -411,31 +405,6 @@ func (mgr *Manager) negatedKnownRefs(ctx context.Context, step *Step) (io.ReadCl return r, nil } -func (mgr *Manager) readRefs(ctx context.Context, path string) ([]git.Reference, error) { - reader, err := mgr.sink.GetReader(ctx, path) - if err != nil { - return nil, fmt.Errorf("read refs: %w", err) - } - defer reader.Close() - - var refs []git.Reference - - d := git.NewShowRefDecoder(reader) - for { - var ref git.Reference - - if err := d.Decode(&ref); err == io.EOF { - break - } else if err != nil { - return refs, fmt.Errorf("read refs: %w", err) - } - - refs = append(refs, ref) - } - - return refs, nil -} - func (mgr *Manager) restoreBundle(ctx context.Context, repo Repository, path string) error { reader, err := mgr.sink.GetReader(ctx, path) if err != nil { diff --git a/internal/backup/backup_test.go b/internal/backup/backup_test.go index fb156d732..46a8e840d 100644 --- a/internal/backup/backup_test.go +++ b/internal/backup/backup_test.go @@ -433,8 +433,6 @@ func TestManager_Restore_latest(t *testing.T) { commitID := gittest.WriteCommit(t, cfg, repoPath, gittest.WithBranch("main")) gittest.WriteTag(t, cfg, repoPath, "v1.0.0", commitID.Revision()) repoChecksum := gittest.ChecksumRepo(t, cfg, repoPath) - repoBundle := gittest.BundleRepo(t, cfg, repoPath, "-") - repoRefs := gittest.Exec(t, cfg, "-C", repoPath, "show-ref", "--head") backupRoot := testhelper.TempDir(t) @@ -454,10 +452,9 @@ func TestManager_Restore_latest(t *testing.T) { repo, _ := gittest.CreateRepository(t, ctx, cfg) relativePath := stripRelativePath(tb, repo) - testhelper.WriteFiles(tb, backupRoot, map[string]any{ - relativePath + ".bundle": repoBundle, - relativePath + ".refs": repoRefs, - }) + require.NoError(tb, os.MkdirAll(filepath.Join(backupRoot, relativePath), perm.PublicDir)) + bundlePath := filepath.Join(backupRoot, relativePath+".bundle") + gittest.BundleRepo(tb, cfg, repoPath, bundlePath) return repo, repoChecksum }, @@ -470,13 +467,10 @@ func TestManager_Restore_latest(t *testing.T) { repo, _ := gittest.CreateRepository(t, ctx, cfg) relativePath := stripRelativePath(tb, repo) + bundlePath := filepath.Join(backupRoot, relativePath+".bundle") customHooksPath := filepath.Join(backupRoot, relativePath, "custom_hooks.tar") - testhelper.WriteFiles(tb, backupRoot, map[string]any{ - relativePath + ".bundle": repoBundle, - relativePath + ".refs": repoRefs, - }) - require.NoError(tb, os.MkdirAll(filepath.Join(backupRoot, relativePath), perm.PublicDir)) + gittest.BundleRepo(tb, cfg, repoPath, bundlePath) testhelper.CopyFile(tb, mustCreateCustomHooksArchive(t, ctx), customHooksPath) return repo, repoChecksum @@ -514,13 +508,13 @@ func TestManager_Restore_latest(t *testing.T) { repo, _ := gittest.CreateRepository(t, ctx, cfg) relativePath := stripRelativePath(tb, repo) - testhelper.WriteFiles(tb, backupRoot, map[string]any{ - relativePath + ".refs": "", - }) + refsPath := filepath.Join(backupRoot, relativePath+".refs") + require.NoError(tb, os.MkdirAll(filepath.Join(backupRoot, relativePath), perm.PublicDir)) + require.NoError(tb, os.WriteFile(refsPath, []byte{}, perm.SharedFile)) - return repo, new(git.Checksum) + return repo, nil }, - expectExists: true, + expectedErrAs: backup.ErrSkipped, }, { desc: "empty backup, always create", @@ -529,11 +523,11 @@ func TestManager_Restore_latest(t *testing.T) { repo, _ := gittest.CreateRepository(t, ctx, cfg) relativePath := stripRelativePath(tb, repo) - testhelper.WriteFiles(tb, backupRoot, map[string]any{ - relativePath + ".refs": "", - }) + refsPath := filepath.Join(backupRoot, relativePath+".refs") + require.NoError(tb, os.MkdirAll(filepath.Join(backupRoot, relativePath), perm.PublicDir)) + require.NoError(tb, os.WriteFile(refsPath, []byte{}, perm.SharedFile)) - return repo, new(git.Checksum) + return repo, nil }, alwaysCreate: true, expectExists: true, @@ -548,10 +542,9 @@ func TestManager_Restore_latest(t *testing.T) { } relativePath := stripRelativePath(tb, repo) - testhelper.WriteFiles(tb, backupRoot, map[string]any{ - relativePath + ".bundle": repoBundle, - relativePath + ".refs": repoRefs, - }) + require.NoError(tb, os.MkdirAll(filepath.Dir(filepath.Join(backupRoot, relativePath)), perm.PublicDir)) + bundlePath := filepath.Join(backupRoot, relativePath+".bundle") + gittest.BundleRepo(tb, cfg, repoPath, bundlePath) return repo, repoChecksum }, @@ -563,14 +556,13 @@ func TestManager_Restore_latest(t *testing.T) { setup: func(tb testing.TB) (*gitalypb.Repository, *git.Checksum) { const backupID = "abc123" repo, _ := gittest.CreateRepository(t, ctx, cfg) - - relativePath := stripRelativePath(tb, repo) - testhelper.WriteFiles(tb, backupRoot, map[string]any{ - filepath.Join(relativePath, "LATEST"): backupID, - filepath.Join(relativePath, backupID, "LATEST"): "001", - filepath.Join(relativePath, backupID, "001.bundle"): repoBundle, - filepath.Join(relativePath, backupID, "001.refs"): repoRefs, - }) + repoBackupPath := joinBackupPath(tb, backupRoot, repo) + backupPath := filepath.Join(repoBackupPath, backupID) + require.NoError(tb, os.MkdirAll(backupPath, perm.PublicDir)) + require.NoError(tb, os.WriteFile(filepath.Join(repoBackupPath, "LATEST"), []byte(backupID), perm.PublicFile)) + require.NoError(tb, os.WriteFile(filepath.Join(backupPath, "LATEST"), []byte("001"), perm.PublicFile)) + bundlePath := filepath.Join(backupPath, "001.bundle") + gittest.BundleRepo(tb, cfg, repoPath, bundlePath) return repo, repoChecksum }, @@ -582,13 +574,13 @@ func TestManager_Restore_latest(t *testing.T) { setup: func(tb testing.TB) (*gitalypb.Repository, *git.Checksum) { const backupID = "abc123" repo, _ := gittest.CreateRepository(t, ctx, cfg) - - relativePath := stripRelativePath(tb, repo) - testhelper.WriteFiles(tb, backupRoot, map[string]any{ - filepath.Join(relativePath, "LATEST"): backupID, - filepath.Join(relativePath, backupID, "LATEST"): "001", - filepath.Join(relativePath, backupID, "001.refs"): "", - }) + repoBackupPath := joinBackupPath(tb, backupRoot, repo) + backupPath := filepath.Join(repoBackupPath, backupID) + require.NoError(tb, os.MkdirAll(backupPath, perm.PublicDir)) + require.NoError(tb, os.WriteFile(filepath.Join(repoBackupPath, "LATEST"), []byte(backupID), perm.PublicFile)) + require.NoError(tb, os.WriteFile(filepath.Join(backupPath, "LATEST"), []byte("001"), perm.PublicFile)) + refsPath := filepath.Join(backupPath, "001.refs") + require.NoError(tb, os.WriteFile(refsPath, []byte{}, perm.SharedFile)) return repo, new(git.Checksum) }, @@ -603,6 +595,11 @@ func TestManager_Restore_latest(t *testing.T) { _, expectedRepoPath := gittest.CreateRepository(t, ctx, cfg) repo, _ := gittest.CreateRepository(t, ctx, cfg) + repoBackupPath := joinBackupPath(tb, backupRoot, repo) + backupPath := filepath.Join(repoBackupPath, backupID) + require.NoError(tb, os.MkdirAll(backupPath, perm.PublicDir)) + require.NoError(tb, os.WriteFile(filepath.Join(repoBackupPath, "LATEST"), []byte(backupID), perm.PublicFile)) + require.NoError(tb, os.WriteFile(filepath.Join(backupPath, "LATEST"), []byte("002"), perm.PublicFile)) root := gittest.WriteCommit(tb, cfg, expectedRepoPath, gittest.WithBranch("master"), @@ -616,35 +613,25 @@ func TestManager_Restore_latest(t *testing.T) { gittest.WithParents(root), ) gittest.Exec(tb, cfg, "-C", expectedRepoPath, "symbolic-ref", "HEAD", "refs/heads/master") - bundle1 := gittest.Exec(tb, cfg, "-C", expectedRepoPath, "bundle", "create", "-", + bundlePath1 := filepath.Join(backupPath, "001.bundle") + gittest.Exec(tb, cfg, "-C", expectedRepoPath, "bundle", "create", bundlePath1, "HEAD", "refs/heads/master", "refs/heads/other", ) - refs1 := gittest.Exec(t, cfg, "-C", expectedRepoPath, "show-ref", "--head") master2 := gittest.WriteCommit(tb, cfg, expectedRepoPath, gittest.WithBranch("master"), gittest.WithParents(master1), ) - bundle2 := gittest.Exec(tb, cfg, "-C", expectedRepoPath, "bundle", "create", "-", + bundlePath2 := filepath.Join(backupPath, "002.bundle") + gittest.Exec(tb, cfg, "-C", expectedRepoPath, "bundle", "create", bundlePath2, "HEAD", "^"+master1.String(), "^"+other.String(), "refs/heads/master", "refs/heads/other", ) - refs2 := gittest.Exec(t, cfg, "-C", expectedRepoPath, "show-ref", "--head") - - relativePath := stripRelativePath(tb, repo) - testhelper.WriteFiles(tb, backupRoot, map[string]any{ - filepath.Join(relativePath, "LATEST"): backupID, - filepath.Join(relativePath, backupID, "LATEST"): "002", - filepath.Join(relativePath, backupID, "001.bundle"): bundle1, - filepath.Join(relativePath, backupID, "002.bundle"): bundle2, - filepath.Join(relativePath, backupID, "001.refs"): refs1, - filepath.Join(relativePath, backupID, "002.refs"): refs2, - }) checksum := new(git.Checksum) checksum.Add(git.NewReference("HEAD", master2)) @@ -774,8 +761,6 @@ func TestManager_Restore_specific(t *testing.T) { commitID := gittest.WriteCommit(t, cfg, repoPath, gittest.WithBranch("main")) gittest.WriteTag(t, cfg, repoPath, "v1.0.0", commitID.Revision()) repoChecksum := gittest.ChecksumRepo(t, cfg, repoPath) - repoBundle := gittest.BundleRepo(t, cfg, repoPath, "-") - repoRefs := gittest.Exec(t, cfg, "-C", repoPath, "show-ref", "--head") backupRoot := testhelper.TempDir(t) @@ -791,14 +776,12 @@ func TestManager_Restore_specific(t *testing.T) { desc: "single incremental", setup: func(tb testing.TB) (*gitalypb.Repository, *git.Checksum) { repo, _ := gittest.CreateRepository(t, ctx, cfg) - - relativePath := stripRelativePath(tb, repo) - testhelper.WriteFiles(tb, backupRoot, map[string]any{ - filepath.Join(relativePath, "LATEST"): backupID, - filepath.Join(relativePath, backupID, "LATEST"): "001", - filepath.Join(relativePath, backupID, "001.bundle"): repoBundle, - filepath.Join(relativePath, backupID, "001.refs"): repoRefs, - }) + repoBackupPath := joinBackupPath(tb, backupRoot, repo) + backupPath := filepath.Join(repoBackupPath, backupID) + require.NoError(tb, os.MkdirAll(backupPath, perm.PublicDir)) + require.NoError(tb, os.WriteFile(filepath.Join(backupPath, "LATEST"), []byte("001"), perm.PublicFile)) + bundlePath := filepath.Join(backupPath, "001.bundle") + gittest.BundleRepo(tb, cfg, repoPath, bundlePath) return repo, repoChecksum }, @@ -810,6 +793,10 @@ func TestManager_Restore_specific(t *testing.T) { _, expectedRepoPath := gittest.CreateRepository(t, ctx, cfg) repo, _ := gittest.CreateRepository(t, ctx, cfg) + repoBackupPath := joinBackupPath(tb, backupRoot, repo) + backupPath := filepath.Join(repoBackupPath, backupID) + require.NoError(tb, os.MkdirAll(backupPath, perm.PublicDir)) + require.NoError(tb, os.WriteFile(filepath.Join(backupPath, "LATEST"), []byte("002"), perm.PublicFile)) root := gittest.WriteCommit(tb, cfg, expectedRepoPath, gittest.WithBranch("master"), @@ -823,35 +810,25 @@ func TestManager_Restore_specific(t *testing.T) { gittest.WithParents(root), ) gittest.Exec(tb, cfg, "-C", expectedRepoPath, "symbolic-ref", "HEAD", "refs/heads/master") - bundle1 := gittest.Exec(tb, cfg, "-C", expectedRepoPath, "bundle", "create", "-", + bundlePath1 := filepath.Join(backupPath, "001.bundle") + gittest.Exec(tb, cfg, "-C", expectedRepoPath, "bundle", "create", bundlePath1, "HEAD", "refs/heads/master", "refs/heads/other", ) - refs1 := gittest.Exec(t, cfg, "-C", expectedRepoPath, "show-ref", "--head") master2 := gittest.WriteCommit(tb, cfg, expectedRepoPath, gittest.WithBranch("master"), gittest.WithParents(master1), ) - bundle2 := gittest.Exec(tb, cfg, "-C", expectedRepoPath, "bundle", "create", "-", + bundlePath2 := filepath.Join(backupPath, "002.bundle") + gittest.Exec(tb, cfg, "-C", expectedRepoPath, "bundle", "create", bundlePath2, "HEAD", "^"+master1.String(), "^"+other.String(), "refs/heads/master", "refs/heads/other", ) - refs2 := gittest.Exec(t, cfg, "-C", expectedRepoPath, "show-ref", "--head") - - relativePath := stripRelativePath(tb, repo) - testhelper.WriteFiles(tb, backupRoot, map[string]any{ - filepath.Join(relativePath, "LATEST"): backupID, - filepath.Join(relativePath, backupID, "LATEST"): "002", - filepath.Join(relativePath, backupID, "001.bundle"): bundle1, - filepath.Join(relativePath, backupID, "002.bundle"): bundle2, - filepath.Join(relativePath, backupID, "001.refs"): refs1, - filepath.Join(relativePath, backupID, "002.refs"): refs2, - }) checksum := new(git.Checksum) checksum.Add(git.NewReference("HEAD", master2)) diff --git a/internal/backup/locator.go b/internal/backup/locator.go index f2897f2e0..6d1419489 100644 --- a/internal/backup/locator.go +++ b/internal/backup/locator.go @@ -61,9 +61,10 @@ func (l LegacyLocator) newFull(repo *gitalypb.Repository) *Step { backupPath := strings.TrimSuffix(repo.RelativePath, ".git") return &Step{ - BundlePath: backupPath + ".bundle", - RefPath: backupPath + ".refs", - CustomHooksPath: filepath.Join(backupPath, "custom_hooks.tar"), + SkippableOnNotFound: true, + BundlePath: backupPath + ".bundle", + RefPath: backupPath + ".refs", + CustomHooksPath: filepath.Join(backupPath, "custom_hooks.tar"), } } diff --git a/internal/backup/locator_test.go b/internal/backup/locator_test.go index 01534d368..bb30379fd 100644 --- a/internal/backup/locator_test.go +++ b/internal/backup/locator_test.go @@ -35,9 +35,10 @@ func TestLegacyLocator(t *testing.T) { t.Parallel() expected := &Step{ - BundlePath: repo.RelativePath + ".bundle", - RefPath: repo.RelativePath + ".refs", - CustomHooksPath: filepath.Join(repo.RelativePath, "custom_hooks.tar"), + SkippableOnNotFound: true, + BundlePath: repo.RelativePath + ".bundle", + RefPath: repo.RelativePath + ".refs", + CustomHooksPath: filepath.Join(repo.RelativePath, "custom_hooks.tar"), } full := l.BeginFull(ctx, repo, "abc123") @@ -53,9 +54,10 @@ func TestLegacyLocator(t *testing.T) { ObjectFormat: git.ObjectHashSHA1.Format, Steps: []Step{ { - BundlePath: repo.RelativePath + ".bundle", - RefPath: repo.RelativePath + ".refs", - CustomHooksPath: filepath.Join(repo.RelativePath, "custom_hooks.tar"), + SkippableOnNotFound: true, + BundlePath: repo.RelativePath + ".bundle", + RefPath: repo.RelativePath + ".refs", + CustomHooksPath: filepath.Join(repo.RelativePath, "custom_hooks.tar"), }, }, } @@ -236,9 +238,10 @@ func TestPointerLocator(t *testing.T) { ObjectFormat: git.ObjectHashSHA1.Format, Steps: []Step{ { - BundlePath: repo.RelativePath + ".bundle", - RefPath: repo.RelativePath + ".refs", - CustomHooksPath: filepath.Join(repo.RelativePath, "custom_hooks.tar"), + SkippableOnNotFound: true, + BundlePath: repo.RelativePath + ".bundle", + RefPath: repo.RelativePath + ".refs", + CustomHooksPath: filepath.Join(repo.RelativePath, "custom_hooks.tar"), }, }, } diff --git a/internal/backup/server_side_test.go b/internal/backup/server_side_test.go index 3329c8a78..fc5e990ac 100644 --- a/internal/backup/server_side_test.go +++ b/internal/backup/server_side_test.go @@ -1,5 +1,3 @@ -//go:build !gitaly_test_sha256 - package backup_test import ( @@ -194,7 +192,7 @@ func TestServerSideAdapter_Restore(t *testing.T) { backupID: "", } }, - expectedErr: fmt.Errorf("server-side restore: %w: rpc error: code = FailedPrecondition desc = restore repository: manager: repository skipped: read refs: doesn't exist", backup.ErrSkipped), + expectedErr: fmt.Errorf("server-side restore: %w: rpc error: code = FailedPrecondition desc = restore repository: manager: repository skipped: restore bundle: \"@test/restore/latest/missing.bundle\": doesn't exist", backup.ErrSkipped), }, } { tc := tc diff --git a/internal/gitaly/service/repository/restore_repository_test.go b/internal/gitaly/service/repository/restore_repository_test.go index 2551ffeb7..df0043a69 100644 --- a/internal/gitaly/service/repository/restore_repository_test.go +++ b/internal/gitaly/service/repository/restore_repository_test.go @@ -138,7 +138,7 @@ func TestRestoreRepository(t *testing.T) { backupID: "", } }, - expectedErr: structerr.NewFailedPrecondition("restore repository: manager: repository skipped: read refs: doesn't exist").WithDetail( + expectedErr: structerr.NewFailedPrecondition("restore repository: manager: repository skipped: restore bundle: \"@test/restore/latest/missing.bundle\": doesn't exist").WithDetail( &gitalypb.RestoreRepositoryResponse_SkippedError{}, ), }, diff --git a/internal/testhelper/testhelper.go b/internal/testhelper/testhelper.go index d4a8bfeb7..17b511bc4 100644 --- a/internal/testhelper/testhelper.go +++ b/internal/testhelper/testhelper.go @@ -76,39 +76,6 @@ func MustReadFile(tb testing.TB, filename string) []byte { return content } -// WriteFiles writes a map of files to the filesystem where the map key is the -// filename relative to root and the value is one of string, []byte or -// io.Reader. -func WriteFiles(tb testing.TB, root string, files map[string]any) { - tb.Helper() - - require.DirExists(tb, root) - - for name, value := range files { - path := filepath.Join(root, name) - - require.NoError(tb, os.MkdirAll(filepath.Dir(path), perm.SharedDir)) - - switch content := value.(type) { - case string: - require.NoError(tb, os.WriteFile(path, []byte(content), perm.PublicFile)) - case []byte: - require.NoError(tb, os.WriteFile(path, content, perm.PublicFile)) - case io.Reader: - func() { - f, err := os.Create(path) - require.NoError(tb, err) - defer MustClose(tb, f) - - _, err = io.Copy(f, content) - require.NoError(tb, err) - }() - default: - tb.Fatalf("WriteFiles: %q: unsupported file content type %T", path, value) - } - } -} - // GitlabTestStoragePath returns the storage path to the gitlab-test repo. func GitlabTestStoragePath() string { if testDirectory == "" { |