mirror of
https://github.com/octoleo/syncthing.git
synced 2025-01-22 22:58:25 +00:00
lib/config, lib/model: Tweaks to the auto accept feature
Fix the folder restart behavior (ignore Label), improve the API for that (imho). Also removes the tab switch animation in the settings modal, because annoying. GitHub-Pull-Request: https://github.com/syncthing/syncthing/pull/4577
This commit is contained in:
parent
445c4edeca
commit
47429d01e8
@ -7,7 +7,7 @@
|
|||||||
<li><a data-toggle="tab" href="#settings-connections" translate>Connections</a></li>
|
<li><a data-toggle="tab" href="#settings-connections" translate>Connections</a></li>
|
||||||
</ul>
|
</ul>
|
||||||
<div class="tab-content">
|
<div class="tab-content">
|
||||||
<div id="settings-general" class="tab-pane fade in active">
|
<div id="settings-general" class="tab-pane in active">
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label translate for="DeviceName">Device Name</label>
|
<label translate for="DeviceName">Device Name</label>
|
||||||
<input id="DeviceName" class="form-control" type="text" ng-model="tmpOptions.deviceName"/>
|
<input id="DeviceName" class="form-control" type="text" ng-model="tmpOptions.deviceName"/>
|
||||||
@ -90,7 +90,7 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div id="settings-gui" class="tab-pane fade">
|
<div id="settings-gui" class="tab-pane">
|
||||||
<div class="form-group" ng-class="{'has-error': settingsEditor.Address.$invalid && settingsEditor.Address.$dirty}">
|
<div class="form-group" ng-class="{'has-error': settingsEditor.Address.$invalid && settingsEditor.Address.$dirty}">
|
||||||
<label translate for="Address">GUI Listen Address</label> <a href="https://docs.syncthing.net/users/guilisten.html" target="_blank"><span class="fa fa-fw fa-book"></span> <span translate>Help</span></a>
|
<label translate for="Address">GUI Listen Address</label> <a href="https://docs.syncthing.net/users/guilisten.html" target="_blank"><span class="fa fa-fw fa-book"></span> <span translate>Help</span></a>
|
||||||
<input id="Address" name="Address" class="form-control" type="text" ng-model="tmpGUI.address" ng-pattern="/.*:0*((102[4-9])|(10[3-9][0-9])|(1[1-9][0-9][0-9])|([2-9][0-9][0-9][0-9])|([1-6]\d{4}))$/"/>
|
<input id="Address" name="Address" class="form-control" type="text" ng-model="tmpGUI.address" ng-pattern="/.*:0*((102[4-9])|(10[3-9][0-9])|(1[1-9][0-9][0-9])|([2-9][0-9][0-9][0-9])|([1-6]\d{4}))$/"/>
|
||||||
@ -150,7 +150,7 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div id="settings-connections" class="tab-pane fade">
|
<div id="settings-connections" class="tab-pane">
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label translate for="ListenAddressesStr">Sync Protocol Listen Addresses</label> <a href="https://docs.syncthing.net/users/config.html#listen-addresses" target="_blank"><span class="fa fa-fw fa-book"></span> <span translate>Help</span></a>
|
<label translate for="ListenAddressesStr">Sync Protocol Listen Addresses</label> <a href="https://docs.syncthing.net/users/config.html#listen-addresses" target="_blank"><span class="fa fa-fw fa-book"></span> <span translate>Help</span></a>
|
||||||
<input id="ListenAddressesStr" class="form-control" type="text" ng-model="tmpOptions._listenAddressesStr"/>
|
<input id="ListenAddressesStr" class="form-control" type="text" ng-model="tmpOptions._listenAddressesStr"/>
|
||||||
|
@ -13,6 +13,7 @@ import (
|
|||||||
|
|
||||||
"github.com/syncthing/syncthing/lib/fs"
|
"github.com/syncthing/syncthing/lib/fs"
|
||||||
"github.com/syncthing/syncthing/lib/protocol"
|
"github.com/syncthing/syncthing/lib/protocol"
|
||||||
|
"github.com/syncthing/syncthing/lib/util"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@ -24,8 +25,8 @@ var (
|
|||||||
const DefaultMarkerName = ".stfolder"
|
const DefaultMarkerName = ".stfolder"
|
||||||
|
|
||||||
type FolderConfiguration struct {
|
type FolderConfiguration struct {
|
||||||
ID string `xml:"id,attr" json:"id" restart:"false"`
|
ID string `xml:"id,attr" json:"id"`
|
||||||
Label string `xml:"label,attr" json:"label"`
|
Label string `xml:"label,attr" json:"label" restart:"false"`
|
||||||
FilesystemType fs.FilesystemType `xml:"filesystemType" json:"filesystemType"`
|
FilesystemType fs.FilesystemType `xml:"filesystemType" json:"filesystemType"`
|
||||||
Path string `xml:"path,attr" json:"path"`
|
Path string `xml:"path,attr" json:"path"`
|
||||||
Type FolderType `xml:"type,attr" json:"type"`
|
Type FolderType `xml:"type,attr" json:"type"`
|
||||||
@ -225,6 +226,25 @@ func (f *FolderConfiguration) prepare() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// RequiresRestartOnly returns a copy with only the attributes that require
|
||||||
|
// restart on change.
|
||||||
|
func (f FolderConfiguration) RequiresRestartOnly() FolderConfiguration {
|
||||||
|
copy := f
|
||||||
|
|
||||||
|
// Manual handling for things that are not taken care of by the tag
|
||||||
|
// copier, yet should not cause a restart.
|
||||||
|
copy.cachedFilesystem = nil
|
||||||
|
|
||||||
|
blank := FolderConfiguration{}
|
||||||
|
util.CopyMatchingTag(&blank, ©, "restart", func(v string) bool {
|
||||||
|
if len(v) > 0 && v != "false" {
|
||||||
|
panic(fmt.Sprintf(`unexpected tag value: %s. expected untagged or "false"`, v))
|
||||||
|
}
|
||||||
|
return v == "false"
|
||||||
|
})
|
||||||
|
return copy
|
||||||
|
}
|
||||||
|
|
||||||
type FolderDeviceConfigurationList []FolderDeviceConfiguration
|
type FolderDeviceConfigurationList []FolderDeviceConfiguration
|
||||||
|
|
||||||
func (l FolderDeviceConfigurationList) Less(a, b int) bool {
|
func (l FolderDeviceConfigurationList) Less(a, b int) bool {
|
||||||
|
@ -10,6 +10,8 @@ import (
|
|||||||
"encoding/json"
|
"encoding/json"
|
||||||
"encoding/xml"
|
"encoding/xml"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
|
"github.com/syncthing/syncthing/lib/util"
|
||||||
)
|
)
|
||||||
|
|
||||||
type WeakHashSelectionMethod int
|
type WeakHashSelectionMethod int
|
||||||
@ -162,3 +164,17 @@ func (orig OptionsConfiguration) Copy() OptionsConfiguration {
|
|||||||
copy(c.UnackedNotificationIDs, orig.UnackedNotificationIDs)
|
copy(c.UnackedNotificationIDs, orig.UnackedNotificationIDs)
|
||||||
return c
|
return c
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// RequiresRestartOnly returns a copy with only the attributes that require
|
||||||
|
// restart on change.
|
||||||
|
func (orig OptionsConfiguration) RequiresRestartOnly() OptionsConfiguration {
|
||||||
|
copy := orig
|
||||||
|
blank := OptionsConfiguration{}
|
||||||
|
util.CopyMatchingTag(&blank, ©, "restart", func(v string) bool {
|
||||||
|
if len(v) > 0 && v != "true" {
|
||||||
|
panic(fmt.Sprintf(`unexpected tag value: %s. expected untagged or "true"`, v))
|
||||||
|
}
|
||||||
|
return v != "true"
|
||||||
|
})
|
||||||
|
return copy
|
||||||
|
}
|
||||||
|
@ -33,7 +33,6 @@ import (
|
|||||||
"github.com/syncthing/syncthing/lib/stats"
|
"github.com/syncthing/syncthing/lib/stats"
|
||||||
"github.com/syncthing/syncthing/lib/sync"
|
"github.com/syncthing/syncthing/lib/sync"
|
||||||
"github.com/syncthing/syncthing/lib/upgrade"
|
"github.com/syncthing/syncthing/lib/upgrade"
|
||||||
"github.com/syncthing/syncthing/lib/util"
|
|
||||||
"github.com/syncthing/syncthing/lib/versioner"
|
"github.com/syncthing/syncthing/lib/versioner"
|
||||||
"github.com/syncthing/syncthing/lib/weakhash"
|
"github.com/syncthing/syncthing/lib/weakhash"
|
||||||
"github.com/thejerf/suture"
|
"github.com/thejerf/suture"
|
||||||
@ -2445,17 +2444,8 @@ func (m *Model) CommitConfiguration(from, to config.Configuration) bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// This folder exists on both sides. Settings might have changed.
|
// This folder exists on both sides. Settings might have changed.
|
||||||
// Check if anything differs, apart from the label.
|
// Check if anything differs that requires a restart.
|
||||||
toCfgCopy := toCfg
|
if !reflect.DeepEqual(fromCfg.RequiresRestartOnly(), toCfg.RequiresRestartOnly()) {
|
||||||
fromCfgCopy := fromCfg
|
|
||||||
util.CopyMatchingTag(&toCfgCopy, &fromCfgCopy, "restart", func(v string) bool {
|
|
||||||
if len(v) > 0 && v != "false" {
|
|
||||||
panic(fmt.Sprintf(`unexpected struct value: %s. expected untagged or "false"`, v))
|
|
||||||
}
|
|
||||||
return v == "false"
|
|
||||||
})
|
|
||||||
|
|
||||||
if !reflect.DeepEqual(fromCfgCopy, toCfgCopy) {
|
|
||||||
m.RestartFolder(toCfg)
|
m.RestartFolder(toCfg)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2495,23 +2485,9 @@ func (m *Model) CommitConfiguration(from, to config.Configuration) bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Some options don't require restart as those components handle it fine
|
// Some options don't require restart as those components handle it fine
|
||||||
// by themselves.
|
// by themselves. Compare the options structs containing only the
|
||||||
|
// attributes that require restart and act apprioriately.
|
||||||
// Copy fields that do not have the field set to true
|
if !reflect.DeepEqual(from.Options.RequiresRestartOnly(), to.Options.RequiresRestartOnly()) {
|
||||||
util.CopyMatchingTag(&from.Options, &to.Options, "restart", func(v string) bool {
|
|
||||||
if len(v) > 0 && v != "true" {
|
|
||||||
panic(fmt.Sprintf(`unexpected struct value: %s. expected untagged or "true"`, v))
|
|
||||||
}
|
|
||||||
return v != "true"
|
|
||||||
})
|
|
||||||
|
|
||||||
// All of the other generic options require restart. Or at least they may;
|
|
||||||
// removing this check requires going through those options carefully and
|
|
||||||
// making sure there are individual services that handle them correctly.
|
|
||||||
// This code is the "original" requires-restart check and protects other
|
|
||||||
// components that haven't yet been converted to VerifyConfig/CommitConfig
|
|
||||||
// handling.
|
|
||||||
if !reflect.DeepEqual(from.Options, to.Options) {
|
|
||||||
l.Debugln(m, "requires restart, options differ")
|
l.Debugln(m, "requires restart, options differ")
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
@ -87,6 +87,11 @@ func CopyMatchingTag(from interface{}, to interface{}, tag string, shouldCopy fu
|
|||||||
fromField := fromStruct.Field(i)
|
fromField := fromStruct.Field(i)
|
||||||
toField := toStruct.Field(i)
|
toField := toStruct.Field(i)
|
||||||
|
|
||||||
|
if !toField.CanSet() {
|
||||||
|
// Unexported fields
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
structTag := toType.Field(i).Tag
|
structTag := toType.Field(i).Tag
|
||||||
|
|
||||||
v := structTag.Get(tag)
|
v := structTag.Get(tag)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user