From 0f46fdce42923a79517b3fd50ad8ce97d9c104b2 Mon Sep 17 00:00:00 2001 From: Dan Turner Date: Thu, 14 Jan 2016 11:42:55 +1100 Subject: [PATCH 1/2] Change deps-cache path to inside home instead of a temp folder Closes #33 --- xgo.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/xgo.go b/xgo.go index 2c2dd1b..0a2148e 100644 --- a/xgo.go +++ b/xgo.go @@ -22,7 +22,7 @@ import ( ) // Path where to cache external dependencies -var depsCache = filepath.Join(os.TempDir(), "xgo-cache") +var depsCache = filepath.Join(os.Getenv("HOME"), ".xgo-cache") // Cross compilation docker containers var dockerBase = "karalabe/xgo-base" From 75c37e116e9ca9c0212aed8cd36461eb2b4f2d24 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C3=A9ter=20Szil=C3=A1gyi?= Date: Thu, 14 Jan 2016 12:53:23 +0200 Subject: [PATCH 2/2] Add a few fallback cache paths, fix folder permissions --- xgo.go | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/xgo.go b/xgo.go index 0a2148e..b2bae9c 100644 --- a/xgo.go +++ b/xgo.go @@ -16,13 +16,27 @@ import ( "net/http" "os" "os/exec" + "os/user" "path/filepath" "strconv" "strings" ) // Path where to cache external dependencies -var depsCache = filepath.Join(os.Getenv("HOME"), ".xgo-cache") +var depsCache string + +func init() { + // Initialize the external dependency cache path to a few possible locations + if home := os.Getenv("HOME"); home != "" { + depsCache = filepath.Join(home, ".xgo-cache") + return + } + if user, err := user.Current(); user != nil && err == nil && user.HomeDir != "" { + depsCache = filepath.Join(user.HomeDir, ".xgo-cache") + return + } + depsCache = filepath.Join(os.TempDir(), "xgo-cache") +} // Cross compilation docker containers var dockerBase = "karalabe/xgo-base" @@ -115,7 +129,7 @@ func main() { } // Cache all external dependencies to prevent always hitting the internet if *crossDeps != "" { - if err := os.MkdirAll(depsCache, 751); err != nil { + if err := os.MkdirAll(depsCache, 0751); err != nil { log.Fatalf("Failed to create dependency cache: %v.", err) } // Download all missing dependencies