mirror of
https://github.com/syncthing/syncthing.git
synced 2024-11-16 02:18:44 -07: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 {
|
||||
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.Folders = []config.FolderConfiguration{
|
||||
{
|
||||
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,
|
||||
},
|
||||
}
|
||||
newCfg.Folders = []config.FolderConfiguration{defaultFolder}
|
||||
newCfg.Devices = []config.DeviceConfiguration{thisDevice}
|
||||
|
||||
port, err := getFreePort("127.0.0.1", 8384)
|
||||
if err != nil {
|
||||
|
@ -17,6 +17,13 @@ type DeviceConfiguration struct {
|
||||
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 {
|
||||
c := orig
|
||||
c.Addresses = make([]string, len(orig.Addresses))
|
||||
|
@ -44,6 +44,15 @@ type FolderDeviceConfiguration struct {
|
||||
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 {
|
||||
c := f
|
||||
c.Devices = make([]FolderDeviceConfiguration, len(f.Devices))
|
||||
|
@ -32,22 +32,11 @@ func init() {
|
||||
device1, _ = protocol.DeviceIDFromString("AIR6LPZ-7K4PTTV-UXQSMUU-CPQ5YWH-OEDFIIQ-JUG777G-2YQXXR5-YD6AWQR")
|
||||
device2, _ = protocol.DeviceIDFromString("GYRZZQB-IRNPV4Z-T7TC52W-EQYJ3TT-FDQW6MW-DFLMU42-SSSU6EM-FBK2VAY")
|
||||
|
||||
defaultFolderConfig = config.FolderConfiguration{
|
||||
ID: "default",
|
||||
RawPath: "testdata",
|
||||
Devices: []config.FolderDeviceConfiguration{
|
||||
{
|
||||
DeviceID: device1,
|
||||
},
|
||||
},
|
||||
}
|
||||
defaultFolderConfig = config.NewFolderConfiguration("default", "testdata")
|
||||
defaultConfig.Devices = []config.FolderDeviceConfiguration{{DeviceID: device1}}
|
||||
_defaultConfig := config.Configuration{
|
||||
Folders: []config.FolderConfiguration{defaultFolderConfig},
|
||||
Devices: []config.DeviceConfiguration{
|
||||
{
|
||||
DeviceID: device1,
|
||||
},
|
||||
},
|
||||
Devices: []config.DeviceConfiguration{config.NewDeviceConfiguration(device1, "device1")},
|
||||
Options: config.OptionsConfiguration{
|
||||
// Don't remove temporaries directly on startup
|
||||
KeepTemporariesH: 1,
|
||||
|
Loading…
Reference in New Issue
Block a user