diff options
author | James Fargher <jfargher@gitlab.com> | 2023-09-19 23:28:53 +0300 |
---|---|---|
committer | James Fargher <jfargher@gitlab.com> | 2023-09-20 01:12:34 +0300 |
commit | 8f8afdb713250153fdbf8c3c3873c7d5b10e8d41 (patch) | |
tree | 6e15004e35b30c1c2891767fb8e2a848d707bddd | |
parent | e68d81db5cf5791f3d50f985dccdd8b2a6f681f3 (diff) |
backup: Convert locator repos to Repository interface
Locators only use repositories to determine paths and so do not need the
concrete repository types.
-rw-r--r-- | internal/backup/backup.go | 8 | ||||
-rw-r--r-- | internal/backup/locator.go | 32 |
2 files changed, 20 insertions, 20 deletions
diff --git a/internal/backup/backup.go b/internal/backup/backup.go index 9100891ca..e924e3081 100644 --- a/internal/backup/backup.go +++ b/internal/backup/backup.go @@ -61,11 +61,11 @@ type Step struct { // Locator finds sink backup paths for repositories type Locator interface { // BeginFull returns the tentative backup paths needed to create a full backup. - BeginFull(ctx context.Context, repo *gitalypb.Repository, backupID string) *Backup + BeginFull(ctx context.Context, repo storage.Repository, backupID string) *Backup // BeginIncremental returns the backup with the last element of Steps being // the tentative step needed to create an incremental backup. - BeginIncremental(ctx context.Context, repo *gitalypb.Repository, backupID string) (*Backup, error) + BeginIncremental(ctx context.Context, repo storage.Repository, backupID string) (*Backup, error) // Commit persists the backup so that it can be looked up by FindLatest. It // is expected that the last element of Steps will be the newly created @@ -73,11 +73,11 @@ type Locator interface { Commit(ctx context.Context, backup *Backup) error // FindLatest returns the latest backup that was written by Commit - FindLatest(ctx context.Context, repo *gitalypb.Repository) (*Backup, error) + FindLatest(ctx context.Context, repo storage.Repository) (*Backup, error) // Find returns the repository backup at the given backupID. If the backup does // not exist then the error ErrDoesntExist is returned. - Find(ctx context.Context, repo *gitalypb.Repository, backupID string) (*Backup, error) + Find(ctx context.Context, repo storage.Repository, backupID string) (*Backup, error) } // Repository abstracts git access required to make a repository backup diff --git a/internal/backup/locator.go b/internal/backup/locator.go index 338db8a18..480e031a0 100644 --- a/internal/backup/locator.go +++ b/internal/backup/locator.go @@ -10,8 +10,8 @@ import ( "strings" "gitlab.com/gitlab-org/gitaly/v16/internal/git" + "gitlab.com/gitlab-org/gitaly/v16/internal/gitaly/storage" "gitlab.com/gitlab-org/gitaly/v16/internal/helper/text" - "gitlab.com/gitlab-org/gitaly/v16/proto/go/gitalypb" ) // LegacyLocator locates backup paths for historic backups. This is the @@ -28,12 +28,12 @@ import ( type LegacyLocator struct{} // BeginFull returns the static paths for a legacy repository backup -func (l LegacyLocator) BeginFull(ctx context.Context, repo *gitalypb.Repository, backupID string) *Backup { +func (l LegacyLocator) BeginFull(ctx context.Context, repo storage.Repository, backupID string) *Backup { return l.newFull(repo) } // BeginIncremental is not supported for legacy backups -func (l LegacyLocator) BeginIncremental(ctx context.Context, repo *gitalypb.Repository, backupID string) (*Backup, error) { +func (l LegacyLocator) BeginIncremental(ctx context.Context, repo storage.Repository, backupID string) (*Backup, error) { return nil, errors.New("legacy layout: begin incremental: not supported") } @@ -43,17 +43,17 @@ func (l LegacyLocator) Commit(ctx context.Context, full *Backup) error { } // FindLatest returns the static paths for a legacy repository backup -func (l LegacyLocator) FindLatest(ctx context.Context, repo *gitalypb.Repository) (*Backup, error) { +func (l LegacyLocator) FindLatest(ctx context.Context, repo storage.Repository) (*Backup, error) { return l.newFull(repo), nil } // Find is not supported for legacy backups. -func (l LegacyLocator) Find(ctx context.Context, repo *gitalypb.Repository, backupID string) (*Backup, error) { +func (l LegacyLocator) Find(ctx context.Context, repo storage.Repository, backupID string) (*Backup, error) { return nil, errors.New("legacy layout: find: not supported") } -func (l LegacyLocator) newFull(repo *gitalypb.Repository) *Backup { - backupPath := strings.TrimSuffix(repo.RelativePath, ".git") +func (l LegacyLocator) newFull(repo storage.Repository) *Backup { + backupPath := strings.TrimSuffix(repo.GetRelativePath(), ".git") return &Backup{ ObjectFormat: git.ObjectHashSHA1.Format, @@ -84,8 +84,8 @@ type PointerLocator struct { } // BeginFull returns a tentative first step needed to create a new full backup. -func (l PointerLocator) BeginFull(ctx context.Context, repo *gitalypb.Repository, backupID string) *Backup { - repoPath := strings.TrimSuffix(repo.RelativePath, ".git") +func (l PointerLocator) BeginFull(ctx context.Context, repo storage.Repository, backupID string) *Backup { + repoPath := strings.TrimSuffix(repo.GetRelativePath(), ".git") return &Backup{ ObjectFormat: git.ObjectHashSHA1.Format, @@ -103,8 +103,8 @@ func (l PointerLocator) BeginFull(ctx context.Context, repo *gitalypb.Repository // backup. The incremental backup is always based off of the latest full // backup. If there is no latest backup, a new full backup step is returned // using fallbackBackupID -func (l PointerLocator) BeginIncremental(ctx context.Context, repo *gitalypb.Repository, fallbackBackupID string) (*Backup, error) { - repoPath := strings.TrimSuffix(repo.RelativePath, ".git") +func (l PointerLocator) BeginIncremental(ctx context.Context, repo storage.Repository, fallbackBackupID string) (*Backup, error) { + repoPath := strings.TrimSuffix(repo.GetRelativePath(), ".git") backupID, err := l.findLatestID(ctx, repoPath) if err != nil { if errors.Is(err, ErrDoesntExist) { @@ -164,8 +164,8 @@ func (l PointerLocator) Commit(ctx context.Context, backup *Backup) error { // FindLatest returns the paths committed by the latest call to CommitFull. // // If there is no `LATEST` file, the result of the `Fallback` is used. -func (l PointerLocator) FindLatest(ctx context.Context, repo *gitalypb.Repository) (*Backup, error) { - repoPath := strings.TrimSuffix(repo.RelativePath, ".git") +func (l PointerLocator) FindLatest(ctx context.Context, repo storage.Repository) (*Backup, error) { + repoPath := strings.TrimSuffix(repo.GetRelativePath(), ".git") backupID, err := l.findLatestID(ctx, repoPath) if err != nil { @@ -184,7 +184,7 @@ func (l PointerLocator) FindLatest(ctx context.Context, repo *gitalypb.Repositor // Find returns the repository backup at the given backupID. If the backup does // not exist then the error ErrDoesntExist is returned. -func (l PointerLocator) Find(ctx context.Context, repo *gitalypb.Repository, backupID string) (*Backup, error) { +func (l PointerLocator) Find(ctx context.Context, repo storage.Repository, backupID string) (*Backup, error) { backup, err := l.find(ctx, repo, backupID) if err != nil { return nil, fmt.Errorf("pointer locator: %w", err) @@ -192,8 +192,8 @@ func (l PointerLocator) Find(ctx context.Context, repo *gitalypb.Repository, bac return backup, nil } -func (l PointerLocator) find(ctx context.Context, repo *gitalypb.Repository, backupID string) (*Backup, error) { - repoPath := strings.TrimSuffix(repo.RelativePath, ".git") +func (l PointerLocator) find(ctx context.Context, repo storage.Repository, backupID string) (*Backup, error) { + repoPath := strings.TrimSuffix(repo.GetRelativePath(), ".git") backupPath := filepath.Join(repoPath, backupID) latestIncrementID, err := l.findLatestID(ctx, backupPath) |