]> Sergey Matveev's repositories - btrtrc.git/commitdiff
chore: remove refs to deprecated io/ioutil
authorguoguangwu <guoguangwu@magic-shield.com>
Sun, 9 Jul 2023 05:29:02 +0000 (13:29 +0800)
committerMatt Joiner <anacrolix@gmail.com>
Sun, 9 Jul 2023 14:20:13 +0000 (00:20 +1000)
bencode/both_test.go
cmd/torrent-pick/main.go
internal/testutil/greeting.go
internal/testutil/spec.go
issue211_test.go
metainfo/metainfo_test.go
mse/mse.go
mse/mse_test.go
storage/piece-resource.go
test/transfer_test.go
tracker/udp_test.go

index b0bb074d38af6b17e236e06a19a5105528a4f499..fdcb90d9f8e44184039c3c6aa825b79d1a6f6667 100644 (file)
@@ -2,7 +2,7 @@ package bencode
 
 import (
        "bytes"
-       "io/ioutil"
+       "os"
        "testing"
 
        "github.com/stretchr/testify/assert"
@@ -10,7 +10,7 @@ import (
 )
 
 func loadFile(name string, t *testing.T) []byte {
-       data, err := ioutil.ReadFile(name)
+       data, err := os.ReadFile(name)
        require.NoError(t, err)
        return data
 }
index 8dd5a773c24485ef1ff3f48e27e6c8c505ab54e1..73a597f3622024604c26e22a9cfeba7d079a66bd 100644 (file)
@@ -5,7 +5,6 @@ import (
        "bufio"
        "fmt"
        "io"
-       "io/ioutil"
        "log"
        "net"
        "net/http"
@@ -107,7 +106,7 @@ func main() {
                return
        }
 
-       tmpdir, err := ioutil.TempDir("", "torrent-pick-")
+       tmpdir, err := os.MkdirTemp("", "torrent-pick-")
        if err != nil {
                log.Fatal(err)
        }
index 954ad9130d55fa644f02c5e946dfc5a249b48d5e..6544483c8b312690764518f4f8be1bfeb241d09f 100644 (file)
@@ -6,7 +6,6 @@
 package testutil
 
 import (
-       "io/ioutil"
        "os"
        "path/filepath"
 
@@ -41,7 +40,7 @@ func GreetingMetaInfo() *metainfo.MetaInfo {
 // and a corresponding metainfo describing it. The temporary directory can be
 // cleaned away with os.RemoveAll.
 func GreetingTestTorrent() (tempDir string, metaInfo *metainfo.MetaInfo) {
-       tempDir, err := ioutil.TempDir(os.TempDir(), "")
+       tempDir, err := os.MkdirTemp(os.TempDir(), "")
        if err != nil {
                panic(err)
        }
index 42d91ba3cfa34b96609145ff16f65ea2eca36f29..63e4a74c633f646bdb1efa7c1607684cf0b807d9 100644 (file)
@@ -2,7 +2,6 @@ package testutil
 
 import (
        "io"
-       "io/ioutil"
        "strings"
 
        "github.com/anacrolix/missinggo/expect"
@@ -53,7 +52,7 @@ func (t *Torrent) Info(pieceLength int64) metainfo.Info {
                }
        }
        err := info.GeneratePieces(func(fi metainfo.FileInfo) (io.ReadCloser, error) {
-               return ioutil.NopCloser(strings.NewReader(t.GetFile(strings.Join(fi.Path, "/")).Data)), nil
+               return io.NopCloser(strings.NewReader(t.GetFile(strings.Join(fi.Path, "/")).Data)), nil
        })
        expect.Nil(err)
        return info
index 7794f8a50137974993485f57d1a14f30f3d5a913..a76be07a8a2da0a6c6682e28038eb610a9d8f140 100644 (file)
@@ -5,7 +5,6 @@ package torrent
 
 import (
        "io"
-       "io/ioutil"
        "testing"
 
        "github.com/stretchr/testify/assert"
@@ -38,5 +37,5 @@ func TestDropTorrentWithMmapStorageWhileHashing(t *testing.T) {
 
        r := tt.NewReader()
        go tt.Drop()
-       io.Copy(ioutil.Discard, r)
+       io.Copy(io.Discard, r)
 }
index d1a6c356c42fa83d304f754e22db963edfdfdea7..335631f9850c7ba6b135612c38ed89958e48bfa9 100644 (file)
@@ -2,7 +2,6 @@ package metainfo
 
 import (
        "io"
-       "io/ioutil"
        "os"
        "path"
        "path/filepath"
@@ -68,7 +67,7 @@ func TestNumPieces(t *testing.T) {
                        PieceLength: _case.PieceLength,
                }
                err := info.GeneratePieces(func(fi FileInfo) (io.ReadCloser, error) {
-                       return ioutil.NopCloser(missinggo.ZeroReader), nil
+                       return io.NopCloser(missinggo.ZeroReader), nil
                })
                assert.NoError(t, err)
                assert.EqualValues(t, _case.NumPieces, info.NumPieces())
index a5477b8f172706af718565cc59a2928651e0b9d5..c3a9f3d3ae840c77eed1c37a881111194ae71c9f 100644 (file)
@@ -12,7 +12,6 @@ import (
        "expvar"
        "fmt"
        "io"
-       "io/ioutil"
        "math"
        "math/big"
        "strconv"
@@ -409,7 +408,7 @@ func (h *handshake) initerSteps() (ret io.ReadWriter, selected CryptoMethod, err
        if err != nil {
                return
        }
-       _, err = io.CopyN(ioutil.Discard, r, int64(padLen))
+       _, err = io.CopyN(io.Discard, r, int64(padLen))
        if err != nil {
                return
        }
@@ -474,7 +473,7 @@ func (h *handshake) receiverSteps() (ret io.ReadWriter, chosen CryptoMethod, err
        }
        cryptoProvidesCount.Add(strconv.FormatUint(uint64(provides), 16), 1)
        chosen = h.chooseMethod(provides)
-       _, err = io.CopyN(ioutil.Discard, r, int64(padLen))
+       _, err = io.CopyN(io.Discard, r, int64(padLen))
        if err != nil {
                return
        }
index a38e9cc109aec619fb38ce7199312dd5979b5d60..f7f7fe7ab9c7f2090f2a30467cc5635414dbdc8d 100644 (file)
@@ -5,7 +5,6 @@ import (
        "crypto/rand"
        "crypto/rc4"
        "io"
-       "io/ioutil"
        "net"
        "sync"
        "testing"
@@ -131,7 +130,7 @@ func (tr *trackReader) Read(b []byte) (n int, err error) {
 
 func TestReceiveRandomData(t *testing.T) {
        tr := trackReader{rand.Reader, 0}
-       _, _, err := ReceiveHandshake(readWriter{&tr, ioutil.Discard}, nil, DefaultCryptoSelector)
+       _, _, err := ReceiveHandshake(readWriter{&tr, io.Discard}, nil, DefaultCryptoSelector)
        // No skey matches
        require.Error(t, err)
        // Establishing S, and then reading the maximum padding for giving up on
index ec3848df2111186259ce1cb76c9f6749aa8623f9..5327f31d1b10e5ca08b1ffeb03e4e76af8ca39c4 100644 (file)
@@ -4,7 +4,6 @@ import (
        "bytes"
        "fmt"
        "io"
-       "io/ioutil"
        "path"
        "sort"
        "strconv"
@@ -141,7 +140,7 @@ func (s piecePerResourcePiece) MarkComplete() error {
                if ccr, ok := s.rp.(ConsecutiveChunkReader); ok {
                        return ccr.ReadConsecutiveChunks(s.incompleteDirPath() + "/")
                }
-               return ioutil.NopCloser(io.NewSectionReader(incompleteChunks, 0, s.mp.Length())), nil
+               return io.NopCloser(io.NewSectionReader(incompleteChunks, 0, s.mp.Length())), nil
        }()
        if err != nil {
                return fmt.Errorf("getting incomplete chunks reader: %w", err)
index 683d589b897059c1b76b24491c66bedecdcc7773..501872fd8fb642971aedd1134ce91f0df16b4574 100644 (file)
@@ -2,7 +2,6 @@ package test
 
 import (
        "io"
-       "io/ioutil"
        "os"
        "sync"
        "testing"
@@ -46,7 +45,7 @@ func newFileCacheClientStorageFactory(ps fileCacheClientStorageFactoryParams) St
                                storage.ResourcePiecesOpts{
                                        Capacity: sharedCapacity,
                                }),
-                       ioutil.NopCloser(nil),
+                       io.NopCloser(nil),
                }
        }
 }
index cf18e0de9f2dc20fc07f7f13fd9a6b99fc48fe03..232aeb1973a51f0229b6591894473ea4a61c94c8 100644 (file)
@@ -6,7 +6,7 @@ import (
        "crypto/rand"
        "errors"
        "fmt"
-       "io/ioutil"
+       "io"
        "net"
        "net/url"
        "sync"
@@ -179,7 +179,7 @@ func TestURLPathOption(t *testing.T) {
        r = bytes.NewReader(b[:n])
        udp.Read(r, &h)
        udp.Read(r, &AnnounceRequest{})
-       all, _ := ioutil.ReadAll(r)
+       all, _ := io.ReadAll(r)
        if string(all) != "\x02\x09/announce" {
                t.FailNow()
        }