Skip to content

Commit

Permalink
fix: remove usage of deprecated "io/ioutil" (#278)
Browse files Browse the repository at this point in the history
  • Loading branch information
donatello authored Apr 25, 2024
1 parent a687cbc commit 40f2130
Show file tree
Hide file tree
Showing 21 changed files with 48 additions and 58 deletions.
3 changes: 1 addition & 2 deletions anonymous-api.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import (
"errors"
"fmt"
"io"
"io/ioutil"
"net/http"
"net/http/cookiejar"
"net/http/httptrace"
Expand Down Expand Up @@ -193,7 +192,7 @@ func (an AnonymousClient) newRequest(ctx context.Context, method string, reqData
}
sum := sha256.Sum256(reqData.content)
req.Header.Set("X-Amz-Content-Sha256", hex.EncodeToString(sum[:]))
req.Body = ioutil.NopCloser(bytes.NewReader(reqData.content))
req.Body = io.NopCloser(bytes.NewReader(reqData.content))

return req, nil
}
Expand Down
3 changes: 1 addition & 2 deletions api-error-response.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import (
"encoding/xml"
"fmt"
"io"
"io/ioutil"
"net/http"
"unicode/utf8"
)
Expand Down Expand Up @@ -76,7 +75,7 @@ func httpRespToErrorResponse(resp *http.Response) error {

defer closeResponse(resp)
// Limit to 100K
body, err := ioutil.ReadAll(io.LimitReader(resp.Body, 100<<10))
body, err := io.ReadAll(io.LimitReader(resp.Body, 100<<10))
if err != nil {
return ErrorResponse{
Code: resp.Status,
Expand Down
11 changes: 5 additions & 6 deletions api.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import (
"errors"
"fmt"
"io"
"io/ioutil"
"math/rand"
"net/http"
"net/http/cookiejar"
Expand Down Expand Up @@ -420,7 +419,7 @@ func (adm AdminClient) executeMethod(ctx context.Context, method string, reqData
}

// Read the body to be saved later.
errBodyBytes, err := ioutil.ReadAll(res.Body)
errBodyBytes, err := io.ReadAll(res.Body)
// res.Body should be closed
closeResponse(res)
if err != nil {
Expand All @@ -429,14 +428,14 @@ func (adm AdminClient) executeMethod(ctx context.Context, method string, reqData

// Save the body.
errBodySeeker := bytes.NewReader(errBodyBytes)
res.Body = ioutil.NopCloser(errBodySeeker)
res.Body = io.NopCloser(errBodySeeker)

// For errors verify if its retryable otherwise fail quickly.
errResponse := ToErrorResponse(httpRespToErrorResponse(res))

// Save the body back again.
errBodySeeker.Seek(0, 0) // Seek back to starting point.
res.Body = ioutil.NopCloser(errBodySeeker)
res.Body = io.NopCloser(errBodySeeker)

// Verify if error response code is retryable.
if isAdminErrCodeRetryable(errResponse.Code) {
Expand Down Expand Up @@ -534,9 +533,9 @@ func (adm AdminClient) newRequest(ctx context.Context, method string, reqData re
sum := sha256.Sum256(reqData.content)
req.Header.Set("X-Amz-Content-Sha256", hex.EncodeToString(sum[:]))
if reqData.contentReader != nil {
req.Body = ioutil.NopCloser(reqData.contentReader)
req.Body = io.NopCloser(reqData.contentReader)
} else {
req.Body = ioutil.NopCloser(bytes.NewReader(reqData.content))
req.Body = io.NopCloser(bytes.NewReader(reqData.content))
}

req = signer.SignV4(*req, accessKeyID, secretAccessKey, sessionToken, location)
Expand Down
3 changes: 1 addition & 2 deletions bucket-metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import (
"context"
"encoding/json"
"io"
"io/ioutil"
"net/http"
"net/url"
)
Expand Down Expand Up @@ -77,7 +76,7 @@ type BucketMetaImportErrs struct {

// ImportBucketMetadata makes an admin call to set bucket metadata of a bucket from imported content
func (adm *AdminClient) ImportBucketMetadata(ctx context.Context, bucket string, contentReader io.ReadCloser) (r BucketMetaImportErrs, err error) {
content, err := ioutil.ReadAll(contentReader)
content, err := io.ReadAll(contentReader)
if err != nil {
return r, err
}
Expand Down
3 changes: 1 addition & 2 deletions cgroup/linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ import (
"bytes"
"fmt"
"io"
"io/ioutil"
"os"
"os/exec"
"path/filepath"
Expand Down Expand Up @@ -168,7 +167,7 @@ func GetMemoryLimit(pid int) (limit uint64, err error) {
// might not be installed. We fallback to using the the sysfs
// path instead to lookup memory limits.
var b []byte
b, err = ioutil.ReadFile(getMemoryLimitFilePath(path))
b, err = os.ReadFile(getMemoryLimitFilePath(path))
if err != nil {
return 0, err
}
Expand Down
3 changes: 1 addition & 2 deletions cgroup/linux_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,13 @@
package cgroup

import (
"io/ioutil"
"os"
"testing"
)

// Testing parsing correctness for various process cgroup files.
func TestProcCGroup(t *testing.T) {
tmpPath, err := ioutil.TempFile("", "cgroup")
tmpPath, err := os.CreateTemp("", "cgroup")
if err != nil {
t.Fatal(err)
}
Expand Down
8 changes: 4 additions & 4 deletions cluster-commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ package madmin
import (
"context"
"encoding/json"
"io/ioutil"
"io"
"net/http"
"net/url"
"strconv"
Expand Down Expand Up @@ -98,7 +98,7 @@ func (adm *AdminClient) SiteReplicationAdd(ctx context.Context, sites []PeerSite
return ReplicateAddStatus{}, httpRespToErrorResponse(resp)
}

b, err := ioutil.ReadAll(resp.Body)
b, err := io.ReadAll(resp.Body)
if err != nil {
return ReplicateAddStatus{}, err
}
Expand Down Expand Up @@ -139,7 +139,7 @@ func (adm *AdminClient) SiteReplicationInfo(ctx context.Context) (info SiteRepli
return info, httpRespToErrorResponse(resp)
}

b, err := ioutil.ReadAll(resp.Body)
b, err := io.ReadAll(resp.Body)
if err != nil {
return info, err
}
Expand Down Expand Up @@ -600,7 +600,7 @@ func (adm *AdminClient) SRPeerGetIDPSettings(ctx context.Context) (info IDPSetti
return info, httpRespToErrorResponse(resp)
}

b, err := ioutil.ReadAll(resp.Body)
b, err := io.ReadAll(resp.Body)
if err != nil {
return info, err
}
Expand Down
6 changes: 3 additions & 3 deletions group-commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ package madmin
import (
"context"
"encoding/json"
"io/ioutil"
"io"
"net/http"
"net/url"
"time"
Expand Down Expand Up @@ -94,7 +94,7 @@ func (adm *AdminClient) GetGroupDescription(ctx context.Context, group string) (
return nil, httpRespToErrorResponse(resp)
}

data, err := ioutil.ReadAll(resp.Body)
data, err := io.ReadAll(resp.Body)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -123,7 +123,7 @@ func (adm *AdminClient) ListGroups(ctx context.Context) ([]string, error) {
return nil, httpRespToErrorResponse(resp)
}

data, err := ioutil.ReadAll(resp.Body)
data, err := io.ReadAll(resp.Body)
if err != nil {
return nil, err
}
Expand Down
6 changes: 3 additions & 3 deletions heal-commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import (
"context"
"encoding/json"
"fmt"
"io/ioutil"
"io"
"net/http"
"net/url"
"sort"
Expand Down Expand Up @@ -278,7 +278,7 @@ func (adm *AdminClient) Heal(ctx context.Context, bucket, prefix string,
return healStart, healTaskStatus, httpRespToErrorResponse(resp)
}

respBytes, err := ioutil.ReadAll(resp.Body)
respBytes, err := io.ReadAll(resp.Body)
if err != nil {
return healStart, healTaskStatus, err
}
Expand Down Expand Up @@ -445,7 +445,7 @@ func (adm *AdminClient) BackgroundHealStatus(ctx context.Context) (BgHealState,
return BgHealState{}, httpRespToErrorResponse(resp)
}

respBytes, err := ioutil.ReadAll(resp.Body)
respBytes, err := io.ReadAll(resp.Body)
if err != nil {
return BgHealState{}, err
}
Expand Down
3 changes: 1 addition & 2 deletions health.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import (
"encoding/json"
"errors"
"io"
"io/ioutil"
"net/http"
"net/url"
"os"
Expand Down Expand Up @@ -274,7 +273,7 @@ func getDriveHwInfo(partDevice string) (info driveHwInfo, err error) {
}

var data []byte
data, err = ioutil.ReadFile(devPath)
data, err = os.ReadFile(devPath)
if err != nil {
return
}
Expand Down
3 changes: 1 addition & 2 deletions iam-migrate.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ package madmin
import (
"context"
"io"
"io/ioutil"
"net/http"
)

Expand All @@ -48,7 +47,7 @@ func (adm *AdminClient) ExportIAM(ctx context.Context) (io.ReadCloser, error) {

// ImportIAM makes an admin call to setup IAM from imported content
func (adm *AdminClient) ImportIAM(ctx context.Context, contentReader io.ReadCloser) error {
content, err := ioutil.ReadAll(contentReader)
content, err := io.ReadAll(contentReader)
if err != nil {
return err
}
Expand Down
6 changes: 3 additions & 3 deletions kernel/kernel.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ package kernel

import (
"fmt"
"io/ioutil"
"os"
"regexp"
"strconv"
"strings"
Expand Down Expand Up @@ -78,7 +78,7 @@ func currentReleaseUname() (string, error) {
}

func currentReleaseUbuntu() (string, error) {
procVersion, err := ioutil.ReadFile("/proc/version_signature")
procVersion, err := os.ReadFile("/proc/version_signature")
if err != nil {
return "", err
}
Expand All @@ -101,7 +101,7 @@ func parseDebianRelease(str string) (string, error) {
}

func currentReleaseDebian() (string, error) {
procVersion, err := ioutil.ReadFile("/proc/version")
procVersion, err := os.ReadFile("/proc/version")
if err != nil {
return "", fmt.Errorf("error reading /proc/version: %s", err)
}
Expand Down
8 changes: 4 additions & 4 deletions policy-commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ package madmin
import (
"context"
"encoding/json"
"io/ioutil"
"io"
"net/http"
"net/url"
"time"
Expand Down Expand Up @@ -52,7 +52,7 @@ func (adm *AdminClient) InfoCannedPolicy(ctx context.Context, policyName string)
return nil, httpRespToErrorResponse(resp)
}

return ioutil.ReadAll(resp.Body)
return io.ReadAll(resp.Body)
}

// PolicyInfo contains information on a policy.
Expand Down Expand Up @@ -101,7 +101,7 @@ func (adm *AdminClient) InfoCannedPolicyV2(ctx context.Context, policyName strin
return nil, httpRespToErrorResponse(resp)
}

data, err := ioutil.ReadAll(resp.Body)
data, err := io.ReadAll(resp.Body)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -129,7 +129,7 @@ func (adm *AdminClient) ListCannedPolicies(ctx context.Context) (map[string]json
return nil, httpRespToErrorResponse(resp)
}

respBytes, err := ioutil.ReadAll(resp.Body)
respBytes, err := io.ReadAll(resp.Body)
if err != nil {
return nil, err
}
Expand Down
3 changes: 1 addition & 2 deletions profiling-commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import (
"errors"
"fmt"
"io"
"io/ioutil"
"net/http"
"net/url"
"time"
Expand Down Expand Up @@ -76,7 +75,7 @@ func (adm *AdminClient) StartProfiling(ctx context.Context, profiler ProfilerTyp
return nil, httpRespToErrorResponse(resp)
}

jsonResult, err := ioutil.ReadAll(resp.Body)
jsonResult, err := io.ReadAll(resp.Body)
if err != nil {
return nil, err
}
Expand Down
4 changes: 2 additions & 2 deletions quota-commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ package madmin
import (
"context"
"encoding/json"
"io/ioutil"
"io"
"net/http"
"net/url"
)
Expand Down Expand Up @@ -81,7 +81,7 @@ func (adm *AdminClient) GetBucketQuota(ctx context.Context, bucket string) (q Bu
return q, httpRespToErrorResponse(resp)
}

b, err := ioutil.ReadAll(resp.Body)
b, err := io.ReadAll(resp.Body)
if err != nil {
return q, err
}
Expand Down
6 changes: 3 additions & 3 deletions rebalance.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ package madmin
import (
"context"
"encoding/json"
"io/ioutil"
"io"
"net/http"
"time"
)
Expand Down Expand Up @@ -72,7 +72,7 @@ func (adm *AdminClient) RebalanceStart(ctx context.Context) (id string, err erro
var rebalInfo struct {
ID string `json:"id"`
}
respBytes, err := ioutil.ReadAll(resp.Body)
respBytes, err := io.ReadAll(resp.Body)
if err != nil {
return id, err
}
Expand All @@ -99,7 +99,7 @@ func (adm *AdminClient) RebalanceStatus(ctx context.Context) (r RebalanceStatus,
return r, httpRespToErrorResponse(resp)
}

respBytes, err := ioutil.ReadAll(resp.Body)
respBytes, err := io.ReadAll(resp.Body)
if err != nil {
return r, err
}
Expand Down
Loading

0 comments on commit 40f2130

Please sign in to comment.