config.go 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640
  1. // Copyright (C) 2014 Jakob Borg and Contributors (see the CONTRIBUTORS file).
  2. //
  3. // This program is free software: you can redistribute it and/or modify it
  4. // under the terms of the GNU General Public License as published by the Free
  5. // Software Foundation, either version 3 of the License, or (at your option)
  6. // any later version.
  7. //
  8. // This program is distributed in the hope that it will be useful, but WITHOUT
  9. // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  10. // FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  11. // more details.
  12. //
  13. // You should have received a copy of the GNU General Public License along
  14. // with this program. If not, see <http://www.gnu.org/licenses/>.
  15. // Package config implements reading and writing of the syncthing configuration file.
  16. package config
  17. import (
  18. "encoding/xml"
  19. "fmt"
  20. "io"
  21. "os"
  22. "path/filepath"
  23. "reflect"
  24. "sort"
  25. "strconv"
  26. "code.google.com/p/go.crypto/bcrypt"
  27. "github.com/syncthing/syncthing/internal/logger"
  28. "github.com/syncthing/syncthing/internal/osutil"
  29. "github.com/syncthing/syncthing/internal/protocol"
  30. )
  31. var l = logger.DefaultLogger
  32. const CurrentVersion = 6
  33. type Configuration struct {
  34. Version int `xml:"version,attr"`
  35. Folders []FolderConfiguration `xml:"folder"`
  36. Devices []DeviceConfiguration `xml:"device"`
  37. GUI GUIConfiguration `xml:"gui"`
  38. Options OptionsConfiguration `xml:"options"`
  39. XMLName xml.Name `xml:"configuration" json:"-"`
  40. OriginalVersion int `xml:"-" json:"-"` // The version we read from disk, before any conversion
  41. Deprecated_Repositories []FolderConfiguration `xml:"repository" json:"-"`
  42. Deprecated_Nodes []DeviceConfiguration `xml:"node" json:"-"`
  43. }
  44. type FolderConfiguration struct {
  45. ID string `xml:"id,attr"`
  46. Path string `xml:"path,attr"`
  47. Devices []FolderDeviceConfiguration `xml:"device"`
  48. ReadOnly bool `xml:"ro,attr"`
  49. RescanIntervalS int `xml:"rescanIntervalS,attr" default:"60"`
  50. IgnorePerms bool `xml:"ignorePerms,attr"`
  51. Versioning VersioningConfiguration `xml:"versioning"`
  52. LenientMtimes bool `xml:"lenientMtimes"`
  53. Invalid string `xml:"-"` // Set at runtime when there is an error, not saved
  54. deviceIDs []protocol.DeviceID
  55. Deprecated_Directory string `xml:"directory,omitempty,attr" json:"-"`
  56. Deprecated_Nodes []FolderDeviceConfiguration `xml:"node" json:"-"`
  57. }
  58. func (f *FolderConfiguration) CreateMarker() error {
  59. if !f.HasMarker() {
  60. marker := filepath.Join(f.Path, ".stfolder")
  61. fd, err := os.Create(marker)
  62. if err != nil {
  63. return err
  64. }
  65. fd.Close()
  66. osutil.HideFile(marker)
  67. }
  68. return nil
  69. }
  70. func (f *FolderConfiguration) HasMarker() bool {
  71. _, err := os.Stat(filepath.Join(f.Path, ".stfolder"))
  72. if err != nil {
  73. return false
  74. }
  75. return true
  76. }
  77. func (r *FolderConfiguration) DeviceIDs() []protocol.DeviceID {
  78. if r.deviceIDs == nil {
  79. for _, n := range r.Devices {
  80. r.deviceIDs = append(r.deviceIDs, n.DeviceID)
  81. }
  82. }
  83. return r.deviceIDs
  84. }
  85. type VersioningConfiguration struct {
  86. Type string `xml:"type,attr"`
  87. Params map[string]string
  88. }
  89. type InternalVersioningConfiguration struct {
  90. Type string `xml:"type,attr,omitempty"`
  91. Params []InternalParam `xml:"param"`
  92. }
  93. type InternalParam struct {
  94. Key string `xml:"key,attr"`
  95. Val string `xml:"val,attr"`
  96. }
  97. func (c *VersioningConfiguration) MarshalXML(e *xml.Encoder, start xml.StartElement) error {
  98. var tmp InternalVersioningConfiguration
  99. tmp.Type = c.Type
  100. for k, v := range c.Params {
  101. tmp.Params = append(tmp.Params, InternalParam{k, v})
  102. }
  103. return e.EncodeElement(tmp, start)
  104. }
  105. func (c *VersioningConfiguration) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error {
  106. var tmp InternalVersioningConfiguration
  107. err := d.DecodeElement(&tmp, &start)
  108. if err != nil {
  109. return err
  110. }
  111. c.Type = tmp.Type
  112. c.Params = make(map[string]string, len(tmp.Params))
  113. for _, p := range tmp.Params {
  114. c.Params[p.Key] = p.Val
  115. }
  116. return nil
  117. }
  118. type DeviceConfiguration struct {
  119. DeviceID protocol.DeviceID `xml:"id,attr"`
  120. Name string `xml:"name,attr,omitempty"`
  121. Addresses []string `xml:"address,omitempty"`
  122. Compression bool `xml:"compression,attr"`
  123. CertName string `xml:"certName,attr,omitempty"`
  124. Introducer bool `xml:"introducer,attr"`
  125. }
  126. type FolderDeviceConfiguration struct {
  127. DeviceID protocol.DeviceID `xml:"id,attr"`
  128. Deprecated_Name string `xml:"name,attr,omitempty" json:"-"`
  129. Deprecated_Addresses []string `xml:"address,omitempty" json:"-"`
  130. }
  131. type OptionsConfiguration struct {
  132. ListenAddress []string `xml:"listenAddress" default:"0.0.0.0:22000"`
  133. GlobalAnnServer string `xml:"globalAnnounceServer" default:"announce.syncthing.net:22026"`
  134. GlobalAnnEnabled bool `xml:"globalAnnounceEnabled" default:"true"`
  135. LocalAnnEnabled bool `xml:"localAnnounceEnabled" default:"true"`
  136. LocalAnnPort int `xml:"localAnnouncePort" default:"21025"`
  137. LocalAnnMCAddr string `xml:"localAnnounceMCAddr" default:"[ff32::5222]:21026"`
  138. MaxSendKbps int `xml:"maxSendKbps"`
  139. MaxRecvKbps int `xml:"maxRecvKbps"`
  140. ReconnectIntervalS int `xml:"reconnectionIntervalS" default:"60"`
  141. StartBrowser bool `xml:"startBrowser" default:"true"`
  142. UPnPEnabled bool `xml:"upnpEnabled" default:"true"`
  143. UPnPLease int `xml:"upnpLeaseMinutes" default:"0"`
  144. UPnPRenewal int `xml:"upnpRenewalMinutes" default:"30"`
  145. URAccepted int `xml:"urAccepted"` // Accepted usage reporting version; 0 for off (undecided), -1 for off (permanently)
  146. RestartOnWakeup bool `xml:"restartOnWakeup" default:"true"`
  147. AutoUpgradeIntervalH int `xml:"autoUpgradeIntervalH" default:"12"` // 0 for off
  148. KeepTemporariesH int `xml:"keepTemporariesH" default:"24"` // 0 for off
  149. Deprecated_RescanIntervalS int `xml:"rescanIntervalS,omitempty" json:"-"`
  150. Deprecated_UREnabled bool `xml:"urEnabled,omitempty" json:"-"`
  151. Deprecated_URDeclined bool `xml:"urDeclined,omitempty" json:"-"`
  152. Deprecated_ReadOnly bool `xml:"readOnly,omitempty" json:"-"`
  153. Deprecated_GUIEnabled bool `xml:"guiEnabled,omitempty" json:"-"`
  154. Deprecated_GUIAddress string `xml:"guiAddress,omitempty" json:"-"`
  155. }
  156. type GUIConfiguration struct {
  157. Enabled bool `xml:"enabled,attr" default:"true"`
  158. Address string `xml:"address" default:"127.0.0.1:8080"`
  159. User string `xml:"user,omitempty"`
  160. Password string `xml:"password,omitempty"`
  161. UseTLS bool `xml:"tls,attr"`
  162. APIKey string `xml:"apikey,omitempty"`
  163. }
  164. func New(myID protocol.DeviceID) Configuration {
  165. var cfg Configuration
  166. cfg.Version = CurrentVersion
  167. cfg.OriginalVersion = CurrentVersion
  168. setDefaults(&cfg)
  169. setDefaults(&cfg.Options)
  170. setDefaults(&cfg.GUI)
  171. cfg.prepare(myID)
  172. return cfg
  173. }
  174. func ReadXML(r io.Reader, myID protocol.DeviceID) (Configuration, error) {
  175. var cfg Configuration
  176. setDefaults(&cfg)
  177. setDefaults(&cfg.Options)
  178. setDefaults(&cfg.GUI)
  179. err := xml.NewDecoder(r).Decode(&cfg)
  180. cfg.OriginalVersion = cfg.Version
  181. cfg.prepare(myID)
  182. return cfg, err
  183. }
  184. func (cfg *Configuration) WriteXML(w io.Writer) error {
  185. e := xml.NewEncoder(w)
  186. e.Indent("", " ")
  187. err := e.Encode(cfg)
  188. if err != nil {
  189. return err
  190. }
  191. _, err = w.Write([]byte("\n"))
  192. return err
  193. }
  194. func (cfg *Configuration) prepare(myID protocol.DeviceID) {
  195. fillNilSlices(&cfg.Options)
  196. cfg.Options.ListenAddress = uniqueStrings(cfg.Options.ListenAddress)
  197. // Initialize an empty slice for folders if the config has none
  198. if cfg.Folders == nil {
  199. cfg.Folders = []FolderConfiguration{}
  200. }
  201. // Check for missing, bad or duplicate folder ID:s
  202. var seenFolders = map[string]*FolderConfiguration{}
  203. var uniqueCounter int
  204. for i := range cfg.Folders {
  205. folder := &cfg.Folders[i]
  206. if len(folder.Path) == 0 {
  207. folder.Invalid = "no directory configured"
  208. continue
  209. }
  210. if folder.ID == "" {
  211. folder.ID = "default"
  212. }
  213. if seen, ok := seenFolders[folder.ID]; ok {
  214. l.Warnf("Multiple folders with ID %q; disabling", folder.ID)
  215. seen.Invalid = "duplicate folder ID"
  216. if seen.ID == folder.ID {
  217. uniqueCounter++
  218. seen.ID = fmt.Sprintf("%s~%d", folder.ID, uniqueCounter)
  219. }
  220. folder.Invalid = "duplicate folder ID"
  221. uniqueCounter++
  222. folder.ID = fmt.Sprintf("%s~%d", folder.ID, uniqueCounter)
  223. } else {
  224. seenFolders[folder.ID] = folder
  225. }
  226. }
  227. if cfg.Options.Deprecated_URDeclined {
  228. cfg.Options.URAccepted = -1
  229. }
  230. cfg.Options.Deprecated_URDeclined = false
  231. cfg.Options.Deprecated_UREnabled = false
  232. // Upgrade to v1 configuration if appropriate
  233. if cfg.Version == 1 {
  234. convertV1V2(cfg)
  235. }
  236. // Upgrade to v3 configuration if appropriate
  237. if cfg.Version == 2 {
  238. convertV2V3(cfg)
  239. }
  240. // Upgrade to v4 configuration if appropriate
  241. if cfg.Version == 3 {
  242. convertV3V4(cfg)
  243. }
  244. // Upgrade to v5 configuration if appropriate
  245. if cfg.Version == 4 {
  246. convertV4V5(cfg)
  247. }
  248. // Upgrade to v6 configuration if appropriate
  249. if cfg.Version == 5 {
  250. convertV5V6(cfg)
  251. }
  252. // Hash old cleartext passwords
  253. if len(cfg.GUI.Password) > 0 && cfg.GUI.Password[0] != '$' {
  254. hash, err := bcrypt.GenerateFromPassword([]byte(cfg.GUI.Password), 0)
  255. if err != nil {
  256. l.Warnln("bcrypting password:", err)
  257. } else {
  258. cfg.GUI.Password = string(hash)
  259. }
  260. }
  261. // Build a list of available devices
  262. existingDevices := make(map[protocol.DeviceID]bool)
  263. for _, device := range cfg.Devices {
  264. existingDevices[device.DeviceID] = true
  265. }
  266. // Ensure this device is present in the config
  267. if !existingDevices[myID] {
  268. myName, _ := os.Hostname()
  269. cfg.Devices = append(cfg.Devices, DeviceConfiguration{
  270. DeviceID: myID,
  271. Name: myName,
  272. })
  273. existingDevices[myID] = true
  274. }
  275. sort.Sort(DeviceConfigurationList(cfg.Devices))
  276. // Ensure that any loose devices are not present in the wrong places
  277. // Ensure that there are no duplicate devices
  278. for i := range cfg.Folders {
  279. cfg.Folders[i].Devices = ensureDevicePresent(cfg.Folders[i].Devices, myID)
  280. cfg.Folders[i].Devices = ensureExistingDevices(cfg.Folders[i].Devices, existingDevices)
  281. cfg.Folders[i].Devices = ensureNoDuplicates(cfg.Folders[i].Devices)
  282. sort.Sort(FolderDeviceConfigurationList(cfg.Folders[i].Devices))
  283. }
  284. // An empty address list is equivalent to a single "dynamic" entry
  285. for i := range cfg.Devices {
  286. n := &cfg.Devices[i]
  287. if len(n.Addresses) == 0 || len(n.Addresses) == 1 && n.Addresses[0] == "" {
  288. n.Addresses = []string{"dynamic"}
  289. }
  290. }
  291. }
  292. // ChangeRequiresRestart returns true if updating the configuration requires a
  293. // complete restart.
  294. func ChangeRequiresRestart(from, to Configuration) bool {
  295. // Adding, removing or changing folders requires restart
  296. if !reflect.DeepEqual(from.Folders, to.Folders) {
  297. return true
  298. }
  299. // Removing a device requres restart
  300. toDevs := make(map[protocol.DeviceID]bool, len(from.Devices))
  301. for _, dev := range to.Devices {
  302. toDevs[dev.DeviceID] = true
  303. }
  304. for _, dev := range from.Devices {
  305. if _, ok := toDevs[dev.DeviceID]; !ok {
  306. return true
  307. }
  308. }
  309. // All of the generic options require restart
  310. if !reflect.DeepEqual(from.Options, to.Options) || !reflect.DeepEqual(from.GUI, to.GUI) {
  311. return true
  312. }
  313. return false
  314. }
  315. func convertV5V6(cfg *Configuration) {
  316. // Added ".stfolder" file at folder roots to identify mount issues
  317. // Doesn't affect the config itself, but uses config migrations to identify
  318. // the migration point.
  319. for _, folder := range Wrap("", *cfg).Folders() {
  320. err := folder.CreateMarker()
  321. if err != nil {
  322. panic(err)
  323. }
  324. }
  325. cfg.Version = 6
  326. }
  327. func convertV4V5(cfg *Configuration) {
  328. // Renamed a bunch of fields in the structs.
  329. if cfg.Deprecated_Nodes == nil {
  330. cfg.Deprecated_Nodes = []DeviceConfiguration{}
  331. }
  332. if cfg.Deprecated_Repositories == nil {
  333. cfg.Deprecated_Repositories = []FolderConfiguration{}
  334. }
  335. cfg.Devices = cfg.Deprecated_Nodes
  336. cfg.Folders = cfg.Deprecated_Repositories
  337. for i := range cfg.Folders {
  338. cfg.Folders[i].Path = cfg.Folders[i].Deprecated_Directory
  339. cfg.Folders[i].Deprecated_Directory = ""
  340. cfg.Folders[i].Devices = cfg.Folders[i].Deprecated_Nodes
  341. cfg.Folders[i].Deprecated_Nodes = nil
  342. }
  343. cfg.Deprecated_Nodes = nil
  344. cfg.Deprecated_Repositories = nil
  345. cfg.Version = 5
  346. }
  347. func convertV3V4(cfg *Configuration) {
  348. // In previous versions, rescan interval was common for each folder.
  349. // From now, it can be set independently. We have to make sure, that after upgrade
  350. // the individual rescan interval will be defined for every existing folder.
  351. for i := range cfg.Deprecated_Repositories {
  352. cfg.Deprecated_Repositories[i].RescanIntervalS = cfg.Options.Deprecated_RescanIntervalS
  353. }
  354. cfg.Options.Deprecated_RescanIntervalS = 0
  355. // In previous versions, folders held full device configurations.
  356. // Since that's the only place where device configs were in V1, we still have
  357. // to define the deprecated fields to be able to upgrade from V1 to V4.
  358. for i, folder := range cfg.Deprecated_Repositories {
  359. for j := range folder.Deprecated_Nodes {
  360. rncfg := cfg.Deprecated_Repositories[i].Deprecated_Nodes[j]
  361. rncfg.Deprecated_Name = ""
  362. rncfg.Deprecated_Addresses = nil
  363. }
  364. }
  365. cfg.Version = 4
  366. }
  367. func convertV2V3(cfg *Configuration) {
  368. // In previous versions, compression was always on. When upgrading, enable
  369. // compression on all existing new. New devices will get compression on by
  370. // default by the GUI.
  371. for i := range cfg.Deprecated_Nodes {
  372. cfg.Deprecated_Nodes[i].Compression = true
  373. }
  374. // The global discovery format and port number changed in v0.9. Having the
  375. // default announce server but old port number is guaranteed to be legacy.
  376. if cfg.Options.GlobalAnnServer == "announce.syncthing.net:22025" {
  377. cfg.Options.GlobalAnnServer = "announce.syncthing.net:22026"
  378. }
  379. cfg.Version = 3
  380. }
  381. func convertV1V2(cfg *Configuration) {
  382. // Collect the list of devices.
  383. // Replace device configs inside folders with only a reference to the
  384. // device ID. Set all folders to read only if the global read only flag is
  385. // set.
  386. var devices = map[string]FolderDeviceConfiguration{}
  387. for i, folder := range cfg.Deprecated_Repositories {
  388. cfg.Deprecated_Repositories[i].ReadOnly = cfg.Options.Deprecated_ReadOnly
  389. for j, device := range folder.Deprecated_Nodes {
  390. id := device.DeviceID.String()
  391. if _, ok := devices[id]; !ok {
  392. devices[id] = device
  393. }
  394. cfg.Deprecated_Repositories[i].Deprecated_Nodes[j] = FolderDeviceConfiguration{DeviceID: device.DeviceID}
  395. }
  396. }
  397. cfg.Options.Deprecated_ReadOnly = false
  398. // Set and sort the list of devices.
  399. for _, device := range devices {
  400. cfg.Deprecated_Nodes = append(cfg.Deprecated_Nodes, DeviceConfiguration{
  401. DeviceID: device.DeviceID,
  402. Name: device.Deprecated_Name,
  403. Addresses: device.Deprecated_Addresses,
  404. })
  405. }
  406. sort.Sort(DeviceConfigurationList(cfg.Deprecated_Nodes))
  407. // GUI
  408. cfg.GUI.Address = cfg.Options.Deprecated_GUIAddress
  409. cfg.GUI.Enabled = cfg.Options.Deprecated_GUIEnabled
  410. cfg.Options.Deprecated_GUIEnabled = false
  411. cfg.Options.Deprecated_GUIAddress = ""
  412. cfg.Version = 2
  413. }
  414. func setDefaults(data interface{}) error {
  415. s := reflect.ValueOf(data).Elem()
  416. t := s.Type()
  417. for i := 0; i < s.NumField(); i++ {
  418. f := s.Field(i)
  419. tag := t.Field(i).Tag
  420. v := tag.Get("default")
  421. if len(v) > 0 {
  422. switch f.Interface().(type) {
  423. case string:
  424. f.SetString(v)
  425. case int:
  426. i, err := strconv.ParseInt(v, 10, 64)
  427. if err != nil {
  428. return err
  429. }
  430. f.SetInt(i)
  431. case bool:
  432. f.SetBool(v == "true")
  433. case []string:
  434. // We don't do anything with string slices here. Any default
  435. // we set will be appended to by the XML decoder, so we fill
  436. // those after decoding.
  437. default:
  438. panic(f.Type())
  439. }
  440. }
  441. }
  442. return nil
  443. }
  444. // fillNilSlices sets default value on slices that are still nil.
  445. func fillNilSlices(data interface{}) error {
  446. s := reflect.ValueOf(data).Elem()
  447. t := s.Type()
  448. for i := 0; i < s.NumField(); i++ {
  449. f := s.Field(i)
  450. tag := t.Field(i).Tag
  451. v := tag.Get("default")
  452. if len(v) > 0 {
  453. switch f.Interface().(type) {
  454. case []string:
  455. if f.IsNil() {
  456. rv := reflect.MakeSlice(reflect.TypeOf([]string{}), 1, 1)
  457. rv.Index(0).SetString(v)
  458. f.Set(rv)
  459. }
  460. }
  461. }
  462. }
  463. return nil
  464. }
  465. func uniqueStrings(ss []string) []string {
  466. var m = make(map[string]bool, len(ss))
  467. for _, s := range ss {
  468. m[s] = true
  469. }
  470. var us = make([]string, 0, len(m))
  471. for k := range m {
  472. us = append(us, k)
  473. }
  474. return us
  475. }
  476. func ensureDevicePresent(devices []FolderDeviceConfiguration, myID protocol.DeviceID) []FolderDeviceConfiguration {
  477. for _, device := range devices {
  478. if device.DeviceID.Equals(myID) {
  479. return devices
  480. }
  481. }
  482. devices = append(devices, FolderDeviceConfiguration{
  483. DeviceID: myID,
  484. })
  485. return devices
  486. }
  487. func ensureExistingDevices(devices []FolderDeviceConfiguration, existingDevices map[protocol.DeviceID]bool) []FolderDeviceConfiguration {
  488. count := len(devices)
  489. i := 0
  490. loop:
  491. for i < count {
  492. if _, ok := existingDevices[devices[i].DeviceID]; !ok {
  493. devices[i] = devices[count-1]
  494. count--
  495. continue loop
  496. }
  497. i++
  498. }
  499. return devices[0:count]
  500. }
  501. func ensureNoDuplicates(devices []FolderDeviceConfiguration) []FolderDeviceConfiguration {
  502. count := len(devices)
  503. i := 0
  504. seenDevices := make(map[protocol.DeviceID]bool)
  505. loop:
  506. for i < count {
  507. id := devices[i].DeviceID
  508. if _, ok := seenDevices[id]; ok {
  509. devices[i] = devices[count-1]
  510. count--
  511. continue loop
  512. }
  513. seenDevices[id] = true
  514. i++
  515. }
  516. return devices[0:count]
  517. }
  518. type DeviceConfigurationList []DeviceConfiguration
  519. func (l DeviceConfigurationList) Less(a, b int) bool {
  520. return l[a].DeviceID.Compare(l[b].DeviceID) == -1
  521. }
  522. func (l DeviceConfigurationList) Swap(a, b int) {
  523. l[a], l[b] = l[b], l[a]
  524. }
  525. func (l DeviceConfigurationList) Len() int {
  526. return len(l)
  527. }
  528. type FolderDeviceConfigurationList []FolderDeviceConfiguration
  529. func (l FolderDeviceConfigurationList) Less(a, b int) bool {
  530. return l[a].DeviceID.Compare(l[b].DeviceID) == -1
  531. }
  532. func (l FolderDeviceConfigurationList) Swap(a, b int) {
  533. l[a], l[b] = l[b], l[a]
  534. }
  535. func (l FolderDeviceConfigurationList) Len() int {
  536. return len(l)
  537. }