Improve handling of layered profile on profile update

This commit is contained in:
Daniel
2022-02-15 16:07:29 +01:00
parent 3be1c78e16
commit d491e51127
3 changed files with 14 additions and 6 deletions

View File

@@ -80,14 +80,17 @@ func startProfileUpdateChecker() error {
// Copy metadata from the old profile.
newProfile.copyMetadataFrom(activeProfile)
// Save the new profile.
err := newProfile.Save()
err = newProfile.Save()
if err != nil {
log.Errorf("profile: failed to save new profile after reset: %s", err)
}
}
// Set to outdated, so it is loaded in the layered profiles.
// If the new profile was successfully created, update layered profile.
activeProfile.outdated.Set()
if err == nil {
newProfile.layeredProfile.Update()
}
}
// Always increase the revision counter of the layer profile.

View File

@@ -14,9 +14,7 @@ var getProfileLock sync.Mutex
// GetProfile fetches a profile. This function ensures that the loaded profile
// is shared among all callers. You must always supply both the scopedID and
// linkedPath parameters whenever available. The linkedPath is used as the key
// for locking concurrent requests, so it must be supplied if available.
// If linkedPath is not supplied, source and id make up the key instead.
// linkedPath parameters whenever available.
func GetProfile(source profileSource, id, linkedPath string, reset bool) ( //nolint:gocognit
profile *Profile,
err error,
@@ -112,6 +110,7 @@ func GetProfile(source profileSource, id, linkedPath string, reset bool) ( //nol
// Add a layeredProfile to local and network profiles.
if profile.Source == SourceLocal || profile.Source == SourceNetwork {
// If we are refetching, assign the layered profile from the previous version.
// The internal references will be updated when the layered profile checks for updates.
if previousVersion != nil {
profile.layeredProfile = previousVersion.layeredProfile
}

View File

@@ -238,13 +238,19 @@ func (lp *LayeredProfile) Update() (revisionCounter uint64) {
for i, layer := range lp.layers {
if layer.outdated.IsSet() {
changed = true
// update layer
// Update layer.
newLayer, err := GetProfile(layer.Source, layer.ID, layer.LinkedPath, false)
if err != nil {
log.Errorf("profiles: failed to update profile %s: %s", layer.ScopedID(), err)
} else {
lp.layers[i] = newLayer
}
// Update local profile reference.
if i == 0 {
lp.localProfile = newLayer
}
}
}
if !lp.globalValidityFlag.IsValid() {