mirror of
https://github.com/octoleo/syncthing.git
synced 2024-11-09 14:50:56 +00:00
Use constructor functions for FolderConfiguration and DeviceConfiguration
This commit is contained in:
parent
58523060f0
commit
55592137a2
@ -904,25 +904,19 @@ func setupGUI(mainSvc *suture.Supervisor, cfg *config.Wrapper, m *model.Model, a
|
|||||||
}
|
}
|
||||||
|
|
||||||
func defaultConfig(myName string) config.Configuration {
|
func defaultConfig(myName string) config.Configuration {
|
||||||
|
defaultFolder := config.NewFolderConfiguration("default", locations[locDefFolder])
|
||||||
|
defaultFolder.RescanIntervalS = 60
|
||||||
|
defaultFolder.MinDiskFreePct = 1
|
||||||
|
defaultFolder.Devices = []config.FolderDeviceConfiguration{{DeviceID: myID}}
|
||||||
|
defaultFolder.AutoNormalize = true
|
||||||
|
defaultFolder.MaxConflicts = -1
|
||||||
|
|
||||||
|
thisDevice := config.NewDeviceConfiguration(myID, myName)
|
||||||
|
thisDevice.Addresses = []string{"dynamic"}
|
||||||
|
|
||||||
newCfg := config.New(myID)
|
newCfg := config.New(myID)
|
||||||
newCfg.Folders = []config.FolderConfiguration{
|
newCfg.Folders = []config.FolderConfiguration{defaultFolder}
|
||||||
{
|
newCfg.Devices = []config.DeviceConfiguration{thisDevice}
|
||||||
ID: "default",
|
|
||||||
RawPath: locations[locDefFolder],
|
|
||||||
RescanIntervalS: 60,
|
|
||||||
MinDiskFreePct: 1,
|
|
||||||
Devices: []config.FolderDeviceConfiguration{{DeviceID: myID}},
|
|
||||||
AutoNormalize: true,
|
|
||||||
MaxConflicts: -1,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
newCfg.Devices = []config.DeviceConfiguration{
|
|
||||||
{
|
|
||||||
DeviceID: myID,
|
|
||||||
Addresses: []string{"dynamic"},
|
|
||||||
Name: myName,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
port, err := getFreePort("127.0.0.1", 8384)
|
port, err := getFreePort("127.0.0.1", 8384)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -17,6 +17,13 @@ type DeviceConfiguration struct {
|
|||||||
Introducer bool `xml:"introducer,attr" json:"introducer"`
|
Introducer bool `xml:"introducer,attr" json:"introducer"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func NewDeviceConfiguration(id protocol.DeviceID, name string) DeviceConfiguration {
|
||||||
|
return DeviceConfiguration{
|
||||||
|
DeviceID: id,
|
||||||
|
Name: name,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func (orig DeviceConfiguration) Copy() DeviceConfiguration {
|
func (orig DeviceConfiguration) Copy() DeviceConfiguration {
|
||||||
c := orig
|
c := orig
|
||||||
c.Addresses = make([]string, len(orig.Addresses))
|
c.Addresses = make([]string, len(orig.Addresses))
|
||||||
|
@ -44,6 +44,15 @@ type FolderDeviceConfiguration struct {
|
|||||||
DeviceID protocol.DeviceID `xml:"id,attr" json:"deviceID"`
|
DeviceID protocol.DeviceID `xml:"id,attr" json:"deviceID"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func NewFolderConfiguration(id, path string) FolderConfiguration {
|
||||||
|
f := FolderConfiguration{
|
||||||
|
ID: id,
|
||||||
|
RawPath: path,
|
||||||
|
}
|
||||||
|
f.prepare()
|
||||||
|
return f
|
||||||
|
}
|
||||||
|
|
||||||
func (f FolderConfiguration) Copy() FolderConfiguration {
|
func (f FolderConfiguration) Copy() FolderConfiguration {
|
||||||
c := f
|
c := f
|
||||||
c.Devices = make([]FolderDeviceConfiguration, len(f.Devices))
|
c.Devices = make([]FolderDeviceConfiguration, len(f.Devices))
|
||||||
|
@ -32,22 +32,11 @@ func init() {
|
|||||||
device1, _ = protocol.DeviceIDFromString("AIR6LPZ-7K4PTTV-UXQSMUU-CPQ5YWH-OEDFIIQ-JUG777G-2YQXXR5-YD6AWQR")
|
device1, _ = protocol.DeviceIDFromString("AIR6LPZ-7K4PTTV-UXQSMUU-CPQ5YWH-OEDFIIQ-JUG777G-2YQXXR5-YD6AWQR")
|
||||||
device2, _ = protocol.DeviceIDFromString("GYRZZQB-IRNPV4Z-T7TC52W-EQYJ3TT-FDQW6MW-DFLMU42-SSSU6EM-FBK2VAY")
|
device2, _ = protocol.DeviceIDFromString("GYRZZQB-IRNPV4Z-T7TC52W-EQYJ3TT-FDQW6MW-DFLMU42-SSSU6EM-FBK2VAY")
|
||||||
|
|
||||||
defaultFolderConfig = config.FolderConfiguration{
|
defaultFolderConfig = config.NewFolderConfiguration("default", "testdata")
|
||||||
ID: "default",
|
defaultConfig.Devices = []config.FolderDeviceConfiguration{{DeviceID: device1}}
|
||||||
RawPath: "testdata",
|
|
||||||
Devices: []config.FolderDeviceConfiguration{
|
|
||||||
{
|
|
||||||
DeviceID: device1,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}
|
|
||||||
_defaultConfig := config.Configuration{
|
_defaultConfig := config.Configuration{
|
||||||
Folders: []config.FolderConfiguration{defaultFolderConfig},
|
Folders: []config.FolderConfiguration{defaultFolderConfig},
|
||||||
Devices: []config.DeviceConfiguration{
|
Devices: []config.DeviceConfiguration{config.NewDeviceConfiguration(device1, "device1")},
|
||||||
{
|
|
||||||
DeviceID: device1,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
Options: config.OptionsConfiguration{
|
Options: config.OptionsConfiguration{
|
||||||
// Don't remove temporaries directly on startup
|
// Don't remove temporaries directly on startup
|
||||||
KeepTemporariesH: 1,
|
KeepTemporariesH: 1,
|
||||||
|
Loading…
Reference in New Issue
Block a user