mirror of
https://github.com/octoleo/syncthing.git
synced 2024-11-09 14:50:56 +00:00
Merge branch 'filoozom-patch-1'
* filoozom-patch-1: Fix divided by zero when the sync folder is empty (tot = 0) Delete cfgFile before renaming it on Windows Set the right config and home dir for each OS Update getHomeDir() to use "os/user"
This commit is contained in:
commit
5d8f0f835e
@ -40,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")
|
||||||
@ -138,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"}},
|
||||||
},
|
},
|
||||||
@ -328,6 +328,13 @@ func saveConfigLoop(cfgFile string) {
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if runtime.GOOS == "windows" {
|
||||||
|
err := os.Remove(cfgFile)
|
||||||
|
if err != nil && !os.IsNotExist(err) {
|
||||||
|
warnln(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
err = os.Rename(cfgFile+".tmp", cfgFile)
|
err = os.Rename(cfgFile+".tmp", cfgFile)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
warnln(err)
|
warnln(err)
|
||||||
@ -554,16 +561,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 {
|
||||||
home := os.Getenv("HOME")
|
home := os.Getenv("HOME")
|
||||||
if home == "" {
|
if home == "" {
|
||||||
fatalln("No home directory?")
|
fatalln("No home directory?")
|
||||||
}
|
}
|
||||||
return home
|
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")
|
||||||
|
}
|
||||||
|
@ -191,7 +191,10 @@ func (m *Model) ConnectionStats() map[string]ConnectionInfo {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ci.Completion = int(100 * have / tot)
|
ci.Completion = 100
|
||||||
|
if tot != 0 {
|
||||||
|
ci.Completion = int(100 * have / tot)
|
||||||
|
}
|
||||||
|
|
||||||
res[node] = ci
|
res[node] = ci
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user