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-09-01 12:09:53 +0300
committerPatrick Steinhardt <psteinhardt@gitlab.com>2021-09-08 12:32:34 +0300
commit8b2e73ee1fe8f69f47872f8616fa133d4901b3bd (patch)
tree73c4cd60ab1024bf9b310b8ca39a4c57aa3f07c9 /internal/gitaly/service/repository/apply_gitattributes.go
parenta05a8088627e3e5d4902676dc06af345559b20cb (diff)
repository: Use proper locking semantics to update gitattributes
Use proper locking semantics to update gitattributes in a race-free manner. Changelog: fixed
Diffstat (limited to 'internal/gitaly/service/repository/apply_gitattributes.go')
-rw-r--r--internal/gitaly/service/repository/apply_gitattributes.go33
1 files changed, 28 insertions, 5 deletions
diff --git a/internal/gitaly/service/repository/apply_gitattributes.go b/internal/gitaly/service/repository/apply_gitattributes.go
index 818a45866..a26b1cc14 100644
--- a/internal/gitaly/service/repository/apply_gitattributes.go
+++ b/internal/gitaly/service/repository/apply_gitattributes.go
@@ -12,7 +12,10 @@ import (
"github.com/grpc-ecosystem/go-grpc-middleware/logging/logrus/ctxlogrus"
"gitlab.com/gitlab-org/gitaly/v14/internal/git"
"gitlab.com/gitlab-org/gitaly/v14/internal/git/catfile"
+ "gitlab.com/gitlab-org/gitaly/v14/internal/gitaly/transaction"
"gitlab.com/gitlab-org/gitaly/v14/internal/helper"
+ "gitlab.com/gitlab-org/gitaly/v14/internal/metadata/featureflag"
+ "gitlab.com/gitlab-org/gitaly/v14/internal/safe"
"gitlab.com/gitlab-org/gitaly/v14/internal/transaction/txinfo"
"gitlab.com/gitlab-org/gitaly/v14/internal/transaction/voting"
"gitlab.com/gitlab-org/gitaly/v14/proto/go/gitalypb"
@@ -58,6 +61,31 @@ func (s *server) applyGitattributes(ctx context.Context, c catfile.Batch, repoPa
return err
}
+ blobObj, err := c.Blob(ctx, git.Revision(blobInfo.Oid))
+ if err != nil {
+ return err
+ }
+
+ if featureflag.TxFileLocking.IsEnabled(ctx) {
+ writer, err := safe.NewLockingFileWriter(attributesPath, safe.LockingFileWriterConfig{
+ FileWriterConfig: safe.FileWriterConfig{FileMode: attributesFileMode},
+ })
+ if err != nil {
+ return fmt.Errorf("creating gitattributes writer: %w", err)
+ }
+ defer writer.Close()
+
+ if _, err := io.CopyN(writer, blobObj.Reader, blobInfo.Size); err != nil {
+ return err
+ }
+
+ if err := transaction.CommitLockedFile(ctx, s.txManager, writer); err != nil {
+ return fmt.Errorf("committing gitattributes: %w", err)
+ }
+
+ return nil
+ }
+
tempFile, err := ioutil.TempFile(infoPath, "attributes")
if err != nil {
return helper.ErrInternalf("creating temporary gitattributes file: %w", err)
@@ -68,11 +96,6 @@ func (s *server) applyGitattributes(ctx context.Context, c catfile.Batch, repoPa
}
}()
- blobObj, err := c.Blob(ctx, git.Revision(blobInfo.Oid))
- if err != nil {
- return err
- }
-
// Write attributes to temp file
if _, err := io.CopyN(tempFile, blobObj.Reader, blobInfo.Size); err != nil {
return err