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:
authorPatrick Steinhardt <psteinhardt@gitlab.com>2021-07-26 12:32:09 +0300
committerPatrick Steinhardt <psteinhardt@gitlab.com>2021-07-26 13:15:02 +0300
commit0663898ba5ba01894c7cbbdc38609edc02ed320b (patch)
tree3ac3407a526a068979124a00e1e24f680f305cef
parentbf55b6fc1a0c9bba1e9d1af29cf4ccab168d30e0 (diff)
repository: Allow voting on missing config
While not likely, it could be that a repository is missing a gitconfig due to whatever reason. While we can mostly cope with it just fine, in the context of transactional voting it would mean that voting fails because we cannot retrieve the file's contents to compute the vote. Fix this issue by handling the case where the config doesn't exist via a constructed vote on an artificial value. Changelog: fixed
-rw-r--r--internal/gitaly/service/repository/config.go27
1 files changed, 16 insertions, 11 deletions
diff --git a/internal/gitaly/service/repository/config.go b/internal/gitaly/service/repository/config.go
index bfa69123e..452eabb82 100644
--- a/internal/gitaly/service/repository/config.go
+++ b/internal/gitaly/service/repository/config.go
@@ -192,19 +192,24 @@ func (s *server) voteOnConfig(ctx context.Context, repo *gitalypb.Repository) er
return fmt.Errorf("get repo path: %w", err)
}
- config, err := os.Open(filepath.Join(repoPath, "config"))
- if err != nil {
- return fmt.Errorf("open repo config: %w", err)
- }
+ var vote voting.Vote
- hash := voting.NewVoteHash()
- if _, err := io.Copy(hash, config); err != nil {
- return fmt.Errorf("seeding vote: %w", err)
- }
+ config, err := os.Open(filepath.Join(repoPath, "config"))
+ switch {
+ case err == nil:
+ hash := voting.NewVoteHash()
+ if _, err := io.Copy(hash, config); err != nil {
+ return fmt.Errorf("seeding vote: %w", err)
+ }
- vote, err := hash.Vote()
- if err != nil {
- return fmt.Errorf("computing vote: %w", err)
+ vote, err = hash.Vote()
+ if err != nil {
+ return fmt.Errorf("computing vote: %w", err)
+ }
+ case os.IsNotExist(err):
+ vote = voting.VoteFromData([]byte("notfound"))
+ default:
+ return fmt.Errorf("open repo config: %w", err)
}
if err := s.txManager.Vote(ctx, tx, vote); err != nil {