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

walkrepos.go « praefect « internal - gitlab.com/gitlab-org/gitaly.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 1f321a4c7dfb54630788b8d914deed2b12543817 (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
package praefect

import (
	"fmt"

	"gitlab.com/gitlab-org/gitaly/v16/internal/gitaly/storage"
	"gitlab.com/gitlab-org/gitaly/v16/internal/praefect/datastore"
	"gitlab.com/gitlab-org/gitaly/v16/internal/structerr"
	"gitlab.com/gitlab-org/gitaly/v16/proto/go/gitalypb"
	"google.golang.org/grpc"
)

// WalkReposHandler implements an interceptor for the WalkRepos RPC, invoked when calling
// through Praefect. Instead of walking the storage directory in the filesystem, this Praefect
// implementation queries the database for all known repositories in the given virtual storage.
// As a consequence, the modification_time parameter can't be populated in the response.
func WalkReposHandler(rs datastore.RepositoryStore) grpc.StreamHandler {
	return func(srv interface{}, stream grpc.ServerStream) error {
		sendRepo := func(relPath string) error {
			return stream.SendMsg(&gitalypb.WalkReposResponse{
				RelativePath: relPath,
			})
		}

		var req gitalypb.WalkReposRequest
		if err := stream.RecvMsg(&req); err != nil {
			return fmt.Errorf("receive request: %w", err)
		}

		if req.StorageName == "" {
			return structerr.NewInvalidArgument("%w", storage.ErrStorageNotSet)
		}

		repos, err := rs.ListRepositoryPaths(stream.Context(), req.StorageName)
		if err != nil {
			return structerr.NewInternal("list repository paths: %w", err)
		}

		for _, repo := range repos {
			if err := sendRepo(repo); err != nil {
				return structerr.NewInternal("send repository path: %w", err)
			}
		}

		return nil
	}
}