2022-03-31 19:12:13 +00:00
|
|
|
package migrations
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"fmt"
|
|
|
|
|
2024-05-10 13:50:52 +00:00
|
|
|
"github.com/restic/restic/internal/repository"
|
2022-03-31 19:12:13 +00:00
|
|
|
"github.com/restic/restic/internal/restic"
|
|
|
|
)
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
register(&UpgradeRepoV2{})
|
|
|
|
}
|
|
|
|
|
|
|
|
type UpgradeRepoV2 struct{}
|
|
|
|
|
|
|
|
func (*UpgradeRepoV2) Name() string {
|
|
|
|
return "upgrade_repo_v2"
|
|
|
|
}
|
|
|
|
|
|
|
|
func (*UpgradeRepoV2) Desc() string {
|
|
|
|
return "upgrade a repository to version 2"
|
|
|
|
}
|
|
|
|
|
2023-05-18 17:18:09 +00:00
|
|
|
func (*UpgradeRepoV2) Check(_ context.Context, repo restic.Repository) (bool, string, error) {
|
2022-03-31 19:12:13 +00:00
|
|
|
isV1 := repo.Config().Version == 1
|
2022-09-03 09:49:31 +00:00
|
|
|
reason := ""
|
|
|
|
if !isV1 {
|
|
|
|
reason = fmt.Sprintf("repository is already upgraded to version %v", repo.Config().Version)
|
|
|
|
}
|
|
|
|
return isV1, reason, nil
|
2022-03-31 19:12:13 +00:00
|
|
|
}
|
|
|
|
|
2022-06-04 21:45:00 +00:00
|
|
|
func (*UpgradeRepoV2) RepoCheck() bool {
|
|
|
|
return true
|
2022-05-01 18:16:49 +00:00
|
|
|
}
|
2022-03-31 19:29:19 +00:00
|
|
|
|
|
|
|
func (m *UpgradeRepoV2) Apply(ctx context.Context, repo restic.Repository) error {
|
2024-05-10 13:50:52 +00:00
|
|
|
return repository.UpgradeRepo(ctx, repo.(*repository.Repository))
|
2022-03-31 19:29:19 +00:00
|
|
|
}
|