github.com/wallyworld/juju@v0.0.0-20161013125918-6cf1bc9d917a/juju/osenv/old_home.go (about) 1 // Copyright 2016 Canonical Ltd. 2 // Licensed under the AGPLv3, see LICENCE file for details. 3 4 package osenv 5 6 import ( 7 "os" 8 "path/filepath" 9 "runtime" 10 11 "github.com/juju/utils" 12 ) 13 14 // Juju1xEnvConfigExists returns true if there is an environments.yaml file in 15 // the expected juju 1.x directory. 16 func Juju1xEnvConfigExists() bool { 17 dir := OldJujuHomeDir() 18 if dir == "" { 19 return false 20 } 21 _, err := os.Stat(filepath.Join(dir, "environments.yaml")) 22 return err == nil 23 } 24 25 // The following code is copied from juju 1.x, only the names have been changed 26 // to protect the innocent. 27 28 // oldJujuHomeEnvKey holds the environment variable that a user could set to 29 // override where juju 1.x stored application data. 30 const oldJujuHomeEnvKey = "JUJU_HOME" 31 32 // OldJujuHomeDir returns the directory where juju 1.x stored 33 // application-specific files. 34 func OldJujuHomeDir() string { 35 JujuHomeDir := os.Getenv(oldJujuHomeEnvKey) 36 if JujuHomeDir == "" { 37 if runtime.GOOS == "windows" { 38 JujuHomeDir = oldJujuHomeWin() 39 } else { 40 JujuHomeDir = oldJujuHomeLinux() 41 } 42 } 43 return JujuHomeDir 44 } 45 46 // oldJujuHomeLinux returns the directory where juju 1.x stored 47 // application-specific files on Linux. 48 func oldJujuHomeLinux() string { 49 home := utils.Home() 50 if home == "" { 51 return "" 52 } 53 return filepath.Join(home, ".juju") 54 } 55 56 // oldJujuHomeWin returns the directory where juju 1.x stored 57 // application-specific files on Windows. 58 func oldJujuHomeWin() string { 59 appdata := os.Getenv("APPDATA") 60 if appdata == "" { 61 return "" 62 } 63 return filepath.Join(appdata, "Juju") 64 }