Enable goconst & interfacer linters

This commit is contained in:
Andrey Smirnov
2017-05-16 00:26:41 +03:00
parent e396a2e6c3
commit 470165a419
26 changed files with 110 additions and 82 deletions

View File

@@ -145,7 +145,7 @@ func apiPublishRepoOrSnapshot(c *gin.Context) {
sources = append(sources, snapshot)
}
} else if b.SourceKind == "local" {
} else if b.SourceKind == deb.SourceLocalRepo {
var localRepo *deb.LocalRepo
localCollection := context.CollectionFactory().LocalRepoCollection()
@@ -264,7 +264,7 @@ func apiPublishUpdateSwitch(c *gin.Context) {
var updatedComponents []string
if published.SourceKind == "local" {
if published.SourceKind == deb.SourceLocalRepo {
if len(b.Snapshots) > 0 {
c.Fail(400, fmt.Errorf("snapshots shouldn't be given when updating local repo"))
return

View File

@@ -14,6 +14,12 @@ import (
"github.com/smira/flag"
)
// Various command flags/UI things
const (
Yes = "yes"
No = "no"
)
// ListPackagesRefList shows list of packages in PackageRefList
func ListPackagesRefList(reflist *deb.PackageRefList) (err error) {
fmt.Printf("Packages:\n")

View File

@@ -125,7 +125,7 @@ func aptlyDbCleanup(cmd *commander.Command, args []string) error {
if verbose {
context.Progress().ColoredPrintf("- @{g}%s:%s/%s{|}", published.Storage, published.Prefix, published.Distribution)
}
if published.SourceKind != "local" {
if published.SourceKind != deb.SourceLocalRepo {
return nil
}
e := context.CollectionFactory().PublishedRepoCollection().LoadComplete(published, context.CollectionFactory())

View File

@@ -37,21 +37,21 @@ func aptlyMirrorShow(cmd *commander.Command, args []string) error {
fmt.Printf("Distribution: %s\n", repo.Distribution)
fmt.Printf("Components: %s\n", strings.Join(repo.Components, ", "))
fmt.Printf("Architectures: %s\n", strings.Join(repo.Architectures, ", "))
downloadSources := "no"
downloadSources := No
if repo.DownloadSources {
downloadSources = "yes"
downloadSources = Yes
}
fmt.Printf("Download Sources: %s\n", downloadSources)
downloadUdebs := "no"
downloadUdebs := No
if repo.DownloadUdebs {
downloadUdebs = "yes"
downloadUdebs = Yes
}
fmt.Printf("Download .udebs: %s\n", downloadUdebs)
if repo.Filter != "" {
fmt.Printf("Filter: %s\n", repo.Filter)
filterWithDeps := "no"
filterWithDeps := No
if repo.FilterWithDeps {
filterWithDeps = "yes"
filterWithDeps = Yes
}
fmt.Printf("Filter With Deps: %s\n", filterWithDeps)
}

View File

@@ -41,13 +41,13 @@ func aptlyPublishShow(cmd *commander.Command, args []string) error {
fmt.Printf("Sources:\n")
for component, sourceID := range repo.Sources {
var name string
if repo.SourceKind == "snapshot" {
if repo.SourceKind == deb.SourceSnapshot {
source, e := context.CollectionFactory().SnapshotCollection().ByUUID(sourceID)
if e != nil {
continue
}
name = source.Name
} else if repo.SourceKind == "local" {
} else if repo.SourceKind == deb.SourceLocalRepo {
source, e := context.CollectionFactory().LocalRepoCollection().ByUUID(sourceID)
if e != nil {
continue

View File

@@ -35,7 +35,7 @@ func aptlyPublishSnapshotOrRepo(cmd *commander.Command, args []string) error {
message string
)
if cmd.Name() == "snapshot" {
if cmd.Name() == "snapshot" { // nolint: goconst
var (
snapshot *deb.Snapshot
emptyWarning = false
@@ -71,7 +71,7 @@ func aptlyPublishSnapshotOrRepo(cmd *commander.Command, args []string) error {
if emptyWarning {
context.Progress().Printf("Warning: publishing from empty source, architectures list should be complete, it can't be changed after publishing (use -architectures flag)\n")
}
} else if cmd.Name() == "repo" {
} else if cmd.Name() == "repo" { // nolint: goconst
var (
localRepo *deb.LocalRepo
emptyWarning = false
@@ -170,7 +170,7 @@ func aptlyPublishSnapshotOrRepo(cmd *commander.Command, args []string) error {
context.Progress().Printf("Now you can add following line to apt sources:\n")
context.Progress().Printf(" deb http://your-server/%s %s %s\n", prefix, distribution, repoComponents)
if utils.StrSliceHasItem(published.Architectures, "source") {
if utils.StrSliceHasItem(published.Architectures, deb.ArchitectureSource) {
context.Progress().Printf(" deb-src http://your-server/%s %s %s\n", prefix, distribution, repoComponents)
}
context.Progress().Printf("Don't forget to add your GPG key to apt with apt-key.\n")

View File

@@ -44,7 +44,7 @@ func aptlyPublishSwitch(cmd *commander.Command, args []string) error {
return fmt.Errorf("unable to update: %s", err)
}
if published.SourceKind != "snapshot" {
if published.SourceKind != deb.SourceSnapshot {
return fmt.Errorf("unable to update: not a snapshot publish")
}

View File

@@ -30,7 +30,7 @@ func aptlyPublishUpdate(cmd *commander.Command, args []string) error {
return fmt.Errorf("unable to update: %s", err)
}
if published.SourceKind != "local" {
if published.SourceKind != deb.SourceLocalRepo {
return fmt.Errorf("unable to update: not a local repository publish")
}

View File

@@ -10,7 +10,7 @@ import (
func aptlyRepoCreate(cmd *commander.Command, args []string) error {
var err error
if !(len(args) == 1 || (len(args) == 4 && args[1] == "from" && args[2] == "snapshot")) {
if !(len(args) == 1 || (len(args) == 4 && args[1] == "from" && args[2] == "snapshot")) { // nolint: goconst
cmd.Usage()
return commander.ErrCommandError
}

View File

@@ -34,7 +34,7 @@ func aptlyRepoMoveCopyImport(cmd *commander.Command, args []string) error {
srcRepo *deb.LocalRepo
)
if command == "copy" || command == "move" {
if command == "copy" || command == "move" { // nolint: goconst
srcRepo, err = context.CollectionFactory().LocalRepoCollection().ByName(args[0])
if err != nil {
return fmt.Errorf("unable to %s: %s", command, err)
@@ -50,7 +50,7 @@ func aptlyRepoMoveCopyImport(cmd *commander.Command, args []string) error {
}
srcRefList = srcRepo.RefList()
} else if command == "import" {
} else if command == "import" { // nolint: goconst
var srcRemoteRepo *deb.RemoteRepo
srcRemoteRepo, err = context.CollectionFactory().RemoteRepoCollection().ByName(args[0])
@@ -122,11 +122,11 @@ func aptlyRepoMoveCopyImport(cmd *commander.Command, args []string) error {
var verb string
if command == "move" {
if command == "move" { // nolint: goconst
verb = "moved"
} else if command == "copy" {
} else if command == "copy" { // nolint: goconst
verb = "copied"
} else if command == "import" {
} else if command == "import" { // nolint: goconst
verb = "imported"
}
@@ -136,7 +136,7 @@ func aptlyRepoMoveCopyImport(cmd *commander.Command, args []string) error {
return err
}
if command == "move" {
if command == "move" { // nolint: goconst
srcList.Remove(p)
}
context.Progress().ColoredPrintf("@g[o]@| %s %s", p, verb)
@@ -156,7 +156,7 @@ func aptlyRepoMoveCopyImport(cmd *commander.Command, args []string) error {
return fmt.Errorf("unable to save: %s", err)
}
if command == "move" {
if command == "move" { // nolint: goconst
srcRepo.UpdateRefList(deb.NewPackageRefListFromPackageList(srcList))
err = context.CollectionFactory().LocalRepoCollection().Update(srcRepo)

View File

@@ -90,7 +90,7 @@ func aptlyServe(cmd *commander.Command, args []string) error {
fmt.Printf("# %s\ndeb http://%s:%s/%s %s %s\n",
repo, listenHost, listenPort, prefix, repo.Distribution, strings.Join(repo.Components(), " "))
if utils.StrSliceHasItem(repo.Architectures, "source") {
if utils.StrSliceHasItem(repo.Architectures, deb.ArchitectureSource) {
fmt.Printf("deb-src http://%s:%s/%s %s %s\n",
listenHost, listenPort, prefix, repo.Distribution, strings.Join(repo.Components(), " "))
}

View File

@@ -13,7 +13,7 @@ func aptlySnapshotCreate(cmd *commander.Command, args []string) error {
snapshot *deb.Snapshot
)
if len(args) == 4 && args[1] == "from" && args[2] == "mirror" {
if len(args) == 4 && args[1] == "from" && args[2] == "mirror" { // nolint: goconst
// aptly snapshot create snap from mirror mirror
var repo *deb.RemoteRepo
@@ -38,7 +38,7 @@ func aptlySnapshotCreate(cmd *commander.Command, args []string) error {
if err != nil {
return fmt.Errorf("unable to create snapshot: %s", err)
}
} else if len(args) == 4 && args[1] == "from" && args[2] == "repo" {
} else if len(args) == 4 && args[1] == "from" && args[2] == "repo" { // nolint: goconst
// aptly snapshot create snap from repo repo
var repo *deb.LocalRepo

View File

@@ -26,7 +26,7 @@ func aptlySnapshotMirrorRepoSearch(cmd *commander.Command, args []string) error
var reflist *deb.PackageRefList
if command == "snapshot" {
if command == "snapshot" { // nolint: goconst
var snapshot *deb.Snapshot
snapshot, err = context.CollectionFactory().SnapshotCollection().ByName(name)
if err != nil {
@@ -52,7 +52,7 @@ func aptlySnapshotMirrorRepoSearch(cmd *commander.Command, args []string) error
}
reflist = repo.RefList()
} else if command == "repo" {
} else if command == "repo" { // nolint: goconst
var repo *deb.LocalRepo
repo, err = context.CollectionFactory().LocalRepoCollection().ByName(name)
if err != nil {

View File

@@ -35,21 +35,21 @@ func aptlySnapshotShow(cmd *commander.Command, args []string) error {
fmt.Printf("Sources:\n")
for _, sourceID := range snapshot.SourceIDs {
var name string
if snapshot.SourceKind == "snapshot" {
if snapshot.SourceKind == deb.SourceSnapshot {
var source *deb.Snapshot
source, err = context.CollectionFactory().SnapshotCollection().ByUUID(sourceID)
if err != nil {
continue
}
name = source.Name
} else if snapshot.SourceKind == "local" {
} else if snapshot.SourceKind == deb.SourceLocalRepo {
var source *deb.LocalRepo
source, err = context.CollectionFactory().LocalRepoCollection().ByUUID(sourceID)
if err != nil {
continue
}
name = source.Name
} else if snapshot.SourceKind == "repo" {
} else if snapshot.SourceKind == deb.SourceRemoteRepo {
var source *deb.RemoteRepo
source, err = context.CollectionFactory().RemoteRepoCollection().ByUUID(sourceID)
if err != nil {

View File

@@ -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}
}

View File

@@ -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()

View File

@@ -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 {

View File

@@ -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)

View File

@@ -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)
}
}

View File

@@ -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
}

View File

@@ -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)
}

View File

@@ -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,
}

View File

@@ -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

View File

@@ -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)
}
}

View File

@@ -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

View File

@@ -13,7 +13,9 @@
"varcheck",
"structcheck",
"aligncheck",
"vetshadow"
"vetshadow",
"goconst",
"interfacer"
],
"Deadline": "20m",
"Vendor": true,