Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitaly.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJames Fargher <jfargher@gitlab.com>2023-05-26 02:00:05 +0300
committerJames Fargher <jfargher@gitlab.com>2023-06-01 03:52:26 +0300
commitc05ac06f41c49fe565563294a99e17f952c00990 (patch)
tree81f1260dbabc203b4cc6cf4254a9e04b33acbeac
parent39e8de2e186786070c33b8c2b38091262b4e135e (diff)
backup: Implement set custom hooks on backup.Repository
In preparation for server-side backup restores here we extract the RPC implementation of set custom hooks and additionally add a local implementation.
-rw-r--r--internal/backup/backup.go33
-rw-r--r--internal/backup/repository.go43
2 files changed, 48 insertions, 28 deletions
diff --git a/internal/backup/backup.go b/internal/backup/backup.go
index 7dc52ed64..544d92710 100644
--- a/internal/backup/backup.go
+++ b/internal/backup/backup.go
@@ -14,7 +14,6 @@ import (
"gitlab.com/gitlab-org/gitaly/v16/internal/gitaly/storage"
"gitlab.com/gitlab-org/gitaly/v16/internal/gitaly/transaction"
"gitlab.com/gitlab-org/gitaly/v16/proto/go/gitalypb"
- "gitlab.com/gitlab-org/gitaly/v16/streamio"
"google.golang.org/protobuf/proto"
)
@@ -90,6 +89,8 @@ type Repository interface {
// FetchBundle fetches references from a bundle. Refs will be mirrored to
// the repository.
FetchBundle(ctx context.Context, reader io.Reader) error
+ // SetCustomHooks updates the custom hooks for the repository.
+ SetCustomHooks(ctx context.Context, reader io.Reader) error
}
// ResolveLocator returns a locator implementation based on a locator identifier.
@@ -298,7 +299,7 @@ func (mgr *Manager) Restore(ctx context.Context, req *RestoreRequest) error {
return fmt.Errorf("manager: %w: %s", ErrSkipped, err.Error())
}
}
- if err := mgr.restoreCustomHooks(ctx, step.CustomHooksPath, req.Server, req.Repository); err != nil {
+ if err := mgr.restoreCustomHooks(ctx, repo, step.CustomHooksPath); err != nil {
return fmt.Errorf("manager: %w", err)
}
}
@@ -456,7 +457,7 @@ func (mgr *Manager) writeCustomHooks(ctx context.Context, repo Repository, path
return nil
}
-func (mgr *Manager) restoreCustomHooks(ctx context.Context, path string, server storage.ServerInfo, repo *gitalypb.Repository) error {
+func (mgr *Manager) restoreCustomHooks(ctx context.Context, repo Repository, path string) error {
reader, err := mgr.sink.GetReader(ctx, path)
if err != nil {
if errors.Is(err, ErrDoesntExist) {
@@ -466,31 +467,7 @@ func (mgr *Manager) restoreCustomHooks(ctx context.Context, path string, server
}
defer reader.Close()
- repoClient, err := mgr.newRepoClient(ctx, server)
- if err != nil {
- return fmt.Errorf("restore custom hooks, %q: %w", path, err)
- }
- stream, err := repoClient.SetCustomHooks(ctx)
- if err != nil {
- return fmt.Errorf("restore custom hooks, %q: %w", path, err)
- }
-
- request := &gitalypb.SetCustomHooksRequest{Repository: repo}
- bundle := streamio.NewWriter(func(p []byte) error {
- request.Data = p
- if err := stream.Send(request); err != nil {
- return err
- }
-
- // Only set `Repository` on the first `Send` of the stream
- request = &gitalypb.SetCustomHooksRequest{}
-
- return nil
- })
- if _, err := io.Copy(bundle, reader); err != nil {
- return fmt.Errorf("restore custom hooks, %q: %w", path, err)
- }
- if _, err = stream.CloseAndRecv(); err != nil {
+ if err := repo.SetCustomHooks(ctx, reader); err != nil {
return fmt.Errorf("restore custom hooks, %q: %w", path, err)
}
return nil
diff --git a/internal/backup/repository.go b/internal/backup/repository.go
index d000baee9..957c4b64d 100644
--- a/internal/backup/repository.go
+++ b/internal/backup/repository.go
@@ -203,6 +203,35 @@ func (rr *remoteRepository) FetchBundle(ctx context.Context, reader io.Reader) e
return nil
}
+// SetCustomHooks updates the custom hooks for the repository.
+func (rr *remoteRepository) SetCustomHooks(ctx context.Context, reader io.Reader) error {
+ repoClient := rr.newRepoClient()
+ stream, err := repoClient.SetCustomHooks(ctx)
+ if err != nil {
+ return fmt.Errorf("remote repository: set custom hooks: %w", err)
+ }
+
+ request := &gitalypb.SetCustomHooksRequest{Repository: rr.repo}
+ bundle := streamio.NewWriter(func(p []byte) error {
+ request.Data = p
+ if err := stream.Send(request); err != nil {
+ return err
+ }
+
+ // Only set `Repository` on the first `Send` of the stream
+ request = &gitalypb.SetCustomHooksRequest{}
+
+ return nil
+ })
+ if _, err := io.Copy(bundle, reader); err != nil {
+ return fmt.Errorf("remote repository: set custom hooks: %w", err)
+ }
+ if _, err = stream.CloseAndRecv(); err != nil {
+ return fmt.Errorf("remote repository: set custom hooks: %w", err)
+ }
+ return nil
+}
+
func (rr *remoteRepository) newRepoClient() gitalypb.RepositoryServiceClient {
return gitalypb.NewRepositoryServiceClient(rr.conn)
}
@@ -333,3 +362,17 @@ func (r *localRepository) FetchBundle(ctx context.Context, reader io.Reader) err
}
return nil
}
+
+// SetCustomHooks updates the custom hooks for the repository.
+func (r *localRepository) SetCustomHooks(ctx context.Context, reader io.Reader) error {
+ if err := repoutil.SetCustomHooks(
+ ctx,
+ r.locator,
+ r.txManager,
+ reader,
+ r.repo,
+ ); err != nil {
+ return fmt.Errorf("local repository: set custom hooks: %w", err)
+ }
+ return nil
+}