Skip to content

Commit

Permalink
Rename profile/icons to profile/binmeta
Browse files Browse the repository at this point in the history
  • Loading branch information
dhaavi committed Dec 19, 2023
1 parent a88de15 commit 2ae2465
Show file tree
Hide file tree
Showing 23 changed files with 49 additions and 49 deletions.
6 changes: 3 additions & 3 deletions process/tags/appimage_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"github.com/safing/portbase/log"
"github.com/safing/portmaster/process"
"github.com/safing/portmaster/profile"
"github.com/safing/portmaster/profile/icons"
"github.com/safing/portmaster/profile/binmeta"
)

func init() {
Expand Down Expand Up @@ -124,7 +124,7 @@ func (h *AppImageHandler) CreateProfile(p *process.Process) *profile.Profile {
if tag, ok := p.GetTag(appImagePathTagKey); ok {
return profile.New(&profile.Profile{
Source: profile.SourceLocal,
Name: icons.GenerateBinaryNameFromPath(p.Path),
Name: binmeta.GenerateBinaryNameFromPath(p.Path),
PresentationPath: p.Path,
UsePresentationPath: true,
Fingerprints: []profile.Fingerprint{
Expand All @@ -141,7 +141,7 @@ func (h *AppImageHandler) CreateProfile(p *process.Process) *profile.Profile {
if tag, ok := p.GetTag(appImageMountIDTagKey); ok {
return profile.New(&profile.Profile{
Source: profile.SourceLocal,
Name: icons.GenerateBinaryNameFromPath(p.Path),
Name: binmeta.GenerateBinaryNameFromPath(p.Path),
PresentationPath: p.Path,
UsePresentationPath: true,
Fingerprints: []profile.Fingerprint{
Expand Down
4 changes: 2 additions & 2 deletions process/tags/flatpak_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (

"github.com/safing/portmaster/process"
"github.com/safing/portmaster/profile"
"github.com/safing/portmaster/profile/icons"
"github.com/safing/portmaster/profile/binmeta"
)

func init() {
Expand Down Expand Up @@ -69,7 +69,7 @@ func (h *flatpakHandler) CreateProfile(p *process.Process) *profile.Profile {
if tag, ok := p.GetTag(flatpakIDTagKey); ok {
return profile.New(&profile.Profile{
Source: profile.SourceLocal,
Name: icons.GenerateBinaryNameFromPath(p.Path),
Name: binmeta.GenerateBinaryNameFromPath(p.Path),
PresentationPath: p.Path,
UsePresentationPath: true,
Fingerprints: []profile.Fingerprint{
Expand Down
4 changes: 2 additions & 2 deletions process/tags/interpreter_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (

"github.com/safing/portmaster/process"
"github.com/safing/portmaster/profile"
"github.com/safing/portmaster/profile/icons"
"github.com/safing/portmaster/profile/binmeta"
)

func init() {
Expand Down Expand Up @@ -161,7 +161,7 @@ func (h *InterpHandler) CreateProfile(p *process.Process) *profile.Profile {
for _, ext := range it.Extensions {
scriptName, _ = strings.CutSuffix(scriptName, ext)
}
scriptName = icons.GenerateBinaryNameFromPath(scriptName)
scriptName = binmeta.GenerateBinaryNameFromPath(scriptName)

return profile.New(&profile.Profile{
Source: profile.SourceLocal,
Expand Down
4 changes: 2 additions & 2 deletions process/tags/snap_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (

"github.com/safing/portmaster/process"
"github.com/safing/portmaster/profile"
"github.com/safing/portmaster/profile/icons"
"github.com/safing/portmaster/profile/binmeta"
)

func init() {
Expand Down Expand Up @@ -117,7 +117,7 @@ func (h *SnapHandler) CreateProfile(p *process.Process) *profile.Profile {

return profile.New(&profile.Profile{
Source: profile.SourceLocal,
Name: icons.GenerateBinaryNameFromPath(tag.Value),
Name: binmeta.GenerateBinaryNameFromPath(tag.Value),
PresentationPath: p.Path,
UsePresentationPath: hasVersion,
Fingerprints: []profile.Fingerprint{
Expand Down
8 changes: 4 additions & 4 deletions process/tags/svchost_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"github.com/safing/portbase/utils/osdetail"
"github.com/safing/portmaster/process"
"github.com/safing/portmaster/profile"
"github.com/safing/portmaster/profile/icons"
"github.com/safing/portmaster/profile/binmeta"
)

func init() {
Expand Down Expand Up @@ -86,7 +86,7 @@ func (h *SVCHostTagHandler) CreateProfile(p *process.Process) *profile.Profile {
// Create new profile based on tag.
newProfile := profile.New(&profile.Profile{
Source: profile.SourceLocal,
Name: "Windows Service: " + icons.GenerateBinaryNameFromPath(tag.Value),
Name: "Windows Service: " + binmeta.GenerateBinaryNameFromPath(tag.Value),
UsePresentationPath: false,
Fingerprints: []profile.Fingerprint{
{
Expand All @@ -99,9 +99,9 @@ func (h *SVCHostTagHandler) CreateProfile(p *process.Process) *profile.Profile {
})

// Load default icon for windows service.
icon, err := icons.LoadAndSaveIcon(context.TODO(), `C:\Windows\System32\@WLOGO_48x48.png`)
icon, err := binmeta.LoadAndSaveIcon(context.TODO(), `C:\Windows\System32\@WLOGO_48x48.png`)
if err == nil {
newProfile.Icons = []icons.Icon{*icon}
newProfile.Icons = []binmeta.Icon{*icon}
}

return newProfile
Expand Down
4 changes: 2 additions & 2 deletions process/tags/winstore_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"github.com/safing/portbase/utils"
"github.com/safing/portmaster/process"
"github.com/safing/portmaster/profile"
"github.com/safing/portmaster/profile/icons"
"github.com/safing/portmaster/profile/binmeta"
)

func init() {
Expand Down Expand Up @@ -101,7 +101,7 @@ func (h *WinStoreHandler) CreateProfile(p *process.Process) *profile.Profile {
if tag, ok := p.GetTag(winStoreAppNameTagKey); ok {
return profile.New(&profile.Profile{
Source: profile.SourceLocal,
Name: icons.GenerateBinaryNameFromPath(tag.Value),
Name: binmeta.GenerateBinaryNameFromPath(tag.Value),
PresentationPath: p.Path,
UsePresentationPath: true,
Fingerprints: []profile.Fingerprint{
Expand Down
6 changes: 3 additions & 3 deletions profile/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"github.com/safing/portbase/api"
"github.com/safing/portbase/formats/dsd"
"github.com/safing/portbase/utils"
"github.com/safing/portmaster/profile/icons"
"github.com/safing/portmaster/profile/binmeta"
)

func registerAPIEndpoints() error {
Expand Down Expand Up @@ -99,7 +99,7 @@ func handleGetProfileIcon(ar *api.Request) (data []byte, err error) {
ext := filepath.Ext(name)

// Get profile icon.
data, err = icons.GetProfileIcon(name)
data, err = binmeta.GetProfileIcon(name)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -153,7 +153,7 @@ func handleUpdateProfileIcon(ar *api.Request) (any, error) {
}

// Update profile icon.
filename, err := icons.UpdateProfileIcon(ar.InputData, ext)
filename, err := binmeta.UpdateProfileIcon(ar.InputData, ext)
if err != nil {
return nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion profile/icons/convert.go → profile/binmeta/convert.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package icons
package binmeta

import (
"bytes"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//go:build !linux && !windows

package icons
package binmeta

import "context"

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package icons
package binmeta

import (
"context"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package icons
package binmeta

import (
"os"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package icons
package binmeta

import (
"bytes"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package icons
package binmeta

import (
"context"
Expand Down
6 changes: 3 additions & 3 deletions profile/icons/icon.go → profile/binmeta/icon.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package icons
package binmeta

import (
"errors"
Expand Down Expand Up @@ -42,8 +42,8 @@ func (t IconType) sortOrder() int {
}
}

// SortAndCompact sorts and compacts a list of icons.
func SortAndCompact(icons []Icon) []Icon {
// SortAndCompactIcons sorts and compacts a list of icons.
func SortAndCompactIcons(icons []Icon) []Icon {
// Sort.
slices.SortFunc[[]Icon, Icon](icons, func(a, b Icon) int {
aOrder := a.Type.sortOrder()
Expand Down
2 changes: 1 addition & 1 deletion profile/icons/icons.go → profile/binmeta/icons.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package icons
package binmeta

import (
"context"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package icons
package binmeta

import (
"fmt"
Expand Down
2 changes: 1 addition & 1 deletion profile/icons/name.go → profile/binmeta/name.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package icons
package binmeta

import (
"path/filepath"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package icons
package binmeta

import (
"testing"
Expand Down
6 changes: 3 additions & 3 deletions profile/merge.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"time"

"github.com/safing/portbase/database/record"
"github.com/safing/portmaster/profile/icons"
"github.com/safing/portmaster/profile/binmeta"
)

// MergeProfiles merges multiple profiles into a new one.
Expand Down Expand Up @@ -52,12 +52,12 @@ func MergeProfiles(name string, primary *Profile, secondaries ...*Profile) (newP
}

// Collect all icons.
newProfile.Icons = make([]icons.Icon, 0, len(secondaries)+1) // Guess the needed space.
newProfile.Icons = make([]binmeta.Icon, 0, len(secondaries)+1) // Guess the needed space.
newProfile.Icons = append(newProfile.Icons, primary.Icons...)
for _, sp := range secondaries {
newProfile.Icons = append(newProfile.Icons, sp.Icons...)
}
newProfile.Icons = icons.SortAndCompact(newProfile.Icons)
newProfile.Icons = binmeta.SortAndCompactIcons(newProfile.Icons)

// Collect all fingerprints.
newProfile.Fingerprints = make([]Fingerprint, 0, len(primary.Fingerprints)+len(secondaries)) // Guess the needed space.
Expand Down
4 changes: 2 additions & 2 deletions profile/migrations.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
"github.com/safing/portbase/database/migration"
"github.com/safing/portbase/database/query"
"github.com/safing/portbase/log"
"github.com/safing/portmaster/profile/icons"
"github.com/safing/portmaster/profile/binmeta"
)

func registerMigrations() error {
Expand Down Expand Up @@ -103,7 +103,7 @@ func migrateIcons(ctx context.Context, _, to *version.Version, db *database.Inte
}

// Migrate to icon list.
profile.Icons = []icons.Icon{{
profile.Icons = []binmeta.Icon{{
Type: profile.IconType,
Value: profile.Icon,
}}
Expand Down
4 changes: 2 additions & 2 deletions profile/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
"github.com/safing/portbase/log"
"github.com/safing/portbase/modules"
_ "github.com/safing/portmaster/core/base"
"github.com/safing/portmaster/profile/icons"
"github.com/safing/portmaster/profile/binmeta"
"github.com/safing/portmaster/updates"
)

Expand Down Expand Up @@ -53,7 +53,7 @@ func prep() error {
if err := iconsDir.Ensure(); err != nil {
return fmt.Errorf("failed to create/check icons directory: %w", err)
}
icons.ProfileIconStoragePath = iconsDir.Path
binmeta.ProfileIconStoragePath = iconsDir.Path

return nil
}
Expand Down
14 changes: 7 additions & 7 deletions profile/profile.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ import (
"github.com/safing/portbase/log"
"github.com/safing/portbase/utils"
"github.com/safing/portmaster/intel/filterlists"
"github.com/safing/portmaster/profile/binmeta"
"github.com/safing/portmaster/profile/endpoints"
"github.com/safing/portmaster/profile/icons"
)

// ProfileSource is the source of the profile.
Expand Down Expand Up @@ -68,9 +68,9 @@ type Profile struct { //nolint:maligned // not worth the effort
// See IconType for more information.
Icon string
// Deprecated: IconType describes the type of the Icon property.
IconType icons.IconType
IconType binmeta.IconType
// Icons holds a list of icons to represent the application.
Icons []icons.Icon
Icons []binmeta.Icon

// Deprecated: LinkedPath used to point to the executableis this
// profile was created for.
Expand Down Expand Up @@ -469,7 +469,7 @@ func (profile *Profile) updateMetadata(binaryPath string) (changed bool) {
// Set Name if unset.
if profile.Name == "" && profile.PresentationPath != "" {
// Generate a default profile name from path.
profile.Name = icons.GenerateBinaryNameFromPath(profile.PresentationPath)
profile.Name = binmeta.GenerateBinaryNameFromPath(profile.PresentationPath)
changed = true
}

Expand Down Expand Up @@ -514,7 +514,7 @@ func (profile *Profile) updateMetadataFromSystem(ctx context.Context, md Matchin
}

// Get binary icon and name.
newIcon, newName, err := icons.GetIconAndName(ctx, profile.PresentationPath, home)
newIcon, newName, err := binmeta.GetIconAndName(ctx, profile.PresentationPath, home)
if err != nil {
log.Warningf("profile: failed to get binary icon/name for %s: %s", profile.PresentationPath, err)
}
Expand All @@ -534,10 +534,10 @@ func (profile *Profile) updateMetadataFromSystem(ctx context.Context, md Matchin
// Apply new icon if found.
if newIcon != nil {
if len(profile.Icons) == 0 {
profile.Icons = []icons.Icon{*newIcon}
profile.Icons = []binmeta.Icon{*newIcon}
} else {
profile.Icons = append(profile.Icons, *newIcon)
profile.Icons = icons.SortAndCompact(profile.Icons)
profile.Icons = binmeta.SortAndCompactIcons(profile.Icons)
}
}
}()
Expand Down
8 changes: 4 additions & 4 deletions sync/profile.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
"github.com/safing/portbase/config"
"github.com/safing/portbase/log"
"github.com/safing/portmaster/profile"
"github.com/safing/portmaster/profile/icons"
"github.com/safing/portmaster/profile/binmeta"
)

// ProfileExport holds an export of a profile.
Expand Down Expand Up @@ -415,12 +415,12 @@ func ImportProfile(r *ProfileImportRequest, requiredProfileSource profile.Profil
if err != nil {
return nil, fmt.Errorf("%w: icon data is invalid: %w", ErrImportFailed, err)
}
filename, err := icons.UpdateProfileIcon(du.Data, du.MediaType.Subtype)
filename, err := binmeta.UpdateProfileIcon(du.Data, du.MediaType.Subtype)
if err != nil {
return nil, fmt.Errorf("%w: icon is invalid: %w", ErrImportFailed, err)
}
p.Icons = []icons.Icon{{
Type: icons.IconTypeAPI,
p.Icons = []binmeta.Icon{{
Type: binmeta.IconTypeAPI,
Value: filename,
}}
}
Expand Down

0 comments on commit 2ae2465

Please sign in to comment.