소스 검색

Minor config cleanup

Jakob Borg 11 년 전
부모
커밋
289d604690
2개의 변경된 파일6개의 추가작업 그리고 12개의 파일을 삭제
  1. 5 11
      internal/config/config.go
  2. 1 1
      internal/config/config_test.go

+ 5 - 11
internal/config/config.go

@@ -51,9 +51,10 @@ type FolderConfiguration struct {
 	ReadOnly        bool                        `xml:"ro,attr"`
 	RescanIntervalS int                         `xml:"rescanIntervalS,attr" default:"60"`
 	IgnorePerms     bool                        `xml:"ignorePerms,attr"`
-	Invalid         string                      `xml:"-"` // Set at runtime when there is an error, not saved
 	Versioning      VersioningConfiguration     `xml:"versioning"`
 
+	Invalid string `xml:"-"` // Set at runtime when there is an error, not saved
+
 	deviceIDs []protocol.DeviceID
 
 	Deprecated_Directory string                      `xml:"directory,omitempty,attr" json:"-"`
@@ -277,25 +278,18 @@ func (cfg *Configuration) prepare(myID protocol.DeviceID) {
 
 	// Build a list of available devices
 	existingDevices := make(map[protocol.DeviceID]bool)
-	existingDevices[myID] = true
 	for _, device := range cfg.Devices {
 		existingDevices[device.DeviceID] = true
 	}
 
-	// Ensure this device is present in all relevant places
-	myIDExists := false
-	for _, dev := range cfg.Devices {
-		if dev.DeviceID == myID {
-			myIDExists = true
-			break
-		}
-	}
-	if !myIDExists {
+	// Ensure this device is present in the config
+	if !existingDevices[myID] {
 		myName, _ := os.Hostname()
 		cfg.Devices = append(cfg.Devices, DeviceConfiguration{
 			DeviceID: myID,
 			Name:     myName,
 		})
+		existingDevices[myID] = true
 	}
 
 	sort.Sort(DeviceConfigurationList(cfg.Devices))

+ 1 - 1
internal/config/config_test.go

@@ -60,7 +60,7 @@ func TestDefaultValues(t *testing.T) {
 }
 
 func TestDeviceConfig(t *testing.T) {
-	for i, ver := range []string{"v3", "v4", "v5"} {
+	for i, ver := range []string{"v1", "v2", "v3", "v4", "v5"} {
 		wr, err := Load("testdata/"+ver+".xml", device1)
 		if err != nil {
 			t.Fatal(err)