Add support to store the path of the loaded packages

This commit is contained in:
Ettore Di Giacinto
2019-11-04 12:35:21 +01:00
parent 8c86f6c84d
commit 4dab89d209
2 changed files with 20 additions and 1 deletions

View File

@@ -54,6 +54,9 @@ type Package interface {
Yaml() ([]byte, error)
Explain()
SetPath(string)
GetPath() string
}
type PackageSet interface {
@@ -96,6 +99,8 @@ type DefaultPackage struct {
PackageRequires []*DefaultPackage `json:"requires"` // Affects YAML field names too.
PackageConflicts []*DefaultPackage `json:"conflicts"` // Affects YAML field names too.
IsSet bool `json:"set"` // Affects YAML field names too.
Path string `json:"-"` // primary key with auto increment
}
// State represent the package state
@@ -112,6 +117,15 @@ func (p *DefaultPackage) GetFingerPrint() string {
return fmt.Sprintf("%s-%s-%s", p.Name, p.Category, p.Version)
}
// GetPath returns the path where the definition file was found
func (p *DefaultPackage) GetPath() string {
return p.Path
}
func (p *DefaultPackage) SetPath(s string) {
p.Path = s
}
// AddUse adds a use to a package
func (p *DefaultPackage) AddUse(use string) {
for _, v := range p.UseFlags {

View File

@@ -28,7 +28,9 @@ import (
pkg "github.com/mudler/luet/pkg/package"
)
const DefinitionFile = "definition.yaml"
const (
DefinitionFile = "definition.yaml"
)
func NewGeneralRecipe() Builder { return &Recipe{} }
@@ -89,6 +91,9 @@ func (r *Recipe) Load(path string) error {
if err != nil {
return err
}
pack.SetPath(filepath.Dir(path))
_, err = r.Tree().GetPackageSet().CreatePackage(&pack)
if err != nil {
return err