-
-
Notifications
You must be signed in to change notification settings - Fork 375
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add basic appstream support #420
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,8 +23,11 @@ type indexFiles struct { | |
type indexFile struct { | ||
parent *indexFiles | ||
discardable bool | ||
compressable bool | ||
onlyGzip bool | ||
ignoreFlat bool | ||
compressOnly bool | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. what's the difference between |
||
compressGzip bool | ||
compressBzip bool | ||
compressGxz bool | ||
signable bool | ||
relativePath string | ||
tempFilename string | ||
|
@@ -61,7 +64,7 @@ func (file *indexFile) Finalize(signer utils.Signer) error { | |
return fmt.Errorf("unable to write to index file: %s", err) | ||
} | ||
|
||
if file.compressable { | ||
if file.compressGzip || file.compressBzip || file.compressGxz { | ||
err = utils.CompressFile(file.tempFile) | ||
if err != nil { | ||
file.tempFile.Close() | ||
|
@@ -71,12 +74,18 @@ func (file *indexFile) Finalize(signer utils.Signer) error { | |
|
||
file.tempFile.Close() | ||
|
||
exts := []string{""} | ||
if file.compressable { | ||
exts = append(exts, ".gz", ".bz2") | ||
if file.onlyGzip { | ||
exts = []string{".gz"} | ||
} | ||
exts := []string{} | ||
if !file.ignoreFlat { | ||
exts = append(exts, "") | ||
} | ||
if file.compressGzip { | ||
exts = append(exts, ".gz") | ||
} | ||
if file.compressBzip { | ||
exts = append(exts, ".bz2") | ||
} | ||
if file.compressGxz { | ||
exts = append(exts, ".xz") | ||
} | ||
|
||
for _, ext := range exts { | ||
|
@@ -95,6 +104,10 @@ func (file *indexFile) Finalize(signer utils.Signer) error { | |
} | ||
|
||
for _, ext := range exts { | ||
if file.compressOnly && !(ext == ".gz" || ext == ".bz2" || ext == ".xz") { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. if |
||
continue | ||
} | ||
|
||
err = file.parent.publishedStorage.PutFile(filepath.Join(file.parent.basePath, file.relativePath+file.parent.suffix+ext), | ||
file.tempFilename+ext) | ||
if err != nil { | ||
|
@@ -175,7 +188,8 @@ func (files *indexFiles) PackageIndex(component, arch string, udeb bool) *indexF | |
file = &indexFile{ | ||
parent: files, | ||
discardable: false, | ||
compressable: true, | ||
compressGzip: true, | ||
compressBzip: true, | ||
signable: false, | ||
relativePath: relativePath, | ||
} | ||
|
@@ -208,7 +222,6 @@ func (files *indexFiles) ReleaseIndex(component, arch string, udeb bool) *indexF | |
file = &indexFile{ | ||
parent: files, | ||
discardable: udeb, | ||
compressable: false, | ||
signable: false, | ||
relativePath: relativePath, | ||
} | ||
|
@@ -237,8 +250,37 @@ func (files *indexFiles) ContentsIndex(component, arch string, udeb bool) *index | |
file = &indexFile{ | ||
parent: files, | ||
discardable: true, | ||
compressable: true, | ||
onlyGzip: true, | ||
ignoreFlat: true, | ||
compressOnly: true, | ||
compressGzip: true, | ||
signable: false, | ||
relativePath: relativePath, | ||
} | ||
|
||
files.indexes[key] = file | ||
} | ||
|
||
return file | ||
} | ||
|
||
func (files *indexFiles) AppStreamIndex(component, name string) *indexFile { | ||
key := fmt.Sprintf("ai-%s-%s", component, name) | ||
file, ok := files.indexes[key] | ||
if !ok { | ||
relativePath := filepath.Join(component, "dep11", name) | ||
ext := filepath.Ext(name) | ||
|
||
xz := false | ||
if ext == ".yml" { | ||
xz = true | ||
} | ||
|
||
file = &indexFile{ | ||
parent: files, | ||
discardable: false, | ||
compressOnly: true, | ||
compressGzip: true, | ||
compressGxz: xz, | ||
signable: false, | ||
relativePath: relativePath, | ||
} | ||
|
@@ -251,11 +293,10 @@ func (files *indexFiles) ContentsIndex(component, arch string, udeb bool) *index | |
|
||
func (files *indexFiles) ReleaseFile() *indexFile { | ||
return &indexFile{ | ||
parent: files, | ||
discardable: false, | ||
compressable: false, | ||
signable: true, | ||
relativePath: "Release", | ||
parent: files, | ||
discardable: false, | ||
signable: true, | ||
relativePath: "Release", | ||
} | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,12 +4,14 @@ import ( | |
"bufio" | ||
"bytes" | ||
"encoding/json" | ||
"errors" | ||
"fmt" | ||
"github.com/smira/aptly/aptly" | ||
"github.com/smira/aptly/database" | ||
"github.com/smira/aptly/utils" | ||
"github.com/smira/go-uuid/uuid" | ||
"github.com/ugorji/go/codec" | ||
"io" | ||
"io/ioutil" | ||
"log" | ||
"os" | ||
|
@@ -452,6 +454,36 @@ func (p *PublishedRepo) GetLabel() string { | |
return p.Label | ||
} | ||
|
||
// GetAppStream returns full path list of appstream files | ||
func (p *PublishedRepo) GetAppStream(component string) ([]string, error) { | ||
if utils.Config.AppStreamDir == "" { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The way I would suggest two changes:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The |
||
return nil, errors.New("AppStream directory unconfigured") | ||
} | ||
|
||
appStreamDir := filepath.Join(utils.Config.AppStreamDir, p.Prefix, "dists", p.Distribution, component) | ||
files := []string{} | ||
|
||
err := filepath.Walk(appStreamDir, func(path string, info os.FileInfo, err error) error { | ||
stat, err := os.Stat(path) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
ext := filepath.Ext(path) | ||
if stat.Mode().IsRegular() && (ext == ".yml" || ext == ".tar") { | ||
files = append(files, path) | ||
} | ||
|
||
return nil | ||
}) | ||
|
||
if err != nil && !os.IsNotExist(err) { | ||
return nil, err | ||
} | ||
|
||
return files, nil | ||
} | ||
|
||
// Publish publishes snapshot (repository) contents, links package files, generates Packages & Release files, signs them | ||
func (p *PublishedRepo) Publish(packagePool aptly.PackagePool, publishedStorageProvider aptly.PublishedStorageProvider, | ||
collectionFactory *CollectionFactory, signer utils.Signer, progress aptly.Progress, forceOverwrite bool) error { | ||
|
@@ -629,6 +661,34 @@ func (p *PublishedRepo) Publish(packagePool aptly.PackagePool, publishedStorageP | |
} | ||
} | ||
|
||
// AppStream file colection | ||
if utils.Config.AppStreamDir != "" { | ||
appstream, err := p.GetAppStream(component) | ||
if err != nil { | ||
return fmt.Errorf("Unable to get AppStream files: %s...\n", err) | ||
} | ||
|
||
for _, file := range appstream { | ||
base := filepath.Base(file) | ||
|
||
fi, err := os.Open(file) | ||
if err != nil { | ||
return fmt.Errorf("unable to open %s file: %v", base, err) | ||
} | ||
defer fi.Close() | ||
|
||
w, err := indexes.AppStreamIndex(component, base).BufWriter() | ||
if err != nil { | ||
return fmt.Errorf("unable to write %s file: %v", base, err) | ||
} | ||
|
||
_, err = io.Copy(w, fi) | ||
if err != nil { | ||
return fmt.Errorf("unable to copy %s file: %v", base, err) | ||
} | ||
} | ||
} | ||
|
||
// For all architectures, generate Release files | ||
for _, arch := range p.Architectures { | ||
for _, udeb := range udebs { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This library says it's "alpha quality", at the same time we have xz decompression via
github.com/smira/go-xz
(which is using external process).Can we keep one or another, or completely skip
.xz
for now? (until Go support becomes more mature?)