Do not use interface in struct used for serialization

This commit is contained in:
Ettore Di Giacinto
2019-11-23 00:29:24 +01:00
parent 43ab851cb9
commit 542d45a646
6 changed files with 36 additions and 19 deletions

View File

@@ -49,24 +49,25 @@ func (i ArtifactIndex) CleanPath() ArtifactIndex {
// which will consist in just of an repository.yaml which is just the repository structure with the list of package artifact.
// In this way a generic client can fetch the packages and, after unpacking the tree, performing queries to install packages.
type PackageArtifact struct {
Path string `json:"path"`
Dependencies []Artifact `json:"dependencies"`
CompileSpec CompilationSpec `json:"compilationspec"`
Path string `json:"path"`
Dependencies []*PackageArtifact `json:"dependencies"`
CompileSpec *LuetCompilationSpec `json:"compilationspec"`
SourceAssertion solver.PackagesAssertions `json:"-"`
}
func NewPackageArtifact(path string) Artifact {
return &PackageArtifact{Path: path, Dependencies: []Artifact{}}
return &PackageArtifact{Path: path, Dependencies: []*PackageArtifact{}}
}
func NewPackageArtifactFromYaml(data []byte) (Artifact, error) {
var p PackageArtifact
p := &PackageArtifact{}
err := yaml.Unmarshal(data, &p)
if err != nil {
return &p, err
return p, err
}
return &p, err
return p, err
}
func (a *PackageArtifact) WriteYaml(dst string) error {
@@ -90,7 +91,7 @@ func (a *PackageArtifact) GetSourceAssertion() solver.PackagesAssertions {
}
func (a *PackageArtifact) SetCompileSpec(as CompilationSpec) {
a.CompileSpec = as
a.CompileSpec = as.(*LuetCompilationSpec)
}
func (a *PackageArtifact) GetCompileSpec() CompilationSpec {
@@ -102,11 +103,19 @@ func (a *PackageArtifact) SetSourceAssertion(as solver.PackagesAssertions) {
}
func (a *PackageArtifact) GetDependencies() []Artifact {
return a.Dependencies
ret := []Artifact{}
for _, d := range a.Dependencies {
ret = append(ret, d)
}
return ret
}
func (a *PackageArtifact) SetDependencies(d []Artifact) {
a.Dependencies = d
ret := []*PackageArtifact{}
for _, dd := range d {
ret = append(ret, dd.(*PackageArtifact))
}
a.Dependencies = ret
}
func (a *PackageArtifact) GetPath() string {

View File

@@ -91,7 +91,7 @@ type LuetCompilationSpec struct {
Prelude []string `json:"prelude"` // Are run inside the image which will be our builder
Image string `json:"image"`
Seed string `json:"seed"`
Package pkg.Package `json:"-"`
Package *pkg.DefaultPackage `json:"-"`
SourceAssertion solver.PackagesAssertions `json:"-"`
OutputPath string `json:"-"` // Where the build processfiles go
@@ -105,7 +105,7 @@ func NewLuetCompilationSpec(b []byte, p pkg.Package) (CompilationSpec, error) {
if err != nil {
return &spec, err
}
spec.Package = p
spec.Package = p.(*pkg.DefaultPackage)
return &spec, nil
}
func (a *LuetCompilationSpec) GetSourceAssertion() solver.PackagesAssertions {

View File

@@ -20,10 +20,10 @@ import (
"os"
// . "github.com/mudler/luet/pkg/installer"
backend "github.com/mudler/luet/pkg/compiler/backend"
compiler "github.com/mudler/luet/pkg/compiler"
backend "github.com/mudler/luet/pkg/compiler/backend"
"github.com/mudler/luet/pkg/helpers"
. "github.com/mudler/luet/pkg/installer"
pkg "github.com/mudler/luet/pkg/package"
"github.com/mudler/luet/pkg/tree"
. "github.com/onsi/ginkgo"
@@ -82,6 +82,9 @@ var _ = Describe("Installer", func() {
Expect(helpers.Exists(spec.Rel("b-test-1.0.package.tar"))).To(BeTrue())
Expect(helpers.Exists(spec.Rel("b-test-1.0.metadata.yaml"))).To(BeTrue())
repo, err := GenerateRepository("test", tmpdir, "local", 1, tmpdir, "../../tests/fixtures/buildable", pkg.NewInMemoryDatabase(false))
Expect(err).ToNot(HaveOccurred())
Expect(repo.GetName()).To(Equal("test"))
})
})

View File

@@ -59,7 +59,7 @@ func GenerateRepository(name, uri, t string, priority int, src, treeDir string,
}
func NewLuetRepository(name, uri, t string, priority int, art []compiler.Artifact, builder tree.Builder) Repository {
return &LuetRepository{Index: art, Type: t, Tree: builder}
return &LuetRepository{Index: art, Type: t, Tree: builder, Name: name, Uri: uri, Priority: priority}
}
func NewLuetRepositoryFromYaml(data []byte) (Repository, error) {
@@ -85,6 +85,8 @@ func buildPackageIndex(path string) ([]compiler.Artifact, error) {
return errors.Wrap(err, "Error reading file "+currentpath)
}
Info("Reading ", currentpath)
Info(helpers.Read(currentpath))
artifact, err := compiler.NewPackageArtifactFromYaml(dat)
if err != nil {
return errors.Wrap(err, "Error reading yaml "+currentpath)

View File

@@ -37,7 +37,7 @@ type PackageHash struct {
// It is composed of a Package and a Value which is indicating the absence or not
// of the associated package state.
type PackageAssert struct {
Package pkg.Package
Package *pkg.DefaultPackage
Value bool
Hash PackageHash
}
@@ -51,7 +51,7 @@ func DecodeModel(model map[string]bool, db pkg.PackageDatabase) (PackagesAsserti
return nil, err
}
ass = append(ass, PackageAssert{Package: a, Value: v})
ass = append(ass, PackageAssert{Package: a.(*pkg.DefaultPackage), Value: v})
}
return ass, nil
}

View File

@@ -306,11 +306,14 @@ func (s *Solver) Install(coll []pkg.Package) (PackagesAssertions, error) {
if s.noRulesWorld() {
var ass PackagesAssertions
for _, p := range s.Installed {
ass = append(ass, PackageAssert{Package: p.IsFlagged(true), Value: true})
pp := p.IsFlagged(true)
ass = append(ass, PackageAssert{Package: pp.(*pkg.DefaultPackage), Value: true})
}
for _, p := range s.Wanted {
ass = append(ass, PackageAssert{Package: p.IsFlagged(true), Value: true})
pp := p.IsFlagged(true)
ass = append(ass, PackageAssert{Package: pp.(*pkg.DefaultPackage), Value: true})
}
return ass, nil
}