Skip to content

Commit

Permalink
Merge pull request #534 from smira/533-ignore-contents-failures
Browse files Browse the repository at this point in the history
When contents generation fails, don't bail out
  • Loading branch information
smira committed Mar 31, 2017
2 parents e6bad63 + 7a5be67 commit bc01d9e
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 12 deletions.
4 changes: 2 additions & 2 deletions deb/contents.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
20 changes: 13 additions & 7 deletions deb/package.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 6 additions & 2 deletions deb/package_collection.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}
Expand All @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion deb/publish.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
Binary file not shown.
14 changes: 14 additions & 0 deletions system/t06_publish/PublishRepo29Test_gold
Original file line number Diff line number Diff line change
@@ -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.
12 changes: 12 additions & 0 deletions system/t06_publish/repo.py
Original file line number Diff line number Diff line change
Expand Up @@ -694,3 +694,15 @@ def check(self):
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

0 comments on commit bc01d9e

Please sign in to comment.