mirror of
https://github.com/octoleo/syncthing.git
synced 2024-12-22 19:08:58 +00:00
Sanitize rescan interval values (fixes #1978)
This commit is contained in:
parent
1d2235abe7
commit
4eb0e24c6e
@ -28,6 +28,7 @@ import (
|
||||
const (
|
||||
OldestHandledVersion = 5
|
||||
CurrentVersion = 10
|
||||
MaxRescanIntervalS = 365 * 24 * 60 * 60
|
||||
)
|
||||
|
||||
type Configuration struct {
|
||||
@ -330,6 +331,12 @@ func (cfg *Configuration) prepare(myID protocol.DeviceID) {
|
||||
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 {
|
||||
l.Warnf("Multiple folders with ID %q; disabling", folder.ID)
|
||||
|
||||
|
@ -578,3 +578,17 @@ func TestPullOrder(t *testing.T) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestLargeRescanInterval(t *testing.T) {
|
||||
wrapper, err := Load("testdata/largeinterval.xml", device1)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if wrapper.Folders()["l1"].RescanIntervalS != MaxRescanIntervalS {
|
||||
t.Error("too large rescan interval should be maxed out")
|
||||
}
|
||||
if wrapper.Folders()["l2"].RescanIntervalS != 0 {
|
||||
t.Error("negative rescan interval should become zero")
|
||||
}
|
||||
}
|
||||
|
4
internal/config/testdata/largeinterval.xml
vendored
Normal file
4
internal/config/testdata/largeinterval.xml
vendored
Normal file
@ -0,0 +1,4 @@
|
||||
<configuration version="10">
|
||||
<folder id="l1" path="~/Sync" rescanIntervalS="60000000000"></folder>
|
||||
<folder id="l2" path="~/Sync" rescanIntervalS="-1"></folder>
|
||||
</configuration>
|
Loading…
Reference in New Issue
Block a user