Enable to configure scan interval per each repository independently
Fix broken tests Bugfix Clean up Refactor variable name Adjust tests Minor fixes Fix typo. Remove indent.
This commit is contained in:
parent
386f9c42c2
commit
0e751b983c
@ -31,13 +31,14 @@ type Configuration struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type RepositoryConfiguration struct {
|
type RepositoryConfiguration struct {
|
||||||
ID string `xml:"id,attr"`
|
ID string `xml:"id,attr"`
|
||||||
Directory string `xml:"directory,attr"`
|
Directory string `xml:"directory,attr"`
|
||||||
Nodes []RepositoryNodeConfiguration `xml:"node"`
|
Nodes []RepositoryNodeConfiguration `xml:"node"`
|
||||||
ReadOnly bool `xml:"ro,attr"`
|
ReadOnly bool `xml:"ro,attr"`
|
||||||
IgnorePerms bool `xml:"ignorePerms,attr"`
|
RescanIntervalS int `xml:"rescanIntervalS,attr" default:"60"`
|
||||||
Invalid string `xml:"-"` // Set at runtime when there is an error, not saved
|
IgnorePerms bool `xml:"ignorePerms,attr"`
|
||||||
Versioning VersioningConfiguration `xml:"versioning"`
|
Invalid string `xml:"-"` // Set at runtime when there is an error, not saved
|
||||||
|
Versioning VersioningConfiguration `xml:"versioning"`
|
||||||
|
|
||||||
nodeIDs []protocol.NodeID
|
nodeIDs []protocol.NodeID
|
||||||
}
|
}
|
||||||
@ -116,7 +117,6 @@ type OptionsConfiguration struct {
|
|||||||
LocalAnnMCAddr string `xml:"localAnnounceMCAddr" default:"[ff32::5222]:21026"`
|
LocalAnnMCAddr string `xml:"localAnnounceMCAddr" default:"[ff32::5222]:21026"`
|
||||||
ParallelRequests int `xml:"parallelRequests" default:"16"`
|
ParallelRequests int `xml:"parallelRequests" default:"16"`
|
||||||
MaxSendKbps int `xml:"maxSendKbps"`
|
MaxSendKbps int `xml:"maxSendKbps"`
|
||||||
RescanIntervalS int `xml:"rescanIntervalS" default:"60"`
|
|
||||||
ReconnectIntervalS int `xml:"reconnectionIntervalS" default:"60"`
|
ReconnectIntervalS int `xml:"reconnectionIntervalS" default:"60"`
|
||||||
StartBrowser bool `xml:"startBrowser" default:"true"`
|
StartBrowser bool `xml:"startBrowser" default:"true"`
|
||||||
UPnPEnabled bool `xml:"upnpEnabled" default:"true"`
|
UPnPEnabled bool `xml:"upnpEnabled" default:"true"`
|
||||||
@ -124,11 +124,12 @@ type OptionsConfiguration struct {
|
|||||||
UPnPRenewal int `xml:"upnpRenewalMinutes" default:"30"`
|
UPnPRenewal int `xml:"upnpRenewalMinutes" default:"30"`
|
||||||
URAccepted int `xml:"urAccepted"` // Accepted usage reporting version; 0 for off (undecided), -1 for off (permanently)
|
URAccepted int `xml:"urAccepted"` // Accepted usage reporting version; 0 for off (undecided), -1 for off (permanently)
|
||||||
|
|
||||||
Deprecated_UREnabled bool `xml:"urEnabled,omitempty" json:"-"`
|
Deprecated_RescanIntervalS int `xml:"rescanIntervalS,omitempty" json:"-"`
|
||||||
Deprecated_URDeclined bool `xml:"urDeclined,omitempty" json:"-"`
|
Deprecated_UREnabled bool `xml:"urEnabled,omitempty" json:"-"`
|
||||||
Deprecated_ReadOnly bool `xml:"readOnly,omitempty" json:"-"`
|
Deprecated_URDeclined bool `xml:"urDeclined,omitempty" json:"-"`
|
||||||
Deprecated_GUIEnabled bool `xml:"guiEnabled,omitempty" json:"-"`
|
Deprecated_ReadOnly bool `xml:"readOnly,omitempty" json:"-"`
|
||||||
Deprecated_GUIAddress string `xml:"guiAddress,omitempty" json:"-"`
|
Deprecated_GUIEnabled bool `xml:"guiEnabled,omitempty" json:"-"`
|
||||||
|
Deprecated_GUIAddress string `xml:"guiAddress,omitempty" json:"-"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type GUIConfiguration struct {
|
type GUIConfiguration struct {
|
||||||
@ -372,10 +373,20 @@ func Load(rd io.Reader, myID protocol.NodeID) (Configuration, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func convertV3V4(cfg *Configuration) {
|
func convertV3V4(cfg *Configuration) {
|
||||||
|
// In previous versions, rescan interval was common for each repository.
|
||||||
|
// From now, it can be set independently. We have to make sure, that after upgrade
|
||||||
|
// the individual rescan interval will be defined for every existing repository.
|
||||||
|
for i := range cfg.Repositories {
|
||||||
|
cfg.Repositories[i].RescanIntervalS = cfg.Options.Deprecated_RescanIntervalS
|
||||||
|
}
|
||||||
|
|
||||||
|
cfg.Options.Deprecated_RescanIntervalS = 0
|
||||||
|
|
||||||
// In previous versions, repositories held full node configurations.
|
// In previous versions, repositories held full node configurations.
|
||||||
// Since that's the only place where node configs were in V1, we still have
|
// Since that's the only place where node configs were in V1, we still have
|
||||||
// to define the deprecated fields to be able to upgrade from V1 to V4.
|
// to define the deprecated fields to be able to upgrade from V1 to V4.
|
||||||
for i, repo := range cfg.Repositories {
|
for i, repo := range cfg.Repositories {
|
||||||
|
|
||||||
for j := range repo.Nodes {
|
for j := range repo.Nodes {
|
||||||
rncfg := cfg.Repositories[i].Nodes[j]
|
rncfg := cfg.Repositories[i].Nodes[j]
|
||||||
rncfg.Deprecated_Name = ""
|
rncfg.Deprecated_Name = ""
|
||||||
|
|||||||
@ -33,7 +33,6 @@ func TestDefaultValues(t *testing.T) {
|
|||||||
LocalAnnMCAddr: "[ff32::5222]:21026",
|
LocalAnnMCAddr: "[ff32::5222]:21026",
|
||||||
ParallelRequests: 16,
|
ParallelRequests: 16,
|
||||||
MaxSendKbps: 0,
|
MaxSendKbps: 0,
|
||||||
RescanIntervalS: 60,
|
|
||||||
ReconnectIntervalS: 60,
|
ReconnectIntervalS: 60,
|
||||||
StartBrowser: true,
|
StartBrowser: true,
|
||||||
UPnPEnabled: true,
|
UPnPEnabled: true,
|
||||||
@ -70,6 +69,7 @@ func TestNodeConfig(t *testing.T) {
|
|||||||
</repository>
|
</repository>
|
||||||
<options>
|
<options>
|
||||||
<readOnly>true</readOnly>
|
<readOnly>true</readOnly>
|
||||||
|
<rescanIntervalS>600</rescanIntervalS>
|
||||||
</options>
|
</options>
|
||||||
</configuration>
|
</configuration>
|
||||||
`)
|
`)
|
||||||
@ -90,6 +90,9 @@ func TestNodeConfig(t *testing.T) {
|
|||||||
<node id="P56IOI7MZJNU2IQGDREYDM2MGTMGL3BXNPQ6W5BTBBZ4TJXZWICQ" name="node two">
|
<node id="P56IOI7MZJNU2IQGDREYDM2MGTMGL3BXNPQ6W5BTBBZ4TJXZWICQ" name="node two">
|
||||||
<address>b</address>
|
<address>b</address>
|
||||||
</node>
|
</node>
|
||||||
|
<options>
|
||||||
|
<rescanIntervalS>600</rescanIntervalS>
|
||||||
|
</options>
|
||||||
</configuration>
|
</configuration>
|
||||||
`)
|
`)
|
||||||
|
|
||||||
@ -105,11 +108,14 @@ func TestNodeConfig(t *testing.T) {
|
|||||||
<node id="P56IOI7-MZJNU2Y-IQGDREY-DM2MGTI-MGL3BXN-PQ6W5BM-TBBZ4TJ-XZWICQ2" name="node two" compression="true">
|
<node id="P56IOI7-MZJNU2Y-IQGDREY-DM2MGTI-MGL3BXN-PQ6W5BM-TBBZ4TJ-XZWICQ2" name="node two" compression="true">
|
||||||
<address>b</address>
|
<address>b</address>
|
||||||
</node>
|
</node>
|
||||||
|
<options>
|
||||||
|
<rescanIntervalS>600</rescanIntervalS>
|
||||||
|
</options>
|
||||||
</configuration>`)
|
</configuration>`)
|
||||||
|
|
||||||
v4data := []byte(`
|
v4data := []byte(`
|
||||||
<configuration version="4">
|
<configuration version="4">
|
||||||
<repository id="test" directory="~/Sync" ro="true" ignorePerms="false">
|
<repository id="test" directory="~/Sync" ro="true" ignorePerms="false" rescanIntervalS="600">
|
||||||
<node id="AIR6LPZ-7K4PTTV-UXQSMUU-CPQ5YWH-OEDFIIQ-JUG777G-2YQXXR5-YD6AWQR"></node>
|
<node id="AIR6LPZ-7K4PTTV-UXQSMUU-CPQ5YWH-OEDFIIQ-JUG777G-2YQXXR5-YD6AWQR"></node>
|
||||||
<node id="P56IOI7-MZJNU2Y-IQGDREY-DM2MGTI-MGL3BXN-PQ6W5BM-TBBZ4TJ-XZWICQ2"></node>
|
<node id="P56IOI7-MZJNU2Y-IQGDREY-DM2MGTI-MGL3BXN-PQ6W5BM-TBBZ4TJ-XZWICQ2"></node>
|
||||||
</repository>
|
</repository>
|
||||||
@ -129,10 +135,11 @@ func TestNodeConfig(t *testing.T) {
|
|||||||
|
|
||||||
expectedRepos := []RepositoryConfiguration{
|
expectedRepos := []RepositoryConfiguration{
|
||||||
{
|
{
|
||||||
ID: "test",
|
ID: "test",
|
||||||
Directory: "~/Sync",
|
Directory: "~/Sync",
|
||||||
Nodes: []RepositoryNodeConfiguration{{NodeID: node1}, {NodeID: node4}},
|
Nodes: []RepositoryNodeConfiguration{{NodeID: node1}, {NodeID: node4}},
|
||||||
ReadOnly: true,
|
ReadOnly: true,
|
||||||
|
RescanIntervalS: 600,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
expectedNodes := []NodeConfiguration{
|
expectedNodes := []NodeConfiguration{
|
||||||
@ -204,7 +211,6 @@ func TestOverriddenValues(t *testing.T) {
|
|||||||
<localAnnounceMCAddr>quux:3232</localAnnounceMCAddr>
|
<localAnnounceMCAddr>quux:3232</localAnnounceMCAddr>
|
||||||
<parallelRequests>32</parallelRequests>
|
<parallelRequests>32</parallelRequests>
|
||||||
<maxSendKbps>1234</maxSendKbps>
|
<maxSendKbps>1234</maxSendKbps>
|
||||||
<rescanIntervalS>600</rescanIntervalS>
|
|
||||||
<reconnectionIntervalS>6000</reconnectionIntervalS>
|
<reconnectionIntervalS>6000</reconnectionIntervalS>
|
||||||
<startBrowser>false</startBrowser>
|
<startBrowser>false</startBrowser>
|
||||||
<upnpEnabled>false</upnpEnabled>
|
<upnpEnabled>false</upnpEnabled>
|
||||||
@ -223,7 +229,6 @@ func TestOverriddenValues(t *testing.T) {
|
|||||||
LocalAnnMCAddr: "quux:3232",
|
LocalAnnMCAddr: "quux:3232",
|
||||||
ParallelRequests: 32,
|
ParallelRequests: 32,
|
||||||
MaxSendKbps: 1234,
|
MaxSendKbps: 1234,
|
||||||
RescanIntervalS: 600,
|
|
||||||
ReconnectIntervalS: 6000,
|
ReconnectIntervalS: 6000,
|
||||||
StartBrowser: false,
|
StartBrowser: false,
|
||||||
UPnPEnabled: false,
|
UPnPEnabled: false,
|
||||||
|
|||||||
@ -497,6 +497,13 @@
|
|||||||
<span translate ng-if="repoEditor.repoPath.$error.required && repoEditor.repoPath.$dirty">The repository path cannot be blank.</span>
|
<span translate ng-if="repoEditor.repoPath.$error.required && repoEditor.repoPath.$dirty">The repository path cannot be blank.</span>
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="form-group" ng-class="{'has-error': repoEditor.rescanIntervalS.$invalid && repoEditor.rescanIntervalS.$dirty}">
|
||||||
|
<label translate for="rescanIntervalS">Rescan Interval (s)</label>
|
||||||
|
<input name="rescanIntervalS" placeholder="60" id="rescanIntervalS" class="form-control" type="number" ng-model="currentRepo.RescanIntervalS" required min="5"></input>
|
||||||
|
<p class="help-block">
|
||||||
|
<span translate ng-if="!repoEditor.rescanIntervalS.$valid && repoEditor.rescanIntervalS.$dirty">The rescan interval must be at least 5 seconds.</span>
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="row">
|
<div class="row">
|
||||||
@ -581,10 +588,6 @@
|
|||||||
<label translate for="MaxSendKbps">Outgoing Rate Limit (KiB/s)</label>
|
<label translate for="MaxSendKbps">Outgoing Rate Limit (KiB/s)</label>
|
||||||
<input id="MaxSendKbps" class="form-control" type="number" ng-model="tmpOptions.MaxSendKbps">
|
<input id="MaxSendKbps" class="form-control" type="number" ng-model="tmpOptions.MaxSendKbps">
|
||||||
</div>
|
</div>
|
||||||
<div class="form-group">
|
|
||||||
<label translate for="RescanIntervalS">Rescan Interval (s)</label>
|
|
||||||
<input id="RescanIntervalS" class="form-control" type="number" ng-model="tmpOptions.RescanIntervalS">
|
|
||||||
</div>
|
|
||||||
<!--
|
<!--
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label translate for="ReconnectIntervalS">Reconnect Interval (s)</label>
|
<label translate for="ReconnectIntervalS">Reconnect Interval (s)</label>
|
||||||
|
|||||||
@ -134,7 +134,7 @@ func newPuller(repoCfg config.RepositoryConfiguration, model *Model, slots int,
|
|||||||
|
|
||||||
func (p *puller) run() {
|
func (p *puller) run() {
|
||||||
changed := true
|
changed := true
|
||||||
scanintv := time.Duration(p.cfg.Options.RescanIntervalS) * time.Second
|
scanintv := time.Duration(p.repoCfg.RescanIntervalS) * time.Second
|
||||||
lastscan := time.Now()
|
lastscan := time.Now()
|
||||||
var prevVer uint64
|
var prevVer uint64
|
||||||
var queued int
|
var queued int
|
||||||
@ -241,7 +241,7 @@ func (p *puller) run() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (p *puller) runRO() {
|
func (p *puller) runRO() {
|
||||||
walkTicker := time.Tick(time.Duration(p.cfg.Options.RescanIntervalS) * time.Second)
|
walkTicker := time.Tick(time.Duration(p.repoCfg.RescanIntervalS) * time.Second)
|
||||||
|
|
||||||
for _ = range walkTicker {
|
for _ = range walkTicker {
|
||||||
if debug {
|
if debug {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user