mirror of
https://github.com/tendermint/tendermint.git
synced 2026-10-01 12:15:45 +00:00
do not use ioutil (#9206)
This commit is contained in:
+3
-4
@@ -4,7 +4,6 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"os/signal"
|
||||
"syscall"
|
||||
@@ -62,11 +61,11 @@ func FileExists(filePath string) bool {
|
||||
}
|
||||
|
||||
func ReadFile(filePath string) ([]byte, error) {
|
||||
return ioutil.ReadFile(filePath)
|
||||
return os.ReadFile(filePath)
|
||||
}
|
||||
|
||||
func MustReadFile(filePath string) []byte {
|
||||
fileBytes, err := ioutil.ReadFile(filePath)
|
||||
fileBytes, err := os.ReadFile(filePath)
|
||||
if err != nil {
|
||||
Exit(fmt.Sprintf("MustReadFile failed: %v", err))
|
||||
return nil
|
||||
@@ -75,7 +74,7 @@ func MustReadFile(filePath string) []byte {
|
||||
}
|
||||
|
||||
func WriteFile(filePath string, contents []byte, mode os.FileMode) error {
|
||||
return ioutil.WriteFile(filePath, contents, mode)
|
||||
return os.WriteFile(filePath, contents, mode)
|
||||
}
|
||||
|
||||
func MustWriteFile(filePath string, contents []byte, mode os.FileMode) {
|
||||
|
||||
+8
-9
@@ -3,7 +3,6 @@ package os
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
@@ -12,7 +11,7 @@ import (
|
||||
)
|
||||
|
||||
func TestCopyFile(t *testing.T) {
|
||||
tmpfile, err := ioutil.TempFile("", "example")
|
||||
tmpfile, err := os.CreateTemp("", "example")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@@ -29,7 +28,7 @@ func TestCopyFile(t *testing.T) {
|
||||
if _, err := os.Stat(copyfile); os.IsNotExist(err) {
|
||||
t.Fatal("copy should exist")
|
||||
}
|
||||
data, err := ioutil.ReadFile(copyfile)
|
||||
data, err := os.ReadFile(copyfile)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@@ -40,7 +39,7 @@ func TestCopyFile(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestEnsureDir(t *testing.T) {
|
||||
tmp, err := ioutil.TempDir("", "ensure-dir")
|
||||
tmp, err := os.MkdirTemp("", "ensure-dir")
|
||||
require.NoError(t, err)
|
||||
defer os.RemoveAll(tmp)
|
||||
|
||||
@@ -54,7 +53,7 @@ func TestEnsureDir(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
|
||||
// Should fail on file.
|
||||
err = ioutil.WriteFile(filepath.Join(tmp, "file"), []byte{}, 0644)
|
||||
err = os.WriteFile(filepath.Join(tmp, "file"), []byte{}, 0644)
|
||||
require.NoError(t, err)
|
||||
err = EnsureDir(filepath.Join(tmp, "file"), 0755)
|
||||
require.Error(t, err)
|
||||
@@ -76,7 +75,7 @@ func TestEnsureDir(t *testing.T) {
|
||||
// the origin is positively a non-directory and that it is ready for copying.
|
||||
// See https://github.com/tendermint/tendermint/issues/6427
|
||||
func TestTrickedTruncation(t *testing.T) {
|
||||
tmpDir, err := ioutil.TempDir(os.TempDir(), "pwn_truncate")
|
||||
tmpDir, err := os.MkdirTemp(os.TempDir(), "pwn_truncate")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@@ -84,12 +83,12 @@ func TestTrickedTruncation(t *testing.T) {
|
||||
|
||||
originalWALPath := filepath.Join(tmpDir, "wal")
|
||||
originalWALContent := []byte("I AM BECOME DEATH, DESTROYER OF ALL WORLDS!")
|
||||
if err := ioutil.WriteFile(originalWALPath, originalWALContent, 0755); err != nil {
|
||||
if err := os.WriteFile(originalWALPath, originalWALContent, 0755); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
// 1. Sanity check.
|
||||
readWAL, err := ioutil.ReadFile(originalWALPath)
|
||||
readWAL, err := os.ReadFile(originalWALPath)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@@ -104,7 +103,7 @@ func TestTrickedTruncation(t *testing.T) {
|
||||
}
|
||||
|
||||
// 3. Check the WAL's content
|
||||
reReadWAL, err := ioutil.ReadFile(originalWALPath)
|
||||
reReadWAL, err := os.ReadFile(originalWALPath)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user