]> Cypherpunks repositories - gostls13.git/commitdiff
os: have UserCacheDir return an error on failure
authorAndrew Bonventre <andybons@golang.org>
Mon, 25 Jun 2018 18:26:53 +0000 (14:26 -0400)
committerAndrew Bonventre <andybons@golang.org>
Mon, 25 Jun 2018 18:59:39 +0000 (18:59 +0000)
Previously, it would return an empty string if it
could not determine the user's cache directory.
Return an error instead.

Change-Id: I74f00b1ad3858efa3fe2700c599271ebfe5764b6
Reviewed-on: https://go-review.googlesource.com/120757
Run-TryBot: Andrew Bonventre <andybons@golang.org>
Reviewed-by: Josh Bleecher Snyder <josharian@gmail.com>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>

api/go1.11.txt
src/os/file.go

index d8428b288fe983d95a0bbb9430d86374675f3f10..1c641eac51e18bdd213dd44bd101d52df3953dbd 100644 (file)
@@ -451,7 +451,7 @@ pkg net/http/httptrace, type ClientTrace struct, Got1xxResponse func(int, textpr
 pkg os, const ModeIrregular = 524288
 pkg os, const ModeIrregular FileMode
 pkg os, const ModeType = 2399666176
-pkg os, func UserCacheDir() string
+pkg os, func UserCacheDir() (string, error)
 pkg os/signal, func Ignored(os.Signal) bool
 pkg regexp/syntax, method (Op) String() string
 pkg runtime/trace, func IsEnabled() bool
index fa73919620da3d08b35e33c5832fb0ed2981c2e2..cba70d78fbfd32fc2baa57cc1d80ccc9ad4366f0 100644 (file)
@@ -342,25 +342,28 @@ func TempDir() string {
 // On Plan 9, it returns $home/lib/cache.
 //
 // If the location cannot be determined (for example, $HOME is not defined),
-// then it will return an empty string.
-func UserCacheDir() string {
+// then it will return an error.
+func UserCacheDir() (string, error) {
        var dir string
 
        switch runtime.GOOS {
        case "windows":
                dir = Getenv("LocalAppData")
+               if dir == "" {
+                       return "", errors.New("%LocalAppData% is not defined")
+               }
 
        case "darwin":
                dir = Getenv("HOME")
                if dir == "" {
-                       return ""
+                       return "", errors.New("$HOME is not defined")
                }
                dir += "/Library/Caches"
 
        case "plan9":
                dir = Getenv("home")
                if dir == "" {
-                       return ""
+                       return "", errors.New("$home is not defined")
                }
                dir += "/lib/cache"
 
@@ -369,13 +372,13 @@ func UserCacheDir() string {
                if dir == "" {
                        dir = Getenv("HOME")
                        if dir == "" {
-                               return ""
+                               return "", errors.New("neither $XDG_CACHE_HOME nor $HOME are defined")
                        }
                        dir += "/.cache"
                }
        }
 
-       return dir
+       return dir, nil
 }
 
 // Chmod changes the mode of the named file to mode.