lib/config: Remove "Invalid" attribute (fixes #2471)
This contains the following behavioral changes: - Duplicate folder IDs is now fatal during startup - Invalid folder flags in the ClusterConfig is fatal for the connection (this will go away soon with the proto changes, as we won't have any unknown flags any more then) - Empty path is a folder error reported at runtime GitHub-Pull-Request: https://github.com/syncthing/syncthing/pull/3370
This commit is contained in:
committed by
Audrius Butkevicius
parent
8e39e2889d
commit
6d357211b2
@@ -39,7 +39,6 @@ type FolderConfiguration struct {
|
||||
DisableSparseFiles bool `xml:"disableSparseFiles" json:"disableSparseFiles"`
|
||||
DisableTempIndexes bool `xml:"disableTempIndexes" json:"disableTempIndexes"`
|
||||
|
||||
Invalid string `xml:"-" json:"invalid"` // Set at runtime when there is an error, not saved
|
||||
cachedPath string
|
||||
|
||||
DeprecatedReadOnly bool `xml:"ro,attr,omitempty" json:"-"`
|
||||
@@ -70,7 +69,7 @@ func (f FolderConfiguration) Path() string {
|
||||
// This is intentionally not a pointer method, because things like
|
||||
// cfg.Folders["default"].Path() should be valid.
|
||||
|
||||
if f.cachedPath == "" {
|
||||
if f.cachedPath == "" && f.RawPath != "" {
|
||||
l.Infoln("bug: uncached path call (should only happen in tests)")
|
||||
return f.cleanedPath()
|
||||
}
|
||||
@@ -108,31 +107,24 @@ func (f *FolderConfiguration) DeviceIDs() []protocol.DeviceID {
|
||||
}
|
||||
|
||||
func (f *FolderConfiguration) prepare() {
|
||||
if len(f.RawPath) == 0 {
|
||||
f.Invalid = "no directory configured"
|
||||
return
|
||||
}
|
||||
if f.RawPath != "" {
|
||||
// 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))
|
||||
|
||||
// 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 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)
|
||||
}
|
||||
}
|
||||
|
||||
f.cachedPath = f.cleanedPath()
|
||||
|
||||
if f.ID == "" {
|
||||
f.ID = "default"
|
||||
}
|
||||
|
||||
if f.RescanIntervalS > MaxRescanIntervalS {
|
||||
f.RescanIntervalS = MaxRescanIntervalS
|
||||
} else if f.RescanIntervalS < 0 {
|
||||
@@ -145,6 +137,10 @@ func (f *FolderConfiguration) prepare() {
|
||||
}
|
||||
|
||||
func (f *FolderConfiguration) cleanedPath() string {
|
||||
if f.RawPath == "" {
|
||||
return ""
|
||||
}
|
||||
|
||||
cleaned := f.RawPath
|
||||
|
||||
// Attempt tilde expansion; leave unchanged in case of error
|
||||
|
||||
Reference in New Issue
Block a user