Skip to content

Commit

Permalink
chore: remove refs to deprecated io/ioutil (#2609)
Browse files Browse the repository at this point in the history
Signed-off-by: guoguangwu <[email protected]>
  • Loading branch information
testwill authored Jul 28, 2023
1 parent 64881af commit acc8049
Show file tree
Hide file tree
Showing 11 changed files with 24 additions and 31 deletions.
3 changes: 1 addition & 2 deletions helpers/man/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ package main
import (
"fmt"
"io/fs"
"io/ioutil"
"os"
"os/exec"
"path/filepath"
Expand Down Expand Up @@ -49,7 +48,7 @@ func main() {
return
}

vs, err := ioutil.ReadFile("VERSION")
vs, err := os.ReadFile("VERSION")
if err != nil {
panic(err)
}
Expand Down
9 changes: 4 additions & 5 deletions helpers/postrel/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import (
"fmt"
"html/template"
"io"
"io/ioutil"
"net/http"
"os"
"os/exec"
Expand Down Expand Up @@ -218,7 +217,7 @@ func (g *ghClient) createMilestone(ctx context.Context, title string, offset int
}

func updateGopasspw(dir string, ver semver.Version) error {
buf, err := ioutil.ReadFile(filepath.Join(dir, "index.tpl"))
buf, err := os.ReadFile(filepath.Join(dir, "index.tpl"))
if err != nil {
return err
}
Expand Down Expand Up @@ -424,7 +423,7 @@ func (u *inUpdater) doUpdate(ctx context.Context, dir string) error {
fmt.Printf("✅ [%s] synced .golangci.yml.\n", dir)

// update VERSION
if err := ioutil.WriteFile(filepath.Join(path, "VERSION"), []byte(u.v.String()+"\n"), 0o644); err != nil {
if err := os.WriteFile(filepath.Join(path, "VERSION"), []byte(u.v.String()+"\n"), 0o644); err != nil {
return err
}
fmt.Printf("✅ [%s] wrote VERSION.\n", dir)
Expand Down Expand Up @@ -485,7 +484,7 @@ func (u *inUpdater) writeVersionGo(path string) error {
func (u *inUpdater) updateChangelog(ctx context.Context, dir string) error {
fn := filepath.Join(dir, "CHANGELOG.md")

buf, err := ioutil.ReadFile(fn)
buf, err := os.ReadFile(fn)
if err != nil {
return err
}
Expand All @@ -501,7 +500,7 @@ func (u *inUpdater) updateChangelog(ctx context.Context, dir string) error {
return err
}

if err := ioutil.WriteFile(fn, []byte(sb.String()), 0o644); err != nil {
if err := os.WriteFile(fn, []byte(sb.String()), 0o644); err != nil {
return err
}

Expand Down
4 changes: 2 additions & 2 deletions internal/action/process.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package action

import (
"io/ioutil"
"os"

"github.com/gopasspw/gopass/internal/action/exit"
"github.com/gopasspw/gopass/internal/out"
Expand All @@ -18,7 +18,7 @@ func (s *Action) Process(c *cli.Context) error {
return exit.Error(exit.Usage, nil, "Usage: %s process <FILE>", s.Name)
}

buf, err := ioutil.ReadFile(file)
buf, err := os.ReadFile(file)
if err != nil {
return exit.Error(exit.IO, err, "Failed to read file: %s", file)
}
Expand Down
3 changes: 1 addition & 2 deletions internal/action/process_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package action
import (
"bytes"
"context"
"io/ioutil"
"os"
"path/filepath"
"testing"
Expand Down Expand Up @@ -42,7 +41,7 @@ func TestProcess(t *testing.T) {
require.NoError(t, act.Store.Set(ctx, "server/local/mysql", sec))

infile := filepath.Join(u.Dir, "my.cnf.tpl")
err = ioutil.WriteFile(infile, []byte(`[client]
err = os.WriteFile(infile, []byte(`[client]
host=127.0.0.1
port=3306
user={{ getval "server/local/mysql" "username" }}
Expand Down
4 changes: 2 additions & 2 deletions internal/audit/output.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"encoding/csv"
"fmt"
"io"
"io/ioutil"
"os"
"sort"
"text/template"
"time"
Expand Down Expand Up @@ -84,7 +84,7 @@ func (r *Report) RenderHTML(w io.Writer) error {
tplStr := htmlTpl

if r.Template != "" {
if buf, err := ioutil.ReadFile(r.Template); err == nil {
if buf, err := os.ReadFile(r.Template); err == nil {
tplStr = string(buf)
} else {
debug.Log("failed to load custom template from %s: %s", r.Template, err)
Expand Down
5 changes: 2 additions & 3 deletions internal/backend/storage/fs/walk_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package fs

import (
"io/fs"
"io/ioutil"
"os"
"path/filepath"
"strings"
Expand All @@ -19,7 +18,7 @@ func TestWalkTooLong(t *testing.T) {
storeDir := filepath.Join(td, "store")
fn := filepath.Join(storeDir, "real", "file.txt")
assert.NoError(t, os.MkdirAll(filepath.Dir(fn), 0o700))
assert.NoError(t, ioutil.WriteFile(fn, []byte("foobar"), 0o600))
assert.NoError(t, os.WriteFile(fn, []byte("foobar"), 0o600))

ptr := filepath.Join(storeDir, "path", "via", "link")

Expand Down Expand Up @@ -55,7 +54,7 @@ func TestWalkSameFile(t *testing.T) {
storeDir := filepath.Join(td, "store")
fn := filepath.Join(storeDir, "real", "file.txt")
assert.NoError(t, os.MkdirAll(filepath.Dir(fn), 0o700))
assert.NoError(t, ioutil.WriteFile(fn, []byte("foobar"), 0o600))
assert.NoError(t, os.WriteFile(fn, []byte("foobar"), 0o600))

ptr1 := filepath.Join(storeDir, "path", "via", "one", "link")
ptr2 := filepath.Join(storeDir, "another", "path", "to", "this", "file")
Expand Down
3 changes: 1 addition & 2 deletions internal/updater/extract.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"errors"
"fmt"
"io"
"io/ioutil"
"os"
"path/filepath"

Expand Down Expand Up @@ -45,7 +44,7 @@ func extractFile(buf []byte, filename, dest string) error {
func extractToTempFile(buf []byte, filename, dest string) (string, error) {
// open a temp file for writing
dir := filepath.Dir(dest)
dfh, err := ioutil.TempFile(dir, "gopass")
dfh, err := os.CreateTemp(dir, "gopass")
if err != nil {
return "", fmt.Errorf("failed to create temp file in %s: %w", dir, err)
}
Expand Down
7 changes: 3 additions & 4 deletions pkg/debug/debug_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package debug

import (
"bytes"
"io/ioutil"
"os"
"path/filepath"
"testing"
Expand Down Expand Up @@ -60,7 +59,7 @@ func TestDebug(t *testing.T) {
Log("%s", testSecret("secret"))
Log("%s", testShort("toolong"))

buf, err := ioutil.ReadFile(fn)
buf, err := os.ReadFile(fn)
require.NoError(t, err)

logStr := string(buf)
Expand Down Expand Up @@ -88,7 +87,7 @@ func TestDebugSecret(t *testing.T) {
Log("foo")
Log("%s", testSecret("secret"))

buf, err := ioutil.ReadFile(fn)
buf, err := os.ReadFile(fn)
require.NoError(t, err)

logStr := string(buf)
Expand Down Expand Up @@ -119,7 +118,7 @@ func TestDebugFilter(t *testing.T) {
Log("foo")
Log("%s", testSecret("secret"))

fbuf, err := ioutil.ReadFile(fn)
fbuf, err := os.ReadFile(fn)
require.NoError(t, err)

logStr := string(fbuf)
Expand Down
3 changes: 1 addition & 2 deletions pkg/fsutil/fsutil_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package fsutil

import (
"crypto/rand"
"io/ioutil"
"os"
"path/filepath"
"runtime"
Expand Down Expand Up @@ -150,7 +149,7 @@ func TestCopyFile(t *testing.T) {

// try to overwrite existing file w/o write bit
dfn = filepath.Join(tempdir, "bar2")
require.NoError(t, ioutil.WriteFile(dfn, []byte("foo"), 0o400))
require.NoError(t, os.WriteFile(dfn, []byte("foo"), 0o400))
assert.Error(t, CopyFile(sfn, dfn))
assert.NoError(t, CopyFileForce(sfn, dfn))
}
4 changes: 2 additions & 2 deletions pkg/gitconfig/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package gitconfig
import (
"bytes"
"fmt"

Check failure on line 5 in pkg/gitconfig/config_test.go

View workflow job for this annotation

GitHub Actions / lint

File is not `gofumpt`-ed (gofumpt)
"io/ioutil"
"os"

Check failure on line 6 in pkg/gitconfig/config_test.go

View workflow job for this annotation

GitHub Actions / lint

File is not `gofmt`-ed with `-s` (gofmt)
"math/rand"
"path/filepath"
"strconv"
Expand Down Expand Up @@ -243,7 +243,7 @@ func TestLoadConfig(t *testing.T) {

td := t.TempDir()
fn := filepath.Join(td, "config")
assert.NoError(t, ioutil.WriteFile(fn, []byte(`[core]
assert.NoError(t, os.WriteFile(fn, []byte(`[core]
int = 7
string = foo
bar = false`), 0o600))
Expand Down
10 changes: 5 additions & 5 deletions pkg/gitconfig/configs_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package gitconfig

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

Expand All @@ -21,18 +21,18 @@ func TestConfigs(t *testing.T) {
c.WorktreeConfig = "worktree"
c.EnvPrefix = "GPTEST"

require.NoError(t, ioutil.WriteFile(c.SystemConfig, []byte(`[system]
require.NoError(t, os.WriteFile(c.SystemConfig, []byte(`[system]
key = system
`), 0o600))
require.NoError(t, ioutil.WriteFile(filepath.Join(td, c.GlobalConfig), []byte(`[global]
require.NoError(t, os.WriteFile(filepath.Join(td, c.GlobalConfig), []byte(`[global]
key = global
[alias "foo"]
key = bar
`), 0o600))
require.NoError(t, ioutil.WriteFile(filepath.Join(td, c.LocalConfig), []byte(`[local]
require.NoError(t, os.WriteFile(filepath.Join(td, c.LocalConfig), []byte(`[local]
key = local
`), 0o600))
require.NoError(t, ioutil.WriteFile(filepath.Join(td, c.WorktreeConfig), []byte(`[worktree]
require.NoError(t, os.WriteFile(filepath.Join(td, c.WorktreeConfig), []byte(`[worktree]
key = worktree
`), 0o600))
t.Setenv("GPTEST_CONFIG_COUNT", "1")
Expand Down

0 comments on commit acc8049

Please sign in to comment.