diff --git a/console/progress.go b/console/progress.go index 4c58b747..4c13ab28 100644 --- a/console/progress.go +++ b/console/progress.go @@ -28,7 +28,6 @@ type printTask struct { // Progress is a progress displaying subroutine, it allows to show download and other operations progress // mixed with progress bar type Progress struct { - stop chan bool stopped chan bool queue chan printTask bar *pb.ProgressBar diff --git a/deb/list.go b/deb/list.go index a421bc36..b65c2826 100644 --- a/deb/list.go +++ b/deb/list.go @@ -34,8 +34,6 @@ const ( type PackageList struct { // Straight list of packages as map packages map[string]*Package - // Has index been prepared? - indexed bool // Indexed list of packages, sorted by name internally packagesIndex []*Package // Map of packages for each virtual package (provides) @@ -44,6 +42,8 @@ type PackageList struct { keyFunc func(p *Package) string // Allow duplicates? duplicatesAllowed bool + // Has index been prepared? + indexed bool } // PackageConflictError means that package can't be added to the list due to error diff --git a/deb/local_test.go b/deb/local_test.go index dc237910..98a99bf8 100644 --- a/deb/local_test.go +++ b/deb/local_test.go @@ -98,14 +98,14 @@ func (s *LocalRepoCollectionSuite) TearDownTest(c *C) { } func (s *LocalRepoCollectionSuite) TestAddByName(c *C) { - r, err := s.collection.ByName("local1") + _, err := s.collection.ByName("local1") c.Assert(err, ErrorMatches, "*.not found") repo := NewLocalRepo("local1", "Comment 1") c.Assert(s.collection.Add(repo), IsNil) c.Assert(s.collection.Add(repo), ErrorMatches, ".*already exists") - r, err = s.collection.ByName("local1") + r, err := s.collection.ByName("local1") c.Assert(err, IsNil) c.Assert(r.String(), Equals, repo.String()) @@ -116,13 +116,13 @@ func (s *LocalRepoCollectionSuite) TestAddByName(c *C) { } func (s *LocalRepoCollectionSuite) TestByUUID(c *C) { - r, err := s.collection.ByUUID("some-uuid") + _, err := s.collection.ByUUID("some-uuid") c.Assert(err, ErrorMatches, "*.not found") repo := NewLocalRepo("local1", "Comment 1") c.Assert(s.collection.Add(repo), IsNil) - r, err = s.collection.ByUUID(repo.UUID) + r, err := s.collection.ByUUID(repo.UUID) c.Assert(err, IsNil) c.Assert(r.String(), Equals, repo.String()) } diff --git a/deb/package.go b/deb/package.go index d36ece65..d434bfbb 100644 --- a/deb/package.go +++ b/deb/package.go @@ -24,12 +24,12 @@ type Package struct { Source string // List of virtual packages this package provides Provides []string + // Hash of files section + FilesHash uint64 // Is this source package IsSource bool // Is this udeb package IsUdeb bool - // Hash of files section - FilesHash uint64 // Is this >= 0.6 package? V06Plus bool // Offload fields diff --git a/deb/publish.go b/deb/publish.go index bec7b8f0..56c05c22 100644 --- a/deb/publish.go +++ b/deb/publish.go @@ -45,8 +45,6 @@ type PublishedRepo struct { Architectures []string // SourceKind is "local"/"repo" SourceKind string - // Skip contents generation - SkipContents bool // Map of sources by each component: component name -> source UUID Sources map[string]string @@ -55,10 +53,12 @@ type PublishedRepo struct { Component string // SourceUUID is UUID of either snapshot or local repo SourceUUID string `codec:"SnapshotUUID"` - // Map of component to source items sourceItems map[string]repoSourceItem + // Skip contents generation + SkipContents bool + // True if repo is being re-published rePublishing bool } @@ -166,23 +166,19 @@ func NewPublishedRepo(storage, prefix, distribution string, architectures []stri component string snapshot *Snapshot localRepo *LocalRepo - ok bool ) // get first source source = sources[0] // figure out source kind - snapshot, ok = source.(*Snapshot) - if ok { + switch source.(type) { + case *Snapshot: result.SourceKind = "snapshot" - } else { - localRepo, ok = source.(*LocalRepo) - if ok { - result.SourceKind = "local" - } else { - panic("unknown source kind") - } + case *LocalRepo: + result.SourceKind = "local" + default: + panic("unknown source kind") } for i := range sources { diff --git a/deb/publish_test.go b/deb/publish_test.go index cd7c6618..b80fd6ec 100644 --- a/deb/publish_test.go +++ b/deb/publish_test.go @@ -277,7 +277,7 @@ func (s *PublishedRepoSuite) TestDistributionComponentGuessing(c *C) { c.Check(repo.Distribution, Equals, "squeeze") c.Check(repo.Components(), DeepEquals, []string{"main"}) - repo, err = NewPublishedRepo("", "ppa", "", nil, []string{"main"}, []interface{}{s.localRepo}, s.factory) + _, err = NewPublishedRepo("", "ppa", "", nil, []string{"main"}, []interface{}{s.localRepo}, s.factory) c.Check(err, ErrorMatches, "unable to guess distribution name, please specify explicitly") s.localRepo.DefaultDistribution = "precise" @@ -301,7 +301,7 @@ func (s *PublishedRepoSuite) TestDistributionComponentGuessing(c *C) { c.Check(repo.Distribution, Equals, "squeeze") c.Check(repo.Components(), DeepEquals, []string{"contrib", "main"}) - repo, err = NewPublishedRepo("", "ppa", "", nil, []string{"", ""}, []interface{}{s.snapshot, s.snapshot2}, s.factory) + _, err = NewPublishedRepo("", "ppa", "", nil, []string{"", ""}, []interface{}{s.snapshot, s.snapshot2}, s.factory) c.Check(err, ErrorMatches, "duplicate component name: main") } @@ -477,7 +477,7 @@ func (s *PublishedRepoCollectionSuite) TearDownTest(c *C) { } func (s *PublishedRepoCollectionSuite) TestAddByStoragePrefixDistribution(c *C) { - r, err := s.collection.ByStoragePrefixDistribution("", "ppa", "anaconda") + _, err := s.collection.ByStoragePrefixDistribution("", "ppa", "anaconda") c.Assert(err, ErrorMatches, "*.not found") c.Assert(s.collection.Add(s.repo1), IsNil) @@ -489,7 +489,7 @@ func (s *PublishedRepoCollectionSuite) TestAddByStoragePrefixDistribution(c *C) c.Assert(s.collection.Add(s.repo4), IsNil) c.Assert(s.collection.Add(s.repo5), IsNil) - r, err = s.collection.ByStoragePrefixDistribution("", "ppa", "anaconda") + r, err := s.collection.ByStoragePrefixDistribution("", "ppa", "anaconda") c.Assert(err, IsNil) err = s.collection.LoadComplete(r, s.factory) @@ -510,12 +510,12 @@ func (s *PublishedRepoCollectionSuite) TestAddByStoragePrefixDistribution(c *C) } func (s *PublishedRepoCollectionSuite) TestByUUID(c *C) { - r, err := s.collection.ByUUID(s.repo1.UUID) + _, err := s.collection.ByUUID(s.repo1.UUID) c.Assert(err, ErrorMatches, "*.not found") c.Assert(s.collection.Add(s.repo1), IsNil) - r, err = s.collection.ByUUID(s.repo1.UUID) + r, err := s.collection.ByUUID(s.repo1.UUID) c.Assert(err, IsNil) err = s.collection.LoadComplete(r, s.factory) diff --git a/deb/remote.go b/deb/remote.go index 4d05cdcd..4c739b21 100644 --- a/deb/remote.go +++ b/deb/remote.go @@ -45,10 +45,6 @@ type RemoteRepo struct { Components []string // List of architectures to fetch, if empty, then fetch all architectures Architectures []string - // Should we download sources? - DownloadSources bool - // Should we download .udebs? - DownloadUdebs bool // Meta-information about repository Meta Stanza // Last update date @@ -57,20 +53,22 @@ type RemoteRepo struct { ReleaseFiles map[string]utils.ChecksumInfo // Filter for packages Filter string + // Status marks state of repository (being updated, no action) + Status int + // WorkerPID is PID of the process modifying the mirror (if any) + WorkerPID int // FilterWithDeps to include dependencies from filter query FilterWithDeps bool // SkipComponentCheck skips component list verification SkipComponentCheck bool // SkipArchitectureCheck skips architecture list verification SkipArchitectureCheck bool - // Status marks state of repository (being updated, no action) - Status int - // WorkerPID is PID of the process modifying the mirror (if any) - WorkerPID int + // Should we download sources? + DownloadSources bool + // Should we download .udebs? + DownloadUdebs bool // "Snapshot" of current list of packages packageRefs *PackageRefList - // Temporary list of package refs - tempPackageRefs *PackageRefList // Parsed archived root archiveRootURL *url.URL // Current list of packages (filled while updating mirror) diff --git a/deb/remote_test.go b/deb/remote_test.go index c5ea86e7..5dae0af8 100644 --- a/deb/remote_test.go +++ b/deb/remote_test.go @@ -618,14 +618,14 @@ func (s *RemoteRepoCollectionSuite) TearDownTest(c *C) { } func (s *RemoteRepoCollectionSuite) TestAddByName(c *C) { - r, err := s.collection.ByName("yandex") + _, err := s.collection.ByName("yandex") c.Assert(err, ErrorMatches, "*.not found") repo, _ := NewRemoteRepo("yandex", "http://mirror.yandex.ru/debian/", "squeeze", []string{"main"}, []string{}, false, false) c.Assert(s.collection.Add(repo), IsNil) c.Assert(s.collection.Add(repo), ErrorMatches, ".*already exists") - r, err = s.collection.ByName("yandex") + r, err := s.collection.ByName("yandex") c.Assert(err, IsNil) c.Assert(r.String(), Equals, repo.String()) @@ -636,13 +636,13 @@ func (s *RemoteRepoCollectionSuite) TestAddByName(c *C) { } func (s *RemoteRepoCollectionSuite) TestByUUID(c *C) { - r, err := s.collection.ByUUID("some-uuid") + _, err := s.collection.ByUUID("some-uuid") c.Assert(err, ErrorMatches, "*.not found") repo, _ := NewRemoteRepo("yandex", "http://mirror.yandex.ru/debian/", "squeeze", []string{"main"}, []string{}, false, false) c.Assert(s.collection.Add(repo), IsNil) - r, err = s.collection.ByUUID(repo.UUID) + r, err := s.collection.ByUUID(repo.UUID) c.Assert(err, IsNil) c.Assert(r.String(), Equals, repo.String()) } diff --git a/deb/snapshot_test.go b/deb/snapshot_test.go index 7571fd54..eb29855b 100644 --- a/deb/snapshot_test.go +++ b/deb/snapshot_test.go @@ -138,7 +138,7 @@ func (s *SnapshotCollectionSuite) TearDownTest(c *C) { } func (s *SnapshotCollectionSuite) TestAddByNameByUUID(c *C) { - snapshot, err := s.collection.ByName("snap1") + _, err := s.collection.ByName("snap1") c.Assert(err, ErrorMatches, "*.not found") c.Assert(s.collection.Add(s.snapshot1), IsNil) @@ -146,7 +146,7 @@ func (s *SnapshotCollectionSuite) TestAddByNameByUUID(c *C) { c.Assert(s.collection.Add(s.snapshot2), IsNil) - snapshot, err = s.collection.ByName("snap1") + snapshot, err := s.collection.ByName("snap1") c.Assert(err, IsNil) c.Assert(snapshot.String(), Equals, s.snapshot1.String()) diff --git a/http/compression_test.go b/http/compression_test.go index 54ec6949..5748b0ec 100644 --- a/http/compression_test.go +++ b/http/compression_test.go @@ -84,7 +84,7 @@ func (s *CompressionSuite) TestDownloadTryCompression(c *C) { d = NewFakeDownloader() d.ExpectError("http://example.com/file.bz2", &Error{Code: 404}) d.ExpectResponse("http://example.com/file.gz", "x") - _, file, err = DownloadTryCompression(d, "http://example.com/file", nil, true, 1) + _, _, err = DownloadTryCompression(d, "http://example.com/file", nil, true, 1) c.Assert(err, ErrorMatches, "unexpected EOF") c.Assert(d.Empty(), Equals, true) } diff --git a/http/temp_test.go b/http/temp_test.go index 9825c967..c4723e2e 100644 --- a/http/temp_test.go +++ b/http/temp_test.go @@ -39,9 +39,10 @@ func (s *TempSuite) TestDownloadTemp(c *C) { func (s *TempSuite) TestDownloadTempWithChecksum(c *C) { f, err := DownloadTempWithChecksum(s.d, s.url+"/test", &utils.ChecksumInfo{Size: 12, MD5: "a1acb0fe91c7db45ec4d775192ec5738", SHA1: "921893bae6ad6fd818401875d6779254ef0ff0ec", SHA256: "b3c92ee1246176ed35f6e8463cd49074f29442f5bbffc3f8591cde1dcc849dac"}, false, 1) - defer f.Close() c.Assert(err, IsNil) + c.Assert(f.Close(), IsNil) + _, err = DownloadTempWithChecksum(s.d, s.url+"/test", &utils.ChecksumInfo{Size: 13}, false, 1) c.Assert(err, ErrorMatches, ".*size check mismatch 12 != 13") } diff --git a/linter.json b/linter.json index 6a701d02..ab0f60e2 100644 --- a/linter.json +++ b/linter.json @@ -8,7 +8,11 @@ "goimports", "misspell", "gosimple", - "ineffassign" + "ineffassign", + "staticcheck", + "varcheck", + "structcheck", + "aligncheck" ], "Deadline": "15m" } diff --git a/s3/public.go b/s3/public.go index bcd39d57..b74788a0 100644 --- a/s3/public.go +++ b/s3/public.go @@ -52,7 +52,10 @@ func NewPublishedStorageRaw( storageClass = "" } - sess := session.New(config) + sess, err := session.NewSession(config) + if err != nil { + return nil, err + } result := &PublishedStorage{ s3: s3.New(sess), diff --git a/utils/config.go b/utils/config.go index 9c722b7b..1d8358e8 100644 --- a/utils/config.go +++ b/utils/config.go @@ -7,7 +7,7 @@ import ( ) // ConfigStructure is structure of main configuration -type ConfigStructure struct { +type ConfigStructure struct { // nolint: aligncheck RootDir string `json:"rootDir"` DownloadConcurrency int `json:"downloadConcurrency"` DownloadLimit int64 `json:"downloadSpeedLimit"`