lib/config: Sanity checks on MaxConcurrentWrites (ref #7064) (#7069)

This commit is contained in:
Simon Frei
2020-11-03 19:09:32 +01:00
committed by GitHub
parent c206fbdc58
commit d0ccea0404
2 changed files with 12 additions and 1 deletions
+1
View File
@@ -129,6 +129,7 @@ func TestDeviceConfig(t *testing.T) {
WeakHashThresholdPct: 25, WeakHashThresholdPct: 25,
MarkerName: DefaultMarkerName, MarkerName: DefaultMarkerName,
JunctionsAsDirs: true, JunctionsAsDirs: true,
MaxConcurrentWrites: maxConcurrentWritesDefault,
}, },
} }
+11 -1
View File
@@ -26,7 +26,11 @@ var (
ErrMarkerMissing = errors.New("folder marker missing (this indicates potential data loss, search docs/forum to get information about how to proceed)") ErrMarkerMissing = errors.New("folder marker missing (this indicates potential data loss, search docs/forum to get information about how to proceed)")
) )
const DefaultMarkerName = ".stfolder" const (
DefaultMarkerName = ".stfolder"
maxConcurrentWritesDefault = 2
maxConcurrentWritesLimit = 64
)
func NewFolderConfiguration(myID protocol.DeviceID, id, label string, fsType fs.FilesystemType, path string) FolderConfiguration { func NewFolderConfiguration(myID protocol.DeviceID, id, label string, fsType fs.FilesystemType, path string) FolderConfiguration {
f := FolderConfiguration{ f := FolderConfiguration{
@@ -206,6 +210,12 @@ func (f *FolderConfiguration) prepare() {
if f.MarkerName == "" { if f.MarkerName == "" {
f.MarkerName = DefaultMarkerName f.MarkerName = DefaultMarkerName
} }
if f.MaxConcurrentWrites <= 0 {
f.MaxConcurrentWrites = maxConcurrentWritesDefault
} else if f.MaxConcurrentWrites > maxConcurrentWritesLimit {
f.MaxConcurrentWrites = maxConcurrentWritesLimit
}
} }
// RequiresRestartOnly returns a copy with only the attributes that require // RequiresRestartOnly returns a copy with only the attributes that require