When contents generation fails, don't bail out

This replaces `panic` which aborts aptly execution with warning
message on console. So aptly continues publishing actions, but
`Contents` indexes might be incomplete.

Error will be printed every time contents generation is triggered.
This commit is contained in:
Andrey Smirnov
2017-03-31 00:40:38 +03:00
parent e6bad637fd
commit 7a5be6736d
7 changed files with 48 additions and 12 deletions

View File

@@ -26,8 +26,8 @@ func NewContentsIndex(db database.Storage) *ContentsIndex {
}
// Push adds package to contents index, calculating package contents as required
func (index *ContentsIndex) Push(p *Package, packagePool aptly.PackagePool) error {
contents := p.Contents(packagePool)
func (index *ContentsIndex) Push(p *Package, packagePool aptly.PackagePool, progress aptly.Progress) error {
contents := p.Contents(packagePool, progress)
qualifiedName := []byte(p.QualifiedName())
for _, path := range contents {

View File

@@ -403,32 +403,38 @@ func (p *Package) Files() PackageFiles {
}
// Contents returns cached package contents
func (p *Package) Contents(packagePool aptly.PackagePool) []string {
func (p *Package) Contents(packagePool aptly.PackagePool, progress aptly.Progress) []string {
if p.IsSource {
return nil
}
return p.collection.loadContents(p, packagePool)
return p.collection.loadContents(p, packagePool, progress)
}
// CalculateContents looks up contents in package file
func (p *Package) CalculateContents(packagePool aptly.PackagePool) []string {
func (p *Package) CalculateContents(packagePool aptly.PackagePool, progress aptly.Progress) ([]string, error) {
if p.IsSource {
return nil
return nil, nil
}
file := p.Files()[0]
path, err := packagePool.Path(file.Filename, file.Checksums.MD5)
if err != nil {
panic(err)
if progress != nil {
progress.ColoredPrintf("@y[!]@| @!Failed to build pool path: @| %s", err)
}
return nil, err
}
contents, err := GetContentsFromDeb(path)
if err != nil {
panic(err)
if progress != nil {
progress.ColoredPrintf("@y[!]@| @!Failed to generate package contents: @| %s", err)
}
return nil, err
}
return contents
return contents, nil
}
// UpdateFiles saves new state of files

View File

@@ -163,7 +163,7 @@ func (collection *PackageCollection) loadFiles(p *Package) *PackageFiles {
}
// loadContents loads or calculates and saves package contents
func (collection *PackageCollection) loadContents(p *Package, packagePool aptly.PackagePool) []string {
func (collection *PackageCollection) loadContents(p *Package, packagePool aptly.PackagePool, progress aptly.Progress) []string {
encoded, err := collection.db.Get(p.Key("xC"))
if err == nil {
contents := []string{}
@@ -181,7 +181,11 @@ func (collection *PackageCollection) loadContents(p *Package, packagePool aptly.
panic("unable to load contents")
}
contents := p.CalculateContents(packagePool)
contents, err := p.CalculateContents(packagePool, progress)
if err != nil {
// failed to acquire contents, don't persist it
return contents
}
var buf bytes.Buffer
err = codec.NewEncoder(&buf, collection.codecHandle).Encode(contents)

View File

@@ -574,7 +574,7 @@ func (p *PublishedRepo) Publish(packagePool aptly.PackagePool, publishedStorageP
contentIndexes[key] = contentIndex
}
contentIndex.Push(pkg, packagePool)
contentIndex.Push(pkg, packagePool, progress)
}
bufWriter, err = indexes.PackageIndex(component, arch, pkg.IsUdeb).BufWriter()

View File

@@ -0,0 +1,14 @@
Loading packages...
Generating metadata files and linking package files...
[!] Failed to generate package contents: unable to read .tar archive from ${HOME}/.aptly/pool/3a/0a/libboost-broken-program-options-dev_1.49.0.1_i386.deb: unexpected EOF
Finalizing metadata files...
Signing file 'Release' with gpg, please enter your passphrase when prompted:
Clearsigning file 'Release' with gpg, please enter your passphrase when prompted:
Local repo local-repo has been successfully published.
Please setup your webserver to serve directory '${HOME}/.aptly/public' with autoindexing.
Now you can add following line to apt sources:
deb http://your-server/ maverick main
Don't forget to add your GPG key to apt with apt-key.
You can also use `aptly serve` to publish your repositories over HTTP quickly.

View File

@@ -694,3 +694,15 @@ class PublishRepo28Test(BaseTest):
self.check_not_exists('public/dists/maverick/main/Contents-i386.gz')
self.check_exists('public/dists/maverick/main/debian-installer/binary-i386/Release')
self.check_not_exists('public/dists/maverick/main/Contents-udeb-i386.gz')
class PublishRepo29Test(BaseTest):
"""
publish repo: broken .deb file for contents
"""
fixtureCmds = [
"aptly repo create local-repo",
"aptly repo add local-repo ${testfiles}",
]
runCmd = "aptly publish repo -keyring=${files}/aptly.pub -secret-keyring=${files}/aptly.sec -distribution=maverick local-repo"
gold_processor = BaseTest.expand_environ