Add accessors to Hash and Verify artifacts

Refers to #28
This commit is contained in:
Ettore Di Giacinto
2019-12-29 13:56:52 +01:00
parent 17982e9527
commit eeb6719529
2 changed files with 30 additions and 5 deletions

View File

@@ -55,7 +55,7 @@ type PackageArtifact struct {
Path string `json:"path"`
Dependencies []*PackageArtifact `json:"dependencies"`
CompileSpec *LuetCompilationSpec `json:"compilationspec"`
Checksums Checksums `json:"checksums"`
SourceAssertion solver.PackagesAssertions `json:"-"`
}
@@ -64,7 +64,7 @@ func NewPackageArtifact(path string) Artifact {
}
func NewPackageArtifactFromYaml(data []byte) (Artifact, error) {
p := &PackageArtifact{}
p := &PackageArtifact{Checksums: Checksums{}}
err := yaml.Unmarshal(data, &p)
if err != nil {
return p, err
@@ -73,7 +73,30 @@ func NewPackageArtifactFromYaml(data []byte) (Artifact, error) {
return p, err
}
func (a *PackageArtifact) Hash() error {
return a.Checksums.Generate(a)
}
func (a *PackageArtifact) Verify() error {
sum := Checksums{}
err := sum.Generate(a)
if err != nil {
return err
}
err = sum.Compare(a.Checksums)
if err != nil {
return err
}
return nil
}
func (a *PackageArtifact) WriteYaml(dst string) error {
// First compute checksum of artifact. When we write the yaml we want to write up-to-date informations.
err := a.Hash()
if err != nil {
return errors.Wrap(err, "Failed generating checksums for artifact")
}
//p := a.CompileSpec.GetPackage().GetPath()
//a.CompileSpec.GetPackage().SetPath("")

View File

@@ -65,6 +65,8 @@ type Artifact interface {
Unpack(dst string, keepPerms bool) error
Compress(src string) error
FileList() ([]string, error)
Hash() error
Verify() error
}
type ArtifactNode struct {