mirror of
https://github.com/aptly-dev/aptly.git
synced 2026-04-20 19:38:39 +00:00
Architecture parsing, package list from reflist.
This commit is contained in:
31
debian/list.go
vendored
31
debian/list.go
vendored
@@ -3,6 +3,7 @@ package debian
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"github.com/smira/aptly/utils"
|
||||
"github.com/ugorji/go/codec"
|
||||
"sort"
|
||||
)
|
||||
@@ -20,6 +21,25 @@ func NewPackageList() *PackageList {
|
||||
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
|
||||
func (l *PackageList) Add(p *Package) error {
|
||||
key := string(p.Key())
|
||||
@@ -51,6 +71,17 @@ func (l *PackageList) Len() int {
|
||||
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
|
||||
const (
|
||||
// DepFollowSource pulls source packages when required
|
||||
|
||||
33
debian/list_test.go
vendored
33
debian/list_test.go
vendored
@@ -2,7 +2,9 @@ package debian
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"github.com/smira/aptly/database"
|
||||
. "launchpad.net/gocheck"
|
||||
"sort"
|
||||
)
|
||||
|
||||
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) {
|
||||
s.list.Add(s.p1)
|
||||
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:.*")
|
||||
}
|
||||
|
||||
func (s *PackageIndexedListSuite) TestArchitectures(c *C) {
|
||||
archs := s.pl.Architectures()
|
||||
sort.Strings(archs)
|
||||
c.Check(archs, DeepEquals, []string{"amd64", "arm", "i386", "s390"})
|
||||
}
|
||||
|
||||
8
debian/publish.go
vendored
8
debian/publish.go
vendored
@@ -66,13 +66,7 @@ func (p *PublishedRepo) Publish(repo *Repository, packageCollection *PackageColl
|
||||
}
|
||||
|
||||
if p.Architectures == nil {
|
||||
p.Architectures = make([]string, 0, 10)
|
||||
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
|
||||
})
|
||||
p.Architectures = list.Architectures()
|
||||
}
|
||||
|
||||
if len(p.Architectures) == 0 {
|
||||
|
||||
Reference in New Issue
Block a user