blob: c4c000f70cf3ae2cf34453b91a4e440ab91f51fc (
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
|
package helper
import (
"os"
"path"
"gitlab.com/gitlab-org/gitaly/internal/config"
pb "gitlab.com/gitlab-org/gitaly-proto/go"
"google.golang.org/grpc"
"google.golang.org/grpc/codes"
)
// GetRepoPath returns the full path of the repository referenced by an
// RPC Repository message. The errors returned are gRPC errors with
// relevant error codes and should be passed back to gRPC without further
// decoration.
func GetRepoPath(repo *pb.Repository) (string, error) {
var repoPath string
if storagePath, ok := config.StoragePath(repo.GetStorageName()); ok {
repoPath = path.Join(storagePath, repo.GetRelativePath())
} else {
repoPath = repo.GetPath()
}
if repoPath == "" {
return "", grpc.Errorf(codes.InvalidArgument, "GetRepoPath: empty repo")
}
if _, err := os.Stat(path.Join(repoPath, "objects")); err != nil {
return "", grpc.Errorf(codes.NotFound, "GetRepoPath: not a git repository '%s'", repoPath)
}
return repoPath, nil
}
|