mirror of
https://github.com/octoleo/syncthing.git
synced 2025-02-02 03:48:26 +00:00
Expand tilde in repository path (fixes #8)
This commit is contained in:
parent
48603a1619
commit
46d828e349
13
main.go
13
main.go
@ -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 == "" {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user