From af06845cf3004701891bf4fdb884bfe4920b3727 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Sat, 26 Jan 2019 20:21:35 -0800 Subject: [PATCH] Add a Reset function --- homedir.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/homedir.go b/homedir.go index fb87bef..2537853 100644 --- a/homedir.go +++ b/homedir.go @@ -76,6 +76,16 @@ func Expand(path string) (string, error) { return filepath.Join(dir, path[1:]), nil } +// Reset clears the cache, forcing the next call to Dir to re-detect +// the home directory. This generally never has to be called, but can be +// useful in tests if you're modifying the home directory via the HOME +// env var or something. +func Reset() { + cacheLock.Lock() + defer cacheLock.Unlock() + homedirCache = "" +} + func dirUnix() (string, error) { homeEnv := "HOME" if runtime.GOOS == "plan9" {