Skip to content

Commit 4a6b50c

Browse files
committed
*: remove remaining stray uses of ioutil
Release justification: low risk, high benefit changes to existing functionality Release note: None
1 parent bcc1682 commit 4a6b50c

File tree

13 files changed

+91
-35
lines changed

13 files changed

+91
-35
lines changed

DEPS.bzl

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1384,6 +1384,16 @@ def go_deps():
13841384
"https://storage.googleapis.com/cockroach-godeps/gomod/github.com/cockroachdb/errors/com_github_cockroachdb_errors-v1.9.0.zip",
13851385
],
13861386
)
1387+
go_repository(
1388+
name = "com_github_cockroachdb_go_bindata",
1389+
build_file_proto_mode = "disable_global",
1390+
importpath = "github.com/cockroachdb/go-bindata",
1391+
sha256 = "aa9eb6adc4628360ccd0a2421c6c4dc0c58fea2ca27459971d644f55d7a2613c",
1392+
strip_prefix = "github.com/cockroachdb/[email protected]",
1393+
urls = [
1394+
"https://storage.googleapis.com/cockroach-godeps/gomod/github.com/cockroachdb/go-bindata/com_github_cockroachdb_go_bindata-v0.0.0-20220907094433-aa69f7239e7a.zip",
1395+
],
1396+
)
13871397
go_repository(
13881398
name = "com_github_cockroachdb_go_test_teamcity",
13891399
build_file_proto_mode = "disable_global",
@@ -4965,16 +4975,6 @@ def go_deps():
49654975
"https://storage.googleapis.com/cockroach-godeps/gomod/github.com/kballard/go-shellquote/com_github_kballard_go_shellquote-v0.0.0-20180428030007-95032a82bc51.zip",
49664976
],
49674977
)
4968-
go_repository(
4969-
name = "com_github_kevinburke_go_bindata",
4970-
build_file_proto_mode = "disable_global",
4971-
importpath = "github.com/kevinburke/go-bindata",
4972-
sha256 = "f087b3a77624a113883bac519ebd1a4de07b70ab2ebe73e61e52325ac30777e0",
4973-
strip_prefix = "github.com/kevinburke/[email protected]+incompatible",
4974-
urls = [
4975-
"https://storage.googleapis.com/cockroach-godeps/gomod/github.com/kevinburke/go-bindata/com_github_kevinburke_go_bindata-v3.13.0+incompatible.zip",
4976-
],
4977-
)
49784978
go_repository(
49794979
name = "com_github_kisielk_errcheck",
49804980
build_file_proto_mode = "disable_global",

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -395,7 +395,7 @@ bin/.bootstrap: $(GITHOOKS) vendor/modules.txt | bin/.submodules-initialized
395395
github.com/goware/modvendor \
396396
github.com/go-swagger/go-swagger/cmd/swagger \
397397
github.com/grpc-ecosystem/grpc-gateway/protoc-gen-grpc-gateway \
398-
github.com/kevinburke/go-bindata/go-bindata \
398+
github.com/cockroachdb/go-bindata/go-bindata \
399399
github.com/kisielk/errcheck \
400400
github.com/mattn/goveralls \
401401
github.com/mibk/dupl \

build/bazelutil/distdir_files.bzl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,7 @@ DISTDIR_FILES = {
183183
"https://storage.googleapis.com/cockroach-godeps/gomod/github.com/cockroachdb/crlfmt/com_github_cockroachdb_crlfmt-v0.0.0-20210128092314-b3eff0b87c79.zip": "452219ca74191eedc6f44a5088b5d64e6f75168b438ac9eafe2256b0db8dbcad",
184184
"https://storage.googleapis.com/cockroach-godeps/gomod/github.com/cockroachdb/datadriven/com_github_cockroachdb_datadriven-v1.0.1.zip": "0f8fe6199b1c7c44cbd4ce9ac0f3f9e1d2f02263f409361e49445fad4a410ab8",
185185
"https://storage.googleapis.com/cockroach-godeps/gomod/github.com/cockroachdb/errors/com_github_cockroachdb_errors-v1.9.0.zip": "ff3814544271799c80da14dadfe408efc4f66e02cbdf17b73e81614ed9f7ae43",
186+
"https://storage.googleapis.com/cockroach-godeps/gomod/github.com/cockroachdb/go-bindata/com_github_cockroachdb_go_bindata-v0.0.0-20220907094433-aa69f7239e7a.zip": "aa9eb6adc4628360ccd0a2421c6c4dc0c58fea2ca27459971d644f55d7a2613c",
186187
"https://storage.googleapis.com/cockroach-godeps/gomod/github.com/cockroachdb/go-test-teamcity/com_github_cockroachdb_go_test_teamcity-v0.0.0-20191211140407-cff980ad0a55.zip": "bac30148e525b79d004da84d16453ddd2d5cd20528e9187f1d7dac708335674b",
187188
"https://storage.googleapis.com/cockroach-godeps/gomod/github.com/cockroachdb/gostdlib/com_github_cockroachdb_gostdlib-v1.13.0.zip": "b3d43d8f95edf65f73a5348f29e1159823cac64b148f8d3bb48340bf55d70872",
188189
"https://storage.googleapis.com/cockroach-godeps/gomod/github.com/cockroachdb/logtags/com_github_cockroachdb_logtags-v0.0.0-20211118104740-dabe8e521a4f.zip": "1972c3f171f118add3fd9e64bcea6cbb9959a3b7fa0ada308e8a7310813fea74",
@@ -532,7 +533,6 @@ DISTDIR_FILES = {
532533
"https://storage.googleapis.com/cockroach-godeps/gomod/github.com/kataras/pio/com_github_kataras_pio-v0.0.2.zip": "ccec5930116d9b46e338e39fd15404b737d1a7baffb65b6247280a37a9ef9e23",
533534
"https://storage.googleapis.com/cockroach-godeps/gomod/github.com/kataras/sitemap/com_github_kataras_sitemap-v0.0.5.zip": "5e86f8ab488803b503071dfa6b678ad7eb61f1155ddc2b8844798f04d3a927d0",
534535
"https://storage.googleapis.com/cockroach-godeps/gomod/github.com/kballard/go-shellquote/com_github_kballard_go_shellquote-v0.0.0-20180428030007-95032a82bc51.zip": "ae4cb7b097dc4eb0c248dff00ed3bbf0f36984c4162ad1d615266084e58bd6cc",
535-
"https://storage.googleapis.com/cockroach-godeps/gomod/github.com/kevinburke/go-bindata/com_github_kevinburke_go_bindata-v3.13.0+incompatible.zip": "f087b3a77624a113883bac519ebd1a4de07b70ab2ebe73e61e52325ac30777e0",
536536
"https://storage.googleapis.com/cockroach-godeps/gomod/github.com/kisielk/errcheck/com_github_kisielk_errcheck-v1.6.1-0.20210625163953-8ddee489636a.zip": "99d3220891162cb684f8e05d54f3d0dc58abdd496a2f0cfda7fd4a28917a719e",
537537
"https://storage.googleapis.com/cockroach-godeps/gomod/github.com/kisielk/gotool/com_github_kisielk_gotool-v1.0.0.zip": "089dbba6e3aa09944fdb40d72acc86694e8bdde01cfc0f40fe0248309eb80a3f",
538538
"https://storage.googleapis.com/cockroach-godeps/gomod/github.com/klauspost/compress/com_github_klauspost_compress-v1.14.2.zip": "25990a3b573b4568fa9c98c880e82abe5fe4dc6a3c784935923643ef28791acd",

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ require (
4444
github.com/cockroachdb/crlfmt v0.0.0-20210128092314-b3eff0b87c79
4545
github.com/cockroachdb/datadriven v1.0.1
4646
github.com/cockroachdb/errors v1.9.0
47+
github.com/cockroachdb/go-bindata v0.0.0-20220907094433-aa69f7239e7a
4748
github.com/cockroachdb/go-test-teamcity v0.0.0-20191211140407-cff980ad0a55
4849
github.com/cockroachdb/gostdlib v1.13.0
4950
github.com/cockroachdb/logtags v0.0.0-20211118104740-dabe8e521a4f
@@ -98,7 +99,6 @@ require (
9899
github.com/jaegertracing/jaeger v1.18.1
99100
github.com/jordan-wright/email v4.0.1-0.20210109023952-943e75fe5223+incompatible
100101
github.com/jordanlewis/gcassert v0.0.0-20210709222130-81f5df3faab8
101-
github.com/kevinburke/go-bindata v3.13.0+incompatible
102102
github.com/kisielk/errcheck v1.6.1-0.20210625163953-8ddee489636a
103103
github.com/kisielk/gotool v1.0.0
104104
github.com/knz/go-libedit v1.10.1

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -463,6 +463,8 @@ github.com/cockroachdb/errors v1.8.8/go.mod h1:z6VnEL3hZ/2ONZEvG7S5Ym0bU2AqPcEKn
463463
github.com/cockroachdb/errors v1.8.9/go.mod h1:vaNcEYYqbIqB5JhKBhFV9CneUqeuEbB2OYJBK4GBNYQ=
464464
github.com/cockroachdb/errors v1.9.0 h1:B48dYem5SlAY7iU8AKsgedb4gH6mo+bDkbtLIvM/a88=
465465
github.com/cockroachdb/errors v1.9.0/go.mod h1:vaNcEYYqbIqB5JhKBhFV9CneUqeuEbB2OYJBK4GBNYQ=
466+
github.com/cockroachdb/go-bindata v0.0.0-20220907094433-aa69f7239e7a h1:g3E7/4/yOukMEwuScd5+UsPISdTpdHV9ZyqxYYK4e8Y=
467+
github.com/cockroachdb/go-bindata v0.0.0-20220907094433-aa69f7239e7a/go.mod h1:fOV1JHch1f33Nb8wQ0Tarl/W2gAOd103ydO9fUedX5c=
466468
github.com/cockroachdb/go-test-teamcity v0.0.0-20191211140407-cff980ad0a55 h1:YqzBA7tf8Gv8Oz0BbBsPenqkyjiohS7EUIwi7p1QJCU=
467469
github.com/cockroachdb/go-test-teamcity v0.0.0-20191211140407-cff980ad0a55/go.mod h1:QqVqNIiRhLqJXif5C9wbM4JydBhrAF2WDMxkv5xkyxQ=
468470
github.com/cockroachdb/gostdlib v1.13.0 h1:TzSEPYgkKDNei3gbLc0rrHu4iHyBp7/+NxPOFmcXGaw=
@@ -1457,8 +1459,6 @@ github.com/kataras/pio v0.0.2/go.mod h1:hAoW0t9UmXi4R5Oyq5Z4irTbaTsOemSrDGUtaTl7
14571459
github.com/kataras/sitemap v0.0.5/go.mod h1:KY2eugMKiPwsJgx7+U103YZehfvNGOXURubcGyk0Bz8=
14581460
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51 h1:Z9n2FFNUXsshfwJMBgNA0RU6/i7WVaAegv3PtuIHPMs=
14591461
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51/go.mod h1:CzGEWj7cYgsdH8dAjBGEr58BoE7ScuLd+fwFZ44+/x8=
1460-
github.com/kevinburke/go-bindata v3.13.0+incompatible h1:hThDhUBH4KjTyhfXfOgacEPfFBNjltnzl/xzfLfrPoQ=
1461-
github.com/kevinburke/go-bindata v3.13.0+incompatible/go.mod h1:/pEEZ72flUW2p0yi30bslSp9YqD9pysLxunQDdb2CPM=
14621462
github.com/kisielk/errcheck v1.1.0/go.mod h1:EZBBE59ingxPouuu3KfxchcWSUPOHkagtvWXihfKN4Q=
14631463
github.com/kisielk/errcheck v1.2.0/go.mod h1:/BMXB+zMLi60iA8Vv6Ksmxu/1UDYcXs4uQLJ+jE2L00=
14641464
github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI2bnpBCr8=

pkg/cmd/import-tools/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import (
2424
_ "github.com/bufbuild/buf/cmd/buf"
2525
_ "github.com/client9/misspell/cmd/misspell"
2626
_ "github.com/cockroachdb/crlfmt"
27+
_ "github.com/cockroachdb/go-bindata/go-bindata"
2728
_ "github.com/cockroachdb/go-test-teamcity"
2829
_ "github.com/cockroachdb/gostdlib/cmd/gofmt"
2930
_ "github.com/cockroachdb/gostdlib/x/tools/cmd/goimports"
@@ -33,7 +34,6 @@ import (
3334
_ "github.com/golang/mock/mockgen"
3435
_ "github.com/goware/modvendor"
3536
_ "github.com/grpc-ecosystem/grpc-gateway/protoc-gen-grpc-gateway"
36-
_ "github.com/kevinburke/go-bindata/go-bindata"
3737
_ "github.com/kisielk/errcheck"
3838
_ "github.com/mattn/goveralls"
3939
_ "github.com/mibk/dupl"

pkg/roachprod/install/cluster_synced.go

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ import (
1717
"fmt"
1818
"io"
1919
"io/fs"
20-
"io/ioutil"
2120
"math"
2221
"os"
2322
"os/exec"
@@ -1883,16 +1882,20 @@ func (c *SyncedCluster) Get(l *logger.Logger, nodes Nodes, src, dest string) err
18831882
return err
18841883
}
18851884

1886-
infos, err := ioutil.ReadDir(src)
1885+
direntries, err := os.ReadDir(src)
18871886
if err != nil {
18881887
return err
18891888
}
18901889

1891-
for _, info := range infos {
1890+
for _, entry := range direntries {
1891+
einfo, err := entry.Info()
1892+
if err != nil {
1893+
return err
1894+
}
18921895
if err := copy(
1893-
filepath.Join(src, info.Name()),
1894-
filepath.Join(dest, info.Name()),
1895-
info,
1896+
filepath.Join(src, einfo.Name()),
1897+
filepath.Join(dest, einfo.Name()),
1898+
einfo,
18961899
); err != nil {
18971900
return err
18981901
}
@@ -2221,7 +2224,7 @@ func (c *SyncedCluster) ParallelE(
22212224
var writer ui.Writer
22222225
out := l.Stdout
22232226
if display == "" {
2224-
out = ioutil.Discard
2227+
out = io.Discard
22252228
}
22262229

22272230
var ticker *time.Ticker

pkg/security/securityassets/security_assets.go

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
package securityassets
1212

1313
import (
14-
"io/ioutil"
14+
"io/fs"
1515
"os"
1616

1717
"github.com/cockroachdb/errors/oserror"
@@ -24,9 +24,26 @@ type Loader struct {
2424
Stat func(name string) (os.FileInfo, error)
2525
}
2626

27+
// TODO(knz): make ReadDir return a fs.DirEntry and remove this function.
28+
func readDir(name string) ([]os.FileInfo, error) {
29+
direntries, err := os.ReadDir(name)
30+
if err != nil {
31+
return nil, err
32+
}
33+
infos := make([]fs.FileInfo, 0, len(direntries))
34+
for _, entry := range direntries {
35+
info, err := entry.Info()
36+
if err != nil {
37+
return nil, err
38+
}
39+
infos = append(infos, info)
40+
}
41+
return infos, nil
42+
}
43+
2744
// defaultLoader uses real filesystem calls.
2845
var defaultLoader = Loader{
29-
ReadDir: ioutil.ReadDir,
46+
ReadDir: readDir,
3047
ReadFile: os.ReadFile,
3148
Stat: os.Stat,
3249
}

pkg/server/dumpstore/dumpstore.go

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ package dumpstore
1212

1313
import (
1414
"context"
15-
"io/ioutil"
15+
"io/fs"
1616
"os"
1717
"path/filepath"
1818
"time"
@@ -90,7 +90,7 @@ func (s *DumpStore) GetFullPath(fileName string) string {
9090
func (s *DumpStore) GC(ctx context.Context, now time.Time, dumper Dumper) {
9191
// NB: ioutil.ReadDir sorts the file names in ascending order.
9292
// This brings the oldest files first.
93-
files, err := ioutil.ReadDir(s.dir)
93+
files, err := readDir(s.dir)
9494
if err != nil {
9595
log.Warningf(ctx, "%v", err)
9696
return
@@ -116,6 +116,23 @@ func (s *DumpStore) GC(ctx context.Context, now time.Time, dumper Dumper) {
116116
removeOldAndTooBigExcept(ctx, dumper, files, now, maxS, preserved, cleanupFn)
117117
}
118118

119+
// TODO(knz): make PreFilter return a fs.DirEntry and remove this function.
120+
func readDir(name string) ([]os.FileInfo, error) {
121+
direntries, err := os.ReadDir(name)
122+
if err != nil {
123+
return nil, err
124+
}
125+
infos := make([]fs.FileInfo, 0, len(direntries))
126+
for _, entry := range direntries {
127+
info, err := entry.Info()
128+
if err != nil {
129+
return nil, err
130+
}
131+
infos = append(infos, info)
132+
}
133+
return infos, nil
134+
}
135+
119136
// removeOldAndTooBigExcept looks at the entries in files and calls
120137
// the fn closure for every entry not in the preserved map whose size
121138
// causes the combined collection of files to exceed maxS.

pkg/server/dumpstore/dumpstore_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ package dumpstore
1313
import (
1414
"context"
1515
"fmt"
16-
"io/ioutil"
1716
"os"
1817
"path/filepath"
1918
"strings"
@@ -192,7 +191,7 @@ func populate(t *testing.T, dirName string, fileNames []string, sizes []int64) [
192191
}
193192

194193
// Retrieve the file list for the remainder of the test.
195-
files, err := ioutil.ReadDir(dirName)
194+
files, err := readDir(dirName)
196195
if err != nil {
197196
t.Fatal(err)
198197
}

0 commit comments

Comments
 (0)