David K. Bainbridge | 528b318 | 2017-01-23 08:51:59 -0800 | [diff] [blame] | 1 | // Copyright 2013 Canonical Ltd. |
| 2 | // Licensed under the LGPLv3, see LICENCE file for details. |
| 3 | |
| 4 | package utils |
| 5 | |
| 6 | import ( |
| 7 | "os" |
| 8 | "path/filepath" |
| 9 | ) |
| 10 | |
| 11 | // Home returns the os-specific home path as specified in the environment. |
| 12 | func Home() string { |
| 13 | return filepath.Join(os.Getenv("HOMEDRIVE"), os.Getenv("HOMEPATH")) |
| 14 | } |
| 15 | |
| 16 | // SetHome sets the os-specific home path in the environment. |
| 17 | func SetHome(s string) error { |
| 18 | v := filepath.VolumeName(s) |
| 19 | if v != "" { |
| 20 | if err := os.Setenv("HOMEDRIVE", v); err != nil { |
| 21 | return err |
| 22 | } |
| 23 | } |
| 24 | return os.Setenv("HOMEPATH", s[len(v):]) |
| 25 | } |