mirror of
https://github.com/golang/go
synced 2024-11-19 01:54:39 -07:00
os: don't create files in local directory
Also, use a random temporary directory rather than os.TempDir. Defer removal of existing random temporary directories. Change-Id: Id7549031cdf78a2bab28c07b6eeff621bdf6e49c Reviewed-on: https://go-review.googlesource.com/c/146457 Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Tobias Klauser <tobias.klauser@gmail.com>
This commit is contained in:
parent
01f0dbbafc
commit
6c9b655ac1
@ -8,18 +8,23 @@ import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
. "os"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestRemoveAll(t *testing.T) {
|
||||
tmpDir := TempDir()
|
||||
// Work directory.
|
||||
file := "file"
|
||||
path := tmpDir + "/_TestRemoveAll_"
|
||||
fpath := path + "/file"
|
||||
dpath := path + "/dir"
|
||||
tmpDir, err := ioutil.TempDir("", "TestRemoveAll-")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer RemoveAll(tmpDir)
|
||||
|
||||
file := filepath.Join(tmpDir, "file")
|
||||
path := filepath.Join(tmpDir, "_TestRemoveAll_")
|
||||
fpath := filepath.Join(path, "file")
|
||||
dpath := filepath.Join(path, "dir")
|
||||
|
||||
// Make a regular file and remove
|
||||
fd, err := Create(file)
|
||||
@ -127,9 +132,13 @@ func TestRemoveAllLarge(t *testing.T) {
|
||||
t.Skip("skipping in short mode")
|
||||
}
|
||||
|
||||
tmpDir := TempDir()
|
||||
// Work directory.
|
||||
path := tmpDir + "/_TestRemoveAllLarge_"
|
||||
tmpDir, err := ioutil.TempDir("", "TestRemoveAll-")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer RemoveAll(tmpDir)
|
||||
|
||||
path := filepath.Join(tmpDir, "_TestRemoveAllLarge_")
|
||||
|
||||
// Make directory with 1000 files and remove.
|
||||
if err := MkdirAll(path, 0777); err != nil {
|
||||
@ -168,6 +177,8 @@ func TestRemoveAllLongPath(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatalf("Could not create TempDir: %s", err)
|
||||
}
|
||||
defer RemoveAll(startPath)
|
||||
|
||||
err = Chdir(startPath)
|
||||
if err != nil {
|
||||
t.Fatalf("Could not chdir %s: %s", startPath, err)
|
||||
@ -215,6 +226,8 @@ func TestRemoveAllDot(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatalf("Could not create TempDir: %s", err)
|
||||
}
|
||||
defer RemoveAll(tempDir)
|
||||
|
||||
err = Chdir(tempDir)
|
||||
if err != nil {
|
||||
t.Fatalf("Could not chdir to tempdir: %s", err)
|
||||
|
Loading…
Reference in New Issue
Block a user