diff options
Diffstat (limited to 'internal/service/repository/replicate.go')
-rw-r--r-- | internal/service/repository/replicate.go | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/internal/service/repository/replicate.go b/internal/service/repository/replicate.go index 9d0d23300..ef09b9792 100644 --- a/internal/service/repository/replicate.go +++ b/internal/service/repository/replicate.go @@ -23,6 +23,10 @@ import ( "google.golang.org/grpc" ) +const ( + replicationLockFileName = "replication.lock" +) + func (s *server) ReplicateRepository(ctx context.Context, in *gitalypb.ReplicateRepositoryRequest) (*gitalypb.ReplicateRepositoryResponse, error) { if err := validateReplicateRepository(in); err != nil { return nil, helper.ErrInvalidArgument(err) @@ -37,6 +41,21 @@ func (s *server) ReplicateRepository(ctx context.Context, in *gitalypb.Replicate return nil, helper.ErrInternal(err) } + // hold lockfile + lockfilePath := filepath.Join(repoPath, replicationLockFileName) + lockFile, err := os.OpenFile(lockfilePath, os.O_EXCL|os.O_CREATE, 0) + if err != nil { + if os.IsExist(err) { + return &gitalypb.ReplicateRepositoryResponse{}, nil + } + return nil, helper.ErrInternal(err) + } + + defer func() { + os.Remove(lockfilePath) + lockFile.Close() + }() + if helper.IsGitDirectory(repoPath) { syncFuncs = append(syncFuncs, s.syncRepository) } else { |