Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

*: remove io/ioutil as changed in Go 1.16 #1153

Merged
merged 3 commits into from
Feb 24, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ check-static: tools/bin/golangci-lint

lint: tools/bin/revive
@echo "linting"
./tools/check/check-lint.sh
@tools/bin/revive -formatter friendly -config tools/check/revive.toml $(FILES)

vet:
Expand Down
3 changes: 1 addition & 2 deletions cmd/clean.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ package cmd

import (
"fmt"
"io/ioutil"
"os"
"path/filepath"

Expand Down Expand Up @@ -49,7 +48,7 @@ func cleanData(env *environment.Environment, names []string, all bool) error {
if utils.IsNotExist(dataDir) {
return nil
}
dirs, err := ioutil.ReadDir(dataDir)
dirs, err := os.ReadDir(dataDir)
if err != nil {
return err
}
Expand Down
7 changes: 3 additions & 4 deletions cmd/mirror.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import (
"bytes"
"encoding/json"
"fmt"
"io/ioutil"
"os"
"path"
"path/filepath"
Expand Down Expand Up @@ -117,7 +116,7 @@ func newMirrorSignCmd() *cobra.Command {
return nil
}

data, err := ioutil.ReadFile(args[0])
data, err := os.ReadFile(args[0])
if err != nil {
return errors.Annotatef(err, "open manifest file %s", args[0])
}
Expand All @@ -126,7 +125,7 @@ func newMirrorSignCmd() *cobra.Command {
return err
}

if err = ioutil.WriteFile(args[0], data, 0664); err != nil {
if err = os.WriteFile(args[0], data, 0664); err != nil {
return errors.Annotatef(err, "write manifest file %s", args[0])
}

Expand Down Expand Up @@ -318,7 +317,7 @@ func editLatestRootManifest() (*v1manifest.Root, error) {
return nil, err
}

file, err := ioutil.TempFile(os.TempDir(), "*.root.json")
file, err := os.CreateTemp(os.TempDir(), "*.root.json")
if err != nil {
return nil, errors.Annotate(err, "create temp file for root.json")
}
Expand Down
3 changes: 1 addition & 2 deletions cmd/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
package cmd

import (
"io/ioutil"
"os"
"path/filepath"
"strconv"
Expand Down Expand Up @@ -47,7 +46,7 @@ func showStatus(env *environment.Environment) error {
var table [][]string
table = append(table, []string{"Name", "Component", "PID", "Status", "Created Time", "Directory", "Binary", "Args"})
if dataDir := env.LocalPath(localdata.DataParentDir); utils.IsExist(dataDir) {
dirs, err := ioutil.ReadDir(dataDir)
dirs, err := os.ReadDir(dataDir)
if err != nil {
return err
}
Expand Down
3 changes: 1 addition & 2 deletions cmd/uninstall.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ package cmd

import (
"fmt"
"io/ioutil"
"os"
"strings"

Expand Down Expand Up @@ -87,7 +86,7 @@ func removeComponents(env *environment.Environment, specs []string, all bool) er
if strings.Contains(spec, ":") {
parts := strings.SplitN(spec, ":", 2)
// after this version is deleted, component will have no version left. delete the whole component dir directly
dir, err := ioutil.ReadDir(env.LocalPath(localdata.ComponentParentDir, parts[0]))
dir, err := os.ReadDir(env.LocalPath(localdata.ComponentParentDir, parts[0]))
if err != nil {
return errors.Trace(err)
}
Expand Down
5 changes: 2 additions & 3 deletions components/client/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import (
"encoding/json"
"fmt"
"io"
"io/ioutil"
"log"
"os"
"os/user"
Expand Down Expand Up @@ -107,7 +106,7 @@ func connect(target string) error {
func scanEndpoint(tiupHome string) ([]*endpoint, error) {
endpoints := []*endpoint{}

files, err := ioutil.ReadDir(path.Join(tiupHome, localdata.DataParentDir))
files, err := os.ReadDir(path.Join(tiupHome, localdata.DataParentDir))
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -203,7 +202,7 @@ func selectEndpoint(endpoints []*endpoint) *endpoint {
uiEvents := ui.PollEvents()
for {
e := <-uiEvents
_ = ioutil.WriteFile("/tmp/log", []byte(e.ID+"\n"), 0664)
_ = os.WriteFile("/tmp/log", []byte(e.ID+"\n"), 0664)
switch e.ID {
case "q", "<C-c>":
return nil
Expand Down
4 changes: 2 additions & 2 deletions components/cluster/command/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ package command

import (
"context"
"io/ioutil"
"os"
"path"

"github.com/pingcap/tiup/pkg/cliutil"
Expand Down Expand Up @@ -76,7 +76,7 @@ func newDeploy() *cobra.Command {
teleCommand = append(teleCommand, version)

topoFile := args[2]
if data, err := ioutil.ReadFile(topoFile); err == nil {
if data, err := os.ReadFile(topoFile); err == nil {
teleTopology = string(data)
}

Expand Down
4 changes: 2 additions & 2 deletions components/cluster/command/scale_out.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
package command

import (
"io/ioutil"
"os"
"path/filepath"

"github.com/pingcap/tiup/pkg/cluster/executor"
Expand Down Expand Up @@ -47,7 +47,7 @@ func newScaleOutCmd() *cobra.Command {
teleCommand = append(teleCommand, scrubClusterName(clusterName))

topoFile := args[1]
if data, err := ioutil.ReadFile(topoFile); err == nil {
if data, err := os.ReadFile(topoFile); err == nil {
teleTopology = string(data)
}

Expand Down
7 changes: 3 additions & 4 deletions components/dm/ansible/import.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import (
"bytes"
"context"
"fmt"
"io/ioutil"
"os"
"path/filepath"
"strconv"
Expand Down Expand Up @@ -173,7 +172,7 @@ func (im *Importer) fetchFile(ctx context.Context, host string, port int, fname
return nil, errors.Annotatef(err, "failed to get executor, target: %s:%d", host, port)
}

tmp, err := ioutil.TempDir("", "tiup")
tmp, err := os.MkdirTemp("", "tiup")
if err != nil {
return nil, errors.AddStack(err)
}
Expand All @@ -186,7 +185,7 @@ func (im *Importer) fetchFile(ctx context.Context, host string, port int, fname
return nil, errors.Annotatef(err, "transfer %s from %s:%d", fname, host, port)
}

data, err = ioutil.ReadFile(tmp)
data, err = os.ReadFile(tmp)
if err != nil {
return nil, errors.AddStack(err)
}
Expand Down Expand Up @@ -240,7 +239,7 @@ func (im *Importer) ScpSourceToMaster(ctx context.Context, topo *spec.Specificat
}

for addr, source := range im.sources {
f, err := ioutil.TempFile("", "tiup-dm-*")
f, err := os.CreateTemp("", "tiup-dm-*")
if err != nil {
return errors.AddStack(err)
}
Expand Down
12 changes: 6 additions & 6 deletions components/dm/ansible/import_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ package ansible

import (
"context"
"io/ioutil"
"os"
"path/filepath"
"strconv"
"strings"
Expand Down Expand Up @@ -61,7 +61,7 @@ func TestParseRunScript(t *testing.T) {
assert := require.New(t)

// parse run_dm-master.sh
data, err := ioutil.ReadFile("./testdata/deploy_dir/172.19.0.101/scripts/run_dm-master.sh")
data, err := os.ReadFile("./testdata/deploy_dir/172.19.0.101/scripts/run_dm-master.sh")
assert.Nil(err)
dir, flags, err := parseRunScript(data)
assert.Nil(err)
Expand All @@ -75,7 +75,7 @@ func TestParseRunScript(t *testing.T) {
assert.Equal(expectedFlags, flags)

// parse run_dm-worker.sh
data, err = ioutil.ReadFile("./testdata/deploy_dir/172.19.0.101/scripts/run_dm-worker.sh")
data, err = os.ReadFile("./testdata/deploy_dir/172.19.0.101/scripts/run_dm-worker.sh")
assert.Nil(err)
dir, flags, err = parseRunScript(data)
assert.Nil(err)
Expand All @@ -90,7 +90,7 @@ func TestParseRunScript(t *testing.T) {
assert.Equal(expectedFlags, flags)

// parse run_prometheus.sh
data, err = ioutil.ReadFile("./testdata/deploy_dir/172.19.0.101/scripts/run_prometheus.sh")
data, err = os.ReadFile("./testdata/deploy_dir/172.19.0.101/scripts/run_prometheus.sh")
assert.Nil(err)
dir, flags, err = parseRunScript(data)
assert.Nil(err)
Expand All @@ -107,7 +107,7 @@ func TestParseRunScript(t *testing.T) {
assert.Equal(expectedFlags, flags)

// parse run_grafana.sh
data, err = ioutil.ReadFile("./testdata/deploy_dir/172.19.0.101/scripts/run_grafana.sh")
data, err = os.ReadFile("./testdata/deploy_dir/172.19.0.101/scripts/run_grafana.sh")
assert.Nil(err)
dir, flags, err = parseRunScript(data)
assert.Nil(err)
Expand All @@ -119,7 +119,7 @@ func TestParseRunScript(t *testing.T) {
assert.Equal(expectedFlags, flags)

// parse run_alertmanager.sh
data, err = ioutil.ReadFile("./testdata/deploy_dir/172.19.0.101/scripts/run_alertmanager.sh")
data, err = os.ReadFile("./testdata/deploy_dir/172.19.0.101/scripts/run_alertmanager.sh")
assert.Nil(err)
dir, flags, err = parseRunScript(data)
assert.Nil(err)
Expand Down
4 changes: 2 additions & 2 deletions components/dm/command/import.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ package command
import (
"context"
"fmt"
"io/ioutil"
"os"

"github.com/fatih/color"
"github.com/pingcap/errors"
Expand Down Expand Up @@ -69,7 +69,7 @@ func newImportCmd() *cobra.Command {
return errors.AddStack(err)
}

f, err := ioutil.TempFile("", "tiup-*")
f, err := os.CreateTemp("", "tiup-*")
if err != nil {
return errors.AddStack(err)
}
Expand Down
3 changes: 1 addition & 2 deletions components/dm/spec/topology_dm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ package spec

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

Expand Down Expand Up @@ -273,7 +272,7 @@ worker_servers:
}

func withTempFile(content string, fn func(string)) {
file, err := ioutil.TempFile("/tmp", "topology-test")
file, err := os.CreateTemp("/tmp", "topology-test")
if err != nil {
panic(fmt.Sprintf("create temp file: %s", err))
}
Expand Down
5 changes: 2 additions & 3 deletions components/errdoc/errdoc-gen/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,6 @@ package main
import (
"bytes"
"flag"
"io/ioutil"
"os"
"reflect"
"fmt"
Expand All @@ -120,7 +119,7 @@ func main() {

// Read-in the exists file and merge the description/workaround from exists file
existDefinition := map[string]spec{}
if file, err := ioutil.ReadFile(outpath); err == nil {
if file, err := os.ReadFile(outpath); err == nil {
err = toml.Unmarshal(file, &existDefinition)
if err != nil {
println(fmt.Sprintf("Invalid toml file %s when merging exists description/workaround: %v", outpath, err))
Expand Down Expand Up @@ -187,7 +186,7 @@ func main() {
}
buffer.WriteString("\n")
}
if err := ioutil.WriteFile(outpath, buffer.Bytes(), os.ModePerm); err != nil {
if err := os.WriteFile(outpath, buffer.Bytes(), os.ModePerm); err != nil {
panic(err)
}
}
Expand Down
11 changes: 5 additions & 6 deletions components/playground/grafana.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ package main
import (
"context"
"fmt"
"io/ioutil"
"os"
"os/exec"
"path"
Expand Down Expand Up @@ -74,7 +73,7 @@ datasources:
`

s := fmt.Sprintf(tpl, clusterName, clusterName, p8sURL)
err = ioutil.WriteFile(fname, []byte(s), 0644)
err = os.WriteFile(fname, []byte(s), 0644)
if err != nil {
return errors.AddStack(err)
}
Expand All @@ -98,7 +97,7 @@ func replaceDatasource(dashboardDir string, datasourceName string) error {
return nil
}

data, err := ioutil.ReadFile(path)
data, err := os.ReadFile(path)
if err != nil {
return errors.AddStack(err)
}
Expand All @@ -109,7 +108,7 @@ func replaceDatasource(dashboardDir string, datasourceName string) error {
s = strings.Replace(s, "${DS_LIGHTNING}", datasourceName, -1)
s = re.ReplaceAllLiteralString(s, datasourceName)

return ioutil.WriteFile(path, []byte(s), 0644)
return os.WriteFile(path, []byte(s), 0644)
})

if err != nil {
Expand Down Expand Up @@ -138,7 +137,7 @@ providers:
`
s := fmt.Sprintf(tpl, clusterName, clusterName, dir)

err = ioutil.WriteFile(fname, []byte(s), 0644)
err = os.WriteFile(fname, []byte(s), 0644)
if err != nil {
return errors.AddStack(err)
}
Expand Down Expand Up @@ -188,7 +187,7 @@ http_port = %d
custome := fmt.Sprintf(tpl, g.host, g.port)
customeFName := filepath.Join(dir, "conf", "custom.ini")

err = ioutil.WriteFile(customeFName, []byte(custome), 0644)
err = os.WriteFile(customeFName, []byte(custome), 0644)
if err != nil {
return errors.AddStack(err)
}
Expand Down
7 changes: 3 additions & 4 deletions components/playground/grafana_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
package main

import (
"io/ioutil"
"os"
"path/filepath"
"strings"
Expand All @@ -31,19 +30,19 @@ c: Test-Cluster
d: ${DS_LIGHTNING}
`

dir, err := ioutil.TempDir("", "play_replace_test_*")
dir, err := os.MkdirTemp("", "play_replace_test_*")
assert.Nil(t, err)
defer os.RemoveAll(dir)

fname := filepath.Join(dir, "a.json")
err = ioutil.WriteFile(fname, []byte(origin), 0644)
err = os.WriteFile(fname, []byte(origin), 0644)
assert.Nil(t, err)

name := "myname"
err = replaceDatasource(dir, name)
assert.Nil(t, err)

data, err := ioutil.ReadFile(fname)
data, err := os.ReadFile(fname)
assert.Nil(t, err)
replaced := string(data)

Expand Down
Loading