Skip to content

Commit 06ed599

Browse files
build: Use Go 1.17 for golangci linting and update golangci/golangci-lint-action (#364)
* Use Go 1.17 for golangci linting and update golangci/golangci-lint-action Go 1.18 is not supported by golangci-lint yet since generics are not supported. Signed-off-by: Ethan Lowman <[email protected]> * Try to make the linter happy Signed-off-by: Ethan Lowman <[email protected]> * Fix go version Signed-off-by: Ethan Lowman <[email protected]> * Remove usage of deprecated io/ioutil Signed-off-by: Ethan Lowman <[email protected]> * Appease gofmt for 1.19 Signed-off-by: Ethan Lowman <[email protected]> * Remove one more ioutil instance Signed-off-by: Ethan Lowman <[email protected]> * Remove decodeRoot Signed-off-by: Ethan Lowman <[email protected]> * Remove more unused functions Signed-off-by: Ethan Lowman <[email protected]> Signed-off-by: Ethan Lowman <[email protected]>
1 parent 64ded18 commit 06ed599

File tree

17 files changed

+51
-95
lines changed

17 files changed

+51
-95
lines changed

.github/workflows/tests.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,11 @@ jobs:
5959
needs: get-go-versions
6060
steps:
6161
- uses: actions/setup-go@268d8c0ca0432bb2cf416faae41297df9d262d7f
62+
with:
63+
go-version: ${{ matrix.go-version }}
6264
- uses: actions/checkout@v3
6365
- name: golangci-lint
6466
uses: golangci/golangci-lint-action@537aa1903e5d359d0b27dbc19ddd22c5087f3fbc
6567
with:
66-
version: v1.45.2
68+
version: v1.49.0
6769
args: --timeout 3m

.golangci.yml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
1+
run:
2+
# Lint using Go 1.17, since some linters are disabled by default for Go 1.18
3+
# until generics are supported.
4+
# See https://github.com/golangci/golangci-lint/issues/2649
5+
go: '1.17'
6+
17
linters:
28
disable-all: true
39
enable:
410
- staticcheck
511
- gofmt
612
- govet
713
- gosimple
8-
- structcheck
9-
- varcheck
1014
- unused
1115
- typecheck

client/client.go

Lines changed: 7 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import (
55
"encoding/hex"
66
"encoding/json"
77
"io"
8-
"io/ioutil"
98

109
"github.com/theupdateframework/go-tuf/data"
1110
"github.com/theupdateframework/go-tuf/util"
@@ -551,7 +550,7 @@ func (c *Client) downloadMetaUnsafe(name string, maxMetaSize int64) ([]byte, err
551550
// although the size has been checked above, use a LimitReader in case
552551
// the reported size is inaccurate, or size is -1 which indicates an
553552
// unknown length
554-
return ioutil.ReadAll(io.LimitReader(r, maxMetaSize))
553+
return io.ReadAll(io.LimitReader(r, maxMetaSize))
555554
}
556555

557556
// remoteGetFunc is the type of function the download method uses to download
@@ -622,7 +621,7 @@ func (c *Client) downloadMeta(name string, version int64, m data.FileMeta) ([]by
622621
stream = r
623622
}
624623

625-
return ioutil.ReadAll(stream)
624+
return io.ReadAll(stream)
626625
}
627626

628627
func (c *Client) downloadMetaFromSnapshot(name string, m data.SnapshotFileMeta) ([]byte, error) {
@@ -673,17 +672,6 @@ func (c *Client) downloadMetaFromTimestamp(name string, m data.TimestampFileMeta
673672
return b, nil
674673
}
675674

676-
// decodeRoot decodes and verifies root metadata.
677-
func (c *Client) decodeRoot(b json.RawMessage) error {
678-
root := &data.Root{}
679-
if err := c.db.Unmarshal(b, root, "root", c.rootVer); err != nil {
680-
return ErrDecodeFailed{"root.json", err}
681-
}
682-
c.rootVer = root.Version
683-
c.consistentSnapshot = root.ConsistentSnapshot
684-
return nil
685-
}
686-
687675
// decodeSnapshot decodes and verifies snapshot metadata, and returns the new
688676
// root and targets file meta.
689677
func (c *Client) decodeSnapshot(b json.RawMessage) (data.SnapshotFiles, error) {
@@ -790,36 +778,6 @@ func (c *Client) localMetaFromSnapshot(name string, m data.SnapshotFileMeta) (js
790778
return b, err == nil
791779
}
792780

793-
// hasTargetsMeta checks whether local metadata has the given snapshot meta
794-
//lint:ignore U1000 unused
795-
func (c *Client) hasTargetsMeta(m data.SnapshotFileMeta) bool {
796-
b, ok := c.localMeta["targets.json"]
797-
if !ok {
798-
return false
799-
}
800-
meta, err := util.GenerateSnapshotFileMeta(bytes.NewReader(b), m.Hashes.HashAlgorithms()...)
801-
if err != nil {
802-
return false
803-
}
804-
err = util.SnapshotFileMetaEqual(meta, m)
805-
return err == nil
806-
}
807-
808-
// hasSnapshotMeta checks whether local metadata has the given meta
809-
//lint:ignore U1000 unused
810-
func (c *Client) hasMetaFromTimestamp(name string, m data.TimestampFileMeta) bool {
811-
b, ok := c.localMeta[name]
812-
if !ok {
813-
return false
814-
}
815-
meta, err := util.GenerateTimestampFileMeta(bytes.NewReader(b), m.Hashes.HashAlgorithms()...)
816-
if err != nil {
817-
return false
818-
}
819-
err = util.TimestampFileMetaEqual(meta, m)
820-
return err == nil
821-
}
822-
823781
type Destination interface {
824782
io.Writer
825783
Delete() error
@@ -829,11 +787,11 @@ type Destination interface {
829787
//
830788
// dest will be deleted and an error returned in the following situations:
831789
//
832-
// * The target does not exist in the local targets.json
833-
// * Failed to fetch the chain of delegations accessible from local snapshot.json
834-
// * The target does not exist in any targets
835-
// * Metadata cannot be generated for the downloaded data
836-
// * Generated metadata does not match local metadata for the given file
790+
// - The target does not exist in the local targets.json
791+
// - Failed to fetch the chain of delegations accessible from local snapshot.json
792+
// - The target does not exist in any targets
793+
// - Metadata cannot be generated for the downloaded data
794+
// - Generated metadata does not match local metadata for the given file
837795
func (c *Client) Download(name string, dest Destination) (err error) {
838796
// delete dest if there is an error
839797
defer func() {

client/client_test.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import (
88
"errors"
99
"fmt"
1010
"io"
11-
"io/ioutil"
1211
"net"
1312
"net/http"
1413
"os"
@@ -400,7 +399,7 @@ func newClientWithMeta(baseDir string, relPath string, serverAddr string) (*Clie
400399
c := NewClient(MemoryLocalStore(), remote)
401400
for _, m := range []string{"root.json", "snapshot.json", "timestamp.json", "targets.json"} {
402401
if _, err := os.Stat(initialStateDir + "/" + m); err == nil {
403-
metadataJSON, err := ioutil.ReadFile(initialStateDir + "/" + m)
402+
metadataJSON, err := os.ReadFile(initialStateDir + "/" + m)
404403
if err != nil {
405404
return nil, err
406405
}
@@ -1213,7 +1212,7 @@ func generateRepoFS(c *C, dir string, files map[string][]byte, consistentSnapsho
12131212
for file, data := range files {
12141213
path := filepath.Join(dir, "staged", "targets", file)
12151214
c.Assert(os.MkdirAll(filepath.Dir(path), 0755), IsNil)
1216-
c.Assert(ioutil.WriteFile(path, data, 0644), IsNil)
1215+
c.Assert(os.WriteFile(path, data, 0644), IsNil)
12171216
c.Assert(repo.AddTarget(file, nil), IsNil)
12181217
}
12191218
c.Assert(repo.Snapshot(), IsNil)

client/delegations_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ import (
55
"encoding/json"
66
"fmt"
77
"io"
8-
"io/ioutil"
98
"net"
109
"net/http"
10+
"os"
1111
"strings"
1212
"testing"
1313
"time"
@@ -273,10 +273,10 @@ func initTestDelegationClient(t *testing.T, dirPrefix string) (*Client, func() e
273273
assert.Nil(t, err)
274274

275275
c := NewClient(MemoryLocalStore(), remote)
276-
rawFile, err := ioutil.ReadFile(initialStateDir + "/" + "root.json")
276+
rawFile, err := os.ReadFile(initialStateDir + "/" + "root.json")
277277
assert.Nil(t, err)
278278
assert.Nil(t, c.Init(rawFile))
279-
files, err := ioutil.ReadDir(initialStateDir)
279+
files, err := os.ReadDir(initialStateDir)
280280
assert.Nil(t, err)
281281

282282
// load local files
@@ -287,7 +287,7 @@ func initTestDelegationClient(t *testing.T, dirPrefix string) (*Client, func() e
287287
name := f.Name()
288288
// ignoring consistent snapshot when loading initial state
289289
if len(strings.Split(name, ".")) == 1 && strings.HasSuffix(name, ".json") {
290-
rawFile, err := ioutil.ReadFile(initialStateDir + "/" + name)
290+
rawFile, err := os.ReadFile(initialStateDir + "/" + name)
291291
assert.Nil(t, err)
292292
assert.Nil(t, c.local.SetMeta(name, rawFile))
293293
}

client/interop_test.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import (
44
"bytes"
55
"fmt"
66
"io"
7-
"io/ioutil"
87
"net"
98
"net/http"
109
"os"
@@ -33,7 +32,7 @@ func checkGoIdentity(c *C, consistentSnapshot bool) {
3332
c.Assert(err, IsNil)
3433
testDataDir := filepath.Join(cwd, "testdata")
3534

36-
tempDir, err := ioutil.TempDir("", "")
35+
tempDir, err := os.MkdirTemp("", "")
3736
c.Assert(err, IsNil)
3837
defer os.RemoveAll(tempDir)
3938

@@ -59,7 +58,7 @@ func computeHashes(c *C, dir string) map[string]string {
5958
return nil
6059
}
6160

62-
bytes, err := ioutil.ReadFile(path)
61+
bytes, err := os.ReadFile(path)
6362
if err != nil {
6463
return err
6564
}
@@ -108,7 +107,7 @@ func newTestCase(c *C, name string, consistentSnapshot bool, options *HTTPRemote
108107
c.Assert(err, IsNil)
109108
testDir := filepath.Join(cwd, "testdata", name, fmt.Sprintf("consistent-snapshot-%t", consistentSnapshot))
110109

111-
dirEntries, err := ioutil.ReadDir(testDir)
110+
dirEntries, err := os.ReadDir(testDir)
112111
c.Assert(err, IsNil)
113112
c.Assert(dirEntries, Not(HasLen), 0)
114113

client/python_interop/python_interop_test.go

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package client
33
import (
44
"bytes"
55
"fmt"
6-
"io/ioutil"
76
"net"
87
"net/http"
98
"net/url"
@@ -58,7 +57,7 @@ func (InteropSuite) TestGoClientPythonGenerated(c *C) {
5857

5958
// initiate a client with the root metadata
6059
client := client.NewClient(client.MemoryLocalStore(), remote)
61-
rootJSON, err := ioutil.ReadFile(filepath.Join(testDataDir, dir, "repository", "metadata", "1.root.json"))
60+
rootJSON, err := os.ReadFile(filepath.Join(testDataDir, dir, "repository", "metadata", "1.root.json"))
6261
c.Assert(err, IsNil)
6362
c.Assert(client.Init(rootJSON), IsNil)
6463

@@ -99,7 +98,7 @@ func generateRepoFS(c *C, dir string, files map[string][]byte, consistentSnapsho
9998
for file, data := range files {
10099
path := filepath.Join(dir, "staged", "targets", file)
101100
c.Assert(os.MkdirAll(filepath.Dir(path), 0755), IsNil)
102-
c.Assert(ioutil.WriteFile(path, data, 0644), IsNil)
101+
c.Assert(os.WriteFile(path, data, 0644), IsNil)
103102
c.Assert(repo.AddTarget(file, nil), IsNil)
104103
}
105104
c.Assert(repo.Snapshot(), IsNil)
@@ -134,9 +133,9 @@ func (InteropSuite) TestPythonClientGoGenerated(c *C) {
134133
prevDir := filepath.Join(clientDir, "tufrepo", "metadata", "previous")
135134
c.Assert(os.MkdirAll(currDir, 0755), IsNil)
136135
c.Assert(os.MkdirAll(prevDir, 0755), IsNil)
137-
rootJSON, err := ioutil.ReadFile(filepath.Join(dir, "repository", "1.root.json"))
136+
rootJSON, err := os.ReadFile(filepath.Join(dir, "repository", "1.root.json"))
138137
c.Assert(err, IsNil)
139-
c.Assert(ioutil.WriteFile(filepath.Join(currDir, "root.json"), rootJSON, 0644), IsNil)
138+
c.Assert(os.WriteFile(filepath.Join(currDir, "root.json"), rootJSON, 0644), IsNil)
140139

141140
args := []string{
142141
filepath.Join(cwd, "testdata", "python-tuf-v1.0.0", "client.py"),
@@ -155,7 +154,7 @@ func (InteropSuite) TestPythonClientGoGenerated(c *C) {
155154

156155
// check the target files got downloaded
157156
for path, expected := range files {
158-
actual, err := ioutil.ReadFile(filepath.Join(clientDir, "tuftargets", url.QueryEscape(path)))
157+
actual, err := os.ReadFile(filepath.Join(clientDir, "tuftargets", url.QueryEscape(path)))
159158
c.Assert(err, IsNil)
160159
c.Assert(actual, DeepEquals, expected)
161160
}

client/testdata/go-tuf-transition-M3/generate.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package main
33
import (
44
"encoding/json"
55
"fmt"
6-
"io/ioutil"
76
"log"
87
"os"
98
"os/exec"
@@ -64,7 +63,7 @@ func addTargets(repo *tuf.Repo, dir string, files map[string][]byte) {
6463
for file, data := range files {
6564
path := filepath.Join(dir, "staged", "targets", file)
6665
assertNoError(os.MkdirAll(filepath.Dir(path), 0755))
67-
assertNoError(ioutil.WriteFile(path, data, 0644))
66+
assertNoError(os.WriteFile(path, data, 0644))
6867
paths = append(paths, file)
6968
}
7069
assertNoError(repo.AddTargetsWithExpires(paths, nil, expirationDate))

client/testdata/go-tuf-transition-M4/generate.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package main
33
import (
44
"encoding/json"
55
"fmt"
6-
"io/ioutil"
76
"log"
87
"os"
98
"os/exec"
@@ -62,7 +61,7 @@ func addTargets(repo *tuf.Repo, dir string, files map[string][]byte) {
6261
for file, data := range files {
6362
path := filepath.Join(dir, "staged", "targets", file)
6463
assertNoError(os.MkdirAll(filepath.Dir(path), 0755))
65-
assertNoError(ioutil.WriteFile(path, data, 0644))
64+
assertNoError(os.WriteFile(path, data, 0644))
6665
paths = append(paths, file)
6766
}
6867
assertNoError(repo.AddTargetsWithExpires(paths, nil, expirationDate))

client/testdata/go-tuf/generator/generator.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import (
55
"fmt"
66
"io"
77
"io/fs"
8-
"io/ioutil"
98
"log"
109
"os"
1110
"path/filepath"
@@ -97,7 +96,7 @@ func addTargets(repo *tuf.Repo, dir string, files map[string][]byte) {
9796
for file, data := range files {
9897
path := filepath.Join(dir, "staged", "targets", file)
9998
assertNoError(os.MkdirAll(filepath.Dir(path), 0755))
100-
assertNoError(ioutil.WriteFile(path, data, 0644))
99+
assertNoError(os.WriteFile(path, data, 0644))
101100
paths = append(paths, file)
102101
}
103102
assertNoError(repo.AddTargetsWithExpires(paths, nil, expirationDate))

0 commit comments

Comments
 (0)