Browse Source

Expand tilde in repository path (fixes #8)

Jakob Borg 12 years ago
parent
commit
46d828e349
1 changed files with 9 additions and 4 deletions
  1. 9 4
      main.go

+ 9 - 4
main.go

@@ -75,9 +75,7 @@ func main() {
 	if len(opts.Debug.TraceModel) > 0 || opts.Debug.LogSource {
 		logger = log.New(os.Stderr, "", log.Lshortfile|log.Ldate|log.Ltime|log.Lmicroseconds)
 	}
-	if strings.HasPrefix(opts.ConfDir, "~/") {
-		opts.ConfDir = strings.Replace(opts.ConfDir, "~", getHomeDir(), 1)
-	}
+	opts.ConfDir = expandTilde(opts.ConfDir)
 
 	infoln("Version", Version)
 
@@ -124,7 +122,7 @@ func main() {
 	config = ini.Parse(cf)
 	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
 	// 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 {
 	home := os.Getenv("HOME")
 	if home == "" {