From 5ce6bf87181a44215113f35f46cc5de8ea6849b9 Mon Sep 17 00:00:00 2001 From: Andrey Smirnov Date: Thu, 4 May 2017 23:00:13 +0300 Subject: [PATCH] Enable `vetshadow` linter --- api/publish.go | 10 +++++----- cmd/api_serve.go | 5 ++++- cmd/db_cleanup.go | 24 ++++++++++++------------ cmd/package_show.go | 21 +++++++++++---------- cmd/publish_list.go | 6 +++--- cmd/publish_show.go | 8 ++++---- cmd/repo_add.go | 2 +- cmd/repo_include.go | 8 +++++--- cmd/repo_list.go | 6 +++--- cmd/serve.go | 6 +++--- cmd/snapshot_search.go | 9 ++++++--- cmd/snapshot_show.go | 10 +++++++--- cmd/task_run.go | 2 +- deb/changes.go | 3 ++- deb/graph.go | 18 +++++++++--------- deb/publish.go | 3 ++- files/public.go | 3 ++- linter.json | 3 ++- 18 files changed, 82 insertions(+), 65 deletions(-) diff --git a/api/publish.go b/api/publish.go index f0dfed35..72ab38ae 100644 --- a/api/publish.go +++ b/api/publish.go @@ -281,15 +281,15 @@ func apiPublishUpdateSwitch(c *gin.Context) { return } - snapshot, err := snapshotCollection.ByName(snapshotInfo.Name) + snapshot, err2 := snapshotCollection.ByName(snapshotInfo.Name) if err != nil { - c.Fail(404, err) + c.Fail(404, err2) return } - err = snapshotCollection.LoadComplete(snapshot) - if err != nil { - c.Fail(500, err) + err2 = snapshotCollection.LoadComplete(snapshot) + if err2 != nil { + c.Fail(500, err2) return } diff --git a/cmd/api_serve.go b/cmd/api_serve.go index fae2702a..2b0d3cdc 100644 --- a/cmd/api_serve.go +++ b/cmd/api_serve.go @@ -59,11 +59,14 @@ func aptlyAPIServe(cmd *commander.Command, args []string) error { if err == nil && listenURL.Scheme == "unix" { file := listenURL.Path os.Remove(file) - listener, err := net.Listen("unix", file) + + var listener net.Listener + listener, err = net.Listen("unix", file) if err != nil { return fmt.Errorf("failed to listen on: %s\n%s", file, err) } defer listener.Close() + err = http.Serve(listener, api.Router(context)) if err != nil { return fmt.Errorf("unable to serve: %s", err) diff --git a/cmd/db_cleanup.go b/cmd/db_cleanup.go index 685c5615..6833a049 100644 --- a/cmd/db_cleanup.go +++ b/cmd/db_cleanup.go @@ -37,9 +37,9 @@ func aptlyDbCleanup(cmd *commander.Command, args []string) error { context.Progress().ColoredPrintf("- @{g}%s@|", repo.Name) } - err := context.CollectionFactory().RemoteRepoCollection().LoadComplete(repo) - if err != nil { - return err + e := context.CollectionFactory().RemoteRepoCollection().LoadComplete(repo) + if e != nil { + return e } if repo.RefList() != nil { existingPackageRefs = existingPackageRefs.Merge(repo.RefList(), false, true) @@ -67,9 +67,9 @@ func aptlyDbCleanup(cmd *commander.Command, args []string) error { context.Progress().ColoredPrintf("- @{g}%s@|", repo.Name) } - err := context.CollectionFactory().LocalRepoCollection().LoadComplete(repo) - if err != nil { - return err + e := context.CollectionFactory().LocalRepoCollection().LoadComplete(repo) + if e != nil { + return e } if repo.RefList() != nil { @@ -98,9 +98,9 @@ func aptlyDbCleanup(cmd *commander.Command, args []string) error { context.Progress().ColoredPrintf("- @{g}%s@|", snapshot.Name) } - err := context.CollectionFactory().SnapshotCollection().LoadComplete(snapshot) - if err != nil { - return err + e := context.CollectionFactory().SnapshotCollection().LoadComplete(snapshot) + if e != nil { + return e } existingPackageRefs = existingPackageRefs.Merge(snapshot.RefList(), false, true) @@ -128,9 +128,9 @@ func aptlyDbCleanup(cmd *commander.Command, args []string) error { if published.SourceKind != "local" { return nil } - err := context.CollectionFactory().PublishedRepoCollection().LoadComplete(published, context.CollectionFactory()) - if err != nil { - return err + e := context.CollectionFactory().PublishedRepoCollection().LoadComplete(published, context.CollectionFactory()) + if e != nil { + return e } for _, component := range published.Components() { diff --git a/cmd/package_show.go b/cmd/package_show.go index 91943c9e..bfac059e 100644 --- a/cmd/package_show.go +++ b/cmd/package_show.go @@ -14,9 +14,9 @@ import ( func printReferencesTo(p *deb.Package) (err error) { err = context.CollectionFactory().RemoteRepoCollection().ForEach(func(repo *deb.RemoteRepo) error { - err := context.CollectionFactory().RemoteRepoCollection().LoadComplete(repo) - if err != nil { - return err + e := context.CollectionFactory().RemoteRepoCollection().LoadComplete(repo) + if e != nil { + return e } if repo.RefList() != nil { if repo.RefList().Has(p) { @@ -30,9 +30,9 @@ func printReferencesTo(p *deb.Package) (err error) { } err = context.CollectionFactory().LocalRepoCollection().ForEach(func(repo *deb.LocalRepo) error { - err := context.CollectionFactory().LocalRepoCollection().LoadComplete(repo) - if err != nil { - return err + e := context.CollectionFactory().LocalRepoCollection().LoadComplete(repo) + if e != nil { + return e } if repo.RefList() != nil { if repo.RefList().Has(p) { @@ -46,9 +46,9 @@ func printReferencesTo(p *deb.Package) (err error) { } err = context.CollectionFactory().SnapshotCollection().ForEach(func(snapshot *deb.Snapshot) error { - err := context.CollectionFactory().SnapshotCollection().LoadComplete(snapshot) - if err != nil { - return err + e := context.CollectionFactory().SnapshotCollection().LoadComplete(snapshot) + if e != nil { + return e } if snapshot.RefList().Has(p) { fmt.Printf(" snapshot %s\n", snapshot) @@ -87,7 +87,8 @@ func aptlyPackageShow(cmd *commander.Command, args []string) error { fmt.Printf("Files in the pool:\n") packagePool := context.PackagePool() for _, f := range p.Files() { - path, err := f.GetPoolPath(packagePool) + var path string + path, err = f.GetPoolPath(packagePool) if err != nil { return err } diff --git a/cmd/publish_list.go b/cmd/publish_list.go index 8e1fdbb5..b821cb9c 100644 --- a/cmd/publish_list.go +++ b/cmd/publish_list.go @@ -20,9 +20,9 @@ func aptlyPublishList(cmd *commander.Command, args []string) error { published := make([]string, 0, context.CollectionFactory().PublishedRepoCollection().Len()) err = context.CollectionFactory().PublishedRepoCollection().ForEach(func(repo *deb.PublishedRepo) error { - err := context.CollectionFactory().PublishedRepoCollection().LoadComplete(repo, context.CollectionFactory()) - if err != nil { - return err + e := context.CollectionFactory().PublishedRepoCollection().LoadComplete(repo, context.CollectionFactory()) + if e != nil { + return e } if raw { diff --git a/cmd/publish_show.go b/cmd/publish_show.go index fbb92aa8..20355f95 100644 --- a/cmd/publish_show.go +++ b/cmd/publish_show.go @@ -42,14 +42,14 @@ func aptlyPublishShow(cmd *commander.Command, args []string) error { for component, sourceID := range repo.Sources { var name string if repo.SourceKind == "snapshot" { - source, err := context.CollectionFactory().SnapshotCollection().ByUUID(sourceID) - if err != nil { + source, e := context.CollectionFactory().SnapshotCollection().ByUUID(sourceID) + if e != nil { continue } name = source.Name } else if repo.SourceKind == "local" { - source, err := context.CollectionFactory().LocalRepoCollection().ByUUID(sourceID) - if err != nil { + source, e := context.CollectionFactory().LocalRepoCollection().ByUUID(sourceID) + if e != nil { continue } name = source.Name diff --git a/cmd/repo_add.go b/cmd/repo_add.go index 581e250e..e0fe0f5f 100644 --- a/cmd/repo_add.go +++ b/cmd/repo_add.go @@ -66,7 +66,7 @@ func aptlyRepoAdd(cmd *commander.Command, args []string) error { processedFiles = utils.StrSliceDeduplicate(processedFiles) for _, file := range processedFiles { - err := os.Remove(file) + err = os.Remove(file) if err != nil { return fmt.Errorf("unable to remove file: %s", err) } diff --git a/cmd/repo_include.go b/cmd/repo_include.go index d575cb21..09b66fcd 100644 --- a/cmd/repo_include.go +++ b/cmd/repo_include.go @@ -97,7 +97,8 @@ func aptlyRepoInclude(cmd *commander.Command, args []string) error { context.Progress().Printf("Loading repository %s for changes file %s...\n", repoName.String(), changes.ChangesName) - repo, err := context.CollectionFactory().LocalRepoCollection().ByName(repoName.String()) + var repo *deb.LocalRepo + repo, err = context.CollectionFactory().LocalRepoCollection().ByName(repoName.String()) if err != nil { failedFiles = append(failedFiles, path) reporter.Warning("unable to process file %s: %s", changes.ChangesName, err) @@ -131,7 +132,8 @@ func aptlyRepoInclude(cmd *commander.Command, args []string) error { return fmt.Errorf("unable to load repo: %s", err) } - list, err := deb.NewPackageListFromRefList(repo.RefList(), context.CollectionFactory().PackageCollection(), context.Progress()) + var list *deb.PackageList + list, err = deb.NewPackageListFromRefList(repo.RefList(), context.CollectionFactory().PackageCollection(), context.Progress()) if err != nil { return fmt.Errorf("unable to load packages: %s", err) } @@ -184,7 +186,7 @@ func aptlyRepoInclude(cmd *commander.Command, args []string) error { processedFiles = utils.StrSliceDeduplicate(processedFiles) for _, file := range processedFiles { - err := os.Remove(file) + err = os.Remove(file) if err != nil { return fmt.Errorf("unable to remove file: %s", err) } diff --git a/cmd/repo_list.go b/cmd/repo_list.go index fece3e11..14b69665 100644 --- a/cmd/repo_list.go +++ b/cmd/repo_list.go @@ -23,9 +23,9 @@ func aptlyRepoList(cmd *commander.Command, args []string) error { if raw { repos[i] = repo.Name } else { - err := context.CollectionFactory().LocalRepoCollection().LoadComplete(repo) - if err != nil { - return err + e := context.CollectionFactory().LocalRepoCollection().LoadComplete(repo) + if e != nil { + return e } repos[i] = fmt.Sprintf(" * %s (packages: %d)", repo.String(), repo.NumPackages()) diff --git a/cmd/serve.go b/cmd/serve.go index 18d03d89..8bfb67c1 100644 --- a/cmd/serve.go +++ b/cmd/serve.go @@ -60,9 +60,9 @@ func aptlyServe(cmd *commander.Command, args []string) error { published := make(map[string]*deb.PublishedRepo, context.CollectionFactory().PublishedRepoCollection().Len()) err = context.CollectionFactory().PublishedRepoCollection().ForEach(func(repo *deb.PublishedRepo) error { - err := context.CollectionFactory().PublishedRepoCollection().LoadComplete(repo, context.CollectionFactory()) - if err != nil { - return err + e := context.CollectionFactory().PublishedRepoCollection().LoadComplete(repo, context.CollectionFactory()) + if e != nil { + return e } sources = append(sources, repo.String()) diff --git a/cmd/snapshot_search.go b/cmd/snapshot_search.go index 98b5beb4..bef3247e 100644 --- a/cmd/snapshot_search.go +++ b/cmd/snapshot_search.go @@ -27,7 +27,8 @@ func aptlySnapshotMirrorRepoSearch(cmd *commander.Command, args []string) error var reflist *deb.PackageRefList if command == "snapshot" { - snapshot, err := context.CollectionFactory().SnapshotCollection().ByName(name) + var snapshot *deb.Snapshot + snapshot, err = context.CollectionFactory().SnapshotCollection().ByName(name) if err != nil { return fmt.Errorf("unable to search: %s", err) } @@ -39,7 +40,8 @@ func aptlySnapshotMirrorRepoSearch(cmd *commander.Command, args []string) error reflist = snapshot.RefList() } else if command == "mirror" { - repo, err := context.CollectionFactory().RemoteRepoCollection().ByName(name) + var repo *deb.RemoteRepo + repo, err = context.CollectionFactory().RemoteRepoCollection().ByName(name) if err != nil { return fmt.Errorf("unable to search: %s", err) } @@ -51,7 +53,8 @@ func aptlySnapshotMirrorRepoSearch(cmd *commander.Command, args []string) error reflist = repo.RefList() } else if command == "repo" { - repo, err := context.CollectionFactory().LocalRepoCollection().ByName(name) + var repo *deb.LocalRepo + repo, err = context.CollectionFactory().LocalRepoCollection().ByName(name) if err != nil { return fmt.Errorf("unable to search: %s", err) } diff --git a/cmd/snapshot_show.go b/cmd/snapshot_show.go index 4615debd..03d8a5a6 100644 --- a/cmd/snapshot_show.go +++ b/cmd/snapshot_show.go @@ -3,6 +3,7 @@ package cmd import ( "fmt" + "github.com/smira/aptly/deb" "github.com/smira/commander" "github.com/smira/flag" ) @@ -35,19 +36,22 @@ func aptlySnapshotShow(cmd *commander.Command, args []string) error { for _, sourceID := range snapshot.SourceIDs { var name string if snapshot.SourceKind == "snapshot" { - source, err := context.CollectionFactory().SnapshotCollection().ByUUID(sourceID) + var source *deb.Snapshot + source, err = context.CollectionFactory().SnapshotCollection().ByUUID(sourceID) if err != nil { continue } name = source.Name } else if snapshot.SourceKind == "local" { - source, err := context.CollectionFactory().LocalRepoCollection().ByUUID(sourceID) + var source *deb.LocalRepo + source, err = context.CollectionFactory().LocalRepoCollection().ByUUID(sourceID) if err != nil { continue } name = source.Name } else if snapshot.SourceKind == "repo" { - source, err := context.CollectionFactory().RemoteRepoCollection().ByUUID(sourceID) + var source *deb.RemoteRepo + source, err = context.CollectionFactory().RemoteRepoCollection().ByUUID(sourceID) if err != nil { continue } diff --git a/cmd/task_run.go b/cmd/task_run.go index 095c6a67..8e18d94c 100644 --- a/cmd/task_run.go +++ b/cmd/task_run.go @@ -82,7 +82,7 @@ func aptlyTaskRun(cmd *commander.Command, args []string) error { for i, command := range cmdList { if !commandErrored { - err := context.ReOpenDatabase() + err = context.ReOpenDatabase() if err != nil { return fmt.Errorf("failed to reopen DB: %s", err) } diff --git a/deb/changes.go b/deb/changes.go index 8737dfd2..7e975587 100644 --- a/deb/changes.go +++ b/deb/changes.go @@ -69,7 +69,8 @@ func (c *Changes) VerifyAndParse(acceptUnsigned, ignoreSignature bool, verifier } if isClearSigned && !ignoreSignature { - keyInfo, err := verifier.VerifyClearsigned(input, false) + var keyInfo *utils.GpgKeyInfo + keyInfo, err = verifier.VerifyClearsigned(input, false) if err != nil { return err } diff --git a/deb/graph.go b/deb/graph.go index ba543bcd..b5b6947e 100644 --- a/deb/graph.go +++ b/deb/graph.go @@ -33,9 +33,9 @@ func BuildGraph(collectionFactory *CollectionFactory, layout string) (gographviz existingNodes := map[string]bool{} err = collectionFactory.RemoteRepoCollection().ForEach(func(repo *RemoteRepo) error { - err := collectionFactory.RemoteRepoCollection().LoadComplete(repo) - if err != nil { - return err + e := collectionFactory.RemoteRepoCollection().LoadComplete(repo) + if e != nil { + return e } graph.AddNode("aptly", repo.UUID, map[string]string{ @@ -55,9 +55,9 @@ func BuildGraph(collectionFactory *CollectionFactory, layout string) (gographviz } err = collectionFactory.LocalRepoCollection().ForEach(func(repo *LocalRepo) error { - err := collectionFactory.LocalRepoCollection().LoadComplete(repo) - if err != nil { - return err + e := collectionFactory.LocalRepoCollection().LoadComplete(repo) + if e != nil { + return e } graph.AddNode("aptly", repo.UUID, map[string]string{ @@ -81,9 +81,9 @@ func BuildGraph(collectionFactory *CollectionFactory, layout string) (gographviz }) err = collectionFactory.SnapshotCollection().ForEach(func(snapshot *Snapshot) error { - err := collectionFactory.SnapshotCollection().LoadComplete(snapshot) - if err != nil { - return err + e := collectionFactory.SnapshotCollection().LoadComplete(snapshot) + if e != nil { + return e } description := snapshot.Description diff --git a/deb/publish.go b/deb/publish.go index 56c05c22..afe0573d 100644 --- a/deb/publish.go +++ b/deb/publish.go @@ -611,7 +611,8 @@ func (p *PublishedRepo) Publish(packagePool aptly.PackagePool, publishedStorageP continue } - bufWriter, err := indexes.ContentsIndex(component, arch, udeb).BufWriter() + var bufWriter *bufio.Writer + bufWriter, err = indexes.ContentsIndex(component, arch, udeb).BufWriter() if err != nil { return fmt.Errorf("unable to generate contents index: %v", err) } diff --git a/files/public.go b/files/public.go index 5b920b80..4147da1a 100644 --- a/files/public.go +++ b/files/public.go @@ -146,7 +146,8 @@ func (storage *PublishedStorage) LinkFromPool(publishedDirectory, baseName strin } } else { // if source and destination have the same checksums, no need to copy - dstMD5, err := utils.MD5ChecksumForFile(filepath.Join(poolPath, baseName)) + var dstMD5 string + dstMD5, err = utils.MD5ChecksumForFile(filepath.Join(poolPath, baseName)) if err != nil { return err diff --git a/linter.json b/linter.json index c06af35c..bbab4e46 100644 --- a/linter.json +++ b/linter.json @@ -12,7 +12,8 @@ "staticcheck", "varcheck", "structcheck", - "aligncheck" + "aligncheck", + "vetshadow" ], "Deadline": "20m", "Vendor": true,