mirror of
https://github.com/aptly-dev/aptly.git
synced 2026-07-26 13:47:40 +00:00
Architecture parsing, package list from reflist.
This commit is contained in:
Vendored
+31
@@ -3,6 +3,7 @@ package debian
|
|||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"github.com/smira/aptly/utils"
|
||||||
"github.com/ugorji/go/codec"
|
"github.com/ugorji/go/codec"
|
||||||
"sort"
|
"sort"
|
||||||
)
|
)
|
||||||
@@ -20,6 +21,25 @@ func NewPackageList() *PackageList {
|
|||||||
return &PackageList{packages: make(map[string]*Package, 1000)}
|
return &PackageList{packages: make(map[string]*Package, 1000)}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// NewPackageListFromRefList loads packages list from PackageRefList
|
||||||
|
func NewPackageListFromRefList(reflist *PackageRefList, collection *PackageCollection) (*PackageList, error) {
|
||||||
|
result := &PackageList{packages: make(map[string]*Package, reflist.Len())}
|
||||||
|
|
||||||
|
err := reflist.ForEach(func(key []byte) error {
|
||||||
|
p, err := collection.ByKey(key)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("unable to load package with key %s: %s", key, err)
|
||||||
|
}
|
||||||
|
return result.Add(p)
|
||||||
|
})
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return result, nil
|
||||||
|
}
|
||||||
|
|
||||||
// Add appends package to package list, additionally checking for uniqueness
|
// Add appends package to package list, additionally checking for uniqueness
|
||||||
func (l *PackageList) Add(p *Package) error {
|
func (l *PackageList) Add(p *Package) error {
|
||||||
key := string(p.Key())
|
key := string(p.Key())
|
||||||
@@ -51,6 +71,17 @@ func (l *PackageList) Len() int {
|
|||||||
return len(l.packages)
|
return len(l.packages)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Architectures returns list of architectures present in packages
|
||||||
|
func (l *PackageList) Architectures() (result []string) {
|
||||||
|
result = make([]string, 0, 10)
|
||||||
|
for _, pkg := range l.packages {
|
||||||
|
if pkg.Architecture != "all" && !utils.StrSliceHasItem(result, pkg.Architecture) {
|
||||||
|
result = append(result, pkg.Architecture)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
// Dependency options
|
// Dependency options
|
||||||
const (
|
const (
|
||||||
// DepFollowSource pulls source packages when required
|
// DepFollowSource pulls source packages when required
|
||||||
|
|||||||
Vendored
+33
@@ -2,7 +2,9 @@ package debian
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
|
"github.com/smira/aptly/database"
|
||||||
. "launchpad.net/gocheck"
|
. "launchpad.net/gocheck"
|
||||||
|
"sort"
|
||||||
)
|
)
|
||||||
|
|
||||||
type PackageListSuite struct {
|
type PackageListSuite struct {
|
||||||
@@ -65,6 +67,31 @@ func (s *PackageListSuite) TestForeach(c *C) {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *PackageListSuite) TestNewPackageListFromRefList(c *C) {
|
||||||
|
db, _ := database.OpenDB(c.MkDir())
|
||||||
|
coll := NewPackageCollection(db)
|
||||||
|
coll.Update(s.p1)
|
||||||
|
coll.Update(s.p3)
|
||||||
|
|
||||||
|
s.list.Add(s.p1)
|
||||||
|
s.list.Add(s.p3)
|
||||||
|
s.list.Add(s.p5)
|
||||||
|
s.list.Add(s.p6)
|
||||||
|
|
||||||
|
reflist := NewPackageRefListFromPackageList(s.list)
|
||||||
|
|
||||||
|
_, err := NewPackageListFromRefList(reflist, coll)
|
||||||
|
c.Assert(err, ErrorMatches, "unable to load package with key.*")
|
||||||
|
|
||||||
|
coll.Update(s.p5)
|
||||||
|
coll.Update(s.p6)
|
||||||
|
|
||||||
|
list, err := NewPackageListFromRefList(reflist, coll)
|
||||||
|
c.Assert(err, IsNil)
|
||||||
|
c.Check(list.Len(), Equals, 4)
|
||||||
|
c.Check(list.Add(s.p4), ErrorMatches, "conflict in package.*")
|
||||||
|
}
|
||||||
|
|
||||||
func (s *PackageListSuite) TestNewPackageRefList(c *C) {
|
func (s *PackageListSuite) TestNewPackageRefList(c *C) {
|
||||||
s.list.Add(s.p1)
|
s.list.Add(s.p1)
|
||||||
s.list.Add(s.p3)
|
s.list.Add(s.p3)
|
||||||
@@ -195,3 +222,9 @@ func (s *PackageIndexedListSuite) TestVerifyDependencies(c *C) {
|
|||||||
|
|
||||||
c.Check(err, ErrorMatches, "unable to process package app-1.0_s390:.*")
|
c.Check(err, ErrorMatches, "unable to process package app-1.0_s390:.*")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *PackageIndexedListSuite) TestArchitectures(c *C) {
|
||||||
|
archs := s.pl.Architectures()
|
||||||
|
sort.Strings(archs)
|
||||||
|
c.Check(archs, DeepEquals, []string{"amd64", "arm", "i386", "s390"})
|
||||||
|
}
|
||||||
|
|||||||
Vendored
+1
-7
@@ -66,13 +66,7 @@ func (p *PublishedRepo) Publish(repo *Repository, packageCollection *PackageColl
|
|||||||
}
|
}
|
||||||
|
|
||||||
if p.Architectures == nil {
|
if p.Architectures == nil {
|
||||||
p.Architectures = make([]string, 0, 10)
|
p.Architectures = list.Architectures()
|
||||||
list.ForEach(func(pkg *Package) error {
|
|
||||||
if pkg.Architecture != "all" && !utils.StrSliceHasItem(p.Architectures, pkg.Architecture) {
|
|
||||||
p.Architectures = append(p.Architectures, pkg.Architecture)
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(p.Architectures) == 0 {
|
if len(p.Architectures) == 0 {
|
||||||
|
|||||||
Reference in New Issue
Block a user