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 65 66 67
|
package localrepo
import (
"os"
"path/filepath"
"strings"
"gitlab.com/gitlab-org/gitaly/v16/internal/gitaly/storage"
"gitlab.com/gitlab-org/gitaly/v16/internal/structerr"
)
// Path returns the on-disk path of the repository.
func (repo *Repo) Path() (string, error) {
return repo.locator.GetRepoPath(repo)
}
// ObjectDirectoryPath returns the full path of the object directory. The errors returned are gRPC
// errors with relevant error codes and should be passed back to gRPC without further decoration.
func (repo *Repo) ObjectDirectoryPath() (string, error) {
repoPath, err := repo.Path()
if err != nil {
return "", err
}
objectDirectoryPath := repo.GetGitObjectDirectory()
if objectDirectoryPath == "" {
return "", structerr.NewInvalidArgument("object directory path is not set")
}
// We need to check whether the relative object directory as given by the repository is
// a valid path. This may either be a path in the Git repository itself, where it may either
// point to the main object directory storage or to an object quarantine directory as
// created by git-receive-pack(1). Alternatively, if that is not the case, then it may be a
// manual object quarantine directory located in the storage's temporary directory. These
// have a repository-specific prefix which we must check in order to determine whether the
// quarantine directory does in fact belong to the repo at hand.
if _, origError := storage.ValidateRelativePath(repoPath, objectDirectoryPath); origError != nil {
tempDir, err := repo.locator.TempDir(repo.GetStorageName())
if err != nil {
return "", structerr.NewInvalidArgument("getting storage's temporary directory: %w", err)
}
expectedQuarantinePrefix := filepath.Join(tempDir, storage.QuarantineDirectoryPrefix(repo))
absoluteObjectDirectoryPath := filepath.Join(repoPath, objectDirectoryPath)
if !strings.HasPrefix(absoluteObjectDirectoryPath, expectedQuarantinePrefix) {
return "", structerr.NewInvalidArgument("not a valid relative path: %w", origError)
}
}
fullPath := filepath.Join(repoPath, objectDirectoryPath)
if _, err := os.Stat(fullPath); os.IsNotExist(err) {
return "", structerr.NewNotFound("object directory does not exist: %q", fullPath)
}
return fullPath, nil
}
// InfoAlternatesPath returns the full path of the alternates file.
func (repo *Repo) InfoAlternatesPath() (string, error) {
repoPath, err := repo.Path()
if err != nil {
return "", err
}
return filepath.Join(repoPath, "objects", "info", "alternates"), nil
}
|