Provided packages should now function correctly

This commit is contained in:
EnumDev 2024-10-07 14:47:57 +03:00
parent a3d1167358
commit 2d35ac12a1

View File

@ -8,6 +8,7 @@ import (
"net/url"
"os"
"path"
"sort"
"strings"
)
@ -21,6 +22,7 @@ type Repository struct {
type RepositoryEntry struct {
Info *PackageInfo `yaml:"info"`
Download string `yaml:"download"`
IsVirtualPackage bool `yaml:"-"`
}
func (repo *Repository) ContainsPackage(pkg string) bool {
@ -39,6 +41,8 @@ func (repo *Repository) ReadLocalDatabase() error {
return err
}
virtualPackages := make(map[string][]string)
data := string(bytes)
for _, b := range strings.Split(data, "---") {
entry := RepositoryEntry{
@ -59,13 +63,31 @@ func (repo *Repository) ReadLocalDatabase() error {
Provides: make([]string, 0),
},
Download: "",
IsVirtualPackage: false,
}
err := yaml.Unmarshal([]byte(b), &entry)
if err != nil {
return err
}
for _, p := range entry.Info.Provides {
virtualPackages[p] = append(virtualPackages[p], entry.Info.Name)
}
repo.Entries[entry.Info.Name] = &entry
}
for key, value := range virtualPackages {
if _, ok := repo.Entries[key]; ok {
continue
}
sort.Strings(value)
entry := RepositoryEntry{
Info: repo.Entries[value[0]].Info,
Download: repo.Entries[value[0]].Download,
IsVirtualPackage: true,
}
repo.Entries[key] = &entry
}
return nil
}