diff --git a/lib/config/config.go b/lib/config/config.go index 4c4ed83c..a7b9552e 100644 --- a/lib/config/config.go +++ b/lib/config/config.go @@ -14,9 +14,7 @@ import ( "math/rand" "net/url" "os" - "path/filepath" "reflect" - "runtime" "sort" "strconv" "strings" @@ -163,35 +161,7 @@ func (cfg *Configuration) prepare(myID protocol.DeviceID) { var seenFolders = map[string]*FolderConfiguration{} for i := range cfg.Folders { folder := &cfg.Folders[i] - - 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 - } + folder.prepare() if seen, ok := seenFolders[folder.ID]; ok { l.Warnf("Multiple folders with ID %q; disabling", folder.ID) diff --git a/lib/config/folderconfiguration.go b/lib/config/folderconfiguration.go index 512708d7..f49fc4a8 100644 --- a/lib/config/folderconfiguration.go +++ b/lib/config/folderconfiguration.go @@ -109,6 +109,37 @@ func (f *FolderConfiguration) DeviceIDs() []protocol.DeviceID { 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 func (l FolderDeviceConfigurationList) Less(a, b int) bool {