]> Cypherpunks repositories - gostls13.git/commitdiff
os: clarify behavior of TempDir
authorBrad Fitzpatrick <bradfitz@golang.org>
Wed, 14 Jun 2017 18:29:49 +0000 (18:29 +0000)
committerBrad Fitzpatrick <bradfitz@golang.org>
Wed, 14 Jun 2017 20:12:49 +0000 (20:12 +0000)
Fixes #19695

Change-Id: Ie5103f7905969e25dba6e5fb37344b70e807fc69
Reviewed-on: https://go-review.googlesource.com/45702
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
src/os/file.go
src/os/file_plan9.go
src/os/file_unix.go
src/os/file_windows.go

index c5db78fe2e96e51a6a3b8bd8d8f3dc5f579ad30d..876bffde6d203c784b4d6a712d61bbe6a3ebba5d 100644 (file)
@@ -279,3 +279,16 @@ func (f *File) wrapErr(op string, err error) error {
        }
        return &PathError{op, f.name, err}
 }
+
+// TempDir returns the default directory to use for temporary files.
+//
+// On Unix systems, it returns $TMPDIR if non-empty, else /tmp.
+// On Windows, it uses GetTempPath, returning the first non-empty
+// value from %TMP%, %TEMP%, %USERPROFILE%, or the Windows directory.
+// On Plan 9, it returns /tmp.
+//
+// The directory is neither guaranteed to exist nor have accessible
+// permissions.
+func TempDir() string {
+       return tempDir()
+}
index 97acb5878d8bec763ca50354473c60fd8141630c..d0d230ba667d756f853de95cf91b11f9d592617f 100644 (file)
@@ -478,8 +478,7 @@ func (f *File) Chown(uid, gid int) error {
        return &PathError{"chown", f.name, syscall.EPLAN9}
 }
 
-// TempDir returns the default directory to use for temporary files.
-func TempDir() string {
+func tempDir() string {
        return "/tmp"
 }
 
index 7f5c84f4bdc5345ef973c30518e15ef943b1a542..8b600d80b9813ac0d0df34c8ae25f5a28f22a27e 100644 (file)
@@ -294,8 +294,7 @@ func Remove(name string) error {
        return &PathError{"remove", name, e}
 }
 
-// TempDir returns the default directory to use for temporary files.
-func TempDir() string {
+func tempDir() string {
        dir := Getenv("TMPDIR")
        if dir == "" {
                if runtime.GOOS == "android" {
index 3e916ae9b2da9af84a14f809f1c2a001b6da35c4..93b6c135c72281fba505de866902bc83fbaeaf5d 100644 (file)
@@ -325,8 +325,7 @@ func Pipe() (r *File, w *File, err error) {
        return newFile(p[0], "|0", "file"), newFile(p[1], "|1", "file"), nil
 }
 
-// TempDir returns the default directory to use for temporary files.
-func TempDir() string {
+func tempDir() string {
        n := uint32(syscall.MAX_PATH)
        for {
                b := make([]uint16, n)