mirror of
https://github.com/syncthing/syncthing.git
synced 2024-11-16 10:28:49 -07:00
3d8b4a42b7
GitHub-Pull-Request: https://github.com/syncthing/syncthing/pull/4228
53 lines
1.1 KiB
Go
53 lines
1.1 KiB
Go
// Copyright (C) 2015 The Syncthing Authors.
|
|
//
|
|
// This Source Code Form is subject to the terms of the Mozilla Public
|
|
// License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
|
// You can obtain one at https://mozilla.org/MPL/2.0/.
|
|
|
|
package main
|
|
|
|
import (
|
|
"log"
|
|
"os"
|
|
"path/filepath"
|
|
"runtime"
|
|
|
|
"github.com/syncthing/syncthing/lib/fs"
|
|
)
|
|
|
|
func nulString(bs []byte) string {
|
|
for i := range bs {
|
|
if bs[i] == 0 {
|
|
return string(bs[:i])
|
|
}
|
|
}
|
|
return string(bs)
|
|
}
|
|
|
|
func defaultConfigDir() string {
|
|
switch runtime.GOOS {
|
|
case "windows":
|
|
if p := os.Getenv("LocalAppData"); p != "" {
|
|
return filepath.Join(p, "Syncthing")
|
|
}
|
|
return filepath.Join(os.Getenv("AppData"), "Syncthing")
|
|
|
|
case "darwin":
|
|
dir, err := fs.ExpandTilde("~/Library/Application Support/Syncthing")
|
|
if err != nil {
|
|
log.Fatal(err)
|
|
}
|
|
return dir
|
|
|
|
default:
|
|
if xdgCfg := os.Getenv("XDG_CONFIG_HOME"); xdgCfg != "" {
|
|
return filepath.Join(xdgCfg, "syncthing")
|
|
}
|
|
dir, err := fs.ExpandTilde("~/.config/syncthing")
|
|
if err != nil {
|
|
log.Fatal(err)
|
|
}
|
|
return dir
|
|
}
|
|
}
|