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

create.go « objectpool « service « gitaly « internal - gitlab.com/gitlab-org/gitaly.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: feb25c22bd429c4cef038c2d17d3eb06379a2089 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
package objectpool

import (
	"context"
	"gitlab.com/gitlab-org/gitaly/v15/structerr"

	"gitlab.com/gitlab-org/gitaly/proto/v15/go/gitalypb"
	"gitlab.com/gitlab-org/gitaly/v15/internal/git/objectpool"
	"gitlab.com/gitlab-org/gitaly/v15/internal/git/stats"
	"gitlab.com/gitlab-org/gitaly/v15/internal/gitaly/repoutil"
	"google.golang.org/grpc/codes"
)

// errMissingOriginRepository is returned when the request is missing the
// origin repository.
var errMissingOriginRepository = structerr.NewInvalidArgument("no origin repository")

func (s *server) CreateObjectPool(ctx context.Context, in *gitalypb.CreateObjectPoolRequest) (*gitalypb.CreateObjectPoolResponse, error) {
	if in.GetOrigin() == nil {
		return nil, errMissingOriginRepository
	}

	poolRepo := in.GetObjectPool().GetRepository()
	if poolRepo == nil {
		return nil, errMissingPool
	}

	if !stats.IsPoolRepository(poolRepo) {
		return nil, errInvalidPoolDir
	}

	if err := repoutil.Create(ctx, s.locator, s.gitCmdFactory, s.txManager, poolRepo, func(poolRepo *gitalypb.Repository) error {
		if _, err := objectpool.Create(
			ctx,
			s.locator,
			s.gitCmdFactory,
			s.catfileCache,
			s.txManager,
			s.housekeepingManager,
			&gitalypb.ObjectPool{
				Repository: poolRepo,
			},
			s.localrepo(in.GetOrigin()),
		); err != nil {
			return err
		}

		return nil
	}, repoutil.WithSkipInit()); err != nil {
		err := structerr.New("creating object pool: %w", err)

		// This is really ugly: Rails expects a FailedPrecondition error code in its
		// rspecs, but `repoutil.Create()` returns `AlreadyExists` instead. So in
		// case we see that error code we override it. We should eventually fix this
		// and instead use something like structured errors.
		if err.Code() == codes.AlreadyExists {
			err = err.WithGRPCCode(codes.FailedPrecondition)
		}

		return nil, err
	}

	return &gitalypb.CreateObjectPoolResponse{}, nil
}