diff --git a/cmd/package_show.go b/cmd/package_show.go index ba9ab0b8..91943c9e 100644 --- a/cmd/package_show.go +++ b/cmd/package_show.go @@ -55,11 +55,8 @@ func printReferencesTo(p *deb.Package) (err error) { } return nil }) - if err != nil { - return err - } - return nil + return err } func aptlyPackageShow(cmd *commander.Command, args []string) error { diff --git a/context/context.go b/context/context.go index 7938ffc3..955416c2 100644 --- a/context/context.go +++ b/context/context.go @@ -273,7 +273,7 @@ func (context *AptlyContext) ReOpenDatabase() error { for try := 0; try < MaxTries; try++ { err := context.database.ReOpen() - if err == nil || strings.Index(err.Error(), "resource temporarily unavailable") == -1 { + if err == nil || !strings.Contains(err.Error(), "resource temporarily unavailable") { return err } context._progress().Printf("Unable to reopen database, sleeping %s\n", Delay) diff --git a/deb/changes.go b/deb/changes.go index 45027827..8737dfd2 100644 --- a/deb/changes.go +++ b/deb/changes.go @@ -103,11 +103,7 @@ func (c *Changes) VerifyAndParse(acceptUnsigned, ignoreSignature bool, verifier c.Architectures = strings.Fields(c.Stanza["Architecture"]) c.Files, err = c.Files.ParseSumFields(c.Stanza) - if err != nil { - return err - } - - return nil + return err } // Prepare creates temporary directory, copies file there and verifies checksums @@ -181,8 +177,7 @@ func (c *Changes) PackageQuery() (PackageQuery, error) { if len(c.Binary) > 0 { binaryQuery = &FieldQuery{Field: "Name", Relation: VersionEqual, Value: c.Binary[0]} // matching debug ddeb packages, they're not present in the Binary field - var ddebQuery PackageQuery - ddebQuery = &FieldQuery{Field: "Name", Relation: VersionEqual, Value: fmt.Sprintf("%s-dbgsym", c.Binary[0])} + var ddebQuery PackageQuery = &FieldQuery{Field: "Name", Relation: VersionEqual, Value: fmt.Sprintf("%s-dbgsym", c.Binary[0])} for _, binary := range c.Binary[1:] { binaryQuery = &OrQuery{ diff --git a/deb/deb.go b/deb/deb.go index af74e29e..ab720923 100644 --- a/deb/deb.go +++ b/deb/deb.go @@ -175,9 +175,7 @@ func GetContentsFromDeb(file aptly.ReadSeekerCloser, packageFile string) ([]stri continue } - if strings.HasPrefix(tarHeader.Name, "./") { - tarHeader.Name = tarHeader.Name[2:] - } + tarHeader.Name = strings.TrimPrefix(tarHeader.Name[2:], "./") results = append(results, tarHeader.Name) } } diff --git a/deb/package.go b/deb/package.go index b6d7f52a..d36ece65 100644 --- a/deb/package.go +++ b/deb/package.go @@ -344,7 +344,7 @@ func (p *Package) GetDependencies(options int) (dependencies []string) { if source == "" { source = p.Name } - if strings.Index(source, ")") != -1 { + if strings.Contains(source, ")") { dependencies = append(dependencies, fmt.Sprintf("%s {source}", source)) } else { dependencies = append(dependencies, fmt.Sprintf("%s (= %s) {source}", source, p.Version)) diff --git a/deb/package_test.go b/deb/package_test.go index 75e2b840..b3d34e76 100644 --- a/deb/package_test.go +++ b/deb/package_test.go @@ -299,7 +299,7 @@ func (s *PackageSuite) TestMatchesDependency(c *C) { // ~ c.Check( p.MatchesDependency(Dependency{Pkg: "alien-arena-common", Architecture: "i386", Relation: VersionRegexp, Version: "7\\.40-.*", - Regexp: regexp.MustCompile("7\\.40-.*")}), Equals, true) + Regexp: regexp.MustCompile(`7\.40-.*`)}), Equals, true) c.Check( p.MatchesDependency(Dependency{Pkg: "alien-arena-common", Architecture: "i386", Relation: VersionRegexp, Version: "7\\.40-.*", Regexp: regexp.MustCompile("40")}), Equals, true) diff --git a/deb/publish.go b/deb/publish.go index 3982b2fd..bec7b8f0 100644 --- a/deb/publish.go +++ b/deb/publish.go @@ -226,12 +226,7 @@ func NewPublishedRepo(storage, prefix, distribution string, architectures []stri // clean & verify prefix prefix = filepath.Clean(prefix) - if strings.HasPrefix(prefix, "/") { - prefix = prefix[1:] - } - if strings.HasSuffix(prefix, "/") { - prefix = prefix[:len(prefix)-1] - } + prefix = strings.TrimPrefix(strings.TrimSuffix(prefix, "/"), "/") prefix = filepath.Clean(prefix) for _, part := range strings.Split(prefix, "/") { @@ -252,7 +247,7 @@ func NewPublishedRepo(storage, prefix, distribution string, architectures []stri } } - if strings.Index(distribution, "/") != -1 { + if strings.Contains(distribution, "/") { return nil, fmt.Errorf("invalid distribution %s, '/' is not allowed", distribution) } @@ -474,8 +469,7 @@ func (p *PublishedRepo) Publish(packagePool aptly.PackagePool, publishedStorageP return err } defer func() { - var e error - e = tempDB.Close() + e := tempDB.Close() if e != nil && progress != nil { progress.Printf("failed to close temp DB: %s", err) } @@ -730,12 +724,7 @@ func (p *PublishedRepo) Publish(packagePool aptly.PackagePool, publishedStorageP return err } - err = indexes.RenameFiles() - if err != nil { - return err - } - - return nil + return indexes.RenameFiles() } // RemoveFiles removes files that were created by Publish diff --git a/deb/publish_test.go b/deb/publish_test.go index e96509e8..cd7c6618 100644 --- a/deb/publish_test.go +++ b/deb/publish_test.go @@ -505,6 +505,7 @@ func (s *PublishedRepoCollectionSuite) TestAddByStoragePrefixDistribution(c *C) c.Assert(r.String(), Equals, s.repo1.String()) r, err = s.collection.ByStoragePrefixDistribution("files:other", "ppa", "precise") + c.Assert(err, IsNil) c.Check(r.String(), Equals, s.repo5.String()) } diff --git a/deb/query.go b/deb/query.go index 9b8ed30b..a96af829 100644 --- a/deb/query.go +++ b/deb/query.go @@ -204,7 +204,7 @@ func (q *FieldQuery) Fast(list PackageCatalog) bool { // String interface func (q *FieldQuery) String() string { escape := func(val string) string { - if strings.IndexAny(val, "()|,!{} \t\n") != -1 { + if strings.ContainsAny(val, "()|,!{} \t\n") { return "'" + strings.Replace(strings.Replace(val, "\\", "\\\\", -1), "'", "\\'", -1) + "'" } return val diff --git a/deb/reflist.go b/deb/reflist.go index 4dcb66ed..1c8a4255 100644 --- a/deb/reflist.go +++ b/deb/reflist.go @@ -92,7 +92,7 @@ func (l *PackageRefList) Has(p *Package) bool { key := p.Key("") i := sort.Search(len(l.Refs), func(j int) bool { return bytes.Compare(l.Refs[j], key) >= 0 }) - return i < len(l.Refs) && bytes.Compare(l.Refs[i], key) == 0 + return i < len(l.Refs) && bytes.Equal(l.Refs[i], key) } // Strings builds list of strings with package keys diff --git a/deb/remote.go b/deb/remote.go index a0f1ae6d..4d05cdcd 100644 --- a/deb/remote.go +++ b/deb/remote.go @@ -331,9 +331,7 @@ ok: if strings.Contains(repo.Distribution, "/") { distributionLast := path.Base(repo.Distribution) + "/" for i := range components { - if strings.HasPrefix(components[i], distributionLast) { - components[i] = components[i][len(distributionLast):] - } + components[i] = strings.TrimPrefix(components[i], distributionLast) } } if len(repo.Components) == 0 { diff --git a/linter.json b/linter.json index c3040f1e..8d5916a9 100644 --- a/linter.json +++ b/linter.json @@ -1,4 +1,13 @@ { "DisableAll": true, - "Enable": ["vet", "golint", "gofmt", "deadcode", "goimports", "misspell"] + "Enable": [ + "vet", + "golint", + "gofmt", + "deadcode", + "goimports", + "misspell", + "gosimple", + "ineffassign" + ] } diff --git a/query/syntax_test.go b/query/syntax_test.go index 50efaed0..1acf3e15 100644 --- a/query/syntax_test.go +++ b/query/syntax_test.go @@ -49,7 +49,7 @@ func (s *SyntaxSuite) TestParsing(c *C) { c.Assert(err, IsNil) c.Check(q, DeepEquals, &deb.DependencyQuery{Dep: deb.Dependency{Pkg: "package", Relation: deb.VersionRegexp, Version: "5\\.3.*~dev", - Regexp: regexp.MustCompile("5\\.3.*~dev")}}) + Regexp: regexp.MustCompile(`5\.3.*~dev`)}}) l, _ = lex("query", "alien-data_1.3.4~dev_i386") q, err = parse(l) diff --git a/s3/public.go b/s3/public.go index 7f709675..bcd39d57 100644 --- a/s3/public.go +++ b/s3/public.go @@ -165,7 +165,7 @@ func (storage *PublishedStorage) putFile(path string, source io.ReadSeeker) erro return err } - if storage.plusWorkaround && strings.Index(path, "+") != -1 { + if storage.plusWorkaround && strings.Contains(path, "+") { _, err = source.Seek(0, 0) if err != nil { return err @@ -187,7 +187,7 @@ func (storage *PublishedStorage) Remove(path string) error { return errors.Wrap(err, fmt.Sprintf("error deleting %s from %s", path, storage)) } - if storage.plusWorkaround && strings.Index(path, "+") != -1 { + if storage.plusWorkaround && strings.Contains(path, "+") { // try to remove workaround version, but don't care about result _ = storage.Remove(strings.Replace(path, "+", " ", -1)) } @@ -332,7 +332,7 @@ func (storage *PublishedStorage) internalFilelist(prefix string, hidePlusWorkaro err = storage.s3.ListObjectsPages(params, func(contents *s3.ListObjectsOutput, lastPage bool) bool { for _, key := range contents.Contents { - if storage.plusWorkaround && hidePlusWorkaround && strings.Index(*key.Key, " ") != -1 { + if storage.plusWorkaround && hidePlusWorkaround && strings.Contains(*key.Key, " ") { // if we use plusWorkaround, we want to hide those duplicates /// from listing continue diff --git a/s3/server_test.go b/s3/server_test.go index 6be5cff6..ccfcd8d9 100644 --- a/s3/server_test.go +++ b/s3/server_test.go @@ -646,7 +646,7 @@ func (objr objectResource) put(a *action) interface{} { fatalError(400, "TODO", "read error") } gotHash := sum.Sum(nil) - if expectHash != nil && bytes.Compare(gotHash, expectHash) != 0 { + if expectHash != nil && !bytes.Equal(gotHash, expectHash) { fatalError(400, "BadDigest", "The Content-MD5 you specified did not match what we received") } if a.req.ContentLength >= 0 && int64(len(data)) != a.req.ContentLength { diff --git a/utils/gpg.go b/utils/gpg.go index 23d3701c..70a46b4a 100644 --- a/utils/gpg.go +++ b/utils/gpg.go @@ -324,16 +324,12 @@ func (g *GpgVerifier) VerifyDetachedSignature(signature, cleartext io.Reader) er func (g *GpgVerifier) IsClearSigned(clearsigned io.Reader) (bool, error) { scanner := bufio.NewScanner(clearsigned) for scanner.Scan() { - if strings.Index(scanner.Text(), "BEGIN PGP SIGN") != -1 { + if strings.Contains(scanner.Text(), "BEGIN PGP SIGN") { return true, nil } } - if err := scanner.Err(); err != nil { - return false, err - } - - return false, nil + return false, scanner.Err() } // VerifyClearsigned verifies clearsigned file using gpgv