mirror of
https://github.com/aptly-dev/aptly.git
synced 2026-05-08 22:30:41 +00:00
PublishedRepo remembers RefList is has been published with. #8
This commit is contained in:
+53
-11
@@ -32,8 +32,9 @@ type PublishedRepo struct {
|
|||||||
// SourceUUID is UUID of either snapshot or local repo
|
// SourceUUID is UUID of either snapshot or local repo
|
||||||
SourceUUID string `codec:"SnapshotUUID"`
|
SourceUUID string `codec:"SnapshotUUID"`
|
||||||
|
|
||||||
snapshot *Snapshot
|
snapshot *Snapshot
|
||||||
localRepo *LocalRepo
|
localRepo *LocalRepo
|
||||||
|
packageRefs *PackageRefList
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewPublishedRepo creates new published repository
|
// NewPublishedRepo creates new published repository
|
||||||
@@ -59,6 +60,7 @@ func NewPublishedRepo(prefix string, distribution string, component string, arch
|
|||||||
if ok {
|
if ok {
|
||||||
result.SourceKind = "local"
|
result.SourceKind = "local"
|
||||||
result.SourceUUID = result.localRepo.UUID
|
result.SourceUUID = result.localRepo.UUID
|
||||||
|
result.packageRefs = result.localRepo.RefList()
|
||||||
} else {
|
} else {
|
||||||
panic("unknown source kind")
|
panic("unknown source kind")
|
||||||
}
|
}
|
||||||
@@ -179,6 +181,19 @@ func (p *PublishedRepo) Key() []byte {
|
|||||||
return []byte("U" + p.Prefix + ">>" + p.Distribution)
|
return []byte("U" + p.Prefix + ">>" + p.Distribution)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// RefKey is a unique id for package reference list
|
||||||
|
func (p *PublishedRepo) RefKey() []byte {
|
||||||
|
return []byte("E" + p.UUID)
|
||||||
|
}
|
||||||
|
|
||||||
|
// RefList returns list of package refs in local repo
|
||||||
|
func (p *PublishedRepo) RefList() *PackageRefList {
|
||||||
|
if p.SourceKind == "local" {
|
||||||
|
return p.packageRefs
|
||||||
|
}
|
||||||
|
return p.snapshot.RefList()
|
||||||
|
}
|
||||||
|
|
||||||
// Encode does msgpack encoding of PublishedRepo
|
// Encode does msgpack encoding of PublishedRepo
|
||||||
func (p *PublishedRepo) Encode() []byte {
|
func (p *PublishedRepo) Encode() []byte {
|
||||||
var buf bytes.Buffer
|
var buf bytes.Buffer
|
||||||
@@ -206,7 +221,8 @@ func (p *PublishedRepo) Decode(input []byte) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Publish publishes snapshot (repository) contents, links package files, generates Packages & Release files, signs them
|
// Publish publishes snapshot (repository) contents, links package files, generates Packages & Release files, signs them
|
||||||
func (p *PublishedRepo) Publish(packagePool aptly.PackagePool, publishedStorage aptly.PublishedStorage, collectionFactory *CollectionFactory, signer utils.Signer, progress aptly.Progress) error {
|
func (p *PublishedRepo) Publish(packagePool aptly.PackagePool, publishedStorage aptly.PublishedStorage,
|
||||||
|
collectionFactory *CollectionFactory, signer utils.Signer, progress aptly.Progress) error {
|
||||||
err := publishedStorage.MkDir(filepath.Join(p.Prefix, "pool"))
|
err := publishedStorage.MkDir(filepath.Join(p.Prefix, "pool"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@@ -489,22 +505,44 @@ func (collection *PublishedRepoCollection) CheckDuplicate(repo *PublishedRepo) *
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Update stores updated information about repo in DB
|
// Update stores updated information about repo in DB
|
||||||
func (collection *PublishedRepoCollection) Update(repo *PublishedRepo) error {
|
func (collection *PublishedRepoCollection) Update(repo *PublishedRepo) (err error) {
|
||||||
err := collection.db.Put(repo.Key(), repo.Encode())
|
err = collection.db.Put(repo.Key(), repo.Encode())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return
|
||||||
}
|
}
|
||||||
return nil
|
|
||||||
|
if repo.SourceKind == "local" {
|
||||||
|
err = collection.db.Put(repo.RefKey(), repo.packageRefs.Encode())
|
||||||
|
}
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// LoadComplete loads additional information for remote repo
|
// LoadComplete loads additional information for remote repo
|
||||||
func (collection *PublishedRepoCollection) LoadComplete(repo *PublishedRepo, collectionFactory *CollectionFactory) error {
|
func (collection *PublishedRepoCollection) LoadComplete(repo *PublishedRepo, collectionFactory *CollectionFactory) (err error) {
|
||||||
var err error
|
|
||||||
|
|
||||||
if repo.SourceKind == "snapshot" {
|
if repo.SourceKind == "snapshot" {
|
||||||
repo.snapshot, err = collectionFactory.SnapshotCollection().ByUUID(repo.SourceUUID)
|
repo.snapshot, err = collectionFactory.SnapshotCollection().ByUUID(repo.SourceUUID)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
err = collectionFactory.SnapshotCollection().LoadComplete(repo.snapshot)
|
||||||
} else if repo.SourceKind == "local" {
|
} else if repo.SourceKind == "local" {
|
||||||
repo.localRepo, err = collectionFactory.LocalRepoCollection().ByUUID(repo.SourceUUID)
|
repo.localRepo, err = collectionFactory.LocalRepoCollection().ByUUID(repo.SourceUUID)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
err = collectionFactory.LocalRepoCollection().LoadComplete(repo.localRepo)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
var encoded []byte
|
||||||
|
encoded, err = collection.db.Get(repo.RefKey())
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
repo.packageRefs = &PackageRefList{}
|
||||||
|
err = repo.packageRefs.Decode(encoded)
|
||||||
} else {
|
} else {
|
||||||
panic("unknown SourceKind")
|
panic("unknown SourceKind")
|
||||||
}
|
}
|
||||||
@@ -603,5 +641,9 @@ func (collection *PublishedRepoCollection) Remove(publishedStorage aptly.Publish
|
|||||||
collection.list[len(collection.list)-1], collection.list[repoPosition], collection.list =
|
collection.list[len(collection.list)-1], collection.list[repoPosition], collection.list =
|
||||||
nil, collection.list[len(collection.list)-1], collection.list[:len(collection.list)-1]
|
nil, collection.list[len(collection.list)-1], collection.list[:len(collection.list)-1]
|
||||||
|
|
||||||
return collection.db.Delete(repo.Key())
|
err = collection.db.Delete(repo.Key())
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return collection.db.Delete(repo.RefKey())
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -99,6 +99,20 @@ func (s *PublishedRepoSuite) TearDownTest(c *C) {
|
|||||||
s.db.Close()
|
s.db.Close()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *PublishedRepoSuite) TestNewPublishedRepo(c *C) {
|
||||||
|
c.Check(s.repo.snapshot, Equals, s.snapshot)
|
||||||
|
c.Check(s.repo.SourceKind, Equals, "snapshot")
|
||||||
|
c.Check(s.repo.SourceUUID, Equals, s.snapshot.UUID)
|
||||||
|
|
||||||
|
c.Check(s.repo2.localRepo, Equals, s.localRepo)
|
||||||
|
c.Check(s.repo2.SourceKind, Equals, "local")
|
||||||
|
c.Check(s.repo2.SourceUUID, Equals, s.localRepo.UUID)
|
||||||
|
c.Check(s.repo2.packageRefs.Len(), Equals, 3)
|
||||||
|
|
||||||
|
c.Check(s.repo.RefList().Len(), Equals, 3)
|
||||||
|
c.Check(s.repo2.RefList().Len(), Equals, 3)
|
||||||
|
}
|
||||||
|
|
||||||
func (s *PublishedRepoSuite) TestPrefixNormalization(c *C) {
|
func (s *PublishedRepoSuite) TestPrefixNormalization(c *C) {
|
||||||
|
|
||||||
for _, t := range []struct {
|
for _, t := range []struct {
|
||||||
@@ -266,6 +280,10 @@ func (s *PublishedRepoSuite) TestKey(c *C) {
|
|||||||
c.Check(s.repo.Key(), DeepEquals, []byte("Uppa>>squeeze"))
|
c.Check(s.repo.Key(), DeepEquals, []byte("Uppa>>squeeze"))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *PublishedRepoSuite) TestRefKey(c *C) {
|
||||||
|
c.Check(s.repo.RefKey(), DeepEquals, []byte("E"+s.repo.UUID))
|
||||||
|
}
|
||||||
|
|
||||||
func (s *PublishedRepoSuite) TestEncodeDecode(c *C) {
|
func (s *PublishedRepoSuite) TestEncodeDecode(c *C) {
|
||||||
encoded := s.repo.Encode()
|
encoded := s.repo.Encode()
|
||||||
repo := &PublishedRepo{}
|
repo := &PublishedRepo{}
|
||||||
@@ -280,6 +298,7 @@ func (s *PublishedRepoSuite) TestEncodeDecode(c *C) {
|
|||||||
err = repo2.Decode(encoded2)
|
err = repo2.Decode(encoded2)
|
||||||
|
|
||||||
s.repo2.localRepo = nil
|
s.repo2.localRepo = nil
|
||||||
|
s.repo2.packageRefs = nil
|
||||||
c.Assert(err, IsNil)
|
c.Assert(err, IsNil)
|
||||||
c.Assert(repo2, DeepEquals, s.repo2)
|
c.Assert(repo2, DeepEquals, s.repo2)
|
||||||
}
|
}
|
||||||
@@ -376,12 +395,15 @@ func (s *PublishedRepoCollectionSuite) TestUpdateLoadComplete(c *C) {
|
|||||||
c.Assert(r.snapshot, IsNil)
|
c.Assert(r.snapshot, IsNil)
|
||||||
c.Assert(s.collection.LoadComplete(r, s.factory), IsNil)
|
c.Assert(s.collection.LoadComplete(r, s.factory), IsNil)
|
||||||
c.Assert(r.snapshot.UUID, Equals, s.repo1.snapshot.UUID)
|
c.Assert(r.snapshot.UUID, Equals, s.repo1.snapshot.UUID)
|
||||||
|
c.Assert(r.RefList().Len(), Equals, 0)
|
||||||
|
|
||||||
r, err = collection.ByPrefixDistribution("ppa", "precise")
|
r, err = collection.ByPrefixDistribution("ppa", "precise")
|
||||||
c.Assert(err, IsNil)
|
c.Assert(err, IsNil)
|
||||||
c.Assert(r.localRepo, IsNil)
|
c.Assert(r.localRepo, IsNil)
|
||||||
c.Assert(s.collection.LoadComplete(r, s.factory), IsNil)
|
c.Assert(s.collection.LoadComplete(r, s.factory), IsNil)
|
||||||
c.Assert(r.localRepo.UUID, Equals, s.repo4.localRepo.UUID)
|
c.Assert(r.localRepo.UUID, Equals, s.repo4.localRepo.UUID)
|
||||||
|
c.Assert(r.packageRefs.Len(), Equals, 0)
|
||||||
|
c.Assert(r.RefList().Len(), Equals, 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *PublishedRepoCollectionSuite) TestForEachAndLen(c *C) {
|
func (s *PublishedRepoCollectionSuite) TestForEachAndLen(c *C) {
|
||||||
@@ -413,6 +435,13 @@ func (s *PublishedRepoCollectionSuite) TestBySnapshot(c *C) {
|
|||||||
c.Check(s.collection.BySnapshot(s.snap2), DeepEquals, []*PublishedRepo{s.repo2})
|
c.Check(s.collection.BySnapshot(s.snap2), DeepEquals, []*PublishedRepo{s.repo2})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *PublishedRepoCollectionSuite) TestByLocalRepo(c *C) {
|
||||||
|
c.Check(s.collection.Add(s.repo1), IsNil)
|
||||||
|
c.Check(s.collection.Add(s.repo4), IsNil)
|
||||||
|
|
||||||
|
c.Check(s.collection.ByLocalRepo(s.localRepo), DeepEquals, []*PublishedRepo{s.repo4})
|
||||||
|
}
|
||||||
|
|
||||||
type PublishedRepoRemoveSuite struct {
|
type PublishedRepoRemoveSuite struct {
|
||||||
PackageListMixinSuite
|
PackageListMixinSuite
|
||||||
db database.Storage
|
db database.Storage
|
||||||
|
|||||||
Reference in New Issue
Block a user