mirror of
https://github.com/aptly-dev/aptly.git
synced 2026-06-07 05:42:42 +00:00
Enable goconst & interfacer linters
This commit is contained in:
+2
-2
@@ -170,7 +170,7 @@ func (c *Changes) PackageQuery() (PackageQuery, error) {
|
||||
|
||||
// if c.Source is empty, this would never match
|
||||
sourceQuery := &AndQuery{
|
||||
L: &FieldQuery{Field: "$PackageType", Relation: VersionEqual, Value: "source"},
|
||||
L: &FieldQuery{Field: "$PackageType", Relation: VersionEqual, Value: ArchitectureSource},
|
||||
R: &FieldQuery{Field: "Name", Relation: VersionEqual, Value: c.Source},
|
||||
}
|
||||
|
||||
@@ -202,7 +202,7 @@ func (c *Changes) PackageQuery() (PackageQuery, error) {
|
||||
}
|
||||
|
||||
binaryQuery = &AndQuery{
|
||||
L: &NotQuery{Q: &FieldQuery{Field: "$PackageType", Relation: VersionEqual, Value: "source"}},
|
||||
L: &NotQuery{Q: &FieldQuery{Field: "$PackageType", Relation: VersionEqual, Value: ArchitectureSource}},
|
||||
R: binaryQuery}
|
||||
}
|
||||
|
||||
|
||||
+8
-2
@@ -14,12 +14,18 @@ import (
|
||||
"github.com/mkrautz/goar"
|
||||
"github.com/pkg/errors"
|
||||
|
||||
"github.com/smira/aptly/aptly"
|
||||
"github.com/smira/aptly/utils"
|
||||
"github.com/smira/go-xz"
|
||||
"github.com/smira/lzma"
|
||||
)
|
||||
|
||||
// Source kinds
|
||||
const (
|
||||
SourceSnapshot = "snapshot"
|
||||
SourceLocalRepo = "local"
|
||||
SourceRemoteRepo = "repo"
|
||||
)
|
||||
|
||||
// GetControlFileFromDeb reads control file from deb package
|
||||
func GetControlFileFromDeb(packageFile string) (Stanza, error) {
|
||||
file, err := os.Open(packageFile)
|
||||
@@ -107,7 +113,7 @@ func GetControlFileFromDsc(dscFile string, verifier utils.Verifier) (Stanza, err
|
||||
}
|
||||
|
||||
// GetContentsFromDeb returns list of files installed by .deb package
|
||||
func GetContentsFromDeb(file aptly.ReadSeekerCloser, packageFile string) ([]string, error) {
|
||||
func GetContentsFromDeb(file io.Reader, packageFile string) ([]string, error) {
|
||||
library := ar.NewReader(file)
|
||||
for {
|
||||
header, err := library.Next()
|
||||
|
||||
+2
-2
@@ -87,7 +87,7 @@ func BuildGraph(collectionFactory *CollectionFactory, layout string) (gographviz
|
||||
}
|
||||
|
||||
description := snapshot.Description
|
||||
if snapshot.SourceKind == "repo" {
|
||||
if snapshot.SourceKind == SourceRemoteRepo {
|
||||
description = "Snapshot from repo"
|
||||
}
|
||||
|
||||
@@ -99,7 +99,7 @@ func BuildGraph(collectionFactory *CollectionFactory, layout string) (gographviz
|
||||
snapshot.Name, description, snapshot.NumPackages(), labelEnd),
|
||||
})
|
||||
|
||||
if snapshot.SourceKind == "repo" || snapshot.SourceKind == "local" || snapshot.SourceKind == "snapshot" {
|
||||
if snapshot.SourceKind == SourceRemoteRepo || snapshot.SourceKind == SourceLocalRepo || snapshot.SourceKind == SourceSnapshot {
|
||||
for _, uuid := range snapshot.SourceIDs {
|
||||
_, exists := existingNodes[uuid]
|
||||
if exists {
|
||||
|
||||
+5
-5
@@ -155,7 +155,7 @@ func newIndexFiles(publishedStorage aptly.PublishedStorage, basePath, tempDir, s
|
||||
}
|
||||
|
||||
func (files *indexFiles) PackageIndex(component, arch string, udeb bool) *indexFile {
|
||||
if arch == "source" {
|
||||
if arch == ArchitectureSource {
|
||||
udeb = false
|
||||
}
|
||||
key := fmt.Sprintf("pi-%s-%s-%v", component, arch, udeb)
|
||||
@@ -163,7 +163,7 @@ func (files *indexFiles) PackageIndex(component, arch string, udeb bool) *indexF
|
||||
if !ok {
|
||||
var relativePath string
|
||||
|
||||
if arch == "source" {
|
||||
if arch == ArchitectureSource {
|
||||
relativePath = filepath.Join(component, "source", "Sources")
|
||||
} else {
|
||||
if udeb {
|
||||
@@ -188,7 +188,7 @@ func (files *indexFiles) PackageIndex(component, arch string, udeb bool) *indexF
|
||||
}
|
||||
|
||||
func (files *indexFiles) ReleaseIndex(component, arch string, udeb bool) *indexFile {
|
||||
if arch == "source" {
|
||||
if arch == ArchitectureSource {
|
||||
udeb = false
|
||||
}
|
||||
key := fmt.Sprintf("ri-%s-%s-%v", component, arch, udeb)
|
||||
@@ -196,7 +196,7 @@ func (files *indexFiles) ReleaseIndex(component, arch string, udeb bool) *indexF
|
||||
if !ok {
|
||||
var relativePath string
|
||||
|
||||
if arch == "source" {
|
||||
if arch == ArchitectureSource {
|
||||
relativePath = filepath.Join(component, "source", "Release")
|
||||
} else {
|
||||
if udeb {
|
||||
@@ -221,7 +221,7 @@ func (files *indexFiles) ReleaseIndex(component, arch string, udeb bool) *indexF
|
||||
}
|
||||
|
||||
func (files *indexFiles) ContentsIndex(component, arch string, udeb bool) *indexFile {
|
||||
if arch == "source" {
|
||||
if arch == ArchitectureSource {
|
||||
udeb = false
|
||||
}
|
||||
key := fmt.Sprintf("ci-%s-%s-%v", component, arch, udeb)
|
||||
|
||||
+1
-1
@@ -238,7 +238,7 @@ func (l *PackageList) Remove(p *Package) {
|
||||
func (l *PackageList) Architectures(includeSource bool) (result []string) {
|
||||
result = make([]string, 0, 10)
|
||||
for _, pkg := range l.packages {
|
||||
if pkg.Architecture != "all" && (pkg.Architecture != "source" || includeSource) && !utils.StrSliceHasItem(result, pkg.Architecture) {
|
||||
if pkg.Architecture != ArchitectureAll && (pkg.Architecture != ArchitectureSource || includeSource) && !utils.StrSliceHasItem(result, pkg.Architecture) {
|
||||
result = append(result, pkg.Architecture)
|
||||
}
|
||||
}
|
||||
|
||||
+18
-4
@@ -41,6 +41,20 @@ type Package struct {
|
||||
collection *PackageCollection
|
||||
}
|
||||
|
||||
// Package types
|
||||
const (
|
||||
PackageTypeBinary = "deb"
|
||||
PackageTypeUdeb = "udeb"
|
||||
PackageTypeSource = "source"
|
||||
)
|
||||
|
||||
// Special arhictectures
|
||||
const (
|
||||
ArchitectureAll = "all"
|
||||
ArhictectureAny = "any"
|
||||
ArchitectureSource = "source"
|
||||
)
|
||||
|
||||
// Check interface
|
||||
var (
|
||||
_ json.Marshaler = &Package{}
|
||||
@@ -218,12 +232,12 @@ func (p *Package) GetField(name string) string {
|
||||
return p.Architecture
|
||||
case "$PackageType":
|
||||
if p.IsSource {
|
||||
return "source"
|
||||
return PackageTypeSource
|
||||
}
|
||||
if p.IsUdeb {
|
||||
return "udeb"
|
||||
return PackageTypeUdeb
|
||||
}
|
||||
return "deb"
|
||||
return PackageTypeBinary
|
||||
case "Name":
|
||||
return p.Name
|
||||
case "Version":
|
||||
@@ -256,7 +270,7 @@ func (p *Package) GetField(name string) string {
|
||||
|
||||
// MatchesArchitecture checks whether packages matches specified architecture
|
||||
func (p *Package) MatchesArchitecture(arch string) bool {
|
||||
if p.Architecture == "all" && arch != "source" {
|
||||
if p.Architecture == ArchitectureAll && arch != ArchitectureSource {
|
||||
return true
|
||||
}
|
||||
|
||||
|
||||
+18
-18
@@ -96,19 +96,19 @@ func walkUpTree(source interface{}, collectionFactory *CollectionFactory) (rootD
|
||||
|
||||
if snapshot, ok := head.(*Snapshot); ok {
|
||||
for _, uuid := range snapshot.SourceIDs {
|
||||
if snapshot.SourceKind == "repo" {
|
||||
if snapshot.SourceKind == SourceRemoteRepo {
|
||||
remoteRepo, err := collectionFactory.RemoteRepoCollection().ByUUID(uuid)
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
current = append(current, remoteRepo)
|
||||
} else if snapshot.SourceKind == "local" {
|
||||
} else if snapshot.SourceKind == SourceLocalRepo {
|
||||
localRepo, err := collectionFactory.LocalRepoCollection().ByUUID(uuid)
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
current = append(current, localRepo)
|
||||
} else if snapshot.SourceKind == "snapshot" {
|
||||
} else if snapshot.SourceKind == SourceSnapshot {
|
||||
snap, err := collectionFactory.SnapshotCollection().ByUUID(uuid)
|
||||
if err != nil {
|
||||
continue
|
||||
@@ -174,9 +174,9 @@ func NewPublishedRepo(storage, prefix, distribution string, architectures []stri
|
||||
// figure out source kind
|
||||
switch source.(type) {
|
||||
case *Snapshot:
|
||||
result.SourceKind = "snapshot"
|
||||
result.SourceKind = SourceSnapshot
|
||||
case *LocalRepo:
|
||||
result.SourceKind = "local"
|
||||
result.SourceKind = SourceLocalRepo
|
||||
default:
|
||||
panic("unknown source kind")
|
||||
}
|
||||
@@ -209,11 +209,11 @@ func NewPublishedRepo(storage, prefix, distribution string, architectures []stri
|
||||
return nil, fmt.Errorf("duplicate component name: %s", component)
|
||||
}
|
||||
|
||||
if result.SourceKind == "snapshot" {
|
||||
if result.SourceKind == SourceSnapshot {
|
||||
snapshot = source.(*Snapshot)
|
||||
result.Sources[component] = snapshot.UUID
|
||||
result.sourceItems[component] = repoSourceItem{snapshot: snapshot}
|
||||
} else if result.SourceKind == "local" {
|
||||
} else if result.SourceKind == SourceLocalRepo {
|
||||
localRepo = source.(*LocalRepo)
|
||||
result.Sources[component] = localRepo.UUID
|
||||
result.sourceItems[component] = repoSourceItem{localRepo: localRepo, packageRefs: localRepo.RefList()}
|
||||
@@ -349,10 +349,10 @@ func (p *PublishedRepo) RefKey(component string) []byte {
|
||||
// RefList returns list of package refs in local repo
|
||||
func (p *PublishedRepo) RefList(component string) *PackageRefList {
|
||||
item := p.sourceItems[component]
|
||||
if p.SourceKind == "local" {
|
||||
if p.SourceKind == SourceLocalRepo {
|
||||
return item.packageRefs
|
||||
}
|
||||
if p.SourceKind == "snapshot" {
|
||||
if p.SourceKind == SourceSnapshot {
|
||||
return item.snapshot.RefList()
|
||||
}
|
||||
panic("unknown source")
|
||||
@@ -371,7 +371,7 @@ func (p *PublishedRepo) Components() []string {
|
||||
|
||||
// UpdateLocalRepo updates content from local repo in component
|
||||
func (p *PublishedRepo) UpdateLocalRepo(component string) {
|
||||
if p.SourceKind != "local" {
|
||||
if p.SourceKind != SourceLocalRepo {
|
||||
panic("not local repo publish")
|
||||
}
|
||||
|
||||
@@ -384,7 +384,7 @@ func (p *PublishedRepo) UpdateLocalRepo(component string) {
|
||||
|
||||
// UpdateSnapshot switches snapshot for component
|
||||
func (p *PublishedRepo) UpdateSnapshot(component string, snapshot *Snapshot) {
|
||||
if p.SourceKind != "snapshot" {
|
||||
if p.SourceKind != SourceSnapshot {
|
||||
panic("not snapshot publish")
|
||||
}
|
||||
|
||||
@@ -416,7 +416,7 @@ func (p *PublishedRepo) Decode(input []byte) error {
|
||||
|
||||
// old PublishedRepo were publishing only snapshots
|
||||
if p.SourceKind == "" {
|
||||
p.SourceKind = "snapshot"
|
||||
p.SourceKind = SourceSnapshot
|
||||
}
|
||||
|
||||
// <0.6 aptly used single SourceUUID + Component instead of Sources
|
||||
@@ -677,7 +677,7 @@ func (p *PublishedRepo) Publish(packagePool aptly.PackagePool, publishedStorageP
|
||||
release["Suite"] = p.Distribution
|
||||
release["Codename"] = p.Distribution
|
||||
release["Date"] = time.Now().UTC().Format("Mon, 2 Jan 2006 15:04:05 MST")
|
||||
release["Architectures"] = strings.Join(utils.StrSlicesSubstract(p.Architectures, []string{"source"}), " ")
|
||||
release["Architectures"] = strings.Join(utils.StrSlicesSubstract(p.Architectures, []string{ArchitectureSource}), " ")
|
||||
release["Description"] = " Generated by aptly\n"
|
||||
release["MD5Sum"] = ""
|
||||
release["SHA1"] = ""
|
||||
@@ -820,7 +820,7 @@ func (collection *PublishedRepoCollection) Update(repo *PublishedRepo) (err erro
|
||||
return
|
||||
}
|
||||
|
||||
if repo.SourceKind == "local" {
|
||||
if repo.SourceKind == SourceLocalRepo {
|
||||
for component, item := range repo.sourceItems {
|
||||
err = collection.db.Put(repo.RefKey(component), item.packageRefs.Encode())
|
||||
if err != nil {
|
||||
@@ -835,7 +835,7 @@ func (collection *PublishedRepoCollection) Update(repo *PublishedRepo) (err erro
|
||||
func (collection *PublishedRepoCollection) LoadComplete(repo *PublishedRepo, collectionFactory *CollectionFactory) (err error) {
|
||||
repo.sourceItems = make(map[string]repoSourceItem)
|
||||
|
||||
if repo.SourceKind == "snapshot" {
|
||||
if repo.SourceKind == SourceSnapshot {
|
||||
for component, sourceUUID := range repo.Sources {
|
||||
item := repoSourceItem{}
|
||||
|
||||
@@ -850,7 +850,7 @@ func (collection *PublishedRepoCollection) LoadComplete(repo *PublishedRepo, col
|
||||
|
||||
repo.sourceItems[component] = item
|
||||
}
|
||||
} else if repo.SourceKind == "local" {
|
||||
} else if repo.SourceKind == SourceLocalRepo {
|
||||
for component, sourceUUID := range repo.Sources {
|
||||
item := repoSourceItem{}
|
||||
|
||||
@@ -918,7 +918,7 @@ func (collection *PublishedRepoCollection) ByUUID(uuid string) (*PublishedRepo,
|
||||
func (collection *PublishedRepoCollection) BySnapshot(snapshot *Snapshot) []*PublishedRepo {
|
||||
var result []*PublishedRepo
|
||||
for _, r := range collection.list {
|
||||
if r.SourceKind == "snapshot" {
|
||||
if r.SourceKind == SourceSnapshot {
|
||||
if r.SourceUUID == snapshot.UUID {
|
||||
result = append(result, r)
|
||||
}
|
||||
@@ -938,7 +938,7 @@ func (collection *PublishedRepoCollection) BySnapshot(snapshot *Snapshot) []*Pub
|
||||
func (collection *PublishedRepoCollection) ByLocalRepo(repo *LocalRepo) []*PublishedRepo {
|
||||
var result []*PublishedRepo
|
||||
for _, r := range collection.list {
|
||||
if r.SourceKind == "local" {
|
||||
if r.SourceKind == SourceLocalRepo {
|
||||
if r.SourceUUID == repo.UUID {
|
||||
result = append(result, r)
|
||||
}
|
||||
|
||||
+1
-1
@@ -562,7 +562,7 @@ func (s *PublishedRepoCollectionSuite) TestLoadPre0_6(c *C) {
|
||||
Prefix: "ppa",
|
||||
Distribution: "anaconda",
|
||||
Architectures: []string{"i386"},
|
||||
SourceKind: "local",
|
||||
SourceKind: SourceLocalRepo,
|
||||
Component: "contrib",
|
||||
SourceUUID: s.localRepo.UUID,
|
||||
}
|
||||
|
||||
+9
-9
@@ -314,7 +314,7 @@ ok:
|
||||
architectures := strings.Split(stanza["Architectures"], " ")
|
||||
sort.Strings(architectures)
|
||||
// "source" architecture is never present, despite Release file claims
|
||||
architectures = utils.StrSlicesSubstract(architectures, []string{"source"})
|
||||
architectures = utils.StrSlicesSubstract(architectures, []string{ArchitectureSource})
|
||||
if len(repo.Architectures) == 0 {
|
||||
repo.Architectures = architectures
|
||||
} else if !repo.SkipArchitectureCheck {
|
||||
@@ -410,20 +410,20 @@ func (repo *RemoteRepo) DownloadPackageIndexes(progress aptly.Progress, d aptly.
|
||||
packagesURLs := [][]string{}
|
||||
|
||||
if repo.IsFlat() {
|
||||
packagesURLs = append(packagesURLs, []string{repo.FlatBinaryURL().String(), "binary"})
|
||||
packagesURLs = append(packagesURLs, []string{repo.FlatBinaryURL().String(), PackageTypeBinary})
|
||||
if repo.DownloadSources {
|
||||
packagesURLs = append(packagesURLs, []string{repo.FlatSourcesURL().String(), "source"})
|
||||
packagesURLs = append(packagesURLs, []string{repo.FlatSourcesURL().String(), PackageTypeSource})
|
||||
}
|
||||
} else {
|
||||
for _, component := range repo.Components {
|
||||
for _, architecture := range repo.Architectures {
|
||||
packagesURLs = append(packagesURLs, []string{repo.BinaryURL(component, architecture).String(), "binary"})
|
||||
packagesURLs = append(packagesURLs, []string{repo.BinaryURL(component, architecture).String(), PackageTypeBinary})
|
||||
if repo.DownloadUdebs {
|
||||
packagesURLs = append(packagesURLs, []string{repo.UdebURL(component, architecture).String(), "udeb"})
|
||||
packagesURLs = append(packagesURLs, []string{repo.UdebURL(component, architecture).String(), PackageTypeUdeb})
|
||||
}
|
||||
}
|
||||
if repo.DownloadSources {
|
||||
packagesURLs = append(packagesURLs, []string{repo.SourcesURL(component).String(), "source"})
|
||||
packagesURLs = append(packagesURLs, []string{repo.SourcesURL(component).String(), PackageTypeSource})
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -455,11 +455,11 @@ func (repo *RemoteRepo) DownloadPackageIndexes(progress aptly.Progress, d aptly.
|
||||
|
||||
var p *Package
|
||||
|
||||
if kind == "binary" {
|
||||
if kind == PackageTypeBinary {
|
||||
p = NewPackageFromControlFile(stanza)
|
||||
} else if kind == "udeb" {
|
||||
} else if kind == PackageTypeUdeb {
|
||||
p = NewUdebPackageFromControlFile(stanza)
|
||||
} else if kind == "source" {
|
||||
} else if kind == PackageTypeSource {
|
||||
p, err = NewSourcePackageFromControlFile(stanza)
|
||||
if err != nil {
|
||||
return err
|
||||
|
||||
+4
-4
@@ -44,7 +44,7 @@ func NewSnapshotFromRepository(name string, repo *RemoteRepo) (*Snapshot, error)
|
||||
UUID: uuid.New(),
|
||||
Name: name,
|
||||
CreatedAt: time.Now(),
|
||||
SourceKind: "repo",
|
||||
SourceKind: SourceRemoteRepo,
|
||||
SourceIDs: []string{repo.UUID},
|
||||
Description: fmt.Sprintf("Snapshot from mirror %s", repo),
|
||||
packageRefs: repo.packageRefs,
|
||||
@@ -57,7 +57,7 @@ func NewSnapshotFromLocalRepo(name string, repo *LocalRepo) (*Snapshot, error) {
|
||||
UUID: uuid.New(),
|
||||
Name: name,
|
||||
CreatedAt: time.Now(),
|
||||
SourceKind: "local",
|
||||
SourceKind: SourceLocalRepo,
|
||||
SourceIDs: []string{repo.UUID},
|
||||
Description: fmt.Sprintf("Snapshot from local repo %s", repo),
|
||||
packageRefs: repo.packageRefs,
|
||||
@@ -257,7 +257,7 @@ func (collection *SnapshotCollection) ByRemoteRepoSource(repo *RemoteRepo) []*Sn
|
||||
var result []*Snapshot
|
||||
|
||||
for _, s := range collection.list {
|
||||
if s.SourceKind == "repo" && utils.StrSliceHasItem(s.SourceIDs, repo.UUID) {
|
||||
if s.SourceKind == SourceRemoteRepo && utils.StrSliceHasItem(s.SourceIDs, repo.UUID) {
|
||||
result = append(result, s)
|
||||
}
|
||||
}
|
||||
@@ -269,7 +269,7 @@ func (collection *SnapshotCollection) ByLocalRepoSource(repo *LocalRepo) []*Snap
|
||||
var result []*Snapshot
|
||||
|
||||
for _, s := range collection.list {
|
||||
if s.SourceKind == "local" && utils.StrSliceHasItem(s.SourceIDs, repo.UUID) {
|
||||
if s.SourceKind == SourceLocalRepo && utils.StrSliceHasItem(s.SourceIDs, repo.UUID) {
|
||||
result = append(result, s)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,7 +26,7 @@ func (s *SnapshotSuite) TestNewSnapshotFromRepository(c *C) {
|
||||
c.Check(snapshot.Name, Equals, "snap1")
|
||||
c.Check(snapshot.NumPackages(), Equals, 3)
|
||||
c.Check(snapshot.RefList().Len(), Equals, 3)
|
||||
c.Check(snapshot.SourceKind, Equals, "repo")
|
||||
c.Check(snapshot.SourceKind, Equals, SourceRemoteRepo)
|
||||
c.Check(snapshot.SourceIDs, DeepEquals, []string{s.repo.UUID})
|
||||
|
||||
s.repo.packageRefs = nil
|
||||
|
||||
Reference in New Issue
Block a user