mirror of
https://github.com/safing/portmaster
synced 2025-09-02 02:29:12 +00:00
Merge pull request #212 from safing/fix/profile-metadata-updating
Fix profile metadata updating
This commit is contained in:
commit
f32e11e0ff
2 changed files with 15 additions and 6 deletions
|
@ -10,8 +10,7 @@ import (
|
|||
// 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.
|
||||
var localProfile *profile.Profile
|
||||
defer p.updateProfileMetadata(localProfile)
|
||||
defer p.UpdateProfileMetadata()
|
||||
|
||||
p.Lock()
|
||||
defer p.Unlock()
|
||||
|
@ -35,7 +34,7 @@ func (p *Process) GetProfile(ctx context.Context) (changed bool, err error) {
|
|||
}
|
||||
|
||||
// Get the (linked) local profile.
|
||||
localProfile, err = profile.GetProfile(profile.SourceLocal, profileID, p.Path)
|
||||
localProfile, err := profile.GetProfile(profile.SourceLocal, profileID, p.Path)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
@ -47,8 +46,9 @@ func (p *Process) GetProfile(ctx context.Context) (changed bool, err error) {
|
|||
return true, nil
|
||||
}
|
||||
|
||||
func (p *Process) updateProfileMetadata(localProfile *profile.Profile) {
|
||||
func (p *Process) UpdateProfileMetadata() {
|
||||
// Check if there is a profile to work with.
|
||||
localProfile := p.Profile().LocalProfile()
|
||||
if localProfile == nil {
|
||||
return
|
||||
}
|
||||
|
|
|
@ -414,7 +414,7 @@ func (profile *Profile) UpdateMetadata(processName string) (changed bool) {
|
|||
|
||||
// Update profile name if it is empty or equals the filename, which is the
|
||||
// case for older profiles.
|
||||
if profile.Name == "" || profile.Name == filename {
|
||||
if strings.TrimSpace(profile.Name) == "" || profile.Name == filename {
|
||||
// Generate a default profile name if does not exist.
|
||||
profile.Name = osdetail.GenerateBinaryNameFromPath(profile.LinkedPath)
|
||||
if profile.Name == filename {
|
||||
|
@ -457,12 +457,21 @@ func (profile *Profile) updateMetadataFromSystem(ctx context.Context) error {
|
|||
// Get binary name from linked path.
|
||||
newName, err := osdetail.GetBinaryNameFromSystem(profile.LinkedPath)
|
||||
if err != nil {
|
||||
if !errors.Is(err, osdetail.ErrNotSupported) {
|
||||
switch {
|
||||
case errors.Is(err, osdetail.ErrNotSupported):
|
||||
case errors.Is(err, osdetail.ErrNotFound):
|
||||
case errors.Is(err, osdetail.ErrEmptyOutput):
|
||||
default:
|
||||
log.Warningf("profile: error while getting binary name for %s: %s", profile.LinkedPath, err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// Check if the new name is valid.
|
||||
if strings.TrimSpace(newName) == "" {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Get filename of linked path for comparison.
|
||||
filename := filepath.Base(profile.LinkedPath)
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue