Skip to content

Commit

Permalink
Merge pull request #3165 from testwill/ioutil
Browse files Browse the repository at this point in the history
chore: remove refs to deprecated io/ioutil
  • Loading branch information
dougm authored Sep 29, 2023
2 parents 81ce307 + 675eebd commit 2ff5e50
Show file tree
Hide file tree
Showing 30 changed files with 59 additions and 80 deletions.
3 changes: 1 addition & 2 deletions govc/cli/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import (
"flag"
"fmt"
"io"
"io/ioutil"
"os"
"path/filepath"
"sort"
Expand Down Expand Up @@ -195,7 +194,7 @@ func Run(args []string) int {
}

fs := flag.NewFlagSet("", flag.ContinueOnError)
fs.SetOutput(ioutil.Discard)
fs.SetOutput(io.Discard)

ctx := context.Background()

Expand Down
4 changes: 2 additions & 2 deletions govc/extension/setcert.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import (
"encoding/pem"
"flag"
"fmt"
"io/ioutil"
"io"
"math/big"
"os"
"strings"
Expand Down Expand Up @@ -150,7 +150,7 @@ func (cmd *setcert) Run(ctx context.Context, f *flag.FlagSet) error {
key := f.Arg(0)

if cmd.cert == "-" {
b, err := ioutil.ReadAll(os.Stdin)
b, err := io.ReadAll(os.Stdin)
if err != nil {
return err
}
Expand Down
3 changes: 1 addition & 2 deletions govc/host/cert/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import (
"context"
"flag"
"io"
"io/ioutil"
"os"
"path/filepath"

Expand Down Expand Up @@ -80,7 +79,7 @@ func (cmd *install) Run(ctx context.Context, f *flag.FlagSet) error {
}
cert = buf.String()
} else {
b, err := ioutil.ReadFile(filepath.Clean(name))
b, err := os.ReadFile(filepath.Clean(name))
if err != nil {
return err
}
Expand Down
3 changes: 1 addition & 2 deletions govc/importx/archive.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import (
"flag"
"fmt"
"io"
"io/ioutil"
"net/url"
"os"
"path"
Expand Down Expand Up @@ -63,7 +62,7 @@ func (f *ArchiveFlag) ReadOvf(fpath string) ([]byte, error) {
}
defer r.Close()

return ioutil.ReadAll(r)
return io.ReadAll(r)
}

func (f *ArchiveFlag) ReadEnvelope(data []byte) (*ovf.Envelope, error) {
Expand Down
3 changes: 1 addition & 2 deletions govc/library/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import (
"flag"
"fmt"
"io"
"io/ioutil"
"net/url"
"os"
"path/filepath"
Expand Down Expand Up @@ -108,7 +107,7 @@ func (cmd *export) Run(ctx context.Context, f *flag.FlagSet) error {
var log io.Writer = os.Stdout
isStdout := one && dst == "-"
if isStdout {
log = ioutil.Discard
log = io.Discard
}

session, err := m.CreateLibraryItemDownloadSession(ctx, library.Session{
Expand Down
3 changes: 1 addition & 2 deletions govc/library/trust/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import (
"context"
"flag"
"io"
"io/ioutil"
"os"
"path/filepath"

Expand Down Expand Up @@ -73,7 +72,7 @@ func (cmd *create) Run(ctx context.Context, f *flag.FlagSet) error {
}
cert = buf.String()
} else {
b, err := ioutil.ReadFile(filepath.Clean(name))
b, err := os.ReadFile(filepath.Clean(name))
if err != nil {
return err
}
Expand Down
4 changes: 2 additions & 2 deletions govc/namespace/service/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (
"encoding/base64"
"flag"
"fmt"
"io/ioutil"
"os"

"github.com/vmware/govmomi/govc/cli"
"github.com/vmware/govmomi/govc/flags"
Expand Down Expand Up @@ -71,7 +71,7 @@ func (cmd *create) Run(ctx context.Context, f *flag.FlagSet) error {
return fmt.Errorf("only vsphere specs are accepted right now")
}

manifestFile, err := ioutil.ReadFile(manifest[0])
manifestFile, err := os.ReadFile(manifest[0])
if err != nil {
return fmt.Errorf("failed to read manifest file: %s", err)
}
Expand Down
3 changes: 1 addition & 2 deletions govc/session/login.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import (
"flag"
"fmt"
"io"
"io/ioutil"
"net/http"
"net/url"
"os"
Expand Down Expand Up @@ -373,7 +372,7 @@ func (cmd *login) Run(ctx context.Context, f *flag.FlagSet) error {
switch cmd.method {
case http.MethodPost, http.MethodPut, http.MethodPatch:
// strings.Reader here as /api wants a Content-Length header
b, err := ioutil.ReadAll(os.Stdin)
b, err := io.ReadAll(os.Stdin)
if err != nil {
return err
}
Expand Down
4 changes: 2 additions & 2 deletions govc/vm/change.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (
"context"
"flag"
"fmt"
"io/ioutil"
"os"
"reflect"
"strings"

Expand Down Expand Up @@ -58,7 +58,7 @@ func (e *extraConfigFile) Set(v string) error {

var fileContents = ""
if len(r[1]) > 0 {
contents, err := ioutil.ReadFile(r[1])
contents, err := os.ReadFile(r[1])
if err != nil {
return fmt.Errorf("failed to parse extraConfigFile '%s': %w", v, err)
}
Expand Down
3 changes: 1 addition & 2 deletions session/cache/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import (
"crypto/sha1"
"encoding/json"
"fmt"
"io/ioutil"
"net/url"
"os"
"os/user"
Expand Down Expand Up @@ -187,7 +186,7 @@ func localTicket(ctx context.Context, m *session.Manager) (*url.Userinfo, error)
return nil, err
}

password, err := ioutil.ReadFile(ticket.PasswordFilePath)
password, err := os.ReadFile(ticket.PasswordFilePath)
if err != nil {
return nil, err
}
Expand Down
3 changes: 1 addition & 2 deletions session/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ package session

import (
"context"
"io/ioutil"
"net/url"
"os"
"strings"
Expand Down Expand Up @@ -47,7 +46,7 @@ func Secret(value string) (string, error) {
if len(value) == 0 {
return value, nil
}
contents, err := ioutil.ReadFile(value)
contents, err := os.ReadFile(value)
if err != nil {
if os.IsPermission(err) {
return "", err
Expand Down
5 changes: 2 additions & 3 deletions simulator/feature_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import (
"bytes"
"context"
"fmt"
"io/ioutil"
"log"
"net/url"
"os"
Expand Down Expand Up @@ -101,14 +100,14 @@ func Example_runContainer() {
log.Fatal(err)
}
f, _ := dc.Folders(ctx)
dir, err := ioutil.TempDir("", "example")
dir, err := os.MkdirTemp("", "example")
if err != nil {
log.Fatal(err)
}
os.Chmod(dir, 0755)
fpath := filepath.Join(dir, "index.html")
fcontent := "foo"
ioutil.WriteFile(fpath, []byte(fcontent), 0644)
os.WriteFile(fpath, []byte(fcontent), 0644)
// just in case umask gets in the way
os.Chmod(fpath, 0644)
defer os.RemoveAll(dir)
Expand Down
9 changes: 4 additions & 5 deletions simulator/host_datastore_browser.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ limitations under the License.
package simulator

import (
"io/ioutil"
"os"
"path"
"strings"
Expand Down Expand Up @@ -149,7 +148,7 @@ func (s *searchDatastore) queryMatch(file os.FileInfo) bool {
}

func (s *searchDatastore) search(ds *types.ManagedObjectReference, folder string, dir string) error {
files, err := ioutil.ReadDir(dir)
files, err := os.ReadDir(dir)
if err != nil {
tracef("search %s: %s", dir, err)
return err
Expand All @@ -162,11 +161,11 @@ func (s *searchDatastore) search(ds *types.ManagedObjectReference, folder string

for _, file := range files {
name := file.Name()

if s.queryMatch(file) {
info, _ := file.Info()
if s.queryMatch(info) {
for _, m := range s.SearchSpec.MatchPattern {
if ok, _ := path.Match(m, name); ok {
s.addFile(file, &res)
s.addFile(info, &res)
break
}
}
Expand Down
5 changes: 2 additions & 3 deletions simulator/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import (
"context"
"crypto/tls"
"fmt"
"io/ioutil"
"log"
"math/rand"
"os"
Expand Down Expand Up @@ -368,7 +367,7 @@ func (m *Model) decode(path string, data interface{}) error {
func (m *Model) loadMethod(obj mo.Reference, dir string) error {
dir = filepath.Join(dir, obj.Reference().Encode())

info, err := ioutil.ReadDir(dir)
info, err := os.ReadDir(dir)
if err != nil {
if os.IsNotExist(err) {
return nil
Expand Down Expand Up @@ -823,7 +822,7 @@ func (m *Model) CreateInfrastructure(ctx *Context) error {
}

func (m *Model) createTempDir(dc string, name string) (string, error) {
dir, err := ioutil.TempDir("", fmt.Sprintf("govcsim-%s-%s-", dc, name))
dir, err := os.MkdirTemp("", fmt.Sprintf("govcsim-%s-%s-", dc, name))
if err == nil {
m.dirs = append(m.dirs, dir)
}
Expand Down
5 changes: 2 additions & 3 deletions simulator/simulator.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import (
"encoding/pem"
"fmt"
"io"
"io/ioutil"
"log"
"net"
"net/http"
Expand Down Expand Up @@ -98,7 +97,7 @@ type Server struct {
// New returns an initialized simulator Service instance
func New(instance *ServiceInstance) *Service {
s := &Service{
readAll: ioutil.ReadAll,
readAll: io.ReadAll,
sm: Map.SessionManager(),
sdk: make(map[string]*Registry),
}
Expand Down Expand Up @@ -772,7 +771,7 @@ func (s *Server) CertificateFile() (string, error) {
return s.caFile, nil
}

f, err := ioutil.TempFile("", "vcsim-")
f, err := os.CreateTemp("", "vcsim-")
if err != nil {
return "", err
}
Expand Down
3 changes: 1 addition & 2 deletions simulator/simulator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import (
"crypto/tls"
"errors"
"io"
"io/ioutil"
"log"
"net/http"
"net/url"
Expand Down Expand Up @@ -306,7 +305,7 @@ func TestServeHTTPS(t *testing.T) {
ts := s.NewServer()
defer ts.Close()

ts.Config.ErrorLog = log.New(ioutil.Discard, "", 0) // silence benign "TLS handshake error" log messages
ts.Config.ErrorLog = log.New(io.Discard, "", 0) // silence benign "TLS handshake error" log messages

ctx := context.Background()

Expand Down
7 changes: 3 additions & 4 deletions simulator/virtual_machine.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ package simulator
import (
"bytes"
"fmt"
"io/ioutil"
"log"
"net"
"os"
Expand Down Expand Up @@ -916,7 +915,7 @@ func (vm *VirtualMachine) RefreshStorageInfo(ctx *Context, req *types.RefreshSto
continue
}

files, err := ioutil.ReadDir(directory)
files, err := os.ReadDir(directory)
if err != nil {
body.Fault_ = Fault("", ctx.Map.FileManager().fault(directory, err, new(types.CannotAccessFile)))
return body
Expand All @@ -927,8 +926,8 @@ func (vm *VirtualMachine) RefreshStorageInfo(ctx *Context, req *types.RefreshSto
Datastore: p.Datastore,
Path: strings.TrimPrefix(file.Name(), datastore.Info.GetDatastoreInfo().Url),
}

vm.addFileLayoutEx(datastorePath, file.Size())
info, _ := file.Info()
vm.addFileLayoutEx(datastorePath, info.Size())
}
}

Expand Down
3 changes: 1 addition & 2 deletions sts/signer.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ import (
"errors"
"fmt"
"io"
"io/ioutil"
mrand "math/rand"
"net"
"net/http"
Expand Down Expand Up @@ -270,7 +269,7 @@ func (s *Signer) SignRequest(req *http.Request) error {
return fmt.Errorf("sts: getting http.Request body: %s", rerr)
}
defer r.Close()
body, rerr = ioutil.ReadAll(r)
body, rerr = io.ReadAll(r)
if rerr != nil {
return fmt.Errorf("sts: reading http.Request body: %s", rerr)
}
Expand Down
Loading

0 comments on commit 2ff5e50

Please sign in to comment.