diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 30aabb81..ec08254e 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -63,7 +63,7 @@ jobs: - name: golangci-lint uses: golangci/golangci-lint-action@v3 with: - version: v1.45.0 + version: v1.50.1 - name: Setup Python uses: actions/setup-python@v2 diff --git a/.golangci.yml b/.golangci.yml index 60d5a032..a8060193 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -5,7 +5,6 @@ run: linters: disable-all: true enable: - - deadcode - goconst - gofmt - goimports @@ -14,6 +13,4 @@ linters: - misspell - revive - staticcheck - - structcheck - - varcheck - vetshadow diff --git a/Makefile b/Makefile index 7207c05c..7cf28047 100644 --- a/Makefile +++ b/Makefile @@ -11,7 +11,7 @@ COVERAGE_DIR?=$(shell mktemp -d) all: modules test bench check system-test prepare: - curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(shell go env GOPATH)/bin v1.45.0 + curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(shell go env GOPATH)/bin v1.50.1 modules: go mod download diff --git a/api/api_test.go b/api/api_test.go index fd8105f0..4de4d45b 100644 --- a/api/api_test.go +++ b/api/api_test.go @@ -3,7 +3,6 @@ package api import ( "encoding/json" "io" - "io/ioutil" "net/http" "net/http/httptest" "os" @@ -31,7 +30,7 @@ type ApiSuite struct { var _ = Suite(&ApiSuite{}) func createTestConfig() *os.File { - file, err := ioutil.TempFile("", "aptly") + file, err := os.CreateTemp("", "aptly") if err != nil { return nil } diff --git a/api/gpg.go b/api/gpg.go index 640e45c7..cc526ee3 100644 --- a/api/gpg.go +++ b/api/gpg.go @@ -2,7 +2,6 @@ package api import ( "fmt" - "io/ioutil" "os" "os/exec" "path/filepath" @@ -37,7 +36,7 @@ func apiGPGAddKey(c *gin.Context) { } if len(b.GpgKeyArmor) > 0 { var tempdir string - tempdir, err = ioutil.TempDir(os.TempDir(), "aptly") + tempdir, err = os.MkdirTemp(os.TempDir(), "aptly") if err != nil { c.AbortWithError(400, err) return diff --git a/cmd/graph.go b/cmd/graph.go index 868e5874..4425d087 100644 --- a/cmd/graph.go +++ b/cmd/graph.go @@ -4,7 +4,6 @@ import ( "bytes" "fmt" "io" - "io/ioutil" "os" "os/exec" "path/filepath" @@ -36,7 +35,7 @@ func aptlyGraph(cmd *commander.Command, args []string) error { buf := bytes.NewBufferString(graph.String()) - tempfile, err := ioutil.TempFile("", "aptly-graph") + tempfile, err := os.CreateTemp("", "aptly-graph") if err != nil { return err } diff --git a/database/goleveldb/storage.go b/database/goleveldb/storage.go index a95c5680..37acf3d8 100644 --- a/database/goleveldb/storage.go +++ b/database/goleveldb/storage.go @@ -3,7 +3,6 @@ package goleveldb import ( "bytes" "errors" - "io/ioutil" "os" "github.com/syndtr/goleveldb/leveldb" @@ -19,7 +18,7 @@ type storage struct { // CreateTemporary creates new DB of the same type in temp dir func (s *storage) CreateTemporary() (database.Storage, error) { - tempdir, err := ioutil.TempDir("", "aptly") + tempdir, err := os.MkdirTemp("", "aptly") if err != nil { return nil, err } diff --git a/deb/changes.go b/deb/changes.go index 3e2c6914..6637034e 100644 --- a/deb/changes.go +++ b/deb/changes.go @@ -4,7 +4,6 @@ import ( "bytes" "fmt" "io" - "io/ioutil" "os" "path/filepath" "sort" @@ -39,7 +38,7 @@ func NewChanges(path string) (*Changes, error) { ChangesName: filepath.Base(path), } - c.TempDir, err = ioutil.TempDir(os.TempDir(), "aptly") + c.TempDir, err = os.MkdirTemp(os.TempDir(), "aptly") if err != nil { return nil, err } diff --git a/deb/format.go b/deb/format.go index 47ea776e..95febe35 100644 --- a/deb/format.go +++ b/deb/format.go @@ -136,7 +136,7 @@ func isMultilineField(field string, isRelease bool) bool { // Write single field from Stanza to writer. // -//nolint: interfacer +// nolint: interfacer func writeField(w *bufio.Writer, field, value string, isRelease bool) (err error) { if !isMultilineField(field, isRelease) { _, err = w.WriteString(field + ": " + value + "\n") diff --git a/deb/publish.go b/deb/publish.go index 8798cc69..81b18338 100644 --- a/deb/publish.go +++ b/deb/publish.go @@ -5,7 +5,6 @@ import ( "bytes" "encoding/json" "fmt" - "io/ioutil" "log" "os" "path/filepath" @@ -596,7 +595,7 @@ func (p *PublishedRepo) Publish(packagePool aptly.PackagePool, publishedStorageP } var tempDir string - tempDir, err = ioutil.TempDir(os.TempDir(), "aptly") + tempDir, err = os.MkdirTemp(os.TempDir(), "aptly") if err != nil { return err } diff --git a/deb/remote_test.go b/deb/remote_test.go index 1ea1d558..82f6fff8 100644 --- a/deb/remote_test.go +++ b/deb/remote_test.go @@ -3,7 +3,6 @@ package deb import ( "errors" "io" - "io/ioutil" "os" "sort" @@ -38,7 +37,7 @@ func (n *NullVerifier) VerifyClearsigned(clearsigned io.Reader, hint bool) (*pgp } func (n *NullVerifier) ExtractClearsigned(clearsigned io.Reader) (text *os.File, err error) { - text, _ = ioutil.TempFile("", "aptly-test") + text, _ = os.CreateTemp("", "aptly-test") io.Copy(text, clearsigned) text.Seek(0, 0) os.Remove(text.Name()) diff --git a/files/package_pool.go b/files/package_pool.go index 8b1e8b25..65a016d5 100644 --- a/files/package_pool.go +++ b/files/package_pool.go @@ -3,7 +3,6 @@ package files import ( "fmt" "io" - "io/ioutil" "os" "path/filepath" "sync" @@ -81,7 +80,7 @@ func (pool *PackagePool) FilepathList(progress aptly.Progress) ([]string, error) pool.Lock() defer pool.Unlock() - dirs, err := ioutil.ReadDir(pool.rootPath) + dirs, err := os.ReadDir(pool.rootPath) if err != nil { if os.IsNotExist(err) { return nil, nil diff --git a/go.sum b/go.sum index 6c9a66b6..9d84159d 100644 --- a/go.sum +++ b/go.sum @@ -43,7 +43,6 @@ github.com/Azure/go-autorest/autorest/adal v0.9.13 h1:Mp5hbtOePIzM8pJVRa3YLrWWmZ github.com/Azure/go-autorest/autorest/adal v0.9.13/go.mod h1:W/MM4U6nLxnIskrw4UwWzlHfGjwUS50aOsc/I3yuU8M= github.com/Azure/go-autorest/autorest/date v0.3.0 h1:7gUk1U5M/CQbp9WoqinNzJar+8KY+LPI6wiWrP/myHw= github.com/Azure/go-autorest/autorest/date v0.3.0/go.mod h1:BI0uouVdmngYNUzGWeSYnokU+TrmwEsOqdt8Y6sso74= -github.com/Azure/go-autorest/autorest/mocks v0.4.1 h1:K0laFcLE6VLTOwNgSxaGbUcLPuGXlNkbVvq4cW4nIHk= github.com/Azure/go-autorest/autorest/mocks v0.4.1/go.mod h1:LTp+uSrOhSkaKrUy935gNZuuIPPVsHlr9DSOxSayd+k= github.com/Azure/go-autorest/logger v0.2.1 h1:IG7i4p/mDa2Ce4TRyAO8IHnVhAVF3RFU+ZtXWSmf4Tg= github.com/Azure/go-autorest/logger v0.2.1/go.mod h1:T9E3cAhj2VqvPOtCYAvby9aBXkZmbF5NWuPV8+WeEW8= @@ -91,7 +90,6 @@ github.com/fatih/color v1.7.0 h1:DkWD4oS2D8LGGgTQ6IvwJJXSL5Vp2ffcQg58nFV38Ys= github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4= github.com/form3tech-oss/jwt-go v3.2.2+incompatible h1:TcekIExNqud5crz4xD2pavyTgWiPvpYe4Xau31I0PRk= github.com/form3tech-oss/jwt-go v3.2.2+incompatible/go.mod h1:pbq4aXjuKjdthFRnoDwaVPLA+WlJuPGy+QneDUgJi2k= -github.com/fsnotify/fsnotify v1.4.7 h1:IXs+QLmnXW2CcXuY+8Mzv/fWEsPGWxqefPtCP5CnV9I= github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= github.com/gin-contrib/sse v0.1.0 h1:Y/yl/+YNO8GZSjAhjMsSuLt29uWRFHdHYUb5lYOV9qE= github.com/gin-contrib/sse v0.1.0/go.mod h1:RHrZQHXnP2xjPF+u1gW/2HnVO7nvIa9PG3Gm+fLHvGI= diff --git a/http/download.go b/http/download.go index 3c2a1ebd..a6e65896 100644 --- a/http/download.go +++ b/http/download.go @@ -4,7 +4,6 @@ import ( "context" "fmt" "io" - "io/ioutil" "net" "net/http" "net/url" @@ -56,7 +55,7 @@ func NewDownloader(downLimit int64, maxTries int, progress aptly.Progress) aptly progressWriter := io.Writer(progress) if progress == nil { - progressWriter = ioutil.Discard + progressWriter = io.Discard } downloader.client.CheckRedirect = downloader.checkRedirect diff --git a/http/download_test.go b/http/download_test.go index 7f89a777..fb4cce2f 100644 --- a/http/download_test.go +++ b/http/download_test.go @@ -3,7 +3,6 @@ package http import ( "context" "fmt" - "io/ioutil" "net" "net/http" "os" @@ -27,7 +26,7 @@ type DownloaderSuiteBase struct { } func (s *DownloaderSuiteBase) SetUpTest(c *C) { - s.tempfile, _ = ioutil.TempFile(os.TempDir(), "aptly-test") + s.tempfile, _ = os.CreateTemp(os.TempDir(), "aptly-test") s.l, _ = net.ListenTCP("tcp4", &net.TCPAddr{IP: net.IPv4(127, 0, 0, 1)}) s.url = fmt.Sprintf("http://localhost:%d", s.l.Addr().(*net.TCPAddr).Port) diff --git a/http/grab_test.go b/http/grab_test.go index 3980c453..1aca9a60 100644 --- a/http/grab_test.go +++ b/http/grab_test.go @@ -3,7 +3,6 @@ package http import ( "context" "fmt" - "io/ioutil" "net" "net/http" "os" @@ -26,7 +25,7 @@ type GrabDownloaderSuiteBase struct { } func (s *GrabDownloaderSuiteBase) SetUpTest(c *C) { - s.tempfile, _ = ioutil.TempFile(os.TempDir(), "aptly-test") + s.tempfile, _ = os.CreateTemp(os.TempDir(), "aptly-test") s.l, _ = net.ListenTCP("tcp4", &net.TCPAddr{IP: net.IPv4(127, 0, 0, 1)}) s.url = fmt.Sprintf("http://localhost:%d", s.l.Addr().(*net.TCPAddr).Port) diff --git a/http/temp.go b/http/temp.go index 8e6a3fde..ddc2d3af 100644 --- a/http/temp.go +++ b/http/temp.go @@ -2,7 +2,6 @@ package http import ( "context" - "io/ioutil" "os" "path/filepath" @@ -21,7 +20,7 @@ func DownloadTemp(ctx context.Context, downloader aptly.Downloader, url string) // // Temporary file would be already removed, so no need to cleanup func DownloadTempWithChecksum(ctx context.Context, downloader aptly.Downloader, url string, expected *utils.ChecksumInfo, ignoreMismatch bool) (*os.File, error) { - tempdir, err := ioutil.TempDir(os.TempDir(), "aptly") + tempdir, err := os.MkdirTemp(os.TempDir(), "aptly") if err != nil { return nil, err } diff --git a/pgp/gnupg.go b/pgp/gnupg.go index 99d06621..1e7896b4 100644 --- a/pgp/gnupg.go +++ b/pgp/gnupg.go @@ -6,7 +6,6 @@ import ( "errors" "fmt" "io" - "io/ioutil" "os" "os/exec" "path/filepath" @@ -200,7 +199,7 @@ func (g *GpgVerifier) runGpgv(args []string, context string, showKeyTip bool) (* args = append([]string{"--status-fd", "3"}, args...) cmd := exec.Command(g.gpgv, args...) - tempf, err := ioutil.TempFile("", "aptly-gpg-status") + tempf, err := os.CreateTemp("", "aptly-gpg-status") if err != nil { return nil, err } @@ -278,7 +277,7 @@ func (g *GpgVerifier) runGpgv(args []string, context string, showKeyTip bool) (* func (g *GpgVerifier) VerifyDetachedSignature(signature, cleartext io.Reader, showKeyTip bool) error { args := g.argsKeyrings() - sigf, err := ioutil.TempFile("", "aptly-gpg") + sigf, err := os.CreateTemp("", "aptly-gpg") if err != nil { return err } @@ -290,7 +289,7 @@ func (g *GpgVerifier) VerifyDetachedSignature(signature, cleartext io.Reader, sh return err } - clearf, err := ioutil.TempFile("", "aptly-gpg") + clearf, err := os.CreateTemp("", "aptly-gpg") if err != nil { return err } @@ -323,7 +322,7 @@ func (g *GpgVerifier) IsClearSigned(clearsigned io.Reader) (bool, error) { func (g *GpgVerifier) VerifyClearsigned(clearsigned io.Reader, showKeyTip bool) (*KeyInfo, error) { args := g.argsKeyrings() - clearf, err := ioutil.TempFile("", "aptly-gpg") + clearf, err := os.CreateTemp("", "aptly-gpg") if err != nil { return nil, err } @@ -341,7 +340,7 @@ func (g *GpgVerifier) VerifyClearsigned(clearsigned io.Reader, showKeyTip bool) // ExtractClearsigned extracts cleartext from clearsigned file WITHOUT signature verification func (g *GpgVerifier) ExtractClearsigned(clearsigned io.Reader) (text *os.File, err error) { - clearf, err := ioutil.TempFile("", "aptly-gpg") + clearf, err := os.CreateTemp("", "aptly-gpg") if err != nil { return } @@ -353,7 +352,7 @@ func (g *GpgVerifier) ExtractClearsigned(clearsigned io.Reader) (text *os.File, return } - text, err = ioutil.TempFile("", "aptly-gpg") + text, err = os.CreateTemp("", "aptly-gpg") if err != nil { return } diff --git a/pgp/internal.go b/pgp/internal.go index add64267..c26348f1 100644 --- a/pgp/internal.go +++ b/pgp/internal.go @@ -4,7 +4,6 @@ import ( "bytes" "fmt" "io" - "io/ioutil" "os" "path/filepath" "sort" @@ -83,7 +82,7 @@ func (g *GoSigner) Init() error { } defer passF.Close() - contents, err := ioutil.ReadAll(passF) + contents, err := io.ReadAll(passF) if err != nil { return errors.Wrap(err, "error reading passphrase file") } @@ -400,7 +399,7 @@ func (g *GoVerifier) VerifyDetachedSignature(signature, cleartext io.Reader, sho // IsClearSigned returns true if file contains signature func (g *GoVerifier) IsClearSigned(clearsigned io.Reader) (bool, error) { - signedBuffer, err := ioutil.ReadAll(clearsigned) + signedBuffer, err := io.ReadAll(clearsigned) if err != nil { return false, errors.Wrap(err, "failed to read clearsigned data") } @@ -412,7 +411,7 @@ func (g *GoVerifier) IsClearSigned(clearsigned io.Reader) (bool, error) { // VerifyClearsigned verifies clearsigned file using gpgv func (g *GoVerifier) VerifyClearsigned(clearsigned io.Reader, showKeyTip bool) (*KeyInfo, error) { - signedBuffer, err := ioutil.ReadAll(clearsigned) + signedBuffer, err := io.ReadAll(clearsigned) if err != nil { return nil, errors.Wrap(err, "failed to read clearsigned data") } @@ -451,7 +450,7 @@ func (g *GoVerifier) VerifyClearsigned(clearsigned io.Reader, showKeyTip bool) ( // ExtractClearsigned extracts cleartext from clearsigned file WITHOUT signature verification func (g *GoVerifier) ExtractClearsigned(clearsigned io.Reader) (text *os.File, err error) { var signedBuffer []byte - signedBuffer, err = ioutil.ReadAll(clearsigned) + signedBuffer, err = io.ReadAll(clearsigned) if err != nil { return nil, errors.Wrap(err, "failed to read clearsigned data") } @@ -461,7 +460,7 @@ func (g *GoVerifier) ExtractClearsigned(clearsigned io.Reader) (text *os.File, e return nil, errors.New("no clearsigned data found") } - text, err = ioutil.TempFile("", "aptly-gpg") + text, err = os.CreateTemp("", "aptly-gpg") if err != nil { return } diff --git a/utils/checksum_test.go b/utils/checksum_test.go index a29d602f..9e41e487 100644 --- a/utils/checksum_test.go +++ b/utils/checksum_test.go @@ -1,7 +1,6 @@ package utils import ( - "io/ioutil" "os" . "gopkg.in/check.v1" @@ -14,7 +13,7 @@ type ChecksumSuite struct { var _ = Suite(&ChecksumSuite{}) func (s *ChecksumSuite) SetUpTest(c *C) { - s.tempfile, _ = ioutil.TempFile(c.MkDir(), "aptly-test") + s.tempfile, _ = os.CreateTemp(c.MkDir(), "aptly-test") s.tempfile.WriteString(testString) } diff --git a/utils/compress_test.go b/utils/compress_test.go index 1a02b354..e5b42274 100644 --- a/utils/compress_test.go +++ b/utils/compress_test.go @@ -18,7 +18,7 @@ var _ = Suite(&CompressSuite{}) const testString = "Quick brown fox jumps over black dog and runs away... Really far away... who knows?" func (s *CompressSuite) SetUpTest(c *C) { - s.tempfile, _ = ioutil.TempFile(c.MkDir(), "aptly-test") + s.tempfile, _ = os.CreateTemp(c.MkDir(), "aptly-test") s.tempfile.WriteString(testString) } diff --git a/utils/copyfile_test.go b/utils/copyfile_test.go index 5b45f0c8..cd2b4446 100644 --- a/utils/copyfile_test.go +++ b/utils/copyfile_test.go @@ -1,7 +1,6 @@ package utils import ( - "io/ioutil" "os" "path/filepath" @@ -16,7 +15,7 @@ type CopyfileSuite struct { var _ = Suite(&CopyfileSuite{}) func (s *CopyfileSuite) SetUpSuite(c *C) { - s.source, _ = ioutil.TempFile(c.MkDir(), "source-file") + s.source, _ = os.CreateTemp(c.MkDir(), "source-file") s.dest = filepath.Join(filepath.Dir(s.source.Name()), "destination-file") } diff --git a/utils/utils_test.go b/utils/utils_test.go index 953714ca..c9838da6 100644 --- a/utils/utils_test.go +++ b/utils/utils_test.go @@ -2,7 +2,6 @@ package utils import ( "fmt" - "io/ioutil" "log" "os" "testing" @@ -22,7 +21,7 @@ type UtilsSuite struct { var _ = Suite(&UtilsSuite{}) func (s *UtilsSuite) SetUpSuite(c *C) { - s.tempfile, _ = ioutil.TempFile(c.MkDir(), "aptly-test-inaccessible") + s.tempfile, _ = os.CreateTemp(c.MkDir(), "aptly-test-inaccessible") if err := os.Chmod(s.tempfile.Name(), 0000); err != nil { log.Fatalln(err) }