mirror of
https://github.com/aptly-dev/aptly.git
synced 2026-01-12 03:21:33 +00:00
Add package refs to mirror state.
This commit is contained in:
46
debian/list.go
vendored
46
debian/list.go
vendored
@@ -1,7 +1,9 @@
|
||||
package debian
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"sort"
|
||||
)
|
||||
|
||||
// PackageList is list of unique (by key) packages
|
||||
@@ -40,7 +42,47 @@ func (l *PackageList) ForEach(handler func(*Package)) {
|
||||
}
|
||||
}
|
||||
|
||||
// Length returns number of packages in the list
|
||||
func (l *PackageList) Length() int {
|
||||
// Len returns number of packages in the list
|
||||
func (l *PackageList) Len() int {
|
||||
return len(l.packages)
|
||||
}
|
||||
|
||||
// PackageRefList is a list of keys of packages, this is basis for snapshot
|
||||
// and similar stuff
|
||||
//
|
||||
// Refs are sorted in lexographical order
|
||||
type PackageRefList struct {
|
||||
// List of package keys
|
||||
Refs [][]byte
|
||||
}
|
||||
|
||||
// NewPackageRefListFromPackageList creates PackageRefList from PackageList
|
||||
func NewPackageRefListFromPackageList(list *PackageList) *PackageRefList {
|
||||
reflist := &PackageRefList{}
|
||||
reflist.Refs = make([][]byte, list.Len())
|
||||
|
||||
i := 0
|
||||
for _, p := range list.packages {
|
||||
reflist.Refs[i] = p.Key()
|
||||
i++
|
||||
}
|
||||
|
||||
sort.Sort(reflist)
|
||||
|
||||
return reflist
|
||||
}
|
||||
|
||||
// Len returns number of refs
|
||||
func (l *PackageRefList) Len() int {
|
||||
return len(l.Refs)
|
||||
}
|
||||
|
||||
// Swap swaps two refs
|
||||
func (l *PackageRefList) Swap(i, j int) {
|
||||
l.Refs[i], l.Refs[j] = l.Refs[j], l.Refs[i]
|
||||
}
|
||||
|
||||
// Compare compares two refs in lexographical order
|
||||
func (l *PackageRefList) Less(i, j int) bool {
|
||||
return bytes.Compare(l.Refs[i], l.Refs[j]) < 0
|
||||
}
|
||||
|
||||
26
debian/list_test.go
vendored
26
debian/list_test.go
vendored
@@ -33,14 +33,14 @@ func (s *PackageListSuite) SetUpTest(c *C) {
|
||||
s.p4 = NewPackageFromControlFile(para)
|
||||
}
|
||||
|
||||
func (s *PackageListSuite) TestAddLength(c *C) {
|
||||
c.Check(s.list.Length(), Equals, 0)
|
||||
func (s *PackageListSuite) TestAddLen(c *C) {
|
||||
c.Check(s.list.Len(), Equals, 0)
|
||||
c.Check(s.list.Add(s.p1), IsNil)
|
||||
c.Check(s.list.Length(), Equals, 1)
|
||||
c.Check(s.list.Len(), Equals, 1)
|
||||
c.Check(s.list.Add(s.p2), IsNil)
|
||||
c.Check(s.list.Length(), Equals, 1)
|
||||
c.Check(s.list.Len(), Equals, 1)
|
||||
c.Check(s.list.Add(s.p3), IsNil)
|
||||
c.Check(s.list.Length(), Equals, 2)
|
||||
c.Check(s.list.Len(), Equals, 2)
|
||||
c.Check(s.list.Add(s.p4), ErrorMatches, "conflict in package.*")
|
||||
}
|
||||
|
||||
@@ -48,10 +48,20 @@ func (s *PackageListSuite) TestForeach(c *C) {
|
||||
s.list.Add(s.p1)
|
||||
s.list.Add(s.p3)
|
||||
|
||||
length := 0
|
||||
Len := 0
|
||||
s.list.ForEach(func(*Package) {
|
||||
length++
|
||||
Len++
|
||||
})
|
||||
|
||||
c.Check(length, Equals, 2)
|
||||
c.Check(Len, Equals, 2)
|
||||
}
|
||||
|
||||
func (s *PackageListSuite) TestNewPackageRefList(c *C) {
|
||||
s.list.Add(s.p1)
|
||||
s.list.Add(s.p3)
|
||||
|
||||
reflist := NewPackageRefListFromPackageList(s.list)
|
||||
c.Assert(reflist.Len(), Equals, 2)
|
||||
c.Assert(reflist.Refs[0], DeepEquals, []byte(s.p1.Key()))
|
||||
c.Assert(reflist.Refs[1], DeepEquals, []byte(s.p3.Key()))
|
||||
}
|
||||
|
||||
12
debian/remote.go
vendored
12
debian/remote.go
vendored
@@ -12,6 +12,7 @@ import (
|
||||
"log"
|
||||
"net/url"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
// RemoteRepo represents remote (fetchable) Debian repository.
|
||||
@@ -32,7 +33,11 @@ type RemoteRepo struct {
|
||||
// List of architectures to fetch, if empty, then fetch all architectures
|
||||
Architectures []string
|
||||
// Meta-information about repository
|
||||
Meta debc.Paragraph
|
||||
Meta debc.Paragraph
|
||||
// Last update date
|
||||
LastDownloadDate time.Time
|
||||
// "Snapshot" of current list of packages
|
||||
PackageRefs *PackageRefList
|
||||
archiveRootURL *url.URL
|
||||
}
|
||||
|
||||
@@ -168,7 +173,7 @@ func (repo *RemoteRepo) Download(d utils.Downloader, db database.Storage, packag
|
||||
})
|
||||
|
||||
// Download all package files
|
||||
ch := make(chan error, list.Length())
|
||||
ch := make(chan error, list.Len())
|
||||
count := 0
|
||||
|
||||
list.ForEach(func(p *Package) {
|
||||
@@ -188,6 +193,9 @@ func (repo *RemoteRepo) Download(d utils.Downloader, db database.Storage, packag
|
||||
count--
|
||||
}
|
||||
|
||||
repo.LastDownloadDate = time.Now()
|
||||
repo.PackageRefs = NewPackageRefListFromPackageList(list)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user