Merge pull request #3767 from thaJeztah/replace_ioutils

replace deprecated io/ioutil
This commit is contained in:
Hayley Swimelar 2022-11-08 09:13:08 +01:00 committed by GitHub
commit 4906c6ee88
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
33 changed files with 113 additions and 202 deletions

View file

@ -4,7 +4,6 @@ import (
"errors" "errors"
"fmt" "fmt"
"io" "io"
"io/ioutil"
"net/http" "net/http"
"reflect" "reflect"
"strings" "strings"
@ -654,7 +653,7 @@ type Proxy struct {
// Configuration.Abc may be replaced by the value of REGISTRY_ABC, // Configuration.Abc may be replaced by the value of REGISTRY_ABC,
// Configuration.Abc.Xyz may be replaced by the value of REGISTRY_ABC_XYZ, and so forth // Configuration.Abc.Xyz may be replaced by the value of REGISTRY_ABC_XYZ, and so forth
func Parse(rd io.Reader) (*Configuration, error) { func Parse(rd io.Reader) (*Configuration, error) {
in, err := ioutil.ReadAll(rd) in, err := io.ReadAll(rd)
if err != nil { if err != nil {
return nil, err return nil, err
} }

View file

@ -2,7 +2,7 @@ package htpasswd
import ( import (
"bytes" "bytes"
"io/ioutil" "io"
"net/http" "net/http"
"net/http/httptest" "net/http/httptest"
"os" "os"
@ -21,7 +21,7 @@ func TestBasicAccessController(t *testing.T) {
MiShil:$2y$05$0oHgwMehvoe8iAWS8I.7l.KoECXrwVaC16RPfaSCU5eVTFrATuMI2 MiShil:$2y$05$0oHgwMehvoe8iAWS8I.7l.KoECXrwVaC16RPfaSCU5eVTFrATuMI2
DeokMan:공주님` DeokMan:공주님`
tempFile, err := ioutil.TempFile("", "htpasswd-test") tempFile, err := os.CreateTemp("", "htpasswd-test")
if err != nil { if err != nil {
t.Fatal("could not create temporary htpasswd file") t.Fatal("could not create temporary htpasswd file")
} }
@ -122,7 +122,7 @@ func TestBasicAccessController(t *testing.T) {
} }
func TestCreateHtpasswdFile(t *testing.T) { func TestCreateHtpasswdFile(t *testing.T) {
tempFile, err := ioutil.TempFile("", "htpasswd-test") tempFile, err := os.CreateTemp("", "htpasswd-test")
if err != nil { if err != nil {
t.Fatalf("could not create temporary htpasswd file %v", err) t.Fatalf("could not create temporary htpasswd file %v", err)
} }
@ -135,7 +135,7 @@ func TestCreateHtpasswdFile(t *testing.T) {
if _, err := newAccessController(options); err != nil { if _, err := newAccessController(options); err != nil {
t.Fatalf("error creating access controller %v", err) t.Fatalf("error creating access controller %v", err)
} }
content, err := ioutil.ReadAll(tempFile) content, err := io.ReadAll(tempFile)
if err != nil { if err != nil {
t.Fatalf("failed to read file %v", err) t.Fatalf("failed to read file %v", err)
} }
@ -150,7 +150,7 @@ func TestCreateHtpasswdFile(t *testing.T) {
if _, err := newAccessController(options); err != nil { if _, err := newAccessController(options); err != nil {
t.Fatalf("error creating access controller %v", err) t.Fatalf("error creating access controller %v", err)
} }
content, err = ioutil.ReadFile(tempFile.Name()) content, err = os.ReadFile(tempFile.Name())
if err != nil { if err != nil {
t.Fatalf("failed to read file %v", err) t.Fatalf("failed to read file %v", err)
} }

View file

@ -7,7 +7,7 @@ import (
"encoding/pem" "encoding/pem"
"errors" "errors"
"fmt" "fmt"
"io/ioutil" "io"
"net/http" "net/http"
"os" "os"
"strings" "strings"
@ -187,7 +187,7 @@ func newAccessController(options map[string]interface{}) (auth.AccessController,
} }
defer fp.Close() defer fp.Close()
rawCertBundle, err := ioutil.ReadAll(fp) rawCertBundle, err := io.ReadAll(fp)
if err != nil { if err != nil {
return nil, fmt.Errorf("unable to read token auth root certificate bundle file %q: %s", config.rootCertBundle, err) return nil, fmt.Errorf("unable to read token auth root certificate bundle file %q: %s", config.rootCertBundle, err)
} }

View file

@ -8,7 +8,6 @@ import (
"encoding/json" "encoding/json"
"encoding/pem" "encoding/pem"
"fmt" "fmt"
"io/ioutil"
"net/http" "net/http"
"os" "os"
"strings" "strings"
@ -285,7 +284,7 @@ func writeTempRootCerts(rootKeys []libtrust.PrivateKey) (filename string, err er
return "", err return "", err
} }
tempFile, err := ioutil.TempFile("", "rootCertBundle") tempFile, err := os.CreateTemp("", "rootCertBundle")
if err != nil { if err != nil {
return "", err return "", err
} }

View file

@ -5,7 +5,6 @@ import (
"context" "context"
"fmt" "fmt"
"io" "io"
"io/ioutil"
"net/http" "net/http"
"time" "time"
@ -38,7 +37,7 @@ func (hbu *httpBlobUpload) handleErrorResponse(resp *http.Response) error {
} }
func (hbu *httpBlobUpload) ReadFrom(r io.Reader) (n int64, err error) { func (hbu *httpBlobUpload) ReadFrom(r io.Reader) (n int64, err error) {
req, err := http.NewRequestWithContext(hbu.ctx, http.MethodPatch, hbu.location, ioutil.NopCloser(r)) req, err := http.NewRequestWithContext(hbu.ctx, http.MethodPatch, hbu.location, io.NopCloser(r))
if err != nil { if err != nil {
return 0, err return 0, err
} }

View file

@ -5,7 +5,6 @@ import (
"errors" "errors"
"fmt" "fmt"
"io" "io"
"io/ioutil"
"net/http" "net/http"
"github.com/distribution/distribution/v3/registry/api/errcode" "github.com/distribution/distribution/v3/registry/api/errcode"
@ -40,7 +39,7 @@ func (e *UnexpectedHTTPResponseError) Error() string {
func parseHTTPErrorResponse(statusCode int, r io.Reader) error { func parseHTTPErrorResponse(statusCode int, r io.Reader) error {
var errors errcode.Errors var errors errcode.Errors
body, err := ioutil.ReadAll(r) body, err := io.ReadAll(r)
if err != nil { if err != nil {
return err return err
} }

View file

@ -7,7 +7,6 @@ import (
"errors" "errors"
"fmt" "fmt"
"io" "io"
"io/ioutil"
"net/http" "net/http"
"net/url" "net/url"
"strconv" "strconv"
@ -227,7 +226,7 @@ func (t *tags) All(ctx context.Context) ([]string, error) {
defer resp.Body.Close() defer resp.Body.Close()
if SuccessStatus(resp.StatusCode) { if SuccessStatus(resp.StatusCode) {
b, err := ioutil.ReadAll(resp.Body) b, err := io.ReadAll(resp.Body)
if err != nil { if err != nil {
return tags, err return tags, err
} }
@ -268,7 +267,7 @@ func descriptorFromResponse(response *http.Response) (distribution.Descriptor, e
digestHeader := headers.Get("Docker-Content-Digest") digestHeader := headers.Get("Docker-Content-Digest")
if digestHeader == "" { if digestHeader == "" {
data, err := ioutil.ReadAll(response.Body) data, err := io.ReadAll(response.Body)
if err != nil { if err != nil {
return distribution.Descriptor{}, err return distribution.Descriptor{}, err
} }
@ -527,7 +526,7 @@ func (ms *manifests) Get(ctx context.Context, dgst digest.Digest, options ...dis
} }
} }
mt := resp.Header.Get("Content-Type") mt := resp.Header.Get("Content-Type")
body, err := ioutil.ReadAll(resp.Body) body, err := io.ReadAll(resp.Body)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -674,7 +673,7 @@ func (bs *blobs) Get(ctx context.Context, dgst digest.Digest) ([]byte, error) {
} }
defer reader.Close() defer reader.Close()
return ioutil.ReadAll(reader) return io.ReadAll(reader)
} }
func (bs *blobs) Open(ctx context.Context, dgst digest.Digest) (distribution.ReadSeekCloser, error) { func (bs *blobs) Open(ctx context.Context, dgst digest.Digest) (distribution.ReadSeekCloser, error) {

View file

@ -6,7 +6,6 @@ import (
"encoding/json" "encoding/json"
"fmt" "fmt"
"io" "io"
"io/ioutil"
"log" "log"
"net/http" "net/http"
"net/http/httptest" "net/http/httptest"
@ -126,7 +125,7 @@ func TestBlobServeBlob(t *testing.T) {
t.Errorf("Error serving blob: %s", err.Error()) t.Errorf("Error serving blob: %s", err.Error())
} }
body, err := ioutil.ReadAll(resp.Body) body, err := io.ReadAll(resp.Body)
if err != nil { if err != nil {
t.Errorf("Error reading response body: %s", err.Error()) t.Errorf("Error reading response body: %s", err.Error())
} }
@ -175,7 +174,7 @@ func TestBlobServeBlobHEAD(t *testing.T) {
t.Errorf("Error serving blob: %s", err.Error()) t.Errorf("Error serving blob: %s", err.Error())
} }
body, err := ioutil.ReadAll(resp.Body) body, err := io.ReadAll(resp.Body)
if err != nil { if err != nil {
t.Errorf("Error reading response body: %s", err.Error()) t.Errorf("Error reading response body: %s", err.Error())
} }

View file

@ -7,7 +7,6 @@ import (
"errors" "errors"
"fmt" "fmt"
"io" "io"
"io/ioutil"
"net/http" "net/http"
"net/http/httptest" "net/http/httptest"
"net/http/httputil" "net/http/httputil"
@ -69,7 +68,7 @@ func TestCheckAPI(t *testing.T) {
"Content-Length": []string{"2"}, "Content-Length": []string{"2"},
}) })
p, err := ioutil.ReadAll(resp.Body) p, err := io.ReadAll(resp.Body)
if err != nil { if err != nil {
t.Fatalf("unexpected error reading response body: %v", err) t.Fatalf("unexpected error reading response body: %v", err)
} }
@ -1857,7 +1856,7 @@ func testManifestAPISchema2(t *testing.T, env *testEnv, imageName reference.Name
} }
defer resp.Body.Close() defer resp.Body.Close()
manifestBytes, err := ioutil.ReadAll(resp.Body) manifestBytes, err := io.ReadAll(resp.Body)
if err != nil { if err != nil {
t.Fatalf("error reading response body: %v", err) t.Fatalf("error reading response body: %v", err)
} }
@ -2091,7 +2090,7 @@ func testManifestAPIManifestList(t *testing.T, env *testEnv, args manifestArgs)
} }
defer resp.Body.Close() defer resp.Body.Close()
manifestBytes, err := ioutil.ReadAll(resp.Body) manifestBytes, err := io.ReadAll(resp.Body)
if err != nil { if err != nil {
t.Fatalf("error reading response body: %v", err) t.Fatalf("error reading response body: %v", err)
} }
@ -2614,7 +2613,7 @@ func checkResponse(t *testing.T, msg string, resp *http.Response, expectedStatus
// expected error codes, returning the error structure, the json slice and a // expected error codes, returning the error structure, the json slice and a
// count of the errors by code. // count of the errors by code.
func checkBodyHasErrorCodes(t *testing.T, msg string, resp *http.Response, errorCodes ...errcode.ErrorCode) (errcode.Errors, []byte, map[errcode.ErrorCode]int) { func checkBodyHasErrorCodes(t *testing.T, msg string, resp *http.Response, errorCodes ...errcode.ErrorCode) (errcode.Errors, []byte, map[errcode.ErrorCode]int) {
p, err := ioutil.ReadAll(resp.Body) p, err := io.ReadAll(resp.Body)
if err != nil { if err != nil {
t.Fatalf("unexpected error reading body %s: %v", msg, err) t.Fatalf("unexpected error reading body %s: %v", msg, err)
} }

View file

@ -1,7 +1,6 @@
package handlers package handlers
import ( import (
"io/ioutil"
"net" "net"
"net/http" "net/http"
"net/http/httptest" "net/http/httptest"
@ -17,7 +16,7 @@ import (
func TestFileHealthCheck(t *testing.T) { func TestFileHealthCheck(t *testing.T) {
interval := time.Second interval := time.Second
tmpfile, err := ioutil.TempFile(os.TempDir(), "healthcheck") tmpfile, err := os.CreateTemp(os.TempDir(), "healthcheck")
if err != nil { if err != nil {
t.Fatalf("could not create temporary file: %v", err) t.Fatalf("could not create temporary file: %v", err)
} }

View file

@ -2,7 +2,6 @@ package proxy
import ( import (
"context" "context"
"io/ioutil"
"math/rand" "math/rand"
"net/http" "net/http"
"net/http/httptest" "net/http/httptest"
@ -114,6 +113,8 @@ func (te *testEnv) RemoteStats() *map[string]int {
// Populate remote store and record the digests // Populate remote store and record the digests
func makeTestEnv(t *testing.T, name string) *testEnv { func makeTestEnv(t *testing.T, name string) *testEnv {
t.Helper()
nameRef, err := reference.WithName(name) nameRef, err := reference.WithName(name)
if err != nil { if err != nil {
t.Fatalf("unable to parse reference: %s", err) t.Fatalf("unable to parse reference: %s", err)
@ -121,15 +122,8 @@ func makeTestEnv(t *testing.T, name string) *testEnv {
ctx := context.Background() ctx := context.Background()
truthDir, err := ioutil.TempDir("", "truth") truthDir := t.TempDir()
if err != nil { cacheDir := t.TempDir()
t.Fatalf("unable to create tempdir: %s", err)
}
cacheDir, err := ioutil.TempDir("", "cache")
if err != nil {
t.Fatalf("unable to create tempdir: %s", err)
}
localDriver, err := filesystem.FromParameters(map[string]interface{}{ localDriver, err := filesystem.FromParameters(map[string]interface{}{
"rootdirectory": truthDir, "rootdirectory": truthDir,

View file

@ -5,7 +5,6 @@ import (
"crypto/tls" "crypto/tls"
"crypto/x509" "crypto/x509"
"fmt" "fmt"
"io/ioutil"
"net/http" "net/http"
"os" "os"
"os/signal" "os/signal"
@ -268,7 +267,7 @@ func (registry *Registry) ListenAndServe() error {
pool := x509.NewCertPool() pool := x509.NewCertPool()
for _, ca := range config.HTTP.TLS.ClientCAs { for _, ca := range config.HTTP.TLS.ClientCAs {
caPem, err := ioutil.ReadFile(ca) caPem, err := os.ReadFile(ca)
if err != nil { if err != nil {
return err return err
} }

View file

@ -13,7 +13,7 @@ import (
"crypto/x509/pkix" "crypto/x509/pkix"
"encoding/pem" "encoding/pem"
"fmt" "fmt"
"io/ioutil" "io"
"math/big" "math/big"
"net" "net"
"net/http" "net/http"
@ -121,7 +121,7 @@ func TestGracefulShutdown(t *testing.T) {
if resp.Status != "200 OK" { if resp.Status != "200 OK" {
t.Error("response status is not 200 OK: ", resp.Status) t.Error("response status is not 200 OK: ", resp.Status)
} }
if body, err := ioutil.ReadAll(resp.Body); err != nil || string(body) != "{}" { if body, err := io.ReadAll(resp.Body); err != nil || string(body) != "{}" {
t.Error("Body is not {}; ", string(body)) t.Error("Body is not {}; ", string(body))
} }
} }
@ -316,7 +316,7 @@ func TestRegistrySupportedCipherSuite(t *testing.T) {
if resp.Status != "200 OK" { if resp.Status != "200 OK" {
t.Error("response status is not 200 OK: ", resp.Status) t.Error("response status is not 200 OK: ", resp.Status)
} }
if body, err := ioutil.ReadAll(resp.Body); err != nil || string(body) != "{}" { if body, err := io.ReadAll(resp.Body); err != nil || string(body) != "{}" {
t.Error("Body is not {}; ", string(body)) t.Error("Body is not {}; ", string(body))
} }

View file

@ -6,7 +6,6 @@ import (
"crypto/sha256" "crypto/sha256"
"fmt" "fmt"
"io" "io"
"io/ioutil"
"path" "path"
"reflect" "reflect"
"testing" "testing"
@ -210,7 +209,7 @@ func TestSimpleBlobUpload(t *testing.T) {
} }
// Re-upload the blob // Re-upload the blob
randomBlob, err := ioutil.ReadAll(randomDataReader) randomBlob, err := io.ReadAll(randomDataReader)
if err != nil { if err != nil {
t.Fatalf("Error reading all of blob %s", err.Error()) t.Fatalf("Error reading all of blob %s", err.Error())
} }
@ -328,7 +327,7 @@ func TestSimpleBlobRead(t *testing.T) {
t.Fatalf("seek failed: expected 0 offset, got %d", offset) t.Fatalf("seek failed: expected 0 offset, got %d", offset)
} }
p, err := ioutil.ReadAll(rc) p, err := io.ReadAll(rc)
if err != nil { if err != nil {
t.Fatalf("error reading all of blob: %v", err) t.Fatalf("error reading all of blob: %v", err)
} }
@ -343,7 +342,7 @@ func TestSimpleBlobRead(t *testing.T) {
t.Fatalf("error resetting layer reader: %v", err) t.Fatalf("error resetting layer reader: %v", err)
} }
randomLayerData, err := ioutil.ReadAll(randomLayerReader) randomLayerData, err := io.ReadAll(randomLayerReader)
if err != nil { if err != nil {
t.Fatalf("random layer read failed: %v", err) t.Fatalf("random layer read failed: %v", err)
} }

View file

@ -8,7 +8,6 @@ import (
"context" "context"
"fmt" "fmt"
"io" "io"
"io/ioutil"
"net/http" "net/http"
"strings" "strings"
"time" "time"
@ -115,7 +114,7 @@ func (d *driver) GetContent(ctx context.Context, path string) ([]byte, error) {
} }
defer blob.Close() defer blob.Close()
return ioutil.ReadAll(blob) return io.ReadAll(blob)
} }
// PutContent stores the []byte content at a location designated by "path". // PutContent stores the []byte content at a location designated by "path".
@ -172,7 +171,7 @@ func (d *driver) Reader(ctx context.Context, path string, offset int64) (io.Read
info := blobRef.Properties info := blobRef.Properties
size := info.ContentLength size := info.ContentLength
if offset >= size { if offset >= size {
return ioutil.NopCloser(bytes.NewReader(nil)), nil return io.NopCloser(bytes.NewReader(nil)), nil
} }
resp, err := blobRef.GetRange(&azure.GetBlobRangeOptions{ resp, err := blobRef.GetRange(&azure.GetBlobRangeOptions{

View file

@ -6,7 +6,6 @@ import (
"context" "context"
"fmt" "fmt"
"io" "io"
"io/ioutil"
"os" "os"
"path" "path"
"time" "time"
@ -123,7 +122,7 @@ func (d *driver) GetContent(ctx context.Context, path string) ([]byte, error) {
} }
defer rc.Close() defer rc.Close()
p, err := ioutil.ReadAll(rc) p, err := io.ReadAll(rc)
if err != nil { if err != nil {
return nil, err return nil, err
} }

View file

@ -1,7 +1,6 @@
package filesystem package filesystem
import ( import (
"io/ioutil"
"os" "os"
"reflect" "reflect"
"testing" "testing"
@ -15,13 +14,13 @@ import (
func Test(t *testing.T) { TestingT(t) } func Test(t *testing.T) { TestingT(t) }
func init() { func init() {
root, err := ioutil.TempDir("", "driver-") root, err := os.MkdirTemp("", "driver-")
if err != nil { if err != nil {
panic(err) panic(err)
} }
defer os.Remove(root) defer os.Remove(root)
driver, err := FromParameters(map[string]interface{}{ drvr, err := FromParameters(map[string]interface{}{
"rootdirectory": root, "rootdirectory": root,
}) })
if err != nil { if err != nil {
@ -29,7 +28,7 @@ func init() {
} }
testsuites.RegisterSuite(func() (storagedriver.StorageDriver, error) { testsuites.RegisterSuite(func() (storagedriver.StorageDriver, error) {
return driver, nil return drvr, nil
}, testsuites.NeverSkip) }, testsuites.NeverSkip)
} }

View file

@ -21,10 +21,10 @@ import (
"encoding/json" "encoding/json"
"fmt" "fmt"
"io" "io"
"io/ioutil"
"math/rand" "math/rand"
"net/http" "net/http"
"net/url" "net/url"
"os"
"reflect" "reflect"
"regexp" "regexp"
"sort" "sort"
@ -151,7 +151,7 @@ func FromParameters(parameters map[string]interface{}) (storagedriver.StorageDri
var ts oauth2.TokenSource var ts oauth2.TokenSource
jwtConf := new(jwt.Config) jwtConf := new(jwt.Config)
if keyfile, ok := parameters["keyfile"]; ok { if keyfile, ok := parameters["keyfile"]; ok {
jsonKey, err := ioutil.ReadFile(fmt.Sprint(keyfile)) jsonKey, err := os.ReadFile(fmt.Sprint(keyfile))
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -263,7 +263,7 @@ func (d *driver) GetContent(context context.Context, path string) ([]byte, error
} }
defer rc.Close() defer rc.Close()
p, err := ioutil.ReadAll(rc) p, err := io.ReadAll(rc)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -299,7 +299,7 @@ func (d *driver) Reader(context context.Context, path string, offset int64) (io.
return nil, err return nil, err
} }
if offset == int64(obj.Size) { if offset == int64(obj.Size) {
return ioutil.NopCloser(bytes.NewReader([]byte{})), nil return io.NopCloser(bytes.NewReader([]byte{})), nil
} }
return nil, storagedriver.InvalidOffsetError{Path: path, Offset: offset} return nil, storagedriver.InvalidOffsetError{Path: path, Offset: offset}
} }
@ -557,7 +557,7 @@ func (w *writer) init(path string) error {
if err != nil { if err != nil {
return err return err
} }
buffer, err := ioutil.ReadAll(res.Body) buffer, err := io.ReadAll(res.Body)
if err != nil { if err != nil {
return err return err
} }

View file

@ -5,7 +5,6 @@ package gcs
import ( import (
"fmt" "fmt"
"io/ioutil"
"os" "os"
"testing" "testing"
@ -43,7 +42,7 @@ func init() {
return return
} }
root, err := ioutil.TempDir("", "driver-") root, err := os.MkdirTemp("", "driver-")
if err != nil { if err != nil {
panic(err) panic(err)
} }
@ -95,11 +94,7 @@ func TestCommitEmpty(t *testing.T) {
t.Skip(skipGCS()) t.Skip(skipGCS())
} }
validRoot, err := ioutil.TempDir("", "driver-") validRoot := t.TempDir()
if err != nil {
t.Fatalf("unexpected error creating temporary directory: %v", err)
}
defer os.Remove(validRoot)
driver, err := gcsDriverConstructor(validRoot) driver, err := gcsDriverConstructor(validRoot)
if err != nil { if err != nil {
@ -141,11 +136,7 @@ func TestCommit(t *testing.T) {
t.Skip(skipGCS()) t.Skip(skipGCS())
} }
validRoot, err := ioutil.TempDir("", "driver-") validRoot := t.TempDir()
if err != nil {
t.Fatalf("unexpected error creating temporary directory: %v", err)
}
defer os.Remove(validRoot)
driver, err := gcsDriverConstructor(validRoot) driver, err := gcsDriverConstructor(validRoot)
if err != nil { if err != nil {
@ -227,11 +218,7 @@ func TestEmptyRootList(t *testing.T) {
t.Skip(skipGCS()) t.Skip(skipGCS())
} }
validRoot, err := ioutil.TempDir("", "driver-") validRoot := t.TempDir()
if err != nil {
t.Fatalf("unexpected error creating temporary directory: %v", err)
}
defer os.Remove(validRoot)
rootedDriver, err := gcsDriverConstructor(validRoot) rootedDriver, err := gcsDriverConstructor(validRoot)
if err != nil { if err != nil {
@ -282,11 +269,7 @@ func TestMoveDirectory(t *testing.T) {
t.Skip(skipGCS()) t.Skip(skipGCS())
} }
validRoot, err := ioutil.TempDir("", "driver-") validRoot := t.TempDir()
if err != nil {
t.Fatalf("unexpected error creating temporary directory: %v", err)
}
defer os.Remove(validRoot)
driver, err := gcsDriverConstructor(validRoot) driver, err := gcsDriverConstructor(validRoot)
if err != nil { if err != nil {

View file

@ -4,7 +4,6 @@ import (
"context" "context"
"fmt" "fmt"
"io" "io"
"io/ioutil"
"sync" "sync"
"time" "time"
@ -79,7 +78,7 @@ func (d *driver) GetContent(ctx context.Context, path string) ([]byte, error) {
} }
defer rc.Close() defer rc.Close()
return ioutil.ReadAll(rc) return io.ReadAll(rc)
} }
// PutContent stores the []byte content at a location designated by "path". // PutContent stores the []byte content at a location designated by "path".
@ -127,7 +126,7 @@ func (d *driver) reader(ctx context.Context, path string, offset int64) (io.Read
return nil, fmt.Errorf("%q is a directory", path) return nil, fmt.Errorf("%q is a directory", path)
} }
return ioutil.NopCloser(found.(*file).sectionReader(offset)), nil return io.NopCloser(found.(*file).sectionReader(offset)), nil
} }
// Writer returns a FileWriter which will store the content written to it // Writer returns a FileWriter which will store the content written to it

View file

@ -7,8 +7,8 @@ import (
"crypto/x509" "crypto/x509"
"encoding/pem" "encoding/pem"
"fmt" "fmt"
"io/ioutil"
"net/url" "net/url"
"os"
"strings" "strings"
"time" "time"
@ -89,7 +89,7 @@ func newCloudFrontStorageMiddleware(storageDriver storagedriver.StorageDriver, o
} }
// get urlSigner from the file specified in pkPath // get urlSigner from the file specified in pkPath
pkBytes, err := ioutil.ReadFile(pkPath) pkBytes, err := os.ReadFile(pkPath)
if err != nil { if err != nil {
return nil, fmt.Errorf("failed to read privatekey file: %s", err) return nil, fmt.Errorf("failed to read privatekey file: %s", err)
} }

View file

@ -1,7 +1,6 @@
package middleware package middleware
import ( import (
"io/ioutil"
"os" "os"
"testing" "testing"
@ -41,7 +40,7 @@ pZeMRablbPQdp8/1NyIwimq1VlG0ohQ4P6qhW7E09ZMC
-----END RSA PRIVATE KEY----- -----END RSA PRIVATE KEY-----
` `
file, err := ioutil.TempFile("", "pkey") file, err := os.CreateTemp("", "pkey")
if err != nil { if err != nil {
t.Fatal("File cannot be created") t.Fatal("File cannot be created")
} }

View file

@ -4,7 +4,7 @@ import (
"context" "context"
"encoding/json" "encoding/json"
"fmt" "fmt"
"io/ioutil" "io"
"net" "net"
"net/http" "net/http"
"strings" "strings"
@ -68,7 +68,7 @@ func fetchAWSIPs(url string) (awsIPResponse, error) {
return response, err return response, err
} }
if resp.StatusCode != 200 { if resp.StatusCode != 200 {
body, _ := ioutil.ReadAll(resp.Body) body, _ := io.ReadAll(resp.Body)
return response, fmt.Errorf("failed to fetch network data. response = %s", body) return response, fmt.Errorf("failed to fetch network data. response = %s", body)
} }
decoder := json.NewDecoder(resp.Body) decoder := json.NewDecoder(resp.Body)

View file

@ -17,7 +17,6 @@ import (
"context" "context"
"fmt" "fmt"
"io" "io"
"io/ioutil"
"net/http" "net/http"
"reflect" "reflect"
"strconv" "strconv"
@ -273,7 +272,7 @@ func (d *driver) Reader(ctx context.Context, path string, offset int64) (io.Read
// OSS sever will always return http.StatusPartialContent if range is acceptable. // OSS sever will always return http.StatusPartialContent if range is acceptable.
if resp.StatusCode != http.StatusPartialContent { if resp.StatusCode != http.StatusPartialContent {
resp.Body.Close() resp.Body.Close()
return ioutil.NopCloser(bytes.NewReader(nil)), nil return io.NopCloser(bytes.NewReader(nil)), nil
} }
return resp.Body, nil return resp.Body, nil

View file

@ -4,7 +4,6 @@
package oss package oss
import ( import (
"io/ioutil"
"os" "os"
"strconv" "strconv"
"testing" "testing"
@ -36,7 +35,7 @@ func init() {
encryptionKeyID = os.Getenv("OSS_ENCRYPTIONKEYID") encryptionKeyID = os.Getenv("OSS_ENCRYPTIONKEYID")
) )
root, err := ioutil.TempDir("", "driver-") root, err := os.MkdirTemp("", "driver-")
if err != nil { if err != nil {
panic(err) panic(err)
} }
@ -102,11 +101,7 @@ func TestEmptyRootList(t *testing.T) {
t.Skip(skipCheck()) t.Skip(skipCheck())
} }
validRoot, err := ioutil.TempDir("", "driver-") validRoot := t.TempDir()
if err != nil {
t.Fatalf("unexpected error creating temporary directory: %v", err)
}
defer os.Remove(validRoot)
rootedDriver, err := ossDriverConstructor(validRoot) rootedDriver, err := ossDriverConstructor(validRoot)
if err != nil { if err != nil {

View file

@ -18,7 +18,6 @@ import (
"errors" "errors"
"fmt" "fmt"
"io" "io"
"io/ioutil"
"math" "math"
"net/http" "net/http"
"path/filepath" "path/filepath"
@ -607,7 +606,7 @@ func (d *driver) GetContent(ctx context.Context, path string) ([]byte, error) {
if err != nil { if err != nil {
return nil, err return nil, err
} }
return ioutil.ReadAll(reader) return io.ReadAll(reader)
} }
// PutContent stores the []byte content at a location designated by "path". // PutContent stores the []byte content at a location designated by "path".
@ -635,7 +634,7 @@ func (d *driver) Reader(ctx context.Context, path string, offset int64) (io.Read
}) })
if err != nil { if err != nil {
if s3Err, ok := err.(awserr.Error); ok && s3Err.Code() == "InvalidRange" { if s3Err, ok := err.(awserr.Error); ok && s3Err.Code() == "InvalidRange" {
return ioutil.NopCloser(bytes.NewReader(nil)), nil return io.NopCloser(bytes.NewReader(nil)), nil
} }
return nil, parseError(path, err) return nil, parseError(path, err)
@ -1356,7 +1355,7 @@ func (w *writer) Write(p []byte) (int, error) {
} }
defer resp.Body.Close() defer resp.Body.Close()
w.parts = nil w.parts = nil
w.readyPart, err = ioutil.ReadAll(resp.Body) w.readyPart, err = io.ReadAll(resp.Body)
if err != nil { if err != nil {
return 0, err return 0, err
} }

View file

@ -4,7 +4,6 @@ import (
"bytes" "bytes"
"errors" "errors"
"fmt" "fmt"
"io/ioutil"
"math/rand" "math/rand"
"os" "os"
"path" "path"
@ -52,7 +51,7 @@ func init() {
accelerate = os.Getenv("S3_ACCELERATE") accelerate = os.Getenv("S3_ACCELERATE")
) )
root, err := ioutil.TempDir("", "driver-") root, err := os.MkdirTemp("", "driver-")
if err != nil { if err != nil {
panic(err) panic(err)
} }
@ -166,12 +165,7 @@ func TestEmptyRootList(t *testing.T) {
t.Skip(skipS3()) t.Skip(skipS3())
} }
validRoot, err := ioutil.TempDir("", "driver-") validRoot := t.TempDir()
if err != nil {
t.Fatalf("unexpected error creating temporary directory: %v", err)
}
defer os.Remove(validRoot)
rootedDriver, err := s3DriverConstructor(validRoot, s3.StorageClassStandard) rootedDriver, err := s3DriverConstructor(validRoot, s3.StorageClassStandard)
if err != nil { if err != nil {
t.Fatalf("unexpected error creating rooted driver: %v", err) t.Fatalf("unexpected error creating rooted driver: %v", err)
@ -204,9 +198,9 @@ func TestEmptyRootList(t *testing.T) {
} }
keys, _ = slashRootDriver.List(ctx, "/") keys, _ = slashRootDriver.List(ctx, "/")
for _, path := range keys { for _, p := range keys {
if !storagedriver.PathRegexp.MatchString(path) { if !storagedriver.PathRegexp.MatchString(p) {
t.Fatalf("unexpected string in path: %q != %q", path, storagedriver.PathRegexp) t.Fatalf("unexpected string in path: %q != %q", p, storagedriver.PathRegexp)
} }
} }
} }
@ -249,12 +243,7 @@ func TestStorageClass(t *testing.T) {
t.Skip(skipS3()) t.Skip(skipS3())
} }
rootDir, err := ioutil.TempDir("", "driver-") rootDir := t.TempDir()
if err != nil {
t.Fatalf("unexpected error creating temporary directory: %v", err)
}
defer os.Remove(rootDir)
contents := []byte("contents") contents := []byte("contents")
ctx := context.Background() ctx := context.Background()
for _, storageClass := range s3StorageClasses { for _, storageClass := range s3StorageClasses {
@ -307,13 +296,9 @@ func TestDelete(t *testing.T) {
t.Skip(skipS3()) t.Skip(skipS3())
} }
rootDir, err := ioutil.TempDir("", "driver-") rootDir := t.TempDir()
if err != nil {
t.Fatalf("unexpected error creating temporary directory: %v", err)
}
defer os.Remove(rootDir)
driver, err := s3DriverConstructor(rootDir, s3.StorageClassStandard) drvr, err := s3DriverConstructor(rootDir, s3.StorageClassStandard)
if err != nil { if err != nil {
t.Fatalf("unexpected error creating driver with standard storage: %v", err) t.Fatalf("unexpected error creating driver with standard storage: %v", err)
} }
@ -421,35 +406,35 @@ func TestDelete(t *testing.T) {
"/file1": true, "/file1": true,
} }
// create a test case for each file // create a test case for each file
for _, path := range objs { for _, p := range objs {
if skipCase[path] { if skipCase[p] {
continue continue
} }
tcs = append(tcs, testCase{ tcs = append(tcs, testCase{
name: fmt.Sprintf("delete path:'%s'", path), name: fmt.Sprintf("delete path:'%s'", p),
delete: path, delete: p,
expected: []string{path}, expected: []string{p},
}) })
} }
init := func() []string { init := func() []string {
// init file structure matching objs // init file structure matching objs
var created []string var created []string
for _, path := range objs { for _, p := range objs {
err := driver.PutContent(context.Background(), path, []byte("content "+path)) err := drvr.PutContent(context.Background(), p, []byte("content "+p))
if err != nil { if err != nil {
fmt.Printf("unable to init file %s: %s\n", path, err) fmt.Printf("unable to init file %s: %s\n", p, err)
continue continue
} }
created = append(created, path) created = append(created, p)
} }
return created return created
} }
cleanup := func(objs []string) { cleanup := func(objs []string) {
var lastErr error var lastErr error
for _, path := range objs { for _, p := range objs {
err := driver.Delete(context.Background(), path) err := drvr.Delete(context.Background(), p)
if err != nil { if err != nil {
switch err.(type) { switch err.(type) {
case storagedriver.PathNotFoundError: case storagedriver.PathNotFoundError:
@ -468,7 +453,7 @@ func TestDelete(t *testing.T) {
t.Run(tc.name, func(t *testing.T) { t.Run(tc.name, func(t *testing.T) {
objs := init() objs := init()
err := driver.Delete(context.Background(), tc.delete) err := drvr.Delete(context.Background(), tc.delete)
if tc.err != nil { if tc.err != nil {
if err == nil { if err == nil {
@ -496,7 +481,7 @@ func TestDelete(t *testing.T) {
return false return false
} }
for _, path := range objs { for _, path := range objs {
stat, err := driver.Stat(context.Background(), path) stat, err := drvr.Stat(context.Background(), path)
if err != nil { if err != nil {
switch err.(type) { switch err.(type) {
case storagedriver.PathNotFoundError: case storagedriver.PathNotFoundError:
@ -530,13 +515,9 @@ func TestWalk(t *testing.T) {
t.Skip(skipS3()) t.Skip(skipS3())
} }
rootDir, err := ioutil.TempDir("", "driver-") rootDir := t.TempDir()
if err != nil {
t.Fatalf("unexpected error creating temporary directory: %v", err)
}
defer os.Remove(rootDir)
driver, err := s3DriverConstructor(rootDir, s3.StorageClassStandard) drvr, err := s3DriverConstructor(rootDir, s3.StorageClassStandard)
if err != nil { if err != nil {
t.Fatalf("unexpected error creating driver with standard storage: %v", err) t.Fatalf("unexpected error creating driver with standard storage: %v", err)
} }
@ -552,22 +533,22 @@ func TestWalk(t *testing.T) {
// create file structure matching fileset above // create file structure matching fileset above
var created []string var created []string
for _, path := range fileset { for _, p := range fileset {
err := driver.PutContent(context.Background(), path, []byte("content "+path)) err := drvr.PutContent(context.Background(), p, []byte("content "+p))
if err != nil { if err != nil {
fmt.Printf("unable to create file %s: %s\n", path, err) fmt.Printf("unable to create file %s: %s\n", p, err)
continue continue
} }
created = append(created, path) created = append(created, p)
} }
// cleanup // cleanup
defer func() { defer func() {
var lastErr error var lastErr error
for _, path := range created { for _, p := range created {
err := driver.Delete(context.Background(), path) err := drvr.Delete(context.Background(), p)
if err != nil { if err != nil {
_ = fmt.Errorf("cleanup failed for path %s: %s", path, err) _ = fmt.Errorf("cleanup failed for path %s: %s", p, err)
lastErr = err lastErr = err
} }
} }
@ -669,7 +650,7 @@ func TestWalk(t *testing.T) {
tc.from = "/" tc.from = "/"
} }
t.Run(tc.name, func(t *testing.T) { t.Run(tc.name, func(t *testing.T) {
err := driver.Walk(context.Background(), tc.from, func(fileInfo storagedriver.FileInfo) error { err := drvr.Walk(context.Background(), tc.from, func(fileInfo storagedriver.FileInfo) error {
walked = append(walked, fileInfo.Path()) walked = append(walked, fileInfo.Path())
return tc.fn(fileInfo) return tc.fn(fileInfo)
}) })
@ -689,12 +670,7 @@ func TestOverThousandBlobs(t *testing.T) {
t.Skip(skipS3()) t.Skip(skipS3())
} }
rootDir, err := ioutil.TempDir("", "driver-") rootDir := t.TempDir()
if err != nil {
t.Fatalf("unexpected error creating temporary directory: %v", err)
}
defer os.Remove(rootDir)
standardDriver, err := s3DriverConstructor(rootDir, s3.StorageClassStandard) standardDriver, err := s3DriverConstructor(rootDir, s3.StorageClassStandard)
if err != nil { if err != nil {
t.Fatalf("unexpected error creating driver with standard storage: %v", err) t.Fatalf("unexpected error creating driver with standard storage: %v", err)
@ -722,12 +698,7 @@ func TestMoveWithMultipartCopy(t *testing.T) {
t.Skip(skipS3()) t.Skip(skipS3())
} }
rootDir, err := ioutil.TempDir("", "driver-") rootDir := t.TempDir()
if err != nil {
t.Fatalf("unexpected error creating temporary directory: %v", err)
}
defer os.Remove(rootDir)
d, err := s3DriverConstructor(rootDir, s3.StorageClassStandard) d, err := s3DriverConstructor(rootDir, s3.StorageClassStandard)
if err != nil { if err != nil {
t.Fatalf("unexpected error creating driver: %v", err) t.Fatalf("unexpected error creating driver: %v", err)
@ -776,12 +747,7 @@ func TestListObjectsV2(t *testing.T) {
t.Skip(skipS3()) t.Skip(skipS3())
} }
rootDir, err := ioutil.TempDir("", "driver-") rootDir := t.TempDir()
if err != nil {
t.Fatalf("unexpected error creating temporary directory: %v", err)
}
defer os.Remove(rootDir)
d, err := s3DriverConstructor(rootDir, s3.StorageClassStandard) d, err := s3DriverConstructor(rootDir, s3.StorageClassStandard)
if err != nil { if err != nil {
t.Fatalf("unexpected error creating driver: %v", err) t.Fatalf("unexpected error creating driver: %v", err)
@ -794,8 +760,8 @@ func TestListObjectsV2(t *testing.T) {
for i := 0; i < n; i++ { for i := 0; i < n; i++ {
filePaths = append(filePaths, fmt.Sprintf("%s/%d", prefix, i)) filePaths = append(filePaths, fmt.Sprintf("%s/%d", prefix, i))
} }
for _, path := range filePaths { for _, p := range filePaths {
if err := d.PutContent(ctx, path, []byte(path)); err != nil { if err := d.PutContent(ctx, p, []byte(p)); err != nil {
t.Fatalf("unexpected error putting content: %v", err) t.Fatalf("unexpected error putting content: %v", err)
} }
} }

View file

@ -25,7 +25,6 @@ import (
"encoding/hex" "encoding/hex"
"fmt" "fmt"
"io" "io"
"io/ioutil"
"net/http" "net/http"
"net/url" "net/url"
"strconv" "strconv"
@ -336,7 +335,7 @@ func (d *driver) Reader(ctx context.Context, path string, offset int64) (io.Read
return nil, storagedriver.PathNotFoundError{Path: path} return nil, storagedriver.PathNotFoundError{Path: path}
} }
if swiftErr, ok := err.(*swift.Error); ok && swiftErr.StatusCode == http.StatusRequestedRangeNotSatisfiable { if swiftErr, ok := err.(*swift.Error); ok && swiftErr.StatusCode == http.StatusRequestedRangeNotSatisfiable {
return ioutil.NopCloser(bytes.NewReader(nil)), nil return io.NopCloser(bytes.NewReader(nil)), nil
} }
return file, err return file, err
} }

View file

@ -1,7 +1,6 @@
package swift package swift
import ( import (
"io/ioutil"
"os" "os"
"reflect" "reflect"
"strconv" "strconv"
@ -58,7 +57,7 @@ func init() {
container = "test" container = "test"
} }
prefix, err := ioutil.TempDir("", "driver-") prefix, err := os.MkdirTemp("", "driver-")
if err != nil { if err != nil {
panic(err) panic(err)
} }
@ -100,11 +99,7 @@ func init() {
} }
func TestEmptyRootList(t *testing.T) { func TestEmptyRootList(t *testing.T) {
validRoot, err := ioutil.TempDir("", "driver-") validRoot := t.TempDir()
if err != nil {
t.Fatalf("unexpected error creating temporary directory: %v", err)
}
defer os.Remove(validRoot)
rootedDriver, err := swiftDriverConstructor(validRoot) rootedDriver, err := swiftDriverConstructor(validRoot)
if err != nil { if err != nil {

View file

@ -5,7 +5,6 @@ import (
"context" "context"
"crypto/sha256" "crypto/sha256"
"io" "io"
"io/ioutil"
"math/rand" "math/rand"
"net/http" "net/http"
"os" "os"
@ -325,7 +324,7 @@ func (suite *DriverSuite) TestReaderWithOffset(c *check.C) {
c.Assert(err, check.IsNil) c.Assert(err, check.IsNil)
defer reader.Close() defer reader.Close()
readContents, err := ioutil.ReadAll(reader) readContents, err := io.ReadAll(reader)
c.Assert(err, check.IsNil) c.Assert(err, check.IsNil)
c.Assert(readContents, check.DeepEquals, append(append(contentsChunk1, contentsChunk2...), contentsChunk3...)) c.Assert(readContents, check.DeepEquals, append(append(contentsChunk1, contentsChunk2...), contentsChunk3...))
@ -334,7 +333,7 @@ func (suite *DriverSuite) TestReaderWithOffset(c *check.C) {
c.Assert(err, check.IsNil) c.Assert(err, check.IsNil)
defer reader.Close() defer reader.Close()
readContents, err = ioutil.ReadAll(reader) readContents, err = io.ReadAll(reader)
c.Assert(err, check.IsNil) c.Assert(err, check.IsNil)
c.Assert(readContents, check.DeepEquals, append(contentsChunk2, contentsChunk3...)) c.Assert(readContents, check.DeepEquals, append(contentsChunk2, contentsChunk3...))
@ -343,7 +342,7 @@ func (suite *DriverSuite) TestReaderWithOffset(c *check.C) {
c.Assert(err, check.IsNil) c.Assert(err, check.IsNil)
defer reader.Close() defer reader.Close()
readContents, err = ioutil.ReadAll(reader) readContents, err = io.ReadAll(reader)
c.Assert(err, check.IsNil) c.Assert(err, check.IsNil)
c.Assert(readContents, check.DeepEquals, contentsChunk3) c.Assert(readContents, check.DeepEquals, contentsChunk3)
@ -643,7 +642,7 @@ func (suite *DriverSuite) TestURLFor(c *check.C) {
c.Assert(err, check.IsNil) c.Assert(err, check.IsNil)
defer response.Body.Close() defer response.Body.Close()
read, err := ioutil.ReadAll(response.Body) read, err := io.ReadAll(response.Body)
c.Assert(err, check.IsNil) c.Assert(err, check.IsNil)
c.Assert(read, check.DeepEquals, contents) c.Assert(read, check.DeepEquals, contents)
@ -874,7 +873,7 @@ func (suite *DriverSuite) TestConcurrentStreamReads(c *check.C) {
reader, err := suite.StorageDriver.Reader(suite.ctx, filename, offset) reader, err := suite.StorageDriver.Reader(suite.ctx, filename, offset)
c.Assert(err, check.IsNil) c.Assert(err, check.IsNil)
readContents, err := ioutil.ReadAll(reader) readContents, err := io.ReadAll(reader)
c.Assert(err, check.IsNil) c.Assert(err, check.IsNil)
c.Assert(readContents, check.DeepEquals, contents[offset:]) c.Assert(readContents, check.DeepEquals, contents[offset:])
} }
@ -941,7 +940,7 @@ func (suite *DriverSuite) TestConcurrentFileStreams(c *check.C) {
// reader, err := suite.StorageDriver.Reader(suite.ctx, filename, offset) // reader, err := suite.StorageDriver.Reader(suite.ctx, filename, offset)
// c.Assert(err, check.IsNil) // c.Assert(err, check.IsNil)
// //
// readContents, err := ioutil.ReadAll(reader) // readContents, err := io.ReadAll(reader)
// c.Assert(err, check.IsNil) // c.Assert(err, check.IsNil)
// //
// c.Assert(readContents, check.DeepEquals, contents) // c.Assert(readContents, check.DeepEquals, contents)
@ -1104,7 +1103,7 @@ func (suite *DriverSuite) benchmarkDeleteFiles(c *check.C, numFiles int64) {
} }
func (suite *DriverSuite) testFileStreams(c *check.C, size int64) { func (suite *DriverSuite) testFileStreams(c *check.C, size int64) {
tf, err := ioutil.TempFile("", "tf") tf, err := os.CreateTemp("", "tf")
c.Assert(err, check.IsNil) c.Assert(err, check.IsNil)
defer os.Remove(tf.Name()) defer os.Remove(tf.Name())
defer tf.Close() defer tf.Close()
@ -1135,7 +1134,7 @@ func (suite *DriverSuite) testFileStreams(c *check.C, size int64) {
c.Assert(err, check.IsNil) c.Assert(err, check.IsNil)
defer reader.Close() defer reader.Close()
readContents, err := ioutil.ReadAll(reader) readContents, err := io.ReadAll(reader)
c.Assert(err, check.IsNil) c.Assert(err, check.IsNil)
c.Assert(readContents, check.DeepEquals, contents) c.Assert(readContents, check.DeepEquals, contents)
@ -1171,7 +1170,7 @@ func (suite *DriverSuite) writeReadCompareStreams(c *check.C, filename string, c
c.Assert(err, check.IsNil) c.Assert(err, check.IsNil)
defer reader.Close() defer reader.Close()
readContents, err := ioutil.ReadAll(reader) readContents, err := io.ReadAll(reader)
c.Assert(err, check.IsNil) c.Assert(err, check.IsNil)
c.Assert(readContents, check.DeepEquals, contents) c.Assert(readContents, check.DeepEquals, contents)

View file

@ -6,7 +6,6 @@ import (
"context" "context"
"fmt" "fmt"
"io" "io"
"io/ioutil"
storagedriver "github.com/distribution/distribution/v3/registry/storage/driver" storagedriver "github.com/distribution/distribution/v3/registry/storage/driver"
) )
@ -126,7 +125,7 @@ func (fr *fileReader) reader() (io.Reader, error) {
// reader that returns io.EOF. However, we do not set fr.rc, // reader that returns io.EOF. However, we do not set fr.rc,
// allowing future attempts at getting a reader to possibly // allowing future attempts at getting a reader to possibly
// succeed if the file turns up later. // succeed if the file turns up later.
return ioutil.NopCloser(bytes.NewReader([]byte{})), nil return io.NopCloser(bytes.NewReader([]byte{})), nil
default: default:
return nil, err return nil, err
} }

View file

@ -4,7 +4,6 @@ import (
"context" "context"
"errors" "errors"
"io" "io"
"io/ioutil"
"github.com/distribution/distribution/v3/registry/storage/driver" "github.com/distribution/distribution/v3/registry/storage/driver"
) )
@ -25,7 +24,7 @@ func getContent(ctx context.Context, driver driver.StorageDriver, p string) ([]b
func readAllLimited(r io.Reader, limit int64) ([]byte, error) { func readAllLimited(r io.Reader, limit int64) ([]byte, error) {
r = limitReader(r, limit) r = limitReader(r, limit)
return ioutil.ReadAll(r) return io.ReadAll(r)
} }
// limitReader returns a new reader limited to n bytes. Unlike io.LimitReader, // limitReader returns a new reader limited to n bytes. Unlike io.LimitReader,

View file

@ -4,7 +4,6 @@ import (
"bytes" "bytes"
"fmt" "fmt"
"io" "io"
"io/ioutil"
"net/http" "net/http"
"net/url" "net/url"
"sort" "sort"
@ -111,7 +110,7 @@ func NewHandler(requestResponseMap RequestResponseMap) http.Handler {
func (app *testHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { func (app *testHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
defer r.Body.Close() defer r.Body.Close()
requestBody, _ := ioutil.ReadAll(r.Body) requestBody, _ := io.ReadAll(r.Body)
request := Request{ request := Request{
Method: r.Method, Method: r.Method,
Route: r.URL.Path, Route: r.URL.Path,