@cryptotaxi247 / kubo / commits / a433064d7

chore: replace ioutil with io and os (#8969)

Co-authored-by: Håvard Anda Estensen <haavard.ae@gmail.com>

Jorropo committed Jun 14, 2022 at 18:37 UTC a433064d72599311702c332546d46ec5e4e647d0
38 files changed +87 -119
cmd/ipfs/add_migrations.go
+1 -2
@@ -5,7 +5,6 @@ import (
5 "errors"
6 "fmt"
7 "io"
8 - "io/ioutil"
8 "os"
9 "path/filepath"
10
@@ -154,7 +153,7 @@ func ipfsGet(ctx context.Context, ufs coreiface.UnixfsAPI, ipfsPath ipath.Path)
153 if !ok {
154 return fmt.Errorf("not a file node: %q", ipfsPath)
155 }
157 - _, err = io.Copy(ioutil.Discard, fnd)
156 + _, err = io.Copy(io.Discard, fnd)
157 if err != nil {
158 return fmt.Errorf("cannot read migration: %w", err)
159 }
cmd/ipfs/daemon.go
+1 -2
@@ -4,7 +4,6 @@ import (
4 "errors"
5 _ "expvar"
6 "fmt"
7 - "io/ioutil"
7 "net"
8 "net/http"
9 _ "net/http/pprof"
@@ -331,7 +330,7 @@ func daemonFunc(req *cmds.Request, re cmds.ResponseEmitter, env cmds.Environment
330
331 if cacheMigrations || pinMigrations {
332 // Create temp directory to store downloaded migration archives
334 - migrations.DownloadDirectory, err = ioutil.TempDir("", "migrations")
333 + migrations.DownloadDirectory, err = os.MkdirTemp("", "migrations")
334 if err != nil {
335 return err
336 }
cmd/ipfs/runmain_test.go
+1 -2
@@ -6,7 +6,6 @@ package main
6 import (
7 "flag"
8 "fmt"
9 - "io/ioutil"
9 "os"
10 "testing"
11 )
@@ -21,7 +20,7 @@ func TestRunMain(t *testing.T) {
20
21 p := os.Getenv("IPFS_COVER_RET_FILE")
22 if len(p) != 0 {
24 - ioutil.WriteFile(p, []byte(fmt.Sprintf("%d\n", ret)), 0777)
23 + os.WriteFile(p, []byte(fmt.Sprintf("%d\n", ret)), 0777)
24 }
25
26 // close outputs so go testing doesn't print anything
core/commands/config.go
+1 -2
@@ -5,7 +5,6 @@ import (
5 "errors"
6 "fmt"
7 "io"
8 - "io/ioutil"
8 "os"
9 "os/exec"
10 "strings"
@@ -192,7 +191,7 @@ NOTE: For security reasons, this command will omit your private key and remote s
191 return err
192 }
193
195 - data, err := ioutil.ReadFile(fname)
194 + data, err := os.ReadFile(fname)
195 if err != nil {
196 return err
197 }
core/commands/dht.go
+1 -2
@@ -6,7 +6,6 @@ import (
6 "errors"
7 "fmt"
8 "io"
9 - "io/ioutil"
9 "time"
10
11 cmdenv "github.com/ipfs/go-ipfs/core/commands/cmdenv"
@@ -580,7 +579,7 @@ identified by QmFoo.
579 }
580 defer file.Close()
581
583 - data, err := ioutil.ReadAll(file)
582 + data, err := io.ReadAll(file)
583 if err != nil {
584 return err
585 }
core/commands/keystore.go
+2 -3
@@ -7,7 +7,6 @@ import (
7 "encoding/pem"
8 "fmt"
9 "io"
10 - "io/ioutil"
10 "os"
11 "path/filepath"
12 "strings"
@@ -276,7 +275,7 @@ elsewhere. For example, using openssl to get a PEM with public key:
275
276 switch exportFormat {
277 case keyFormatPemCleartextOption:
279 - privKeyBytes, err := ioutil.ReadAll(outReader)
278 + privKeyBytes, err := io.ReadAll(outReader)
279 if err != nil {
280 return err
281 }
@@ -344,7 +343,7 @@ The PEM format allows for key generation outside of the IPFS node:
343 }
344 defer file.Close()
345
347 - data, err := ioutil.ReadAll(file)
346 + data, err := io.ReadAll(file)
347 if err != nil {
348 return err
349 }
core/commands/multibase.go
+4 -4
@@ -3,7 +3,7 @@ package commands
3 import (
4 "bytes"
5 "fmt"
6 - "io/ioutil"
6 + "io"
7 "strings"
8
9 cmds "github.com/ipfs/go-ipfs-cmds"
@@ -66,7 +66,7 @@ but one can customize used base with -b:
66 if err != nil {
67 return fmt.Errorf("failed to access file: %w", err)
68 }
69 - buf, err := ioutil.ReadAll(file)
69 + buf, err := io.ReadAll(file)
70 if err != nil {
71 return fmt.Errorf("failed to read file contents: %w", err)
72 }
@@ -105,7 +105,7 @@ This command expects multibase inside of a file or via stdin:
105 if err != nil {
106 return fmt.Errorf("failed to access file: %w", err)
107 }
108 - encoded_data, err := ioutil.ReadAll(file)
108 + encoded_data, err := io.ReadAll(file)
109 if err != nil {
110 return fmt.Errorf("failed to read file contents: %w", err)
111 }
@@ -156,7 +156,7 @@ but one can customize used base with -b:
156 if err != nil {
157 return fmt.Errorf("failed to access file: %w", err)
158 }
159 - encoded_data, err := ioutil.ReadAll(file)
159 + encoded_data, err := io.ReadAll(file)
160 if err != nil {
161 return fmt.Errorf("failed to read file contents: %w", err)
162 }
core/commands/object/object.go
+1 -2
@@ -5,7 +5,6 @@ import (
5 "errors"
6 "fmt"
7 "io"
8 - "io/ioutil"
8 "text/tabwriter"
9
10 cmds "github.com/ipfs/go-ipfs-cmds"
@@ -230,7 +229,7 @@ DEPRECATED and provided for legacy reasons. Use 'ipfs dag get' instead.
229 return err
230 }
231
233 - data, err := ioutil.ReadAll(r)
232 + data, err := io.ReadAll(r)
233 if err != nil {
234 return err
235 }
core/commands/pubsub.go
+1 -2
@@ -4,7 +4,6 @@ import (
4 "context"
5 "fmt"
6 "io"
7 - "io/ioutil"
7 "net/http"
8 "sort"
9
@@ -191,7 +190,7 @@ HTTP RPC ENCODING
190 return err
191 }
192 defer file.Close()
194 - data, err := ioutil.ReadAll(file)
193 + data, err := io.ReadAll(file)
194 if err != nil {
195 return err
196 }
core/coreapi/block.go
+1 -2
@@ -5,7 +5,6 @@ import (
5 "context"
6 "errors"
7 "io"
8 - "io/ioutil"
8
9 blocks "github.com/ipfs/go-block-format"
10 cid "github.com/ipfs/go-cid"
@@ -36,7 +35,7 @@ func (api *BlockAPI) Put(ctx context.Context, src io.Reader, opts ...caopts.Bloc
35 return nil, err
36 }
37
39 - data, err := ioutil.ReadAll(src)
38 + data, err := io.ReadAll(src)
39 if err != nil {
40 return nil, err
41 }
core/coreapi/object.go
+2 -3
@@ -9,7 +9,6 @@ import (
9 "errors"
10 "fmt"
11 "io"
12 - "io/ioutil"
12
13 cid "github.com/ipfs/go-cid"
14 pin "github.com/ipfs/go-ipfs-pinner"
@@ -79,7 +78,7 @@ func (api *ObjectAPI) Put(ctx context.Context, src io.Reader, opts ...caopts.Obj
78 attribute.String("inputenc", options.InputEnc),
79 )
80
82 - data, err := ioutil.ReadAll(io.LimitReader(src, inputLimit+10))
81 + data, err := io.ReadAll(io.LimitReader(src, inputLimit+10))
82 if err != nil {
83 return nil, err
84 }
@@ -316,7 +315,7 @@ func (api *ObjectAPI) patchData(ctx context.Context, path ipath.Path, r io.Reade
315 return nil, dag.ErrNotProtobuf
316 }
317
319 - data, err := ioutil.ReadAll(r)
318 + data, err := io.ReadAll(r)
319 if err != nil {
320 return nil, err
321 }
core/coredag/cbor.go
+1 -2
@@ -2,7 +2,6 @@ package coredag
2
3 import (
4 "io"
5 - "io/ioutil"
5
6 ipldcbor "github.com/ipfs/go-ipld-cbor"
7 ipld "github.com/ipfs/go-ipld-format"
@@ -18,7 +17,7 @@ func cborJSONParser(r io.Reader, mhType uint64, mhLen int) ([]ipld.Node, error)
17 }
18
19 func cborRawParser(r io.Reader, mhType uint64, mhLen int) ([]ipld.Node, error) {
21 - data, err := ioutil.ReadAll(r)
20 + data, err := io.ReadAll(r)
21 if err != nil {
22 return nil, err
23 }
core/coredag/dagpb.go
+2 -3
@@ -2,7 +2,6 @@ package coredag
2
3 import (
4 "io"
5 - "io/ioutil"
5 "math"
6
7 "github.com/ipfs/go-merkledag"
@@ -13,7 +12,7 @@ import (
12 )
13
14 func dagpbJSONParser(r io.Reader, mhType uint64, mhLen int) ([]ipld.Node, error) {
16 - data, err := ioutil.ReadAll(r)
15 + data, err := io.ReadAll(r)
16 if err != nil {
17 return nil, err
18 }
@@ -31,7 +30,7 @@ func dagpbJSONParser(r io.Reader, mhType uint64, mhLen int) ([]ipld.Node, error)
30 }
31
32 func dagpbRawParser(r io.Reader, mhType uint64, mhLen int) ([]ipld.Node, error) {
34 - data, err := ioutil.ReadAll(r)
33 + data, err := io.ReadAll(r)
34 if err != nil {
35 return nil, err
36 }
core/coredag/raw.go
+1 -2
@@ -2,7 +2,6 @@ package coredag
2
3 import (
4 "io"
5 - "io/ioutil"
5 "math"
6
7 "github.com/ipfs/go-merkledag"
@@ -18,7 +17,7 @@ func rawRawParser(r io.Reader, mhType uint64, mhLen int) ([]ipld.Node, error) {
17 mhType = mh.SHA2_256
18 }
19
21 - data, err := ioutil.ReadAll(r)
20 + data, err := io.ReadAll(r)
21 if err != nil {
22 return nil, err
23 }
core/corehttp/gateway_handler_block.go
+2 -2
@@ -3,7 +3,7 @@ package corehttp
3 import (
4 "bytes"
5 "context"
6 - "io/ioutil"
6 + "io"
7 "net/http"
8 "time"
9
@@ -23,7 +23,7 @@ func (i *gatewayHandler) serveRawBlock(ctx context.Context, w http.ResponseWrite
23 webError(w, "ipfs block get "+blockCid.String(), err, http.StatusInternalServerError)
24 return
25 }
26 - block, err := ioutil.ReadAll(blockReader)
26 + block, err := io.ReadAll(blockReader)
27 if err != nil {
28 webError(w, "ipfs block get "+blockCid.String(), err, http.StatusInternalServerError)
29 return
core/corehttp/gateway_test.go
+7 -7
@@ -3,7 +3,7 @@ package corehttp
3 import (
4 "context"
5 "errors"
6 - "io/ioutil"
6 + "io"
7 "net/http"
8 "net/http/httptest"
9 "regexp"
@@ -267,7 +267,7 @@ func TestGatewayGet(t *testing.T) {
267 if contentType != "text/plain; charset=utf-8" {
268 t.Errorf("expected content type to be text/plain, got %s", contentType)
269 }
270 - body, err := ioutil.ReadAll(resp.Body)
270 + body, err := io.ReadAll(resp.Body)
271 if resp.StatusCode != test.status {
272 t.Errorf("(%d) got %d, expected %d from %s", i, resp.StatusCode, test.status, urlstr)
273 t.Errorf("Body: %s", body)
@@ -335,7 +335,7 @@ func TestPretty404(t *testing.T) {
335 if resp.StatusCode != test.status {
336 t.Fatalf("got %d, expected %d, from %s", resp.StatusCode, test.status, test.path)
337 }
338 - body, err := ioutil.ReadAll(resp.Body)
338 + body, err := io.ReadAll(resp.Body)
339 if err != nil {
340 t.Fatalf("error reading response from %s: %s", test.path, err)
341 }
@@ -482,7 +482,7 @@ func TestIPNSHostnameBacklinks(t *testing.T) {
482 }
483
484 // expect correct links
485 - body, err := ioutil.ReadAll(res.Body)
485 + body, err := io.ReadAll(res.Body)
486 if err != nil {
487 t.Fatalf("error reading response: %s", err)
488 }
@@ -519,7 +519,7 @@ func TestIPNSHostnameBacklinks(t *testing.T) {
519 }
520
521 // expect correct backlinks at root
522 - body, err = ioutil.ReadAll(res.Body)
522 + body, err = io.ReadAll(res.Body)
523 if err != nil {
524 t.Fatalf("error reading response: %s", err)
525 }
@@ -556,7 +556,7 @@ func TestIPNSHostnameBacklinks(t *testing.T) {
556 }
557
558 // expect correct backlinks
559 - body, err = ioutil.ReadAll(res.Body)
559 + body, err = io.ReadAll(res.Body)
560 if err != nil {
561 t.Fatalf("error reading response: %s", err)
562 }
@@ -638,7 +638,7 @@ func TestVersion(t *testing.T) {
638 if err != nil {
639 t.Fatal(err)
640 }
641 - body, err := ioutil.ReadAll(res.Body)
641 + body, err := io.ReadAll(res.Body)
642 if err != nil {
643 t.Fatalf("error reading response: %s", err)
644 }
core/corehttp/lazyseek_test.go
+4 -5
@@ -3,7 +3,6 @@ package corehttp
3 import (
4 "fmt"
5 "io"
6 - "io/ioutil"
6 "strings"
7 "testing"
8 )
@@ -37,7 +36,7 @@ func TestLazySeekerError(t *testing.T) {
36 }
37
38 // shouldn't have actually seeked.
40 - b, err := ioutil.ReadAll(s)
39 + b, err := io.ReadAll(s)
40 if err != nil {
41 t.Fatal(err)
42 }
@@ -53,7 +52,7 @@ func TestLazySeekerError(t *testing.T) {
52 if off != 0 {
53 t.Fatal("expected to seek to the start")
54 }
56 - b, err = ioutil.ReadAll(s)
55 + b, err = io.ReadAll(s)
56 if err != nil {
57 t.Fatal(err)
58 }
@@ -70,7 +69,7 @@ func TestLazySeekerError(t *testing.T) {
69 t.Fatal("expected to seek to the start")
70 }
71 // right here...
73 - b, err = ioutil.ReadAll(s)
72 + b, err = io.ReadAll(s)
73 if err == nil {
74 t.Fatalf("expected an error, got output %s", string(b))
75 }
@@ -120,7 +119,7 @@ func TestLazySeeker(t *testing.T) {
119 }
120
121 expectSeek(io.SeekEnd, 0, s.size, "")
123 - b, err := ioutil.ReadAll(s)
122 + b, err := io.ReadAll(s)
123 if err != nil {
124 t.Fatal(err)
125 }
core/coreunix/add_test.go
+1 -2
@@ -4,7 +4,6 @@ import (
4 "bytes"
5 "context"
6 "io"
7 - "io/ioutil"
7 "math/rand"
8 "os"
9 "path/filepath"
@@ -282,7 +281,7 @@ func testAddWPosInfo(t *testing.T, rawLeaves bool) {
281
282 data := make([]byte, 5*1024*1024)
283 rand.New(rand.NewSource(2)).Read(data) // Rand.Read never returns an error
285 - fileData := ioutil.NopCloser(bytes.NewBuffer(data))
284 + fileData := io.NopCloser(bytes.NewBuffer(data))
285 fileInfo := dummyFileInfo{"foo.txt", int64(len(data)), time.Now()}
286 file, _ := files.NewReaderPathFile(filepath.Join(os.TempDir(), "foo.txt"), fileData, &fileInfo)
287
core/coreunix/metadata_test.go
+1 -2
@@ -4,7 +4,6 @@ import (
4 "bytes"
5 "context"
6 "io"
7 - "io/ioutil"
7 "testing"
8
9 bserv "github.com/ipfs/go-blockservice"
@@ -87,7 +86,7 @@ func TestMetadata(t *testing.T) {
86 t.Fatal(err)
87 }
88
90 - out, err := ioutil.ReadAll(ndr)
89 + out, err := io.ReadAll(ndr)
90 if err != nil {
91 t.Fatal(err)
92 }
core/mock/mock.go
+2 -2
@@ -3,7 +3,7 @@ package coremock
3 import (
4 "context"
5 "fmt"
6 - "io/ioutil"
6 + "io"
7
8 libp2p2 "github.com/ipfs/go-ipfs/core/node/libp2p"
9
@@ -75,7 +75,7 @@ func MockCmdsCtx() (commands.Context, error) {
75
76 func MockPublicNode(ctx context.Context, mn mocknet.Mocknet) (*core.IpfsNode, error) {
77 ds := syncds.MutexWrap(datastore.NewMapDatastore())
78 - cfg, err := config.Init(ioutil.Discard, 2048)
78 + cfg, err := config.Init(io.Discard, 2048)
79 if err != nil {
80 return nil, err
81 }
coverage/main/main.go
+4 -4
@@ -5,7 +5,7 @@ package main
5
6 import (
7 "fmt"
8 - "io/ioutil"
8 + "io"
9 "os"
10 "os/exec"
11 "os/signal"
@@ -19,13 +19,13 @@ func main() {
19 fmt.Println("IPFS_COVER_DIR not defined")
20 os.Exit(1)
21 }
22 - coverFile, err := ioutil.TempFile(coverDir, "coverage-")
22 + coverFile, err := os.CreateTemp(coverDir, "coverage-")
23 if err != nil {
24 fmt.Println(err.Error())
25 os.Exit(1)
26 }
27
28 - retFile, err := ioutil.TempFile("", "cover-ret-file")
28 + retFile, err := os.CreateTemp("", "cover-ret-file")
29 if err != nil {
30 fmt.Println(err.Error())
31 os.Exit(1)
@@ -69,7 +69,7 @@ func main() {
69 os.Exit(1)
70 }
71
72 - b, err := ioutil.ReadAll(retFile)
72 + b, err := io.ReadAll(retFile)
73 if err != nil {
74 fmt.Println(err.Error())
75 os.Exit(1)
docs/examples/go-ipfs-as-a-library/main.go
+4 -4
@@ -4,7 +4,7 @@ import (
4 "context"
5 "flag"
6 "fmt"
7 - "io/ioutil"
7 + "io"
8 "log"
9 "os"
10 "path/filepath"
@@ -47,13 +47,13 @@ func setupPlugins(externalPluginsPath string) error {
47 }
48
49 func createTempRepo() (string, error) {
50 - repoPath, err := ioutil.TempDir("", "ipfs-shell")
50 + repoPath, err := os.MkdirTemp("", "ipfs-shell")
51 if err != nil {
52 return "", fmt.Errorf("failed to get temp dir: %s", err)
53 }
54
55 // Create a config with default options and a 2048 bit key
56 - cfg, err := config.Init(ioutil.Discard, 2048)
56 + cfg, err := config.Init(io.Discard, 2048)
57 if err != nil {
58 return "", err
59 }
@@ -252,7 +252,7 @@ func main() {
252
253 /// --- Part III: Getting the file and directory you added back
254
255 - outputBasePath, err := ioutil.TempDir("", "example")
255 + outputBasePath, err := os.MkdirTemp("", "example")
256 if err != nil {
257 panic(fmt.Errorf("could not create output dir (%v)", err))
258 }
fuse/ipns/ipns_test.go
+8 -9
@@ -8,7 +8,6 @@ import (
8 "context"
9 "fmt"
10 "io"
11 - "io/ioutil"
11 mrand "math/rand"
12 "os"
13 "sync"
@@ -57,12 +56,12 @@ func writeFileOrFail(t *testing.T, size int, path string) []byte {
56
57 func writeFile(size int, path string) ([]byte, error) {
58 data := randBytes(size)
60 - err := ioutil.WriteFile(path, data, 0666)
59 + err := os.WriteFile(path, data, 0666)
60 return data, err
61 }
62
63 func verifyFile(t *testing.T, path string, wantData []byte) {
65 - isData, err := ioutil.ReadFile(path)
64 + isData, err := os.ReadFile(path)
65 if err != nil {
66 t.Fatal(err)
67 }
@@ -168,7 +167,7 @@ func TestIpnsBasicIO(t *testing.T) {
167 fname := mnt.Dir + "/local/testfile"
168 data := writeFileOrFail(t, 10, fname)
169
171 - rbuf, err := ioutil.ReadFile(fname)
170 + rbuf, err := os.ReadFile(fname)
171 if err != nil {
172 t.Fatal(err)
173 }
@@ -178,7 +177,7 @@ func TestIpnsBasicIO(t *testing.T) {
177 }
178
179 fname2 := mnt.Dir + "/" + nd.Identity.Pretty() + "/testfile"
181 - rbuf, err = ioutil.ReadFile(fname2)
180 + rbuf, err = os.ReadFile(fname2)
181 if err != nil {
182 t.Fatal(err)
183 }
@@ -204,7 +203,7 @@ func TestFilePersistence(t *testing.T) {
203 _, mnt = setupIpnsTest(t, node)
204 defer mnt.Close()
205
207 - rbuf, err := ioutil.ReadFile(mnt.Dir + fname)
206 + rbuf, err := os.ReadFile(mnt.Dir + fname)
207 if err != nil {
208 t.Fatal(err)
209 }
@@ -324,7 +323,7 @@ func TestAppendFile(t *testing.T) {
323
324 data = append(data, nudata...)
325
327 - rbuf, err := ioutil.ReadFile(fname)
326 + rbuf, err := os.ReadFile(fname)
327 if err != nil {
328 t.Fatal(err)
329 }
@@ -453,7 +452,7 @@ func TestFSThrash(t *testing.T) {
452
453 wg.Wait()
454 for name, data := range files {
456 - out, err := ioutil.ReadFile(name)
455 + out, err := os.ReadFile(name)
456 if err != nil {
457 t.Error(err)
458 }
@@ -492,7 +491,7 @@ func TestMultiWrite(t *testing.T) {
491 }
492 fi.Close()
493
495 - rbuf, err := ioutil.ReadFile(fpath)
494 + rbuf, err := os.ReadFile(fpath)
495 if err != nil {
496 t.Fatal(err)
497 }
fuse/node/mount_test.go
+1 -2
@@ -4,7 +4,6 @@
4 package node
5
6 import (
7 - "io/ioutil"
7 "os"
8 "strings"
9 "testing"
@@ -54,7 +53,7 @@ func TestExternalUnmount(t *testing.T) {
53 }
54
55 // get the test dir paths (/tmp/fusetestXXXX)
57 - dir, err := ioutil.TempDir("", "fusetest")
56 + dir, err := os.MkdirTemp("", "fusetest")
57 if err != nil {
58 t.Fatal(err)
59 }
fuse/readonly/ipfs_test.go
+5 -6
@@ -9,7 +9,6 @@ import (
9 "errors"
10 "fmt"
11 "io"
12 - "io/ioutil"
12 "math/rand"
13 "os"
14 "path"
@@ -91,7 +90,7 @@ func TestIpfsBasicRead(t *testing.T) {
90 fi, data := randObj(t, nd, 10000)
91 k := fi.Cid()
92 fname := path.Join(mnt.Dir, k.String())
94 - rbuf, err := ioutil.ReadFile(fname)
93 + rbuf, err := os.ReadFile(fname)
94 if err != nil {
95 t.Fatal(err)
96 }
@@ -190,7 +189,7 @@ func TestIpfsStressRead(t *testing.T) {
189 relpath := strings.Replace(item.String(), item.Namespace(), "", 1)
190 fname := path.Join(mnt.Dir, relpath)
191
193 - rbuf, err := ioutil.ReadFile(fname)
192 + rbuf, err := os.ReadFile(fname)
193 if err != nil {
194 errs <- err
195 }
@@ -204,7 +203,7 @@ func TestIpfsStressRead(t *testing.T) {
203 errs <- err
204 }
205
207 - data, err := ioutil.ReadAll(read.(files.File))
206 + data, err := io.ReadAll(read.(files.File))
207 if err != nil {
208 errs <- err
209 }
@@ -260,12 +259,12 @@ func TestIpfsBasicDirRead(t *testing.T) {
259
260 dirname := path.Join(mnt.Dir, d1nd.Cid().String())
261 fname := path.Join(dirname, "actual")
263 - rbuf, err := ioutil.ReadFile(fname)
262 + rbuf, err := os.ReadFile(fname)
263 if err != nil {
264 t.Fatal(err)
265 }
266
268 - dirents, err := ioutil.ReadDir(dirname)
267 + dirents, err := os.ReadDir(dirname)
268 if err != nil {
269 t.Fatal(err)
270 }
repo/fsrepo/config_test.go
+4 -5
@@ -2,7 +2,6 @@ package fsrepo_test
2
3 import (
4 "encoding/json"
5 - "io/ioutil"
5 "os"
6 "reflect"
7 "testing"
@@ -89,7 +88,7 @@ func TestDefaultDatastoreConfig(t *testing.T) {
88 t.Fatal(err)
89 }
90
92 - dir, err := ioutil.TempDir("", "ipfs-datastore-config-test")
91 + dir, err := os.MkdirTemp("", "ipfs-datastore-config-test")
92 if err != nil {
93 t.Fatal(err)
94 }
@@ -127,7 +126,7 @@ func TestLevelDbConfig(t *testing.T) {
126 if err != nil {
127 t.Fatal(err)
128 }
130 - dir, err := ioutil.TempDir("", "ipfs-datastore-config-test")
129 + dir, err := os.MkdirTemp("", "ipfs-datastore-config-test")
130 if err != nil {
131 t.Fatal(err)
132 }
@@ -165,7 +164,7 @@ func TestFlatfsConfig(t *testing.T) {
164 if err != nil {
165 t.Fatal(err)
166 }
168 - dir, err := ioutil.TempDir("", "ipfs-datastore-config-test")
167 + dir, err := os.MkdirTemp("", "ipfs-datastore-config-test")
168 if err != nil {
169 t.Fatal(err)
170 }
@@ -203,7 +202,7 @@ func TestMeasureConfig(t *testing.T) {
202 if err != nil {
203 t.Fatal(err)
204 }
206 - dir, err := ioutil.TempDir("", "ipfs-datastore-config-test")
205 + dir, err := os.MkdirTemp("", "ipfs-datastore-config-test")
206 if err != nil {
207 t.Fatal(err)
208 }
repo/fsrepo/fsrepo.go
+5 -6
@@ -5,7 +5,6 @@ import (
5 "errors"
6 "fmt"
7 "io"
8 - "io/ioutil"
8 "os"
9 "path/filepath"
10 "strings"
@@ -270,7 +269,7 @@ func initSpec(path string, conf map[string]interface{}) error {
269 }
270 bytes := dsc.DiskSpec().Bytes()
271
273 - return ioutil.WriteFile(fn, bytes, 0600)
272 + return os.WriteFile(fn, bytes, 0600)
273 }
274
275 // Init initializes a new FSRepo at the given path with the provided config.
@@ -338,7 +337,7 @@ func APIAddr(repoPath string) (ma.Multiaddr, error) {
337 // some hidden wisdom. However, I'm fixing it such that:
338 // 1. We don't read too little.
339 // 2. We don't truncate and succeed.
341 - buf, err := ioutil.ReadAll(io.LimitReader(f, 2048))
340 + buf, err := io.ReadAll(io.LimitReader(f, 2048))
341 if err != nil {
342 return nil, err
343 }
@@ -454,7 +453,7 @@ func (r *FSRepo) readSpec() (string, error) {
453 if err != nil {
454 return "", err
455 }
457 - b, err := ioutil.ReadFile(fn)
456 + b, err := os.ReadFile(fn)
457 if err != nil {
458 return "", err
459 }
@@ -515,7 +514,7 @@ func (r *FSRepo) FileManager() *filestore.FileManager {
514 }
515
516 func (r *FSRepo) BackupConfig(prefix string) (string, error) {
518 - temp, err := ioutil.TempFile(r.path, "config-"+prefix)
517 + temp, err := os.CreateTemp(r.path, "config-"+prefix)
518 if err != nil {
519 return "", err
520 }
@@ -667,7 +666,7 @@ func (r *FSRepo) SwarmKey() ([]byte, error) {
666 }
667 defer f.Close()
668
670 - return ioutil.ReadAll(f)
669 + return io.ReadAll(f)
670 }
671
672 var _ io.Closer = &FSRepo{}
repo/fsrepo/fsrepo_test.go
+1 -2
@@ -3,7 +3,6 @@ package fsrepo
3 import (
4 "bytes"
5 "context"
6 - "io/ioutil"
6 "os"
7 "path/filepath"
8 "testing"
@@ -16,7 +15,7 @@ import (
15
16 // swap arg order
17 func testRepoPath(p string, t *testing.T) string {
19 - name, err := ioutil.TempDir("", p)
18 + name, err := os.MkdirTemp("", p)
19 if err != nil {
20 t.Fatal(err)
21 }
repo/fsrepo/migrations/fetch.go
+1 -2
@@ -6,7 +6,6 @@ import (
6 "context"
7 "fmt"
8 "io"
9 - "io/ioutil"
9 "os"
10 "os/exec"
11 "path/filepath"
@@ -89,7 +88,7 @@ func FetchBinary(ctx context.Context, fetcher Fetcher, dist, ver, binName, out s
88 }
89 } else {
90 // Create temp directory to store download
92 - tmpDir, err = ioutil.TempDir("", arcName)
91 + tmpDir, err = os.MkdirTemp("", arcName)
92 if err != nil {
93 return "", err
94 }
repo/fsrepo/migrations/httpfetcher.go
+2 -3
@@ -4,7 +4,6 @@ import (
4 "context"
5 "fmt"
6 "io"
7 - "io/ioutil"
7 "net/http"
8 "path"
9 "strings"
@@ -81,7 +80,7 @@ func (f *HttpFetcher) Fetch(ctx context.Context, filePath string) ([]byte, error
80
81 if resp.StatusCode >= 400 {
82 defer resp.Body.Close()
84 - mes, err := ioutil.ReadAll(resp.Body)
83 + mes, err := io.ReadAll(resp.Body)
84 if err != nil {
85 return nil, fmt.Errorf("error reading error body: %s", err)
86 }
@@ -96,7 +95,7 @@ func (f *HttpFetcher) Fetch(ctx context.Context, filePath string) ([]byte, error
95 }
96 defer rc.Close()
97
99 - return ioutil.ReadAll(rc)
98 + return io.ReadAll(rc)
99 }
100
101 func (f *HttpFetcher) Close() error {
repo/fsrepo/migrations/ipfsdir.go
+2 -3
@@ -3,7 +3,6 @@ package migrations
3 import (
4 "errors"
5 "fmt"
6 - "io/ioutil"
6 "os"
7 "path/filepath"
8 "strconv"
@@ -85,11 +84,11 @@ func WriteRepoVersion(ipfsDir string, version int) error {
84 }
85
86 vFilePath := filepath.Join(ipfsDir, versionFile)
88 - return ioutil.WriteFile(vFilePath, []byte(fmt.Sprintf("%d\n", version)), 0644)
87 + return os.WriteFile(vFilePath, []byte(fmt.Sprintf("%d\n", version)), 0644)
88 }
89
90 func repoVersion(ipfsDir string) (int, error) {
92 - c, err := ioutil.ReadFile(filepath.Join(ipfsDir, versionFile))
91 + c, err := os.ReadFile(filepath.Join(ipfsDir, versionFile))
92 if err != nil {
93 return 0, err
94 }
repo/fsrepo/migrations/ipfsdir_test.go
+1 -2
@@ -1,7 +1,6 @@
1 package migrations
2
3 import (
4 - "io/ioutil"
4 "os"
5 "path/filepath"
6 "testing"
@@ -139,7 +138,7 @@ func testRepoVersion(t *testing.T) {
138 t.Fatal(err)
139 }
140 vFilePath := filepath.Join(ipfsDir, versionFile)
142 - err = ioutil.WriteFile(vFilePath, []byte("bad-version-data\n"), 0644)
141 + err = os.WriteFile(vFilePath, []byte("bad-version-data\n"), 0644)
142 if err != nil {
143 panic(err)
144 }
repo/fsrepo/migrations/ipfsfetcher/ipfsfetcher.go
+3 -4
@@ -5,7 +5,6 @@ import (
5 "encoding/json"
6 "fmt"
7 "io"
8 - "io/ioutil"
8 "net/url"
9 "os"
10 "path"
@@ -134,7 +133,7 @@ func (f *IpfsFetcher) Fetch(ctx context.Context, filePath string) ([]byte, error
133 }
134 defer rc.Close()
135
137 - return ioutil.ReadAll(rc)
136 + return io.ReadAll(rc)
137 }
138
139 func (f *IpfsFetcher) Close() error {
@@ -171,7 +170,7 @@ func (f *IpfsFetcher) recordFetched(fetchedPath ipath.Path) {
170 }
171
172 func initTempNode(ctx context.Context, bootstrap []string, peers []peer.AddrInfo) (string, error) {
174 - identity, err := config.CreateIdentity(ioutil.Discard, []options.KeyGenerateOption{
173 + identity, err := config.CreateIdentity(io.Discard, []options.KeyGenerateOption{
174 options.Key.Type(options.Ed25519Key),
175 })
176 if err != nil {
@@ -183,7 +182,7 @@ func initTempNode(ctx context.Context, bootstrap []string, peers []peer.AddrInfo
182 }
183
184 // create temporary ipfs directory
186 - dir, err := ioutil.TempDir("", "ipfs-temp")
185 + dir, err := os.MkdirTemp("", "ipfs-temp")
186 if err != nil {
187 return "", fmt.Errorf("failed to get temp dir: %s", err)
188 }
repo/fsrepo/migrations/migrations.go
+1 -2
@@ -5,7 +5,6 @@ import (
5 "encoding/json"
6 "errors"
7 "fmt"
8 - "io/ioutil"
8 "log"
9 "net/url"
10 "os"
@@ -63,7 +62,7 @@ func RunMigration(ctx context.Context, fetcher Fetcher, targetVer int, ipfsDir s
62
63 logger.Println("Need", len(missing), "migrations, downloading.")
64
66 - tmpDir, err := ioutil.TempDir("", "migrations")
65 + tmpDir, err := os.MkdirTemp("", "migrations")
66 if err != nil {
67 return err
68 }
repo/fsrepo/migrations/unpack_test.go
+2 -3
@@ -6,7 +6,6 @@ import (
6 "bufio"
7 "compress/gzip"
8 "io"
9 - "io/ioutil"
9 "os"
10 "path"
11 "path/filepath"
@@ -36,7 +35,7 @@ func TestUnpackTgz(t *testing.T) {
35 tmpDir := t.TempDir()
36
37 badTarGzip := filepath.Join(tmpDir, "bad.tar.gz")
39 - err := ioutil.WriteFile(badTarGzip, []byte("bad-data\n"), 0644)
38 + err := os.WriteFile(badTarGzip, []byte("bad-data\n"), 0644)
39 if err != nil {
40 panic(err)
41 }
@@ -80,7 +79,7 @@ func TestUnpackZip(t *testing.T) {
79 tmpDir := t.TempDir()
80
81 badZip := filepath.Join(tmpDir, "bad.zip")
83 - err := ioutil.WriteFile(badZip, []byte("bad-data\n"), 0644)
82 + err := os.WriteFile(badZip, []byte("bad-data\n"), 0644)
83 if err != nil {
84 panic(err)
85 }
test/bench/bench_cli_ipfs_add/main.go
+2 -3
@@ -3,7 +3,6 @@ package main
3 import (
4 "flag"
5 "fmt"
6 - "io/ioutil"
6 "log"
7 "os"
8 "os/exec"
@@ -46,7 +45,7 @@ func benchmarkAdd(amount int64) (*testing.BenchmarkResult, error) {
45 b.SetBytes(amount)
46 for i := 0; i < b.N; i++ {
47 b.StopTimer()
49 - tmpDir, err := ioutil.TempDir("", "")
48 + tmpDir, err := os.MkdirTemp("", "")
49 if err != nil {
50 benchmarkError = err
51 b.Fatal(err)
@@ -73,7 +72,7 @@ func benchmarkAdd(amount int64) (*testing.BenchmarkResult, error) {
72 }
73
74 const seed = 1
76 - f, err := ioutil.TempFile("", "")
75 + f, err := os.CreateTemp("", "")
76 if err != nil {
77 benchmarkError = err
78 b.Fatal(err)
test/bench/offline_add/main.go
+2 -3
@@ -2,7 +2,6 @@ package main
2
3 import (
4 "fmt"
5 - "io/ioutil"
5 "log"
6 "os"
7 "os/exec"
@@ -38,7 +37,7 @@ func benchmarkAdd(amount int64) (*testing.BenchmarkResult, error) {
37 b.SetBytes(amount)
38 for i := 0; i < b.N; i++ {
39 b.StopTimer()
41 - tmpDir, err := ioutil.TempDir("", "")
40 + tmpDir, err := os.MkdirTemp("", "")
41 if err != nil {
42 b.Fatal(err)
43 }
@@ -56,7 +55,7 @@ func benchmarkAdd(amount int64) (*testing.BenchmarkResult, error) {
55 }
56
57 const seed = 1
59 - f, err := ioutil.TempFile("", "")
58 + f, err := os.CreateTemp("", "")
59 if err != nil {
60 b.Fatal(err)
61 }
test/dependencies/ma-pipe-unidir/main.go
+2 -3
@@ -4,7 +4,6 @@ import (
4 "flag"
5 "fmt"
6 "io"
7 - "io/ioutil"
7 "os"
8 "strconv"
9
@@ -58,7 +57,7 @@ func app() int {
57
58 if len(opts.PidFile) > 0 {
59 data := []byte(strconv.Itoa(os.Getpid()))
61 - err := ioutil.WriteFile(opts.PidFile, data, 0644)
60 + err := os.WriteFile(opts.PidFile, data, 0644)
61 if err != nil {
62 return 1
63 }
@@ -79,7 +78,7 @@ func app() int {
78
79 if len(opts.PidFile) > 0 {
80 data := []byte(strconv.Itoa(os.Getpid()))
82 - err := ioutil.WriteFile(opts.PidFile, data, 0644)
81 + err := os.WriteFile(opts.PidFile, data, 0644)
82 if err != nil {
83 return 1
84 }