Expand tilde in repository path (fixes #8)

This commit is contained in:
Jakob Borg 2014-01-06 19:37:26 +01:00
parent 48603a1619
commit 46d828e349

13
main.go
View File

@ -75,9 +75,7 @@ func main() {
if len(opts.Debug.TraceModel) > 0 || opts.Debug.LogSource { if len(opts.Debug.TraceModel) > 0 || opts.Debug.LogSource {
logger = log.New(os.Stderr, "", log.Lshortfile|log.Ldate|log.Ltime|log.Lmicroseconds) logger = log.New(os.Stderr, "", log.Lshortfile|log.Ldate|log.Ltime|log.Lmicroseconds)
} }
if strings.HasPrefix(opts.ConfDir, "~/") { opts.ConfDir = expandTilde(opts.ConfDir)
opts.ConfDir = strings.Replace(opts.ConfDir, "~", getHomeDir(), 1)
}
infoln("Version", Version) infoln("Version", Version)
@ -124,7 +122,7 @@ func main() {
config = ini.Parse(cf) config = ini.Parse(cf)
cf.Close() cf.Close()
var dir = config.Get("repository", "dir") var dir = expandTilde(config.Get("repository", "dir"))
// Create a map of desired node connections based on the configuration file // Create a map of desired node connections based on the configuration file
// directives. // directives.
@ -388,6 +386,13 @@ func ensureDir(dir string, mode int) {
} }
} }
func expandTilde(p string) string {
if strings.HasPrefix(p, "~/") {
return strings.Replace(p, "~", getHomeDir(), 1)
}
return p
}
func getHomeDir() string { func getHomeDir() string {
home := os.Getenv("HOME") home := os.Getenv("HOME")
if home == "" { if home == "" {