aboutsummaryrefslogtreecommitdiff
path: root/libgo/go/os
diff options
context:
space:
mode:
authorIan Lance Taylor <iant@golang.org>2022-07-27 10:15:41 -0700
committerIan Lance Taylor <iant@golang.org>2022-07-27 10:15:41 -0700
commit9f62ed218fa656607740b386c0caa03e65dcd283 (patch)
tree6bde49bc5e4c4241266b108e4277baef4b85535d /libgo/go/os
parent71e955da39cea0ebffcfee3432effa622d14ca99 (diff)
parent5eb9f117a361538834b9740d59219911680717d1 (diff)
downloadgcc-9f62ed218fa656607740b386c0caa03e65dcd283.zip
gcc-9f62ed218fa656607740b386c0caa03e65dcd283.tar.gz
gcc-9f62ed218fa656607740b386c0caa03e65dcd283.tar.bz2
Merge from trunk revision 5eb9f117a361538834b9740d59219911680717d1.
Diffstat (limited to 'libgo/go/os')
-rw-r--r--libgo/go/os/example_test.go22
-rw-r--r--libgo/go/os/exec/internal/fdtest/exists_unix.go2
-rw-r--r--libgo/go/os/os_test.go40
-rw-r--r--libgo/go/os/tempfile.go2
-rw-r--r--libgo/go/os/user/cgo_listgroups_unix.go2
-rw-r--r--libgo/go/os/user/getgrouplist_unix.go2
-rw-r--r--libgo/go/os/user/listgroups_unix.go1
7 files changed, 53 insertions, 18 deletions
diff --git a/libgo/go/os/example_test.go b/libgo/go/os/example_test.go
index e8554b0..53e3c52 100644
--- a/libgo/go/os/example_test.go
+++ b/libgo/go/os/example_test.go
@@ -241,3 +241,25 @@ func ExampleWriteFile() {
log.Fatal(err)
}
}
+
+func ExampleMkdir() {
+ err := os.Mkdir("testdir", 0750)
+ if err != nil && !os.IsExist(err) {
+ log.Fatal(err)
+ }
+ err = os.WriteFile("testdir/testfile.txt", []byte("Hello, Gophers!"), 0660)
+ if err != nil {
+ log.Fatal(err)
+ }
+}
+
+func ExampleMkdirAll() {
+ err := os.MkdirAll("test/subdir", 0750)
+ if err != nil && !os.IsExist(err) {
+ log.Fatal(err)
+ }
+ err = os.WriteFile("test/subdir/testfile.txt", []byte("Hello, Gophers!"), 0660)
+ if err != nil {
+ log.Fatal(err)
+ }
+}
diff --git a/libgo/go/os/exec/internal/fdtest/exists_unix.go b/libgo/go/os/exec/internal/fdtest/exists_unix.go
index 49f264c..fca328f 100644
--- a/libgo/go/os/exec/internal/fdtest/exists_unix.go
+++ b/libgo/go/os/exec/internal/fdtest/exists_unix.go
@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
-//go:build aix || darwin || dragonfly || freebsd || linux || netbsd || openbsd || solaris
+//go:build aix || darwin || dragonfly || freebsd || hurd || linux || netbsd || openbsd || solaris
// Package fdtest provides test helpers for working with file descriptors across exec.
package fdtest
diff --git a/libgo/go/os/os_test.go b/libgo/go/os/os_test.go
index e90b89d..59e4fb6 100644
--- a/libgo/go/os/os_test.go
+++ b/libgo/go/os/os_test.go
@@ -28,6 +28,16 @@ import (
"time"
)
+func TestMain(m *testing.M) {
+ if Getenv("GO_OS_TEST_DRAIN_STDIN") == "1" {
+ os.Stdout.Close()
+ io.Copy(io.Discard, os.Stdin)
+ Exit(0)
+ }
+
+ Exit(m.Run())
+}
+
var dot = []string{
"dir.go",
"env.go",
@@ -2261,9 +2271,18 @@ func testKillProcess(t *testing.T, processKiller func(p *Process)) {
testenv.MustHaveExec(t)
t.Parallel()
- // Re-exec the test binary itself to emulate "sleep 1".
- cmd := osexec.Command(Args[0], "-test.run", "TestSleep")
- err := cmd.Start()
+ // Re-exec the test binary to start a process that hangs until stdin is closed.
+ cmd := osexec.Command(Args[0])
+ cmd.Env = append(os.Environ(), "GO_OS_TEST_DRAIN_STDIN=1")
+ stdout, err := cmd.StdoutPipe()
+ if err != nil {
+ t.Fatal(err)
+ }
+ stdin, err := cmd.StdinPipe()
+ if err != nil {
+ t.Fatal(err)
+ }
+ err = cmd.Start()
if err != nil {
t.Fatalf("Failed to start test process: %v", err)
}
@@ -2272,19 +2291,14 @@ func testKillProcess(t *testing.T, processKiller func(p *Process)) {
if err := cmd.Wait(); err == nil {
t.Errorf("Test process succeeded, but expected to fail")
}
+ stdin.Close() // Keep stdin alive until the process has finished dying.
}()
- time.Sleep(100 * time.Millisecond)
- processKiller(cmd.Process)
-}
+ // Wait for the process to be started.
+ // (It will close its stdout when it reaches TestMain.)
+ io.Copy(io.Discard, stdout)
-// TestSleep emulates "sleep 1". It is a helper for testKillProcess, so we
-// don't have to rely on an external "sleep" command being available.
-func TestSleep(t *testing.T) {
- if testing.Short() {
- t.Skip("Skipping in short mode")
- }
- time.Sleep(time.Second)
+ processKiller(cmd.Process)
}
func TestKillStartProcess(t *testing.T) {
diff --git a/libgo/go/os/tempfile.go b/libgo/go/os/tempfile.go
index 5b681fc..3be3d13 100644
--- a/libgo/go/os/tempfile.go
+++ b/libgo/go/os/tempfile.go
@@ -46,7 +46,7 @@ func CreateTemp(dir, pattern string) (*File, error) {
if try++; try < 10000 {
continue
}
- return nil, &PathError{Op: "createtemp", Path: dir + string(PathSeparator) + prefix + "*" + suffix, Err: ErrExist}
+ return nil, &PathError{Op: "createtemp", Path: prefix + "*" + suffix, Err: ErrExist}
}
return f, err
}
diff --git a/libgo/go/os/user/cgo_listgroups_unix.go b/libgo/go/os/user/cgo_listgroups_unix.go
index 5621c1a..09ec1cc 100644
--- a/libgo/go/os/user/cgo_listgroups_unix.go
+++ b/libgo/go/os/user/cgo_listgroups_unix.go
@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
-//go:build (dragonfly || darwin || freebsd || (!android && linux) || netbsd || openbsd || (solaris && !illumos)) && cgo && !osusergo
+//go:build (dragonfly || darwin || freebsd || hurd || (!android && linux) || netbsd || openbsd || (solaris && !illumos)) && cgo && !osusergo
package user
diff --git a/libgo/go/os/user/getgrouplist_unix.go b/libgo/go/os/user/getgrouplist_unix.go
index 527d941..e97e0bc 100644
--- a/libgo/go/os/user/getgrouplist_unix.go
+++ b/libgo/go/os/user/getgrouplist_unix.go
@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
-//go:build (dragonfly || freebsd || (!android && linux) || netbsd || openbsd || (solaris && !illumos)) && cgo && !osusergo
+//go:build (dragonfly || freebsd || hurd || (!android && linux) || netbsd || openbsd || (solaris && !illumos)) && cgo && !osusergo
package user
diff --git a/libgo/go/os/user/listgroups_unix.go b/libgo/go/os/user/listgroups_unix.go
index b3cf839..af9b544 100644
--- a/libgo/go/os/user/listgroups_unix.go
+++ b/libgo/go/os/user/listgroups_unix.go
@@ -14,7 +14,6 @@ import (
"io"
"os"
"strconv"
- "syscall"
)
const groupFile = "/etc/group"