2022-08-05 22:55:54 +02:00
|
|
|
package settings
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
|
2023-03-07 22:04:06 +01:00
|
|
|
"github.com/Jguer/yay/v12/pkg/db"
|
2023-03-13 09:48:39 +01:00
|
|
|
"github.com/Jguer/yay/v12/pkg/text"
|
2022-08-05 22:55:54 +02:00
|
|
|
|
|
|
|
"github.com/leonelquinteros/gotext"
|
|
|
|
)
|
|
|
|
|
|
|
|
type configMigration interface {
|
|
|
|
// Description of what the migration does
|
|
|
|
fmt.Stringer
|
|
|
|
// return true if migration was done
|
|
|
|
Do(config *Configuration) bool
|
|
|
|
// Target version of the migration (e.g. "11.2.1")
|
|
|
|
// Should match the version of yay releasing this migration
|
|
|
|
TargetVersion() string
|
|
|
|
}
|
|
|
|
|
|
|
|
type configProviderMigration struct{}
|
|
|
|
|
|
|
|
func (migration *configProviderMigration) String() string {
|
|
|
|
return gotext.Get("Disable 'provides' setting by default")
|
|
|
|
}
|
|
|
|
|
|
|
|
func (migration *configProviderMigration) Do(config *Configuration) bool {
|
|
|
|
if config.Provides {
|
|
|
|
config.Provides = false
|
|
|
|
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
func (migration *configProviderMigration) TargetVersion() string {
|
|
|
|
return "11.2.1"
|
|
|
|
}
|
|
|
|
|
|
|
|
func DefaultMigrations() []configMigration {
|
|
|
|
return []configMigration{
|
|
|
|
&configProviderMigration{},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-03-13 09:48:39 +01:00
|
|
|
func (c *Configuration) RunMigrations(migrations []configMigration,
|
|
|
|
configPath, newVersion string,
|
|
|
|
) error {
|
2022-08-05 22:55:54 +02:00
|
|
|
saveConfig := false
|
|
|
|
|
|
|
|
for _, migration := range migrations {
|
|
|
|
if db.VerCmp(migration.TargetVersion(), c.Version) > 0 {
|
|
|
|
if migration.Do(c) {
|
2023-03-13 09:48:39 +01:00
|
|
|
text.Infoln("Config migration executed (",
|
2022-08-05 22:55:54 +02:00
|
|
|
migration.TargetVersion(), "):", migration)
|
|
|
|
|
|
|
|
saveConfig = true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if saveConfig {
|
2023-03-13 09:48:39 +01:00
|
|
|
return c.Save(configPath, newVersion)
|
2022-08-05 22:55:54 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|