mirror of
https://github.com/aptly-dev/aptly.git
synced 2026-06-02 04:50:49 +00:00
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:
+2
-2
@@ -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 {
|
||||
|
||||
+13
-7
@@ -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
|
||||
|
||||
@@ -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)
|
||||
|
||||
+1
-1
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user