all: replace deprecated ioutil

Change-Id: I60b0bbf5b68b066e2d44b8b99438594d600a3c2d
This commit is contained in:
Egon Elbre 2022-10-31 17:12:17 +02:00 committed by Storj Robot
parent c25391e976
commit aeb645d32b
10 changed files with 13 additions and 23 deletions

View File

@ -9,7 +9,6 @@ import (
"bytes"
"context"
"io"
"io/ioutil"
"net/http"
"os"
"os/exec"
@ -42,7 +41,7 @@ func binaryVersion(location string) (version.SemVer, error) {
}
func downloadBinary(ctx context.Context, url, target string) error {
f, err := ioutil.TempFile("", createPattern(url))
f, err := os.CreateTemp("", createPattern(url))
if err != nil {
return errs.New("cannot create temporary archive: %v", err)
}

View File

@ -7,7 +7,6 @@ import (
"context"
"errors"
"io"
"io/ioutil"
"net"
"os"
"path/filepath"
@ -158,7 +157,7 @@ func NewCustom(ctx *testcontext.Context, log *zap.Logger, config Config, satelli
}
var err error
planet.directory, err = ioutil.TempDir("", "planet")
planet.directory, err = os.MkdirTemp("", "planet")
if err != nil {
return nil, err
}

View File

@ -10,7 +10,6 @@ import (
"errors"
"fmt"
"io"
"io/ioutil"
"log"
"net"
"os"
@ -71,7 +70,7 @@ func Start(ctx context.Context) (Server, error) {
// Process starts a redis-server test process.
func Process(ctx context.Context) (Server, error) {
tmpdir, err := ioutil.TempDir("", "storj-redis")
tmpdir, err := os.MkdirTemp("", "storj-redis")
if err != nil {
return nil, err
}

View File

@ -7,7 +7,6 @@ import (
"encoding/json"
"fmt"
"io"
"io/ioutil"
"net/http"
"net/http/cookiejar"
"strings"
@ -147,7 +146,7 @@ func (testClient *testClient) do(req *http.Request) (_ Response, body string) {
resp, err := testClient.client.Do(req)
require.NoError(testClient.t, err)
data, err := ioutil.ReadAll(resp.Body)
data, err := io.ReadAll(resp.Body)
require.NoError(testClient.t, err)
require.NoError(testClient.t, resp.Body.Close())
return Response{resp}, string(data)

View File

@ -16,7 +16,6 @@ import (
"flag"
"fmt"
"io"
"io/ioutil"
"math/rand"
"os"
"os/exec"
@ -176,7 +175,7 @@ func runTest() error {
configDir: configDir,
logLevel: "error",
}
tempDir, err := ioutil.TempDir("", "storj-test-network-stalls.")
tempDir, err := os.MkdirTemp("", "storj-test-network-stalls.")
if err != nil {
return err
}

View File

@ -6,7 +6,6 @@ package boltdb
import (
"context"
"fmt"
"io/ioutil"
"os"
"path/filepath"
"testing"
@ -18,7 +17,7 @@ import (
)
func TestSuite(t *testing.T) {
tempdir, err := ioutil.TempDir("", "storj-bolt")
tempdir, err := os.MkdirTemp("", "storj-bolt")
if err != nil {
t.Fatal(err)
}
@ -40,7 +39,7 @@ func TestSuite(t *testing.T) {
}
func BenchmarkSuite(b *testing.B) {
tempdir, err := ioutil.TempDir("", "storj-bolt")
tempdir, err := os.MkdirTemp("", "storj-bolt")
if err != nil {
b.Fatal(err)
}
@ -93,7 +92,7 @@ var _ testsuite.BulkImporter = &boltLongBenchmarkStore{}
var _ testsuite.BulkCleaner = &boltLongBenchmarkStore{}
func BenchmarkSuiteLong(b *testing.B) {
tempdir, err := ioutil.TempDir("", "storj-bolt")
tempdir, err := os.MkdirTemp("", "storj-bolt")
if err != nil {
b.Fatal(err)
}

View File

@ -9,7 +9,6 @@ import (
"encoding/base32"
"errors"
"io"
"io/ioutil"
"math"
"os"
"path/filepath"
@ -138,7 +137,7 @@ func (dir *Dir) CreateTemporaryFile(ctx context.Context, prealloc int64) (_ *os.
prealloc = preallocLimit
}
file, err := ioutil.TempFile(dir.tempdir(), "blob-*.partial")
file, err := os.CreateTemp(dir.tempdir(), "blob-*.partial")
if err != nil {
return nil, err
}

View File

@ -8,7 +8,6 @@ import (
"encoding/hex"
"errors"
"io"
"io/ioutil"
"os"
"path/filepath"
"time"
@ -261,7 +260,7 @@ func (store *blobStore) FreeSpace(ctx context.Context) (int64, error) {
// CheckWritability tests writability of the storage directory by creating and deleting a file.
func (store *blobStore) CheckWritability(ctx context.Context) error {
f, err := ioutil.TempFile(store.dir.Path(), "write-test")
f, err := os.CreateTemp(store.dir.Path(), "write-test")
if err != nil {
return err
}

View File

@ -10,7 +10,6 @@ import (
"fmt"
"go/format"
"io"
"io/ioutil"
"os"
"path/filepath"
"sort"
@ -56,7 +55,7 @@ func printWithLines(w io.Writer, data []byte) {
}
func runSchemaGen(ctx context.Context, log *zap.Logger) (_ []byte, err error) {
storagePath, err := ioutil.TempDir("", "testdb")
storagePath, err := os.MkdirTemp("", "testdb")
if err != nil {
return nil, errs.New("Error getting test storage path: %+w", err)
}

View File

@ -13,7 +13,6 @@ import (
"encoding/binary"
"encoding/pem"
"fmt"
"io/ioutil"
"math/big"
"net"
"os"
@ -146,12 +145,12 @@ func Edge(t *testing.T, test EdgeTest) {
func createSelfSignedCertificateFile(t *testing.T, hostname string) (certFile *os.File, keyFile *os.File, certificatePEM []byte, privateKeyPEM []byte) {
certificatePEM, privateKeyPEM = createSelfSignedCertificate(t, hostname)
certFile, err := ioutil.TempFile(os.TempDir(), "*-cert.pem")
certFile, err := os.CreateTemp(os.TempDir(), "*-cert.pem")
require.NoError(t, err)
_, err = certFile.Write(certificatePEM)
require.NoError(t, err)
keyFile, err = ioutil.TempFile(os.TempDir(), "*-key.pem")
keyFile, err = os.CreateTemp(os.TempDir(), "*-key.pem")
require.NoError(t, err)
_, err = keyFile.Write(privateKeyPEM)
require.NoError(t, err)