mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
all: update to use os.ReadFile, os.WriteFile, os.CreateTemp, os.MkdirTemp
As part of #42026, these helpers from io/ioutil were moved to os. (ioutil.TempFile and TempDir became os.CreateTemp and MkdirTemp.) Update the Go tree to use the preferred names. As usual, code compiled with the Go 1.4 bootstrap toolchain and code vendored from other sources is excluded. ReadDir changes are in a separate CL, because they are not a simple search and replace. For #42026. Change-Id: If318df0216d57e95ea0c4093b89f65e5b0ababb3 Reviewed-on: https://go-review.googlesource.com/c/go/+/266365 Trust: Russ Cox <rsc@golang.org> Run-TryBot: Russ Cox <rsc@golang.org> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
This commit is contained in:
parent
5627a4dc30
commit
4f1b0a44cb
215 changed files with 556 additions and 704 deletions
|
|
@ -11,7 +11,6 @@ import (
|
|||
"fmt"
|
||||
"internal/testenv"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"os/exec"
|
||||
"os/user"
|
||||
|
|
@ -65,7 +64,7 @@ func skipNoUserNamespaces(t *testing.T) {
|
|||
func skipUnprivilegedUserClone(t *testing.T) {
|
||||
// Skip the test if the sysctl that prevents unprivileged user
|
||||
// from creating user namespaces is enabled.
|
||||
data, errRead := ioutil.ReadFile("/proc/sys/kernel/unprivileged_userns_clone")
|
||||
data, errRead := os.ReadFile("/proc/sys/kernel/unprivileged_userns_clone")
|
||||
if errRead != nil || len(data) < 1 || data[0] == '0' {
|
||||
t.Skip("kernel prohibits user namespace in unprivileged process")
|
||||
}
|
||||
|
|
@ -98,7 +97,7 @@ func checkUserNS(t *testing.T) {
|
|||
// On Centos 7 make sure they set the kernel parameter user_namespace=1
|
||||
// See issue 16283 and 20796.
|
||||
if _, err := os.Stat("/sys/module/user_namespace/parameters/enable"); err == nil {
|
||||
buf, _ := ioutil.ReadFile("/sys/module/user_namespace/parameters/enabled")
|
||||
buf, _ := os.ReadFile("/sys/module/user_namespace/parameters/enabled")
|
||||
if !strings.HasPrefix(string(buf), "Y") {
|
||||
t.Skip("kernel doesn't support user namespaces")
|
||||
}
|
||||
|
|
@ -106,7 +105,7 @@ func checkUserNS(t *testing.T) {
|
|||
|
||||
// On Centos 7.5+, user namespaces are disabled if user.max_user_namespaces = 0
|
||||
if _, err := os.Stat("/proc/sys/user/max_user_namespaces"); err == nil {
|
||||
buf, errRead := ioutil.ReadFile("/proc/sys/user/max_user_namespaces")
|
||||
buf, errRead := os.ReadFile("/proc/sys/user/max_user_namespaces")
|
||||
if errRead == nil && buf[0] == '0' {
|
||||
t.Skip("kernel doesn't support user namespaces")
|
||||
}
|
||||
|
|
@ -226,7 +225,7 @@ func TestUnshare(t *testing.T) {
|
|||
t.Fatal(err)
|
||||
}
|
||||
|
||||
orig, err := ioutil.ReadFile(path)
|
||||
orig, err := os.ReadFile(path)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
|
@ -349,7 +348,7 @@ func TestUnshareMountNameSpace(t *testing.T) {
|
|||
t.Skip("kernel prohibits unshare in unprivileged process, unless using user namespace")
|
||||
}
|
||||
|
||||
d, err := ioutil.TempDir("", "unshare")
|
||||
d, err := os.MkdirTemp("", "unshare")
|
||||
if err != nil {
|
||||
t.Fatalf("tempdir: %v", err)
|
||||
}
|
||||
|
|
@ -391,7 +390,7 @@ func TestUnshareMountNameSpaceChroot(t *testing.T) {
|
|||
t.Skip("kernel prohibits unshare in unprivileged process, unless using user namespace")
|
||||
}
|
||||
|
||||
d, err := ioutil.TempDir("", "unshare")
|
||||
d, err := os.MkdirTemp("", "unshare")
|
||||
if err != nil {
|
||||
t.Fatalf("tempdir: %v", err)
|
||||
}
|
||||
|
|
@ -599,7 +598,7 @@ func testAmbientCaps(t *testing.T, userns bool) {
|
|||
}
|
||||
|
||||
// Copy the test binary to a temporary location which is readable by nobody.
|
||||
f, err := ioutil.TempFile("", "gotest")
|
||||
f, err := os.CreateTemp("", "gotest")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue