Show progress when loading packages from reflist.

This commit is contained in:
Andrey Smirnov
2014-03-07 00:04:35 +04:00
parent 81dd5a398b
commit 6f86bfec72
8 changed files with 27 additions and 13 deletions

View File

@@ -37,7 +37,7 @@ func aptlyRepoAdd(cmd *commander.Command, args []string) error {
context.progress.Printf("Loading packages...\n")
packageCollection := debian.NewPackageCollection(context.database)
list, err := debian.NewPackageListFromRefList(repo.RefList(), packageCollection)
list, err := debian.NewPackageListFromRefList(repo.RefList(), packageCollection, context.progress)
if err != nil {
return fmt.Errorf("unable to load packages: %s", err)
}

View File

@@ -75,12 +75,12 @@ func aptlyRepoMoveCopyImport(cmd *commander.Command, args []string) error {
context.progress.Printf("Loading packages...\n")
packageCollection := debian.NewPackageCollection(context.database)
dstList, err := debian.NewPackageListFromRefList(dstRepo.RefList(), packageCollection)
dstList, err := debian.NewPackageListFromRefList(dstRepo.RefList(), packageCollection, context.progress)
if err != nil {
return fmt.Errorf("unable to load packages: %s", err)
}
srcList, err := debian.NewPackageListFromRefList(srcRefList, packageCollection)
srcList, err := debian.NewPackageListFromRefList(srcRefList, packageCollection, context.progress)
if err != nil {
return fmt.Errorf("unable to load packages: %s", err)
}

View File

@@ -30,7 +30,7 @@ func aptlyRepoRemove(cmd *commander.Command, args []string) error {
context.progress.Printf("Loading packages...\n")
packageCollection := debian.NewPackageCollection(context.database)
list, err := debian.NewPackageListFromRefList(repo.RefList(), packageCollection)
list, err := debian.NewPackageListFromRefList(repo.RefList(), packageCollection, context.progress)
if err != nil {
return fmt.Errorf("unable to load packages: %s", err)
}

View File

@@ -49,12 +49,12 @@ func aptlySnapshotPull(cmd *commander.Command, args []string) error {
// Convert snapshot to package list
context.progress.Printf("Loading packages (%d)...\n", snapshot.RefList().Len()+source.RefList().Len())
packageList, err := debian.NewPackageListFromRefList(snapshot.RefList(), packageCollection)
packageList, err := debian.NewPackageListFromRefList(snapshot.RefList(), packageCollection, context.progress)
if err != nil {
return fmt.Errorf("unable to load packages: %s", err)
}
sourcePackageList, err := debian.NewPackageListFromRefList(source.RefList(), packageCollection)
sourcePackageList, err := debian.NewPackageListFromRefList(source.RefList(), packageCollection, context.progress)
if err != nil {
return fmt.Errorf("unable to load packages: %s", err)
}

View File

@@ -31,7 +31,9 @@ func aptlySnapshotVerify(cmd *commander.Command, args []string) error {
}
}
packageList, err := debian.NewPackageListFromRefList(snapshots[0].RefList(), packageCollection)
context.progress.Printf("Loading packages...\n")
packageList, err := debian.NewPackageListFromRefList(snapshots[0].RefList(), packageCollection, context.progress)
if err != nil {
fmt.Errorf("unable to load packages: %s", err)
}
@@ -43,7 +45,7 @@ func aptlySnapshotVerify(cmd *commander.Command, args []string) error {
}
for i := 1; i < len(snapshots); i++ {
pL, err := debian.NewPackageListFromRefList(snapshots[i].RefList(), packageCollection)
pL, err := debian.NewPackageListFromRefList(snapshots[i].RefList(), packageCollection, context.progress)
if err != nil {
fmt.Errorf("unable to load packages: %s", err)
}

14
debian/list.go vendored
View File

@@ -2,6 +2,7 @@ package debian
import (
"fmt"
"github.com/smira/aptly/aptly"
"github.com/smira/aptly/utils"
"sort"
"strings"
@@ -49,7 +50,7 @@ func NewPackageList() *PackageList {
}
// NewPackageListFromRefList loads packages list from PackageRefList
func NewPackageListFromRefList(reflist *PackageRefList, collection *PackageCollection) (*PackageList, error) {
func NewPackageListFromRefList(reflist *PackageRefList, collection *PackageCollection, progress aptly.Progress) (*PackageList, error) {
// empty reflist
if reflist == nil {
return NewPackageList(), nil
@@ -57,14 +58,25 @@ func NewPackageListFromRefList(reflist *PackageRefList, collection *PackageColle
result := &PackageList{packages: make(map[string]*Package, reflist.Len())}
if progress != nil {
progress.InitBar(int64(reflist.Len()), false)
}
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)
}
if progress != nil {
progress.AddBar(1)
}
return result.Add(p)
})
if progress != nil {
progress.ShutdownBar()
}
if err != nil {
return nil, err
}

2
debian/publish.go vendored
View File

@@ -105,7 +105,7 @@ func (p *PublishedRepo) Publish(packagePool aptly.PackagePool, publishedStorage
}
// Load all packages
list, err := NewPackageListFromRefList(p.snapshot.RefList(), packageCollection)
list, err := NewPackageListFromRefList(p.snapshot.RefList(), packageCollection, nil)
if err != nil {
return fmt.Errorf("unable to load packages: %s", err)
}

View File

@@ -46,18 +46,18 @@ func (s *PackageRefListSuite) TestNewPackageListFromRefList(c *C) {
reflist := NewPackageRefListFromPackageList(s.list)
_, err := NewPackageListFromRefList(reflist, coll)
_, err := NewPackageListFromRefList(reflist, coll, nil)
c.Assert(err, ErrorMatches, "unable to load package with key.*")
coll.Update(s.p5)
coll.Update(s.p6)
list, err := NewPackageListFromRefList(reflist, coll)
list, err := NewPackageListFromRefList(reflist, coll, nil)
c.Assert(err, IsNil)
c.Check(list.Len(), Equals, 4)
c.Check(list.Add(s.p4), ErrorMatches, "conflict in package.*")
list, err = NewPackageListFromRefList(nil, coll)
list, err = NewPackageListFromRefList(nil, coll, nil)
c.Assert(err, IsNil)
c.Check(list.Len(), Equals, 0)
}