leveldb.go 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. // Copyright (C) 2014 The Syncthing Authors.
  2. //
  3. // This Source Code Form is subject to the terms of the Mozilla Public
  4. // License, v. 2.0. If a copy of the MPL was not distributed with this file,
  5. // You can obtain one at https://mozilla.org/MPL/2.0/.
  6. package db
  7. import (
  8. "bytes"
  9. "fmt"
  10. "github.com/syncthing/syncthing/lib/protocol"
  11. )
  12. const dbVersion = 2
  13. const (
  14. KeyTypeDevice = iota
  15. KeyTypeGlobal
  16. KeyTypeBlock
  17. KeyTypeDeviceStatistic
  18. KeyTypeFolderStatistic
  19. KeyTypeVirtualMtime
  20. KeyTypeFolderIdx
  21. KeyTypeDeviceIdx
  22. KeyTypeIndexID
  23. KeyTypeFolderMeta
  24. KeyTypeMiscData
  25. KeyTypeSequence
  26. )
  27. func (l VersionList) String() string {
  28. var b bytes.Buffer
  29. var id protocol.DeviceID
  30. b.WriteString("{")
  31. for i, v := range l.Versions {
  32. if i > 0 {
  33. b.WriteString(", ")
  34. }
  35. copy(id[:], v.Device)
  36. fmt.Fprintf(&b, "{%v, %v}", v.Version, id)
  37. }
  38. b.WriteString("}")
  39. return b.String()
  40. }
  41. type fileList []protocol.FileInfo
  42. func (l fileList) Len() int {
  43. return len(l)
  44. }
  45. func (l fileList) Swap(a, b int) {
  46. l[a], l[b] = l[b], l[a]
  47. }
  48. func (l fileList) Less(a, b int) bool {
  49. return l[a].Name < l[b].Name
  50. }
  51. // Flush batches to disk when they contain this many records.
  52. const batchFlushSize = 64