all: Remove usage of deprecated io/ioutil (#7971)
As of Go 1.16 io/ioutil is deprecated. This replaces usage with the corresponding functions in package os and package io.
This commit is contained in:
@@ -43,7 +43,7 @@ func CreateAtomic(path string) (*AtomicWriter, error) {
|
||||
// permissions.
|
||||
func CreateAtomicFilesystem(filesystem fs.Filesystem, path string) (*AtomicWriter, error) {
|
||||
// The security of this depends on the tempfile having secure
|
||||
// permissions, 0600, from the beginning. This is what ioutil.TempFile
|
||||
// permissions, 0600, from the beginning. This is what os.CreateTemp
|
||||
// does. We have a test that verifies that that is the case, should this
|
||||
// ever change in the standard library in the future.
|
||||
fd, err := TempFile(filesystem, filepath.Dir(path), TempPrefix)
|
||||
|
||||
@@ -8,7 +8,6 @@ package osutil
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
@@ -35,7 +34,7 @@ func TestCreateAtomicCreate(t *testing.T) {
|
||||
t.Fatal("written bytes", n, "!= 5")
|
||||
}
|
||||
|
||||
if _, err := ioutil.ReadFile("testdata/file"); err == nil {
|
||||
if _, err := os.ReadFile("testdata/file"); err == nil {
|
||||
t.Fatal("file should not exist")
|
||||
}
|
||||
|
||||
@@ -43,7 +42,7 @@ func TestCreateAtomicCreate(t *testing.T) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
bs, err := ioutil.ReadFile("testdata/file")
|
||||
bs, err := os.ReadFile("testdata/file")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@@ -62,7 +61,7 @@ func TestCreateAtomicReplaceReadOnly(t *testing.T) {
|
||||
func testCreateAtomicReplace(t *testing.T, oldPerms os.FileMode) {
|
||||
t.Helper()
|
||||
|
||||
testdir, err := ioutil.TempDir("", "syncthing")
|
||||
testdir, err := os.MkdirTemp("", "syncthing")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@@ -75,7 +74,7 @@ func testCreateAtomicReplace(t *testing.T, oldPerms os.FileMode) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if err := ioutil.WriteFile(testfile, []byte("some old data"), oldPerms); err != nil {
|
||||
if err := os.WriteFile(testfile, []byte("some old data"), oldPerms); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
@@ -103,7 +102,7 @@ func testCreateAtomicReplace(t *testing.T, oldPerms os.FileMode) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
bs, err := ioutil.ReadFile(testfile)
|
||||
bs, err := os.ReadFile(testfile)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
@@ -12,7 +12,6 @@
|
||||
package osutil
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"syscall"
|
||||
"testing"
|
||||
@@ -24,7 +23,7 @@ func TestTempFilePermissions(t *testing.T) {
|
||||
oldMask := syscall.Umask(0)
|
||||
defer syscall.Umask(oldMask)
|
||||
|
||||
fd, err := ioutil.TempFile("", "test")
|
||||
fd, err := os.CreateTemp("", "test")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
package osutil_test
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
"io"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
@@ -83,7 +83,7 @@ func TestIsDeleted(t *testing.T) {
|
||||
func TestRenameOrCopy(t *testing.T) {
|
||||
mustTempDir := func() string {
|
||||
t.Helper()
|
||||
tmpDir, err := ioutil.TempDir("", "")
|
||||
tmpDir, err := os.MkdirTemp("", "")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@@ -131,7 +131,7 @@ func TestRenameOrCopy(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
buf, err := ioutil.ReadAll(fd)
|
||||
buf, err := io.ReadAll(fd)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@@ -147,7 +147,7 @@ func TestRenameOrCopy(t *testing.T) {
|
||||
if fd, err := test.dst.Open("new"); err != nil {
|
||||
t.Fatal(err)
|
||||
} else {
|
||||
if buf, err := ioutil.ReadAll(fd); err != nil {
|
||||
if buf, err := io.ReadAll(fd); err != nil {
|
||||
t.Fatal(err)
|
||||
} else if string(buf) != content {
|
||||
t.Fatalf("expected %s got %s", content, string(buf))
|
||||
|
||||
@@ -7,7 +7,6 @@
|
||||
package osutil_test
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
@@ -18,7 +17,7 @@ import (
|
||||
)
|
||||
|
||||
func TestTraversesSymlink(t *testing.T) {
|
||||
tmpDir, err := ioutil.TempDir(".", ".test-TraversesSymlink-")
|
||||
tmpDir, err := os.MkdirTemp(".", ".test-TraversesSymlink-")
|
||||
if err != nil {
|
||||
panic("Failed to create temporary testing dir")
|
||||
}
|
||||
@@ -71,7 +70,7 @@ func TestTraversesSymlink(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestIssue4875(t *testing.T) {
|
||||
tmpDir, err := ioutil.TempDir("", ".test-Issue4875-")
|
||||
tmpDir, err := os.MkdirTemp("", ".test-Issue4875-")
|
||||
if err != nil {
|
||||
panic("Failed to create temporary testing dir")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user