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:
authorAlejandro Rodríguez <alejorro70@gmail.com>2018-08-16 18:01:54 +0300
committerAlejandro Rodríguez <alejorro70@gmail.com>2018-08-16 18:01:54 +0300
commit7b334395c9cd6a6257a5d93c00e365d326531bc0 (patch)
tree484f7d1593fcf07475fa77360df46ca235ae0969
parentc95257b6f82930ad4e6cbfd4fa8da332d2ac67d5 (diff)
parent94f69de913a2b64f30c923989bf904365c15c40b (diff)
Merge branch 'zj-head-lokc' into 'master'
Remove stale HEAD.lock if it exists Closes gitlab-ce#50042 See merge request gitlab-org/gitaly!861
-rw-r--r--changelogs/unreleased/zj-head-lokc.yml5
-rw-r--r--internal/service/repository/cleanup.go28
-rw-r--r--internal/service/repository/cleanup_test.go36
3 files changed, 40 insertions, 29 deletions
diff --git a/changelogs/unreleased/zj-head-lokc.yml b/changelogs/unreleased/zj-head-lokc.yml
new file mode 100644
index 000000000..d2078fadf
--- /dev/null
+++ b/changelogs/unreleased/zj-head-lokc.yml
@@ -0,0 +1,5 @@
+---
+title: Remove stale HEAD.lock if it exists
+merge_request: 861
+author:
+type: fixed
diff --git a/internal/service/repository/cleanup.go b/internal/service/repository/cleanup.go
index 571cf2059..9f076316c 100644
--- a/internal/service/repository/cleanup.go
+++ b/internal/service/repository/cleanup.go
@@ -15,6 +15,8 @@ import (
"gitlab.com/gitlab-org/gitaly/internal/helper"
)
+var lockFiles = []string{"config.lock", "HEAD.lock"}
+
func (server) Cleanup(_ctx context.Context, in *pb.CleanupRequest) (*pb.CleanupResponse, error) {
repoPath, err := helper.GetRepoPath(in.GetRepository())
if err != nil {
@@ -43,7 +45,7 @@ func cleanupRepo(repoPath string) error {
}
configLockThreshod := time.Now().Add(-15 * time.Minute)
- if err := cleanupConfigLock(repoPath, configLockThreshod); err != nil {
+ if err := cleanFileLocks(repoPath, configLockThreshod); err != nil {
return status.Errorf(codes.Internal, "Cleanup: cleanupConfigLock: %v", err)
}
@@ -127,20 +129,22 @@ func cleanStaleWorktrees(repoPath string, threshold time.Time) error {
return nil
}
-func cleanupConfigLock(repoPath string, threshold time.Time) error {
- configLockPath := filepath.Join(repoPath, "config.lock")
+func cleanFileLocks(repoPath string, threshold time.Time) error {
+ for _, fileName := range lockFiles {
+ lockPath := filepath.Join(repoPath, fileName)
- fi, err := os.Stat(configLockPath)
- if err != nil {
- if os.IsNotExist(err) {
- return nil
+ fi, err := os.Stat(lockPath)
+ if err != nil {
+ if os.IsNotExist(err) {
+ continue
+ }
+ return err
}
- return err
- }
- if fi.ModTime().Before(threshold) {
- if err := os.Remove(configLockPath); err != nil && !os.IsNotExist(err) {
- return err
+ if fi.ModTime().Before(threshold) {
+ if err := os.Remove(lockPath); err != nil && !os.IsNotExist(err) {
+ return err
+ }
}
}
diff --git a/internal/service/repository/cleanup_test.go b/internal/service/repository/cleanup_test.go
index 6db127de5..0a24cf767 100644
--- a/internal/service/repository/cleanup_test.go
+++ b/internal/service/repository/cleanup_test.go
@@ -186,7 +186,7 @@ func TestCleanupDeletesStaleWorktrees(t *testing.T) {
}
}
-func TestCleanupConfigLocks(t *testing.T) {
+func TestCleanupFileLocks(t *testing.T) {
server, serverSocketPath := runRepoServer(t)
defer server.Stop()
@@ -200,21 +200,23 @@ func TestCleanupConfigLocks(t *testing.T) {
defer cancel()
req := &pb.CleanupRequest{Repository: testRepo}
- lockPath := filepath.Join(testRepoPath, "config.lock")
- // No file on the lock path
- _, err := client.Cleanup(ctx, req)
- assert.NoError(t, err)
-
- // Fresh lock should remain
- createFileWithTimes(lockPath, freshTime)
- _, err = client.Cleanup(ctx, req)
- assert.NoError(t, err)
- assert.FileExists(t, lockPath)
-
- // Old lock should be removed
- createFileWithTimes(lockPath, oldTime)
- _, err = client.Cleanup(ctx, req)
- assert.NoError(t, err)
- testhelper.AssertFileNotExists(t, lockPath)
+ for _, fileName := range lockFiles {
+ lockPath := filepath.Join(testRepoPath, fileName)
+ // No file on the lock path
+ _, err := client.Cleanup(ctx, req)
+ assert.NoError(t, err)
+
+ // Fresh lock should remain
+ createFileWithTimes(lockPath, freshTime)
+ _, err = client.Cleanup(ctx, req)
+ assert.NoError(t, err)
+ assert.FileExists(t, lockPath)
+
+ // Old lock should be removed
+ createFileWithTimes(lockPath, oldTime)
+ _, err = client.Cleanup(ctx, req)
+ assert.NoError(t, err)
+ testhelper.AssertFileNotExists(t, lockPath)
+ }
}