aboutsummaryrefslogtreecommitdiff
path: root/src/syscall
diff options
context:
space:
mode:
authorRuss Cox <rsc@golang.org>2020-10-29 14:17:47 -0400
committerRuss Cox <rsc@golang.org>2020-12-09 19:12:23 +0000
commit4f1b0a44cb46f3df28f5ef82e5769ebeac1bc493 (patch)
treec186cc25257b05fcb21cd8c1f1ee5961ebef6eb3 /src/syscall
parent5627a4dc3013fed02c4b8097413643b682cac276 (diff)
downloadgo-4f1b0a44cb46f3df28f5ef82e5769ebeac1bc493.tar.gz
go-4f1b0a44cb46f3df28f5ef82e5769ebeac1bc493.zip
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>
Diffstat (limited to 'src/syscall')
-rw-r--r--src/syscall/dirent_test.go9
-rw-r--r--src/syscall/exec_linux_test.go15
-rw-r--r--src/syscall/getdirentries_test.go5
-rw-r--r--src/syscall/mkasm_darwin.go9
-rw-r--r--src/syscall/syscall_linux_test.go11
-rw-r--r--src/syscall/syscall_unix_test.go7
-rw-r--r--src/syscall/syscall_windows_test.go3
7 files changed, 26 insertions, 33 deletions
diff --git a/src/syscall/dirent_test.go b/src/syscall/dirent_test.go
index f63153340a..7dac98ff4b 100644
--- a/src/syscall/dirent_test.go
+++ b/src/syscall/dirent_test.go
@@ -9,7 +9,6 @@ package syscall_test
import (
"bytes"
"fmt"
- "io/ioutil"
"os"
"path/filepath"
"runtime"
@@ -27,7 +26,7 @@ func TestDirent(t *testing.T) {
filenameMinSize = 11
)
- d, err := ioutil.TempDir("", "dirent-test")
+ d, err := os.MkdirTemp("", "dirent-test")
if err != nil {
t.Fatalf("tempdir: %v", err)
}
@@ -36,7 +35,7 @@ func TestDirent(t *testing.T) {
for i, c := range []byte("0123456789") {
name := string(bytes.Repeat([]byte{c}, filenameMinSize+i))
- err = ioutil.WriteFile(filepath.Join(d, name), nil, 0644)
+ err = os.WriteFile(filepath.Join(d, name), nil, 0644)
if err != nil {
t.Fatalf("writefile: %v", err)
}
@@ -93,7 +92,7 @@ func TestDirentRepeat(t *testing.T) {
}
// Make a directory containing N files
- d, err := ioutil.TempDir("", "direntRepeat-test")
+ d, err := os.MkdirTemp("", "direntRepeat-test")
if err != nil {
t.Fatalf("tempdir: %v", err)
}
@@ -104,7 +103,7 @@ func TestDirentRepeat(t *testing.T) {
files = append(files, fmt.Sprintf("file%d", i))
}
for _, file := range files {
- err = ioutil.WriteFile(filepath.Join(d, file), []byte("contents"), 0644)
+ err = os.WriteFile(filepath.Join(d, file), []byte("contents"), 0644)
if err != nil {
t.Fatalf("writefile: %v", err)
}
diff --git a/src/syscall/exec_linux_test.go b/src/syscall/exec_linux_test.go
index b79dee7525..ac3a5754ae 100644
--- a/src/syscall/exec_linux_test.go
+++ b/src/syscall/exec_linux_test.go
@@ -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)
}
diff --git a/src/syscall/getdirentries_test.go b/src/syscall/getdirentries_test.go
index 2a3419c230..66bb8acba2 100644
--- a/src/syscall/getdirentries_test.go
+++ b/src/syscall/getdirentries_test.go
@@ -8,7 +8,6 @@ package syscall_test
import (
"fmt"
- "io/ioutil"
"os"
"path/filepath"
"sort"
@@ -29,7 +28,7 @@ func testGetdirentries(t *testing.T, count int) {
if count > 100 && testing.Short() && os.Getenv("GO_BUILDER_NAME") == "" {
t.Skip("skipping in -short mode")
}
- d, err := ioutil.TempDir("", "getdirentries-test")
+ d, err := os.MkdirTemp("", "getdirentries-test")
if err != nil {
t.Fatalf("Tempdir: %v", err)
}
@@ -41,7 +40,7 @@ func testGetdirentries(t *testing.T, count int) {
// Make files in the temp directory
for _, name := range names {
- err := ioutil.WriteFile(filepath.Join(d, name), []byte("data"), 0)
+ err := os.WriteFile(filepath.Join(d, name), []byte("data"), 0)
if err != nil {
t.Fatalf("WriteFile: %v", err)
}
diff --git a/src/syscall/mkasm_darwin.go b/src/syscall/mkasm_darwin.go
index f6f75f99f6..1783387a53 100644
--- a/src/syscall/mkasm_darwin.go
+++ b/src/syscall/mkasm_darwin.go
@@ -11,23 +11,22 @@ package main
import (
"bytes"
"fmt"
- "io/ioutil"
"log"
"os"
"strings"
)
func main() {
- in1, err := ioutil.ReadFile("syscall_darwin.go")
+ in1, err := os.ReadFile("syscall_darwin.go")
if err != nil {
log.Fatalf("can't open syscall_darwin.go: %s", err)
}
arch := os.Args[1]
- in2, err := ioutil.ReadFile(fmt.Sprintf("syscall_darwin_%s.go", arch))
+ in2, err := os.ReadFile(fmt.Sprintf("syscall_darwin_%s.go", arch))
if err != nil {
log.Fatalf("can't open syscall_darwin_%s.go: %s", arch, err)
}
- in3, err := ioutil.ReadFile(fmt.Sprintf("zsyscall_darwin_%s.go", arch))
+ in3, err := os.ReadFile(fmt.Sprintf("zsyscall_darwin_%s.go", arch))
if err != nil {
log.Fatalf("can't open zsyscall_darwin_%s.go: %s", arch, err)
}
@@ -51,7 +50,7 @@ func main() {
fmt.Fprintf(&out, "\tJMP\t%s(SB)\n", fn)
}
}
- err = ioutil.WriteFile(fmt.Sprintf("zsyscall_darwin_%s.s", arch), out.Bytes(), 0644)
+ err = os.WriteFile(fmt.Sprintf("zsyscall_darwin_%s.s", arch), out.Bytes(), 0644)
if err != nil {
log.Fatalf("can't write zsyscall_darwin_%s.s: %s", arch, err)
}
diff --git a/src/syscall/syscall_linux_test.go b/src/syscall/syscall_linux_test.go
index 92764323ee..153d0efef1 100644
--- a/src/syscall/syscall_linux_test.go
+++ b/src/syscall/syscall_linux_test.go
@@ -9,7 +9,6 @@ import (
"fmt"
"io"
"io/fs"
- "io/ioutil"
"os"
"os/exec"
"os/signal"
@@ -30,7 +29,7 @@ func chtmpdir(t *testing.T) func() {
if err != nil {
t.Fatalf("chtmpdir: %v", err)
}
- d, err := ioutil.TempDir("", "test")
+ d, err := os.MkdirTemp("", "test")
if err != nil {
t.Fatalf("chtmpdir: %v", err)
}
@@ -160,7 +159,7 @@ func TestLinuxDeathSignal(t *testing.T) {
// Copy the test binary to a location that a non-root user can read/execute
// after we drop privileges
- tempDir, err := ioutil.TempDir("", "TestDeathSignal")
+ tempDir, err := os.MkdirTemp("", "TestDeathSignal")
if err != nil {
t.Fatalf("cannot create temporary directory: %v", err)
}
@@ -321,7 +320,7 @@ func TestSyscallNoError(t *testing.T) {
// Copy the test binary to a location that a non-root user can read/execute
// after we drop privileges
- tempDir, err := ioutil.TempDir("", "TestSyscallNoError")
+ tempDir, err := os.MkdirTemp("", "TestSyscallNoError")
if err != nil {
t.Fatalf("cannot create temporary directory: %v", err)
}
@@ -543,7 +542,7 @@ func TestAllThreadsSyscall(t *testing.T) {
func compareStatus(filter, expect string) error {
expected := filter + expect
pid := syscall.Getpid()
- fs, err := ioutil.ReadDir(fmt.Sprintf("/proc/%d/task", pid))
+ fs, err := os.ReadDir(fmt.Sprintf("/proc/%d/task", pid))
if err != nil {
return fmt.Errorf("unable to find %d tasks: %v", pid, err)
}
@@ -551,7 +550,7 @@ func compareStatus(filter, expect string) error {
foundAThread := false
for _, f := range fs {
tf := fmt.Sprintf("/proc/%s/status", f.Name())
- d, err := ioutil.ReadFile(tf)
+ d, err := os.ReadFile(tf)
if err != nil {
// There are a surprising number of ways this
// can error out on linux. We've seen all of
diff --git a/src/syscall/syscall_unix_test.go b/src/syscall/syscall_unix_test.go
index 1c34ed2c27..7e6a8c9043 100644
--- a/src/syscall/syscall_unix_test.go
+++ b/src/syscall/syscall_unix_test.go
@@ -11,7 +11,6 @@ import (
"fmt"
"internal/testenv"
"io"
- "io/ioutil"
"net"
"os"
"os/exec"
@@ -79,7 +78,7 @@ func TestFcntlFlock(t *testing.T) {
}
if os.Getenv("GO_WANT_HELPER_PROCESS") == "" {
// parent
- tempDir, err := ioutil.TempDir("", "TestFcntlFlock")
+ tempDir, err := os.MkdirTemp("", "TestFcntlFlock")
if err != nil {
t.Fatalf("Failed to create temp dir: %v", err)
}
@@ -157,7 +156,7 @@ func TestPassFD(t *testing.T) {
}
- tempDir, err := ioutil.TempDir("", "TestPassFD")
+ tempDir, err := os.MkdirTemp("", "TestPassFD")
if err != nil {
t.Fatal(err)
}
@@ -257,7 +256,7 @@ func passFDChild() {
// We make it in tempDir, which our parent will clean up.
flag.Parse()
tempDir := flag.Arg(0)
- f, err := ioutil.TempFile(tempDir, "")
+ f, err := os.CreateTemp(tempDir, "")
if err != nil {
fmt.Printf("TempFile: %v", err)
return
diff --git a/src/syscall/syscall_windows_test.go b/src/syscall/syscall_windows_test.go
index d146911073..a9ae54752b 100644
--- a/src/syscall/syscall_windows_test.go
+++ b/src/syscall/syscall_windows_test.go
@@ -5,7 +5,6 @@
package syscall_test
import (
- "io/ioutil"
"os"
"path/filepath"
"syscall"
@@ -13,7 +12,7 @@ import (
)
func TestWin32finddata(t *testing.T) {
- dir, err := ioutil.TempDir("", "go-build")
+ dir, err := os.MkdirTemp("", "go-build")
if err != nil {
t.Fatalf("failed to create temp directory: %v", err)
}