Improve profile metadata handling

This commit is contained in:
Daniel
2022-10-06 10:33:25 +02:00
parent c4943a96b1
commit 595f4c0106
9 changed files with 165 additions and 137 deletions

View File

@@ -15,9 +15,6 @@ var ownPID = os.Getpid()
// GetProfile finds and assigns a profile set to the process.
func (p *Process) GetProfile(ctx context.Context) (changed bool, err error) {
// Update profile metadata outside of *Process lock.
defer p.UpdateProfileMetadata()
p.Lock()
defer p.Unlock()
@@ -114,24 +111,3 @@ func (p *Process) loadSpecialProfile(_ context.Context) (*profile.Profile, error
// Return special profile.
return profile.GetSpecialProfile(specialProfileID, p.Path)
}
// UpdateProfileMetadata updates the metadata of the local profile
// as required.
func (p *Process) UpdateProfileMetadata() {
// Check if there is a profile to work with.
localProfile := p.Profile().LocalProfile()
if localProfile == nil {
return
}
// Update metadata of profile.
metadataUpdated := localProfile.UpdateMetadata(p.Path)
// Save the profile if we changed something.
if metadataUpdated {
err := localProfile.Save()
if err != nil {
log.Warningf("process: failed to save profile %s: %s", localProfile.ScopedID(), err)
}
}
}