]> Cypherpunks repositories - gostls13.git/commitdiff
os: don't create files in local directory
authorIan Lance Taylor <iant@golang.org>
Wed, 31 Oct 2018 22:06:59 +0000 (15:06 -0700)
committerTobias Klauser <tobias.klauser@gmail.com>
Thu, 1 Nov 2018 08:36:12 +0000 (08:36 +0000)
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>
src/os/removeall_test.go

index 4b6f3e92565e08c446c7ba492ebb6553f83006e3..93a6733d6abfe338f35528d0c5ef29c7051b1bfc 100644 (file)
@@ -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)