mirror of
https://github.com/octoleo/syncthing.git
synced 2025-02-13 00:58:32 +00:00
Refactor: move folder prepare to it's own function
This commit is contained in:
parent
a9691dbdf4
commit
00c363829c
@ -14,9 +14,7 @@ import (
|
|||||||
"math/rand"
|
"math/rand"
|
||||||
"net/url"
|
"net/url"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
|
||||||
"reflect"
|
"reflect"
|
||||||
"runtime"
|
|
||||||
"sort"
|
"sort"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
@ -163,35 +161,7 @@ func (cfg *Configuration) prepare(myID protocol.DeviceID) {
|
|||||||
var seenFolders = map[string]*FolderConfiguration{}
|
var seenFolders = map[string]*FolderConfiguration{}
|
||||||
for i := range cfg.Folders {
|
for i := range cfg.Folders {
|
||||||
folder := &cfg.Folders[i]
|
folder := &cfg.Folders[i]
|
||||||
|
folder.prepare()
|
||||||
if len(folder.RawPath) == 0 {
|
|
||||||
folder.Invalid = "no directory configured"
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
// The reason it's done like this:
|
|
||||||
// C: -> C:\ -> C:\ (issue that this is trying to fix)
|
|
||||||
// C:\somedir -> C:\somedir\ -> C:\somedir
|
|
||||||
// C:\somedir\ -> C:\somedir\\ -> C:\somedir
|
|
||||||
// This way in the tests, we get away without OS specific separators
|
|
||||||
// in the test configs.
|
|
||||||
folder.RawPath = filepath.Dir(folder.RawPath + string(filepath.Separator))
|
|
||||||
|
|
||||||
// If we're not on Windows, we want the path to end with a slash to
|
|
||||||
// penetrate symlinks. On Windows, paths must not end with a slash.
|
|
||||||
if runtime.GOOS != "windows" && folder.RawPath[len(folder.RawPath)-1] != filepath.Separator {
|
|
||||||
folder.RawPath = folder.RawPath + string(filepath.Separator)
|
|
||||||
}
|
|
||||||
|
|
||||||
if folder.ID == "" {
|
|
||||||
folder.ID = "default"
|
|
||||||
}
|
|
||||||
|
|
||||||
if folder.RescanIntervalS > MaxRescanIntervalS {
|
|
||||||
folder.RescanIntervalS = MaxRescanIntervalS
|
|
||||||
} else if folder.RescanIntervalS < 0 {
|
|
||||||
folder.RescanIntervalS = 0
|
|
||||||
}
|
|
||||||
|
|
||||||
if seen, ok := seenFolders[folder.ID]; ok {
|
if seen, ok := seenFolders[folder.ID]; ok {
|
||||||
l.Warnf("Multiple folders with ID %q; disabling", folder.ID)
|
l.Warnf("Multiple folders with ID %q; disabling", folder.ID)
|
||||||
|
@ -109,6 +109,37 @@ func (f *FolderConfiguration) DeviceIDs() []protocol.DeviceID {
|
|||||||
return deviceIDs
|
return deviceIDs
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (f *FolderConfiguration) prepare() {
|
||||||
|
if len(f.RawPath) == 0 {
|
||||||
|
f.Invalid = "no directory configured"
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// The reason it's done like this:
|
||||||
|
// C: -> C:\ -> C:\ (issue that this is trying to fix)
|
||||||
|
// C:\somedir -> C:\somedir\ -> C:\somedir
|
||||||
|
// C:\somedir\ -> C:\somedir\\ -> C:\somedir
|
||||||
|
// This way in the tests, we get away without OS specific separators
|
||||||
|
// in the test configs.
|
||||||
|
f.RawPath = filepath.Dir(f.RawPath + string(filepath.Separator))
|
||||||
|
|
||||||
|
// If we're not on Windows, we want the path to end with a slash to
|
||||||
|
// penetrate symlinks. On Windows, paths must not end with a slash.
|
||||||
|
if runtime.GOOS != "windows" && f.RawPath[len(f.RawPath)-1] != filepath.Separator {
|
||||||
|
f.RawPath = f.RawPath + string(filepath.Separator)
|
||||||
|
}
|
||||||
|
|
||||||
|
if f.ID == "" {
|
||||||
|
f.ID = "default"
|
||||||
|
}
|
||||||
|
|
||||||
|
if f.RescanIntervalS > MaxRescanIntervalS {
|
||||||
|
f.RescanIntervalS = MaxRescanIntervalS
|
||||||
|
} else if f.RescanIntervalS < 0 {
|
||||||
|
f.RescanIntervalS = 0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
type FolderDeviceConfigurationList []FolderDeviceConfiguration
|
type FolderDeviceConfigurationList []FolderDeviceConfiguration
|
||||||
|
|
||||||
func (l FolderDeviceConfigurationList) Less(a, b int) bool {
|
func (l FolderDeviceConfigurationList) Less(a, b int) bool {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user