diff options
author | Toon Claes <toon@gitlab.com> | 2021-07-30 09:39:31 +0300 |
---|---|---|
committer | Toon Claes <toon@gitlab.com> | 2021-07-30 09:39:31 +0300 |
commit | 62df8b573693651703266fc487ee9448ab276671 (patch) | |
tree | 42bd93abc97eec82a5ce2b04420b5cf524de56ba | |
parent | 9b1bdfc5d16fe86d42a7ccde30a29d6a71267537 (diff) |
repository: Move worktree helper functions
The `IsRebaseInProgress` RPC is no longer used, so we'd like to remove
it. But it shares some functionality with `IsSquashInProgress`.
This change moves those functions/constants to another file, so we can
later remove the `IsRebaseInProgress` handling simply by dropping the
whole file.
-rw-r--r-- | internal/gitaly/service/repository/rebase_in_progress.go | 27 | ||||
-rw-r--r-- | internal/gitaly/service/repository/squash_in_progress.go | 27 |
2 files changed, 27 insertions, 27 deletions
diff --git a/internal/gitaly/service/repository/rebase_in_progress.go b/internal/gitaly/service/repository/rebase_in_progress.go index d6e4c855e..69db5c8a0 100644 --- a/internal/gitaly/service/repository/rebase_in_progress.go +++ b/internal/gitaly/service/repository/rebase_in_progress.go @@ -3,21 +3,15 @@ package repository import ( "context" "fmt" - "os" - "path/filepath" "strings" - "time" - "gitlab.com/gitlab-org/gitaly/v14/internal/git/housekeeping" "gitlab.com/gitlab-org/gitaly/v14/proto/go/gitalypb" "google.golang.org/grpc/codes" "google.golang.org/grpc/status" ) const ( - worktreePrefix = "gitlab-worktree" rebaseWorktreePrefix = "rebase" - freshTimeout = 15 * time.Minute ) func (s *server) IsRebaseInProgress(ctx context.Context, req *gitalypb.IsRebaseInProgressRequest) (*gitalypb.IsRebaseInProgressResponse, error) { @@ -37,27 +31,6 @@ func (s *server) IsRebaseInProgress(ctx context.Context, req *gitalypb.IsRebaseI return &gitalypb.IsRebaseInProgressResponse{InProgress: inProg}, nil } -func freshWorktree(ctx context.Context, repoPath, prefix, id string) (bool, error) { - worktreePath := filepath.Join(repoPath, worktreePrefix, fmt.Sprintf("%s-%s", prefix, id)) - - fs, err := os.Stat(worktreePath) - if err != nil { - return false, nil - } - - if time.Since(fs.ModTime()) > freshTimeout { - if err = os.RemoveAll(worktreePath); err != nil { - if err = housekeeping.FixDirectoryPermissions(ctx, worktreePath); err != nil { - return false, err - } - err = os.RemoveAll(worktreePath) - } - return false, err - } - - return true, nil -} - func validateIsRebaseInProgressRequest(req *gitalypb.IsRebaseInProgressRequest) error { if req.GetRepository() == nil { return fmt.Errorf("empty Repository") diff --git a/internal/gitaly/service/repository/squash_in_progress.go b/internal/gitaly/service/repository/squash_in_progress.go index 00711e75f..b362379d8 100644 --- a/internal/gitaly/service/repository/squash_in_progress.go +++ b/internal/gitaly/service/repository/squash_in_progress.go @@ -3,15 +3,21 @@ package repository import ( "context" "fmt" + "os" + "path/filepath" "strings" + "time" + "gitlab.com/gitlab-org/gitaly/v14/internal/git/housekeeping" "gitlab.com/gitlab-org/gitaly/v14/proto/go/gitalypb" "google.golang.org/grpc/codes" "google.golang.org/grpc/status" ) const ( + worktreePrefix = "gitlab-worktree" squashWorktreePrefix = "squash" + freshTimeout = 15 * time.Minute ) func (s *server) IsSquashInProgress(ctx context.Context, req *gitalypb.IsSquashInProgressRequest) (*gitalypb.IsSquashInProgressResponse, error) { @@ -46,3 +52,24 @@ func validateIsSquashInProgressRequest(req *gitalypb.IsSquashInProgressRequest) return nil } + +func freshWorktree(ctx context.Context, repoPath, prefix, id string) (bool, error) { + worktreePath := filepath.Join(repoPath, worktreePrefix, fmt.Sprintf("%s-%s", prefix, id)) + + fs, err := os.Stat(worktreePath) + if err != nil { + return false, nil + } + + if time.Since(fs.ModTime()) > freshTimeout { + if err = os.RemoveAll(worktreePath); err != nil { + if err = housekeeping.FixDirectoryPermissions(ctx, worktreePath); err != nil { + return false, err + } + err = os.RemoveAll(worktreePath) + } + return false, err + } + + return true, nil +} |