From ef2f741823bdb8cc9ebefb45183612a9cf630d5e Mon Sep 17 00:00:00 2001 From: Zachary Walters Date: Tue, 21 Feb 2023 21:47:33 -0600 Subject: [PATCH] Updated the deprecated ioutil dependency (#4239) --- weed/command/update.go | 7 +++---- weed/security/tls.go | 4 ++-- weed/server/raft_server.go | 3 +-- weed/shell/command_volume_fsck.go | 5 ++--- 4 files changed, 8 insertions(+), 11 deletions(-) diff --git a/weed/command/update.go b/weed/command/update.go index 70a075f80..314a903f2 100644 --- a/weed/command/update.go +++ b/weed/command/update.go @@ -11,7 +11,6 @@ import ( "encoding/json" "fmt" "io" - "io/ioutil" "net/http" "os" "path/filepath" @@ -215,7 +214,7 @@ func GitHubLatestRelease(ctx context.Context, ver string, owner, repo string) (R return Release{}, fmt.Errorf("unexpected status %v (%v) returned", res.StatusCode, res.Status) } - buf, err := ioutil.ReadAll(res.Body) + buf, err := io.ReadAll(res.Body) if err != nil { return Release{}, err } @@ -265,7 +264,7 @@ func getGithubData(ctx context.Context, url string) ([]byte, error) { return nil, fmt.Errorf("unexpected status %v (%v) returned", res.StatusCode, res.Status) } - buf, err := ioutil.ReadAll(res.Body) + buf, err := io.ReadAll(res.Body) if err != nil { return nil, err } @@ -337,7 +336,7 @@ func extractToFile(buf []byte, filename, target string) error { // Write everything to a temp file dir := filepath.Dir(target) - new, err := ioutil.TempFile(dir, "weed") + new, err := os.CreateTemp(dir, "weed") if err != nil { return err } diff --git a/weed/security/tls.go b/weed/security/tls.go index e20b32437..d5384fc51 100644 --- a/weed/security/tls.go +++ b/weed/security/tls.go @@ -7,7 +7,7 @@ import ( "google.golang.org/grpc/credentials/insecure" "google.golang.org/grpc/credentials/tls/certprovider/pemfile" "google.golang.org/grpc/security/advancedtls" - "io/ioutil" + "os" "strings" "time" @@ -136,7 +136,7 @@ func LoadClientTLS(config *util.ViperProxy, component string) grpc.DialOption { } func LoadClientTLSHTTP(clientCertFile string) *tls.Config { - clientCerts, err := ioutil.ReadFile(clientCertFile) + clientCerts, err := os.ReadFile(clientCertFile) if err != nil { glog.Fatal(err) } diff --git a/weed/server/raft_server.go b/weed/server/raft_server.go index 0e184308d..d718ecac7 100644 --- a/weed/server/raft_server.go +++ b/weed/server/raft_server.go @@ -4,7 +4,6 @@ import ( "encoding/json" transport "github.com/Jille/raft-grpc-transport" "io" - "io/ioutil" "math/rand" "os" "path" @@ -90,7 +89,7 @@ func (s *StateMachine) Snapshot() (hashicorpRaft.FSMSnapshot, error) { } func (s *StateMachine) Restore(r io.ReadCloser) error { - b, err := ioutil.ReadAll(r) + b, err := io.ReadAll(r) if err != nil { return err } diff --git a/weed/shell/command_volume_fsck.go b/weed/shell/command_volume_fsck.go index 02956e9ca..5559be956 100644 --- a/weed/shell/command_volume_fsck.go +++ b/weed/shell/command_volume_fsck.go @@ -20,7 +20,6 @@ import ( "github.com/seaweedfs/seaweedfs/weed/storage/types" "github.com/seaweedfs/seaweedfs/weed/util" "io" - "io/ioutil" "math" "net/http" "net/url" @@ -409,7 +408,7 @@ func (c *commandVolumeFsck) collectOneVolumeFileIds(dataNodeId string, volumeId } buf.Write(resp.FileContent) } - if vinfo.isReadOnly == false { + if !vinfo.isReadOnly { index, err := idx.FirstInvalidIndex(buf.Bytes(), func(key types.NeedleId, offset types.Offset, size types.Size) (bool, error) { resp, err := volumeServerClient.ReadNeedleMeta(context.Background(), &volume_server_pb.ReadNeedleMetaRequest{ @@ -535,7 +534,7 @@ func (c *commandVolumeFsck) httpDelete(path util.FullPath) { } defer resp.Body.Close() - _, err = ioutil.ReadAll(resp.Body) + _, err = io.ReadAll(resp.Body) if err != nil { fmt.Fprintf(c.writer, "DELETE response error: %v\n", err) }