github.com/makyo/juju@v0.0.0-20160425123129-2608902037e9/juju/osenv/old_home.go (about)

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