mirror of
https://github.com/octoleo/syncthing.git
synced 2025-01-24 07:28:27 +00:00
Set the right config and home dir for each OS
Use %AppData%\syncthing for the config files and %USERPROFILE%\Sync as sync folder for Windows.
This commit is contained in:
parent
23593c3d20
commit
043dea760f
41
main.go
41
main.go
@ -11,7 +11,6 @@ import (
|
|||||||
_ "net/http/pprof"
|
_ "net/http/pprof"
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"os/user"
|
|
||||||
"path"
|
"path"
|
||||||
"runtime"
|
"runtime"
|
||||||
"runtime/debug"
|
"runtime/debug"
|
||||||
@ -41,7 +40,7 @@ var (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
flag.StringVar(&confDir, "home", "~/.syncthing", "Set configuration directory")
|
flag.StringVar(&confDir, "home", getDefaultConfDir(), "Set configuration directory")
|
||||||
flag.StringVar(&trace, "debug.trace", "", "(connect,net,idx,file,pull)")
|
flag.StringVar(&trace, "debug.trace", "", "(connect,net,idx,file,pull)")
|
||||||
flag.StringVar(&profiler, "debug.profiler", "", "(addr)")
|
flag.StringVar(&profiler, "debug.profiler", "", "(addr)")
|
||||||
flag.BoolVar(&showVersion, "version", false, "Show version")
|
flag.BoolVar(&showVersion, "version", false, "Show version")
|
||||||
@ -139,7 +138,7 @@ func main() {
|
|||||||
cfg, err = readConfigXML(nil)
|
cfg, err = readConfigXML(nil)
|
||||||
cfg.Repositories = []RepositoryConfiguration{
|
cfg.Repositories = []RepositoryConfiguration{
|
||||||
{
|
{
|
||||||
Directory: "~/Sync",
|
Directory: path.Join(getHomeDir(), "Sync"),
|
||||||
Nodes: []NodeConfiguration{
|
Nodes: []NodeConfiguration{
|
||||||
{NodeID: myID, Addresses: []string{"dynamic"}},
|
{NodeID: myID, Addresses: []string{"dynamic"}},
|
||||||
},
|
},
|
||||||
@ -555,20 +554,38 @@ func ensureDir(dir string, mode int) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func expandTilde(p string) string {
|
func expandTilde(p string) string {
|
||||||
|
if runtime.GOOS == "windows" {
|
||||||
|
return p
|
||||||
|
}
|
||||||
|
|
||||||
if strings.HasPrefix(p, "~/") {
|
if strings.HasPrefix(p, "~/") {
|
||||||
return strings.Replace(p, "~", getHomeDir(), 1)
|
return strings.Replace(p, "~", getUnixHomeDir(), 1)
|
||||||
}
|
}
|
||||||
return p
|
return p
|
||||||
}
|
}
|
||||||
|
|
||||||
func getHomeDir() string {
|
func getUnixHomeDir() string {
|
||||||
usr, err := user.Current()
|
home := os.Getenv("HOME")
|
||||||
if err != nil {
|
if home == "" {
|
||||||
fatalln(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
if usr.HomeDir == "" {
|
|
||||||
fatalln("No home directory?")
|
fatalln("No home directory?")
|
||||||
}
|
}
|
||||||
return usr.HomeDir
|
return home
|
||||||
|
}
|
||||||
|
|
||||||
|
func getHomeDir() string {
|
||||||
|
if runtime.GOOS == "windows" {
|
||||||
|
home := os.Getenv("HOMEDRIVE") + os.Getenv("HOMEPATH")
|
||||||
|
if home == "" {
|
||||||
|
home = os.Getenv("USERPROFILE")
|
||||||
|
}
|
||||||
|
return home
|
||||||
|
}
|
||||||
|
return getUnixHomeDir()
|
||||||
|
}
|
||||||
|
|
||||||
|
func getDefaultConfDir() string {
|
||||||
|
if runtime.GOOS == "windows" {
|
||||||
|
return path.Join(os.Getenv("AppData"), "syncthing")
|
||||||
|
}
|
||||||
|
return expandTilde("~/.syncthing")
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user