mirror of
https://github.com/aptly-dev/aptly.git
synced 2026-05-06 22:18:28 +00:00
Listing of packages in snapshot.
This commit is contained in:
@@ -87,6 +87,14 @@ func aptlySnapshotShow(cmd *commander.Command, args []string) error {
|
|||||||
fmt.Printf("Created At: %s\n", snapshot.CreatedAt.Format("2006-01-02 15:04:05 MST"))
|
fmt.Printf("Created At: %s\n", snapshot.CreatedAt.Format("2006-01-02 15:04:05 MST"))
|
||||||
fmt.Printf("Description: %s\n", snapshot.Description)
|
fmt.Printf("Description: %s\n", snapshot.Description)
|
||||||
fmt.Printf("Number of packages: %d\n", snapshot.NumPackages())
|
fmt.Printf("Number of packages: %d\n", snapshot.NumPackages())
|
||||||
|
fmt.Printf("Packages:\n")
|
||||||
|
|
||||||
|
packageCollection := debian.NewPackageCollection(context.database)
|
||||||
|
|
||||||
|
snapshot.RefList().ForEach(func(key []byte) {
|
||||||
|
p, _ := packageCollection.ByKey(key)
|
||||||
|
fmt.Printf(" %s\n", p)
|
||||||
|
})
|
||||||
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|||||||
Vendored
+9
@@ -103,3 +103,12 @@ func (l *PackageRefList) Decode(input []byte) error {
|
|||||||
decoder := codec.NewDecoderBytes(input, &codec.MsgpackHandle{})
|
decoder := codec.NewDecoderBytes(input, &codec.MsgpackHandle{})
|
||||||
return decoder.Decode(l)
|
return decoder.Decode(l)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ForEach calls handler for each package ref in list
|
||||||
|
//
|
||||||
|
// TODO: Error handling
|
||||||
|
func (l *PackageRefList) ForEach(handler func([]byte)) {
|
||||||
|
for _, p := range l.Refs {
|
||||||
|
handler(p)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Vendored
+16
@@ -90,3 +90,19 @@ func (s *PackageListSuite) TestPackageRefListEncodeDecode(c *C) {
|
|||||||
c.Check(reflist2.Len(), Equals, reflist.Len())
|
c.Check(reflist2.Len(), Equals, reflist.Len())
|
||||||
c.Check(reflist2.Refs, DeepEquals, reflist.Refs)
|
c.Check(reflist2.Refs, DeepEquals, reflist.Refs)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *PackageListSuite) TestPackageRefListForeach(c *C) {
|
||||||
|
s.list.Add(s.p1)
|
||||||
|
s.list.Add(s.p3)
|
||||||
|
s.list.Add(s.p5)
|
||||||
|
s.list.Add(s.p6)
|
||||||
|
|
||||||
|
reflist := NewPackageRefListFromPackageList(s.list)
|
||||||
|
|
||||||
|
Len := 0
|
||||||
|
reflist.ForEach(func([]byte) {
|
||||||
|
Len++
|
||||||
|
})
|
||||||
|
|
||||||
|
c.Check(Len, Equals, 4)
|
||||||
|
}
|
||||||
|
|||||||
Vendored
+5
@@ -56,6 +56,11 @@ func (s *Snapshot) NumPackages() int {
|
|||||||
return s.packageRefs.Len()
|
return s.packageRefs.Len()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// RefList returns list of package refs in snapshot
|
||||||
|
func (s *Snapshot) RefList() *PackageRefList {
|
||||||
|
return s.packageRefs
|
||||||
|
}
|
||||||
|
|
||||||
// Key is a unique id in DB
|
// Key is a unique id in DB
|
||||||
func (s *Snapshot) Key() []byte {
|
func (s *Snapshot) Key() []byte {
|
||||||
return []byte("S" + s.UUID)
|
return []byte("S" + s.UUID)
|
||||||
|
|||||||
Vendored
+1
@@ -22,6 +22,7 @@ func (s *SnapshotSuite) TestNewSnapshotFromRepository(c *C) {
|
|||||||
snapshot, _ := NewSnapshotFromRepository("snap1", s.repo)
|
snapshot, _ := NewSnapshotFromRepository("snap1", s.repo)
|
||||||
c.Check(snapshot.Name, Equals, "snap1")
|
c.Check(snapshot.Name, Equals, "snap1")
|
||||||
c.Check(snapshot.NumPackages(), Equals, 3)
|
c.Check(snapshot.NumPackages(), Equals, 3)
|
||||||
|
c.Check(snapshot.RefList().Len(), Equals, 3)
|
||||||
|
|
||||||
s.repo.packageRefs = nil
|
s.repo.packageRefs = nil
|
||||||
_, err := NewSnapshotFromRepository("snap2", s.repo)
|
_, err := NewSnapshotFromRepository("snap2", s.repo)
|
||||||
|
|||||||
Reference in New Issue
Block a user