Skip to content

Commit

Permalink
Fix backward compatibility issues in config file migration. Closes #2042
Browse files Browse the repository at this point in the history
  • Loading branch information
pskrbasu committed May 11, 2022
1 parent b0adb24 commit b226aa3
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 0 deletions.
5 changes: 5 additions & 0 deletions ociinstaller/versionfile/db_version_file.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,11 @@ func readDatabaseVersionFile(path string) (*DatabaseVersionFile, error) {
func (f *DatabaseVersionFile) Save() error {
// set the struct version
f.StructVersion = DatabaseStructVersion
// maintain the legacy properties for backward compatibility
f.LegacyFdwExtension = f.FdwExtension
f.LegacyFdwExtension.MaintainLegacy()
f.LegacyEmbeddedDB = f.EmbeddedDB
f.LegacyEmbeddedDB.MaintainLegacy()

versionFilePath := filepaths.DatabaseVersionFilePath()
return f.write(versionFilePath)
Expand Down
9 changes: 9 additions & 0 deletions ociinstaller/versionfile/installed_version.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,12 @@ func (f *InstalledVersion) MigrateLegacy() {
f.InstallDate = f.LegacyInstallDate
f.LastCheckedDate = f.LegacyLastCheckedDate
}

// MaintainLegacy keeps the values of the legacy properties for backward
// compatibility
func (f *InstalledVersion) MaintainLegacy() {
f.LegacyImageDigest = f.ImageDigest
f.LegacyInstalledFrom = f.InstalledFrom
f.LegacyInstallDate = f.InstallDate
f.LegacyLastCheckedDate = f.LastCheckedDate
}
4 changes: 4 additions & 0 deletions ociinstaller/versionfile/plugin_version_file.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ func (f *PluginVersionFile) Save() error {
// set struct version
f.StructVersion = PluginStructVersion
versionFilePath := filepaths.PluginVersionFilePath()
// maintain the legacy properties for backward compatibility
for _, v := range f.Plugins {
v.MaintainLegacy()
}
return f.write(versionFilePath)
}

Expand Down
10 changes: 10 additions & 0 deletions statefile/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ func (s *State) Save() error {
s.StructVersion = StateStructVersion

s.LastCheck = nowTimeString()
s.LegacyLastCheck = nowTimeString()
// maintain the legacy properties for backward compatibility
s.MaintainLegacy()
// ensure internal dirs exists
_ = os.MkdirAll(filepaths.EnsureInternalDir(), os.ModePerm)
stateFilePath := filepath.Join(filepaths.EnsureInternalDir(), filepaths.StateFileName())
Expand All @@ -90,6 +93,13 @@ func (s *State) MigrateFrom() migrate.Migrateable {
return s
}

// MaintainLegacy keeps the values of the legacy properties for backward
// compatibility
func (s *State) MaintainLegacy() {
s.LegacyLastCheck = s.LastCheck
s.LegacyInstallationID = s.InstallationID
}

func newInstallationID() string {
return uuid.New().String()
}
Expand Down

0 comments on commit b226aa3

Please sign in to comment.