From 3957be37c82124c3eea881ce1e4b5b9af56026f4 Mon Sep 17 00:00:00 2001 From: Elias Naur Date: Wed, 6 May 2020 16:48:31 +0200 Subject: [PATCH] app: [Android] tweak environment for os.UserHomeDir and os.UserConfigDir Set the fallback environment variables XDG_CONFIG_HOME and HOME to make os.UserConfigDir and os.UserHomeDir report useful paths. Signed-off-by: Elias Naur --- app/datadir_android.go | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/app/datadir_android.go b/app/datadir_android.go index db585d4a..450e6cfd 100644 --- a/app/datadir_android.go +++ b/app/datadir_android.go @@ -23,8 +23,19 @@ func dataDir() (string, error) { dataDirOnce.Do(func() { dataPath = window.GetDataDir() // Set XDG_CACHE_HOME to make os.UserCacheDir work. - cachePath := filepath.Join(dataPath, "cache") - os.Setenv("XDG_CACHE_HOME", cachePath) + if _, exists := os.LookupEnv("XDG_CACHE_HOME"); !exists { + cachePath := filepath.Join(dataPath, "cache") + os.Setenv("XDG_CACHE_HOME", cachePath) + } + // Set XDG_CONFIG_HOME to make os.UserConfigDir work. + if _, exists := os.LookupEnv("XDG_CONFIG_HOME"); !exists { + cfgPath := filepath.Join(dataPath, "config") + os.Setenv("XDG_CONFIG_HOME", cfgPath) + } + // Set HOME to make os.UserHomeDir work. + if _, exists := os.LookupEnv("HOME"); !exists { + os.Setenv("HOME", dataPath) + } }) return dataPath, nil }