Package equality, string representation.

This commit is contained in:
Andrey Smirnov
2013-12-18 12:11:19 +04:00
parent 148bbc8b2a
commit a2a51358f9
2 changed files with 36 additions and 2 deletions
+16 -1
View File
@@ -2,6 +2,8 @@ package debian
import (
"bytes"
"fmt"
"github.com/smira/aptly/utils"
debc "github.com/smira/godebiancontrol"
"github.com/ugorji/go/codec"
"strings"
@@ -59,7 +61,7 @@ func NewPackageFromControlFile(input debc.Paragraph) *Package {
// Key returns unique key identifying package
func (p *Package) Key() []byte {
return []byte(p.Name + " " + p.Version + " " + p.Architecture)
return []byte("P" + p.Name + " " + p.Version + " " + p.Architecture)
}
// Encode does msgpack encoding of Package
@@ -77,3 +79,16 @@ func (p *Package) Decode(input []byte) error {
decoder := codec.NewDecoderBytes(input, &codec.MsgpackHandle{})
return decoder.Decode(p)
}
// String creates readable representation
func (p *Package) String() string {
return fmt.Sprintf("%s-%s_%s", p.Name, p.Version, p.Architecture)
}
// Equals compares two packages to be identical
func (p *Package) Equals(p2 *Package) bool {
return p.Name == p2.Name && p.Version == p2.Version && p.Filename == p2.Filename &&
p.Architecture == p2.Architecture && utils.StrSlicesEqual(p.Depends, p2.Depends) &&
utils.StrSlicesEqual(p.PreDepends, p2.PreDepends) && utils.StrSlicesEqual(p.Suggests, p2.Suggests) &&
utils.StrSlicesEqual(p.Recommends, p2.Recommends) && utils.StrMapsEqual(p.Extra, p2.Extra)
}