Remove pq and sql dep from syncthing, split build targets
This commit is contained in:
+19
-58
@@ -7,39 +7,15 @@
|
|||||||
package contract
|
package contract
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"database/sql/driver"
|
|
||||||
"encoding/json"
|
|
||||||
"errors"
|
"errors"
|
||||||
"reflect"
|
"reflect"
|
||||||
"sort"
|
"sort"
|
||||||
"strconv"
|
"strconv"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/lib/pq"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type IntMap map[string]int
|
type IntMap map[string]int
|
||||||
|
|
||||||
func (p IntMap) Value() (driver.Value, error) {
|
|
||||||
return json.Marshal(p)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (p *IntMap) Scan(src interface{}) error {
|
|
||||||
source, ok := src.([]byte)
|
|
||||||
if !ok {
|
|
||||||
return errors.New("Type assertion .([]byte) failed.")
|
|
||||||
}
|
|
||||||
|
|
||||||
var i map[string]int
|
|
||||||
err := json.Unmarshal(source, &i)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
*p = i
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
type Report struct {
|
type Report struct {
|
||||||
// Generated
|
// Generated
|
||||||
Received time.Time `json:"-"` // Only from DB
|
Received time.Time `json:"-"` // Only from DB
|
||||||
@@ -109,8 +85,8 @@ type Report struct {
|
|||||||
UpgradeAllowedAuto bool `json:"upgradeAllowedAuto,omitempty" since:"2"`
|
UpgradeAllowedAuto bool `json:"upgradeAllowedAuto,omitempty" since:"2"`
|
||||||
|
|
||||||
// V2.5 fields (fields that were in v2 but never added to the database
|
// V2.5 fields (fields that were in v2 but never added to the database
|
||||||
UpgradeAllowedPre bool `json:"upgradeAllowedPre,omitempty" since:"2"`
|
UpgradeAllowedPre bool `json:"upgradeAllowedPre,omitempty" since:"2"`
|
||||||
RescanIntvs pq.Int64Array `json:"rescanIntvs,omitempty" since:"2"`
|
RescanIntvs Int64Array `json:"rescanIntvs,omitempty" since:"2"`
|
||||||
|
|
||||||
// v3 fields
|
// v3 fields
|
||||||
|
|
||||||
@@ -132,18 +108,18 @@ type Report struct {
|
|||||||
CustomStunServers bool `json:"customStunServers,omitempty" since:"3"`
|
CustomStunServers bool `json:"customStunServers,omitempty" since:"3"`
|
||||||
|
|
||||||
FolderUsesV3 struct {
|
FolderUsesV3 struct {
|
||||||
ScanProgressDisabled int `json:"scanProgressDisabled,omitempty" since:"3"`
|
ScanProgressDisabled int `json:"scanProgressDisabled,omitempty" since:"3"`
|
||||||
ConflictsDisabled int `json:"conflictsDisabled,omitempty" since:"3"`
|
ConflictsDisabled int `json:"conflictsDisabled,omitempty" since:"3"`
|
||||||
ConflictsUnlimited int `json:"conflictsUnlimited,omitempty" since:"3"`
|
ConflictsUnlimited int `json:"conflictsUnlimited,omitempty" since:"3"`
|
||||||
ConflictsOther int `json:"conflictsOther,omitempty" since:"3"`
|
ConflictsOther int `json:"conflictsOther,omitempty" since:"3"`
|
||||||
DisableSparseFiles int `json:"disableSparseFiles,omitempty" since:"3"`
|
DisableSparseFiles int `json:"disableSparseFiles,omitempty" since:"3"`
|
||||||
DisableTempIndexes int `json:"disableTempIndexes,omitempty" since:"3"`
|
DisableTempIndexes int `json:"disableTempIndexes,omitempty" since:"3"`
|
||||||
AlwaysWeakHash int `json:"alwaysWeakHash,omitempty" since:"3"`
|
AlwaysWeakHash int `json:"alwaysWeakHash,omitempty" since:"3"`
|
||||||
CustomWeakHashThreshold int `json:"customWeakHashThreshold,omitempty" since:"3"`
|
CustomWeakHashThreshold int `json:"customWeakHashThreshold,omitempty" since:"3"`
|
||||||
FsWatcherEnabled int `json:"fsWatcherEnabled,omitempty" since:"3"`
|
FsWatcherEnabled int `json:"fsWatcherEnabled,omitempty" since:"3"`
|
||||||
PullOrder IntMap `json:"pullOrder,omitempty" since:"3"`
|
PullOrder IntMap `json:"pullOrder,omitempty" since:"3"`
|
||||||
FilesystemType IntMap `json:"filesystemType,omitempty" since:"3"`
|
FilesystemType IntMap `json:"filesystemType,omitempty" since:"3"`
|
||||||
FsWatcherDelays pq.Int64Array `json:"fsWatcherDelays,omitempty" since:"3"`
|
FsWatcherDelays Int64Array `json:"fsWatcherDelays,omitempty" since:"3"`
|
||||||
} `json:"folderUsesV3,omitempty" since:"3"`
|
} `json:"folderUsesV3,omitempty" since:"3"`
|
||||||
|
|
||||||
GUIStats struct {
|
GUIStats struct {
|
||||||
@@ -193,8 +169,8 @@ func New() *Report {
|
|||||||
r.FolderUsesV3.FilesystemType = make(IntMap)
|
r.FolderUsesV3.FilesystemType = make(IntMap)
|
||||||
r.GUIStats.Theme = make(IntMap)
|
r.GUIStats.Theme = make(IntMap)
|
||||||
r.TransportStats = make(IntMap)
|
r.TransportStats = make(IntMap)
|
||||||
r.RescanIntvs = make(pq.Int64Array, 0)
|
r.RescanIntvs = make(Int64Array, 0)
|
||||||
r.FolderUsesV3.FsWatcherDelays = make(pq.Int64Array, 0)
|
r.FolderUsesV3.FsWatcherDelays = make(Int64Array, 0)
|
||||||
return r
|
return r
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -409,21 +385,6 @@ func (r *Report) FieldNames() []string {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r Report) Value() (driver.Value, error) {
|
|
||||||
// This needs to be string, yet we read back bytes..
|
|
||||||
bs, err := json.Marshal(r)
|
|
||||||
return string(bs), err
|
|
||||||
}
|
|
||||||
|
|
||||||
func (r *Report) Scan(value interface{}) error {
|
|
||||||
b, ok := value.([]byte)
|
|
||||||
if !ok {
|
|
||||||
return errors.New("type assertion to []byte failed")
|
|
||||||
}
|
|
||||||
|
|
||||||
return json.Unmarshal(b, &r)
|
|
||||||
}
|
|
||||||
|
|
||||||
func clear(v interface{}, since int) error {
|
func clear(v interface{}, since int) error {
|
||||||
s := reflect.ValueOf(v).Elem()
|
s := reflect.ValueOf(v).Elem()
|
||||||
t := s.Type()
|
t := s.Type()
|
||||||
@@ -461,8 +422,8 @@ func clear(v interface{}, since int) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func SortPqInt64Array(slice pq.Int64Array) {
|
func (arr Int64Array) Sort() {
|
||||||
sort.Slice(slice, func(a, b int) bool {
|
sort.Slice(arr, func(a, b int) bool {
|
||||||
return slice[a] < slice[b]
|
return arr[a] < arr[b]
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,11 @@
|
|||||||
|
// Copyright (C) 2020 The Syncthing Authors.
|
||||||
|
//
|
||||||
|
// This Source Code Form is subject to the terms of the Mozilla Public
|
||||||
|
// License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
||||||
|
// You can obtain one at https://mozilla.org/MPL/2.0/.
|
||||||
|
|
||||||
|
// +build !ursrv
|
||||||
|
|
||||||
|
package contract
|
||||||
|
|
||||||
|
type Int64Array []int64
|
||||||
@@ -0,0 +1,54 @@
|
|||||||
|
// Copyright (C) 2020 The Syncthing Authors.
|
||||||
|
//
|
||||||
|
// This Source Code Form is subject to the terms of the Mozilla Public
|
||||||
|
// License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
||||||
|
// You can obtain one at https://mozilla.org/MPL/2.0/.
|
||||||
|
|
||||||
|
// +build ursrv
|
||||||
|
|
||||||
|
package contract
|
||||||
|
|
||||||
|
import (
|
||||||
|
"database/sql/driver"
|
||||||
|
"encoding/json"
|
||||||
|
"errors"
|
||||||
|
|
||||||
|
"github.com/lib/pq"
|
||||||
|
)
|
||||||
|
|
||||||
|
type Int64Array pq.Int64Array
|
||||||
|
|
||||||
|
func (p IntMap) Value() (driver.Value, error) {
|
||||||
|
return json.Marshal(p)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *IntMap) Scan(src interface{}) error {
|
||||||
|
source, ok := src.([]byte)
|
||||||
|
if !ok {
|
||||||
|
return errors.New("Type assertion .([]byte) failed.")
|
||||||
|
}
|
||||||
|
|
||||||
|
var i map[string]int
|
||||||
|
err := json.Unmarshal(source, &i)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
*p = i
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r Report) Value() (driver.Value, error) {
|
||||||
|
// This needs to be string, yet we read back bytes..
|
||||||
|
bs, err := json.Marshal(r)
|
||||||
|
return string(bs), err
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r *Report) Scan(value interface{}) error {
|
||||||
|
b, ok := value.([]byte)
|
||||||
|
if !ok {
|
||||||
|
return errors.New("type assertion to []byte failed")
|
||||||
|
}
|
||||||
|
|
||||||
|
return json.Unmarshal(b, &r)
|
||||||
|
}
|
||||||
@@ -153,7 +153,7 @@ func (s *Service) reportData(ctx context.Context, urVersion int, preview bool) (
|
|||||||
l.Warnf("Unhandled versioning type for usage reports: %s", cfg.Versioning.Type)
|
l.Warnf("Unhandled versioning type for usage reports: %s", cfg.Versioning.Type)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
contract.SortPqInt64Array(report.RescanIntvs)
|
report.RescanIntvs.Sort()
|
||||||
|
|
||||||
for _, cfg := range s.cfg.Devices() {
|
for _, cfg := range s.cfg.Devices() {
|
||||||
if cfg.Introducer {
|
if cfg.Introducer {
|
||||||
@@ -256,7 +256,7 @@ func (s *Service) reportData(ctx context.Context, urVersion int, preview bool) (
|
|||||||
report.FolderUsesV3.FilesystemType[cfg.FilesystemType.String()]++
|
report.FolderUsesV3.FilesystemType[cfg.FilesystemType.String()]++
|
||||||
report.FolderUsesV3.FsWatcherDelays = append(report.FolderUsesV3.FsWatcherDelays, int64(cfg.FSWatcherDelayS))
|
report.FolderUsesV3.FsWatcherDelays = append(report.FolderUsesV3.FsWatcherDelays, int64(cfg.FSWatcherDelayS))
|
||||||
}
|
}
|
||||||
contract.SortPqInt64Array(report.FolderUsesV3.FsWatcherDelays)
|
report.FolderUsesV3.FsWatcherDelays.Sort()
|
||||||
|
|
||||||
guiCfg := s.cfg.GUI()
|
guiCfg := s.cfg.GUI()
|
||||||
// Anticipate multiple GUI configs in the future, hence store counts.
|
// Anticipate multiple GUI configs in the future, hence store counts.
|
||||||
|
|||||||
Reference in New Issue
Block a user