mirror of
https://github.com/aptly-dev/aptly.git
synced 2026-05-06 22:18:28 +00:00
Switch to using internal debian control file parser.
This commit is contained in:
Vendored
+9
@@ -10,6 +10,15 @@ import (
|
|||||||
// Stanza or paragraph of Debian control file
|
// Stanza or paragraph of Debian control file
|
||||||
type Stanza map[string]string
|
type Stanza map[string]string
|
||||||
|
|
||||||
|
// Copy returns copy of Stanza
|
||||||
|
func (s Stanza) Copy() (result Stanza) {
|
||||||
|
result = make(Stanza, len(s))
|
||||||
|
for k, v := range s {
|
||||||
|
result[k] = v
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
// Parsing errors
|
// Parsing errors
|
||||||
var (
|
var (
|
||||||
ErrMalformedStanza = errors.New("malformed stanza syntax")
|
ErrMalformedStanza = errors.New("malformed stanza syntax")
|
||||||
|
|||||||
Vendored
+14
-23
@@ -1,7 +1,6 @@
|
|||||||
package debian
|
package debian
|
||||||
|
|
||||||
import (
|
import (
|
||||||
debc "github.com/smira/godebiancontrol"
|
|
||||||
. "launchpad.net/gocheck"
|
. "launchpad.net/gocheck"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -15,28 +14,20 @@ var _ = Suite(&PackageListSuite{})
|
|||||||
func (s *PackageListSuite) SetUpTest(c *C) {
|
func (s *PackageListSuite) SetUpTest(c *C) {
|
||||||
s.list = NewPackageList()
|
s.list = NewPackageList()
|
||||||
|
|
||||||
paraGen := func() debc.Paragraph {
|
s.p1 = NewPackageFromControlFile(packageStanza.Copy())
|
||||||
para := make(debc.Paragraph)
|
s.p2 = NewPackageFromControlFile(packageStanza.Copy())
|
||||||
for k, v := range packagePara {
|
stanza := packageStanza.Copy()
|
||||||
para[k] = v
|
stanza["Package"] = "mars-invaders"
|
||||||
}
|
s.p3 = NewPackageFromControlFile(stanza)
|
||||||
return para
|
stanza = packageStanza.Copy()
|
||||||
}
|
stanza["Size"] = "42"
|
||||||
|
s.p4 = NewPackageFromControlFile(stanza)
|
||||||
s.p1 = NewPackageFromControlFile(paraGen())
|
stanza = packageStanza.Copy()
|
||||||
s.p2 = NewPackageFromControlFile(paraGen())
|
stanza["Package"] = "lonely-strangers"
|
||||||
para := paraGen()
|
s.p5 = NewPackageFromControlFile(stanza)
|
||||||
para["Package"] = "mars-invaders"
|
stanza = packageStanza.Copy()
|
||||||
s.p3 = NewPackageFromControlFile(para)
|
stanza["Version"] = "99.1"
|
||||||
para = paraGen()
|
s.p6 = NewPackageFromControlFile(stanza)
|
||||||
para["Size"] = "42"
|
|
||||||
s.p4 = NewPackageFromControlFile(para)
|
|
||||||
para = paraGen()
|
|
||||||
para["Package"] = "lonely-strangers"
|
|
||||||
s.p5 = NewPackageFromControlFile(para)
|
|
||||||
para = paraGen()
|
|
||||||
para["Version"] = "99.1"
|
|
||||||
s.p6 = NewPackageFromControlFile(para)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *PackageListSuite) TestAddLen(c *C) {
|
func (s *PackageListSuite) TestAddLen(c *C) {
|
||||||
|
|||||||
Vendored
+3
-4
@@ -5,7 +5,6 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"github.com/smira/aptly/database"
|
"github.com/smira/aptly/database"
|
||||||
"github.com/smira/aptly/utils"
|
"github.com/smira/aptly/utils"
|
||||||
debc "github.com/smira/godebiancontrol"
|
|
||||||
"github.com/ugorji/go/codec"
|
"github.com/ugorji/go/codec"
|
||||||
"os"
|
"os"
|
||||||
"strconv"
|
"strconv"
|
||||||
@@ -25,10 +24,10 @@ type Package struct {
|
|||||||
PreDepends []string
|
PreDepends []string
|
||||||
Suggests []string
|
Suggests []string
|
||||||
Recommends []string
|
Recommends []string
|
||||||
Extra debc.Paragraph
|
Extra Stanza
|
||||||
}
|
}
|
||||||
|
|
||||||
func parseDependencies(input debc.Paragraph, key string) []string {
|
func parseDependencies(input Stanza, key string) []string {
|
||||||
value, ok := input[key]
|
value, ok := input[key]
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil
|
return nil
|
||||||
@@ -40,7 +39,7 @@ func parseDependencies(input debc.Paragraph, key string) []string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// NewPackageFromControlFile creates Package from parsed Debian control file
|
// NewPackageFromControlFile creates Package from parsed Debian control file
|
||||||
func NewPackageFromControlFile(input debc.Paragraph) *Package {
|
func NewPackageFromControlFile(input Stanza) *Package {
|
||||||
result := &Package{
|
result := &Package{
|
||||||
Name: input["Package"],
|
Name: input["Package"],
|
||||||
Version: input["Version"],
|
Version: input["Version"],
|
||||||
|
|||||||
Vendored
+6
-17
@@ -2,23 +2,19 @@ package debian
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/smira/aptly/database"
|
"github.com/smira/aptly/database"
|
||||||
debc "github.com/smira/godebiancontrol"
|
|
||||||
. "launchpad.net/gocheck"
|
. "launchpad.net/gocheck"
|
||||||
)
|
)
|
||||||
|
|
||||||
var packagePara = debc.Paragraph{"Source": "alien-arena", "Depends": "libc6 (>= 2.7), alien-arena-data (>= 7.40)", "Filename": "pool/contrib/a/alien-arena/alien-arena-common_7.40-2_i386.deb", "SHA1": "46955e48cad27410a83740a21d766ce362364024", "SHA256": "eb4afb9885cba6dc70cccd05b910b2dbccc02c5900578be5e99f0d3dbf9d76a5", "Priority": "extra", "Maintainer": "Debian Games Team <pkg-games-devel@lists.alioth.debian.org>", "Description": "Common files for Alien Arena client and server ALIEN ARENA is a standalone 3D first person online deathmatch shooter\n crafted from the original source code of Quake II and Quake III, released\n by id Software under the GPL license. With features including 32 bit\n graphics, new particle engine and effects, light blooms, reflective water,\n hi resolution textures and skins, hi poly models, stain maps, ALIEN ARENA\n pushes the envelope of graphical beauty rivaling today's top games.\n .\n This package installs the common files for Alien Arena.\n", "Homepage": "http://red.planetarena.org", "Tag": "role::app-data, role::shared-lib, special::auto-inst-parts", "Installed-Size": "456", "Version": "7.40-2", "Replaces": "alien-arena (<< 7.33-1)", "Size": "187518", "MD5sum": "1e8cba92c41420aa7baa8a5718d67122", "Package": "alien-arena-common", "Section": "contrib/games", "Architecture": "i386"}
|
var packageStanza = Stanza{"Source": "alien-arena", "Depends": "libc6 (>= 2.7), alien-arena-data (>= 7.40)", "Filename": "pool/contrib/a/alien-arena/alien-arena-common_7.40-2_i386.deb", "SHA1": "46955e48cad27410a83740a21d766ce362364024", "SHA256": "eb4afb9885cba6dc70cccd05b910b2dbccc02c5900578be5e99f0d3dbf9d76a5", "Priority": "extra", "Maintainer": "Debian Games Team <pkg-games-devel@lists.alioth.debian.org>", "Description": "Common files for Alien Arena client and server ALIEN ARENA is a standalone 3D first person online deathmatch shooter\n crafted from the original source code of Quake II and Quake III, released\n by id Software under the GPL license. With features including 32 bit\n graphics, new particle engine and effects, light blooms, reflective water,\n hi resolution textures and skins, hi poly models, stain maps, ALIEN ARENA\n pushes the envelope of graphical beauty rivaling today's top games.\n .\n This package installs the common files for Alien Arena.\n", "Homepage": "http://red.planetarena.org", "Tag": "role::app-data, role::shared-lib, special::auto-inst-parts", "Installed-Size": "456", "Version": "7.40-2", "Replaces": "alien-arena (<< 7.33-1)", "Size": "187518", "MD5sum": "1e8cba92c41420aa7baa8a5718d67122", "Package": "alien-arena-common", "Section": "contrib/games", "Architecture": "i386"}
|
||||||
|
|
||||||
type PackageSuite struct {
|
type PackageSuite struct {
|
||||||
para debc.Paragraph
|
para Stanza
|
||||||
}
|
}
|
||||||
|
|
||||||
var _ = Suite(&PackageSuite{})
|
var _ = Suite(&PackageSuite{})
|
||||||
|
|
||||||
func (s *PackageSuite) SetUpTest(c *C) {
|
func (s *PackageSuite) SetUpTest(c *C) {
|
||||||
s.para = make(debc.Paragraph)
|
s.para = packageStanza.Copy()
|
||||||
for k, v := range packagePara {
|
|
||||||
s.para[k] = v
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *PackageSuite) TestNewFromPara(c *C) {
|
func (s *PackageSuite) TestNewFromPara(c *C) {
|
||||||
@@ -57,11 +53,8 @@ func (s *PackageSuite) TestString(c *C) {
|
|||||||
func (s *PackageSuite) TestEquals(c *C) {
|
func (s *PackageSuite) TestEquals(c *C) {
|
||||||
p := NewPackageFromControlFile(s.para)
|
p := NewPackageFromControlFile(s.para)
|
||||||
|
|
||||||
para2 := make(debc.Paragraph)
|
stanza2 := packageStanza.Copy()
|
||||||
for k, v := range packagePara {
|
p2 := NewPackageFromControlFile(stanza2)
|
||||||
para2[k] = v
|
|
||||||
}
|
|
||||||
p2 := NewPackageFromControlFile(para2)
|
|
||||||
c.Check(p.Equals(p2), Equals, true)
|
c.Check(p.Equals(p2), Equals, true)
|
||||||
|
|
||||||
p2.Depends = []string{"package1"}
|
p2.Depends = []string{"package1"}
|
||||||
@@ -77,11 +70,7 @@ type PackageCollectionSuite struct {
|
|||||||
var _ = Suite(&PackageCollectionSuite{})
|
var _ = Suite(&PackageCollectionSuite{})
|
||||||
|
|
||||||
func (s *PackageCollectionSuite) SetUpTest(c *C) {
|
func (s *PackageCollectionSuite) SetUpTest(c *C) {
|
||||||
para := make(debc.Paragraph)
|
s.p = NewPackageFromControlFile(packageStanza.Copy())
|
||||||
for k, v := range packagePara {
|
|
||||||
para[k] = v
|
|
||||||
}
|
|
||||||
s.p = NewPackageFromControlFile(para)
|
|
||||||
s.db, _ = database.OpenDB(c.MkDir())
|
s.db, _ = database.OpenDB(c.MkDir())
|
||||||
s.collection = NewPackageCollection(s.db)
|
s.collection = NewPackageCollection(s.db)
|
||||||
}
|
}
|
||||||
|
|||||||
Vendored
+20
-21
@@ -7,7 +7,6 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"github.com/smira/aptly/database"
|
"github.com/smira/aptly/database"
|
||||||
"github.com/smira/aptly/utils"
|
"github.com/smira/aptly/utils"
|
||||||
debc "github.com/smira/godebiancontrol"
|
|
||||||
"github.com/ugorji/go/codec"
|
"github.com/ugorji/go/codec"
|
||||||
"log"
|
"log"
|
||||||
"net/url"
|
"net/url"
|
||||||
@@ -33,7 +32,7 @@ type RemoteRepo struct {
|
|||||||
// List of architectures to fetch, if empty, then fetch all architectures
|
// List of architectures to fetch, if empty, then fetch all architectures
|
||||||
Architectures []string
|
Architectures []string
|
||||||
// Meta-information about repository
|
// Meta-information about repository
|
||||||
Meta debc.Paragraph
|
Meta Stanza
|
||||||
// Last update date
|
// Last update date
|
||||||
LastDownloadDate time.Time
|
LastDownloadDate time.Time
|
||||||
// "Snapshot" of current list of packages
|
// "Snapshot" of current list of packages
|
||||||
@@ -109,18 +108,13 @@ func (repo *RemoteRepo) Fetch(d utils.Downloader) error {
|
|||||||
}
|
}
|
||||||
defer release.Close()
|
defer release.Close()
|
||||||
|
|
||||||
paras, err := debc.Parse(release)
|
sreader := NewControlFileReader(release)
|
||||||
|
stanza, err := sreader.ReadStanza()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(paras) != 1 {
|
architectures := strings.Split(stanza["Architectures"], " ")
|
||||||
return fmt.Errorf("wrong number of parts in Release file")
|
|
||||||
}
|
|
||||||
|
|
||||||
para := paras[0]
|
|
||||||
|
|
||||||
architectures := strings.Split(para["Architectures"], " ")
|
|
||||||
if len(repo.Architectures) == 0 {
|
if len(repo.Architectures) == 0 {
|
||||||
repo.Architectures = architectures
|
repo.Architectures = architectures
|
||||||
} else {
|
} else {
|
||||||
@@ -131,7 +125,7 @@ func (repo *RemoteRepo) Fetch(d utils.Downloader) error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
components := strings.Split(para["Components"], " ")
|
components := strings.Split(stanza["Components"], " ")
|
||||||
if len(repo.Components) == 0 {
|
if len(repo.Components) == 0 {
|
||||||
repo.Components = components
|
repo.Components = components
|
||||||
} else {
|
} else {
|
||||||
@@ -142,10 +136,10 @@ func (repo *RemoteRepo) Fetch(d utils.Downloader) error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
delete(para, "MD5Sum")
|
delete(stanza, "MD5Sum")
|
||||||
delete(para, "SHA1")
|
delete(stanza, "SHA1")
|
||||||
delete(para, "SHA256")
|
delete(stanza, "SHA256")
|
||||||
repo.Meta = para
|
repo.Meta = stanza
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@@ -163,13 +157,18 @@ func (repo *RemoteRepo) Download(d utils.Downloader, packageCollection *PackageC
|
|||||||
}
|
}
|
||||||
defer packagesFile.Close()
|
defer packagesFile.Close()
|
||||||
|
|
||||||
paras, err := debc.Parse(packagesReader)
|
sreader := NewControlFileReader(packagesReader)
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, para := range paras {
|
for {
|
||||||
p := NewPackageFromControlFile(para)
|
stanza, err := sreader.ReadStanza()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if stanza == nil {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
|
||||||
|
p := NewPackageFromControlFile(stanza)
|
||||||
|
|
||||||
list.Add(p)
|
list.Add(p)
|
||||||
}
|
}
|
||||||
|
|||||||
Vendored
+7
-16
@@ -3,7 +3,6 @@ package debian
|
|||||||
import (
|
import (
|
||||||
"github.com/smira/aptly/database"
|
"github.com/smira/aptly/database"
|
||||||
"github.com/smira/aptly/utils"
|
"github.com/smira/aptly/utils"
|
||||||
debc "github.com/smira/godebiancontrol"
|
|
||||||
. "launchpad.net/gocheck"
|
. "launchpad.net/gocheck"
|
||||||
"testing"
|
"testing"
|
||||||
)
|
)
|
||||||
@@ -22,21 +21,13 @@ type PackageListMixinSuite struct {
|
|||||||
func (s *PackageListMixinSuite) SetUpPackages() {
|
func (s *PackageListMixinSuite) SetUpPackages() {
|
||||||
s.list = NewPackageList()
|
s.list = NewPackageList()
|
||||||
|
|
||||||
paraGen := func() debc.Paragraph {
|
s.p1 = NewPackageFromControlFile(packageStanza.Copy())
|
||||||
para := make(debc.Paragraph)
|
stanza := packageStanza.Copy()
|
||||||
for k, v := range packagePara {
|
stanza["Package"] = "mars-invaders"
|
||||||
para[k] = v
|
s.p2 = NewPackageFromControlFile(stanza)
|
||||||
}
|
stanza = packageStanza.Copy()
|
||||||
return para
|
stanza["Package"] = "lonely-strangers"
|
||||||
}
|
s.p3 = NewPackageFromControlFile(stanza)
|
||||||
|
|
||||||
s.p1 = NewPackageFromControlFile(paraGen())
|
|
||||||
para := paraGen()
|
|
||||||
para["Package"] = "mars-invaders"
|
|
||||||
s.p2 = NewPackageFromControlFile(para)
|
|
||||||
para = paraGen()
|
|
||||||
para["Package"] = "lonely-strangers"
|
|
||||||
s.p3 = NewPackageFromControlFile(para)
|
|
||||||
|
|
||||||
s.list.Add(s.p1)
|
s.list.Add(s.p1)
|
||||||
s.list.Add(s.p2)
|
s.list.Add(s.p2)
|
||||||
|
|||||||
Reference in New Issue
Block a user