Merge pull request #1099 from syncthing/vet-and-lint
Various changes for vet and lint
This commit is contained in:
8
build.sh
8
build.sh
@@ -2,7 +2,7 @@
|
|||||||
set -euo pipefail
|
set -euo pipefail
|
||||||
IFS=$'\n\t'
|
IFS=$'\n\t'
|
||||||
|
|
||||||
DOCKERIMGV=1.4-1
|
DOCKERIMGV=1.4-2
|
||||||
|
|
||||||
case "${1:-default}" in
|
case "${1:-default}" in
|
||||||
default)
|
default)
|
||||||
@@ -113,7 +113,11 @@ case "${1:-default}" in
|
|||||||
-v $(pwd):/go/src/github.com/syncthing/syncthing \
|
-v $(pwd):/go/src/github.com/syncthing/syncthing \
|
||||||
-w /go/src/github.com/syncthing/syncthing \
|
-w /go/src/github.com/syncthing/syncthing \
|
||||||
syncthing/build:$DOCKERIMGV \
|
syncthing/build:$DOCKERIMGV \
|
||||||
sh -c './build.sh clean && ./build.sh all && STTRACE=all ./build.sh test-cov'
|
sh -c './build.sh clean \
|
||||||
|
&& go vet ./cmd/... ./internal/... \
|
||||||
|
&& ( golint ./cmd/... ; golint ./internal/... ) | egrep -v "comment on exported|should have comment" \
|
||||||
|
&& ./build.sh all \
|
||||||
|
&& STTRACE=all ./build.sh test-cov'
|
||||||
;;
|
;;
|
||||||
|
|
||||||
docker-test)
|
docker-test)
|
||||||
|
|||||||
@@ -334,44 +334,44 @@ func restPostConfig(m *model.Model, w http.ResponseWriter, r *http.Request) {
|
|||||||
l.Warnln("decoding posted config:", err)
|
l.Warnln("decoding posted config:", err)
|
||||||
http.Error(w, err.Error(), 500)
|
http.Error(w, err.Error(), 500)
|
||||||
return
|
return
|
||||||
} else {
|
|
||||||
if newCfg.GUI.Password != cfg.GUI().Password {
|
|
||||||
if newCfg.GUI.Password != "" {
|
|
||||||
hash, err := bcrypt.GenerateFromPassword([]byte(newCfg.GUI.Password), 0)
|
|
||||||
if err != nil {
|
|
||||||
l.Warnln("bcrypting password:", err)
|
|
||||||
http.Error(w, err.Error(), 500)
|
|
||||||
return
|
|
||||||
} else {
|
|
||||||
newCfg.GUI.Password = string(hash)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Start or stop usage reporting as appropriate
|
|
||||||
|
|
||||||
if curAcc := cfg.Options().URAccepted; newCfg.Options.URAccepted > curAcc {
|
|
||||||
// UR was enabled
|
|
||||||
newCfg.Options.URAccepted = usageReportVersion
|
|
||||||
newCfg.Options.URUniqueID = randomString(8)
|
|
||||||
err := sendUsageReport(m)
|
|
||||||
if err != nil {
|
|
||||||
l.Infoln("Usage report:", err)
|
|
||||||
}
|
|
||||||
go usageReportingLoop(m)
|
|
||||||
} else if newCfg.Options.URAccepted < curAcc {
|
|
||||||
// UR was disabled
|
|
||||||
newCfg.Options.URAccepted = -1
|
|
||||||
newCfg.Options.URUniqueID = ""
|
|
||||||
stopUsageReporting()
|
|
||||||
}
|
|
||||||
|
|
||||||
// Activate and save
|
|
||||||
|
|
||||||
configInSync = !config.ChangeRequiresRestart(cfg.Raw(), newCfg)
|
|
||||||
cfg.Replace(newCfg)
|
|
||||||
cfg.Save()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if newCfg.GUI.Password != cfg.GUI().Password {
|
||||||
|
if newCfg.GUI.Password != "" {
|
||||||
|
hash, err := bcrypt.GenerateFromPassword([]byte(newCfg.GUI.Password), 0)
|
||||||
|
if err != nil {
|
||||||
|
l.Warnln("bcrypting password:", err)
|
||||||
|
http.Error(w, err.Error(), 500)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
newCfg.GUI.Password = string(hash)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Start or stop usage reporting as appropriate
|
||||||
|
|
||||||
|
if curAcc := cfg.Options().URAccepted; newCfg.Options.URAccepted > curAcc {
|
||||||
|
// UR was enabled
|
||||||
|
newCfg.Options.URAccepted = usageReportVersion
|
||||||
|
newCfg.Options.URUniqueID = randomString(8)
|
||||||
|
err := sendUsageReport(m)
|
||||||
|
if err != nil {
|
||||||
|
l.Infoln("Usage report:", err)
|
||||||
|
}
|
||||||
|
go usageReportingLoop(m)
|
||||||
|
} else if newCfg.Options.URAccepted < curAcc {
|
||||||
|
// UR was disabled
|
||||||
|
newCfg.Options.URAccepted = -1
|
||||||
|
newCfg.Options.URUniqueID = ""
|
||||||
|
stopUsageReporting()
|
||||||
|
}
|
||||||
|
|
||||||
|
// Activate and save
|
||||||
|
|
||||||
|
configInSync = !config.ChangeRequiresRestart(cfg.Raw(), newCfg)
|
||||||
|
cfg.Replace(newCfg)
|
||||||
|
cfg.Save()
|
||||||
}
|
}
|
||||||
|
|
||||||
func restGetConfigInSync(w http.ResponseWriter, r *http.Request) {
|
func restGetConfigInSync(w http.ResponseWriter, r *http.Request) {
|
||||||
@@ -598,7 +598,7 @@ func restPostUpgrade(w http.ResponseWriter, r *http.Request) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if upgrade.CompareVersions(rel.Tag, Version) == 1 {
|
if upgrade.CompareVersions(rel.Tag, Version) == 1 {
|
||||||
err = upgrade.UpgradeTo(rel)
|
err = upgrade.To(rel)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
l.Warnln("upgrading:", err)
|
l.Warnln("upgrading:", err)
|
||||||
http.Error(w, err.Error(), 500)
|
http.Error(w, err.Error(), 500)
|
||||||
|
|||||||
@@ -102,10 +102,10 @@ func init() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
cfg *config.ConfigWrapper
|
cfg *config.Wrapper
|
||||||
myID protocol.DeviceID
|
myID protocol.DeviceID
|
||||||
confDir string
|
confDir string
|
||||||
logFlags int = log.Ltime
|
logFlags = log.Ltime
|
||||||
writeRateLimit *ratelimit.Bucket
|
writeRateLimit *ratelimit.Bucket
|
||||||
readRateLimit *ratelimit.Bucket
|
readRateLimit *ratelimit.Bucket
|
||||||
stop = make(chan int)
|
stop = make(chan int)
|
||||||
@@ -332,15 +332,14 @@ func main() {
|
|||||||
l.Fatalln("Cannot upgrade, database seems to be locked. Is another copy of Syncthing already running?")
|
l.Fatalln("Cannot upgrade, database seems to be locked. Is another copy of Syncthing already running?")
|
||||||
}
|
}
|
||||||
|
|
||||||
err = upgrade.UpgradeTo(rel)
|
err = upgrade.To(rel)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
l.Fatalln("Upgrade:", err) // exits 1
|
l.Fatalln("Upgrade:", err) // exits 1
|
||||||
}
|
}
|
||||||
l.Okf("Upgraded to %q", rel.Tag)
|
l.Okf("Upgraded to %q", rel.Tag)
|
||||||
return
|
|
||||||
} else {
|
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if reset {
|
if reset {
|
||||||
@@ -610,7 +609,7 @@ func syncthingMain() {
|
|||||||
os.Exit(code)
|
os.Exit(code)
|
||||||
}
|
}
|
||||||
|
|
||||||
func setupGUI(cfg *config.ConfigWrapper, m *model.Model) {
|
func setupGUI(cfg *config.Wrapper, m *model.Model) {
|
||||||
opts := cfg.Options()
|
opts := cfg.Options()
|
||||||
guiCfg := overrideGUIConfig(cfg.GUI(), guiAddress, guiAuthentication, guiAPIKey)
|
guiCfg := overrideGUIConfig(cfg.GUI(), guiAddress, guiAuthentication, guiAPIKey)
|
||||||
|
|
||||||
@@ -651,7 +650,7 @@ func setupGUI(cfg *config.ConfigWrapper, m *model.Model) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func sanityCheckFolders(cfg *config.ConfigWrapper, m *model.Model) {
|
func sanityCheckFolders(cfg *config.Wrapper, m *model.Model) {
|
||||||
nextFolder:
|
nextFolder:
|
||||||
for id, folder := range cfg.Folders() {
|
for id, folder := range cfg.Folders() {
|
||||||
if folder.Invalid != "" {
|
if folder.Invalid != "" {
|
||||||
@@ -756,7 +755,7 @@ func setupUPnP() {
|
|||||||
if len(igds) > 0 {
|
if len(igds) > 0 {
|
||||||
// Configure the first discovered IGD only. This is a work-around until we have a better mechanism
|
// Configure the first discovered IGD only. This is a work-around until we have a better mechanism
|
||||||
// for handling multiple IGDs, which will require changes to the global discovery service
|
// for handling multiple IGDs, which will require changes to the global discovery service
|
||||||
igd = igds[0]
|
igd = &igds[0]
|
||||||
|
|
||||||
externalPort = setupExternalPort(igd, port)
|
externalPort = setupExternalPort(igd, port)
|
||||||
if externalPort == 0 {
|
if externalPort == 0 {
|
||||||
@@ -804,7 +803,7 @@ func renewUPnP(port int) {
|
|||||||
if len(igds) > 0 {
|
if len(igds) > 0 {
|
||||||
// Configure the first discovered IGD only. This is a work-around until we have a better mechanism
|
// Configure the first discovered IGD only. This is a work-around until we have a better mechanism
|
||||||
// for handling multiple IGDs, which will require changes to the global discovery service
|
// for handling multiple IGDs, which will require changes to the global discovery service
|
||||||
igd = igds[0]
|
igd = &igds[0]
|
||||||
} else {
|
} else {
|
||||||
if debugNet {
|
if debugNet {
|
||||||
l.Debugln("Failed to discover IGD during UPnP port mapping renewal.")
|
l.Debugln("Failed to discover IGD during UPnP port mapping renewal.")
|
||||||
@@ -1256,7 +1255,7 @@ func autoUpgrade() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
l.Infof("Automatic upgrade (current %q < latest %q)", Version, rel.Tag)
|
l.Infof("Automatic upgrade (current %q < latest %q)", Version, rel.Tag)
|
||||||
err = upgrade.UpgradeTo(rel)
|
err = upgrade.To(rel)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
l.Warnln("Automatic upgrade:", err)
|
l.Warnln("Automatic upgrade:", err)
|
||||||
continue
|
continue
|
||||||
|
|||||||
@@ -46,7 +46,7 @@ func TestRandomString(t *testing.T) {
|
|||||||
for _, l := range []int{0, 1, 2, 3, 4, 8, 42} {
|
for _, l := range []int{0, 1, 2, 3, 4, 8, 42} {
|
||||||
s := randomString(l)
|
s := randomString(l)
|
||||||
if len(s) != l {
|
if len(s) != l {
|
||||||
t.Errorf("Incorrect length %d != %s", len(s), l)
|
t.Errorf("Incorrect length %d != %d", len(s), l)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -51,6 +51,11 @@ RUN go get github.com/tools/godep \
|
|||||||
&& go get github.com/axw/gocov/gocov \
|
&& go get github.com/axw/gocov/gocov \
|
||||||
&& go get github.com/AlekSi/gocov-xml
|
&& go get github.com/AlekSi/gocov-xml
|
||||||
|
|
||||||
|
# Install tools "go vet" and "golint"
|
||||||
|
|
||||||
|
RUN go get golang.org/x/tools/cmd/vet \
|
||||||
|
&& go get github.com/golang/lint/golint
|
||||||
|
|
||||||
# Build standard library for race
|
# Build standard library for race
|
||||||
|
|
||||||
RUN go install -race std
|
RUN go install -race std
|
||||||
|
|||||||
@@ -92,13 +92,13 @@ func (f *FolderConfiguration) HasMarker() bool {
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *FolderConfiguration) DeviceIDs() []protocol.DeviceID {
|
func (f *FolderConfiguration) DeviceIDs() []protocol.DeviceID {
|
||||||
if r.deviceIDs == nil {
|
if f.deviceIDs == nil {
|
||||||
for _, n := range r.Devices {
|
for _, n := range f.Devices {
|
||||||
r.deviceIDs = append(r.deviceIDs, n.DeviceID)
|
f.deviceIDs = append(f.deviceIDs, n.DeviceID)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return r.deviceIDs
|
return f.deviceIDs
|
||||||
}
|
}
|
||||||
|
|
||||||
type VersioningConfiguration struct {
|
type VersioningConfiguration struct {
|
||||||
|
|||||||
@@ -42,7 +42,7 @@ func (fn HandlerFunc) Changed(cfg Configuration) error {
|
|||||||
// A wrapper around a Configuration that manages loads, saves and published
|
// A wrapper around a Configuration that manages loads, saves and published
|
||||||
// notifications of changes to registered Handlers
|
// notifications of changes to registered Handlers
|
||||||
|
|
||||||
type ConfigWrapper struct {
|
type Wrapper struct {
|
||||||
cfg Configuration
|
cfg Configuration
|
||||||
path string
|
path string
|
||||||
|
|
||||||
@@ -57,8 +57,8 @@ type ConfigWrapper struct {
|
|||||||
|
|
||||||
// Wrap wraps an existing Configuration structure and ties it to a file on
|
// Wrap wraps an existing Configuration structure and ties it to a file on
|
||||||
// disk.
|
// disk.
|
||||||
func Wrap(path string, cfg Configuration) *ConfigWrapper {
|
func Wrap(path string, cfg Configuration) *Wrapper {
|
||||||
w := &ConfigWrapper{cfg: cfg, path: path}
|
w := &Wrapper{cfg: cfg, path: path}
|
||||||
w.replaces = make(chan Configuration)
|
w.replaces = make(chan Configuration)
|
||||||
go w.Serve()
|
go w.Serve()
|
||||||
return w
|
return w
|
||||||
@@ -66,7 +66,7 @@ func Wrap(path string, cfg Configuration) *ConfigWrapper {
|
|||||||
|
|
||||||
// Load loads an existing file on disk and returns a new configuration
|
// Load loads an existing file on disk and returns a new configuration
|
||||||
// wrapper.
|
// wrapper.
|
||||||
func Load(path string, myID protocol.DeviceID) (*ConfigWrapper, error) {
|
func Load(path string, myID protocol.DeviceID) (*Wrapper, error) {
|
||||||
fd, err := os.Open(path)
|
fd, err := os.Open(path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@@ -84,7 +84,7 @@ func Load(path string, myID protocol.DeviceID) (*ConfigWrapper, error) {
|
|||||||
// Serve handles configuration replace events and calls any interested
|
// Serve handles configuration replace events and calls any interested
|
||||||
// handlers. It is started automatically by Wrap() and Load() and should not
|
// handlers. It is started automatically by Wrap() and Load() and should not
|
||||||
// be run manually.
|
// be run manually.
|
||||||
func (w *ConfigWrapper) Serve() {
|
func (w *Wrapper) Serve() {
|
||||||
for cfg := range w.replaces {
|
for cfg := range w.replaces {
|
||||||
w.sMut.Lock()
|
w.sMut.Lock()
|
||||||
subs := w.subs
|
subs := w.subs
|
||||||
@@ -97,25 +97,25 @@ func (w *ConfigWrapper) Serve() {
|
|||||||
|
|
||||||
// Stop stops the Serve() loop. Set and Replace operations will panic after a
|
// Stop stops the Serve() loop. Set and Replace operations will panic after a
|
||||||
// Stop.
|
// Stop.
|
||||||
func (w *ConfigWrapper) Stop() {
|
func (w *Wrapper) Stop() {
|
||||||
close(w.replaces)
|
close(w.replaces)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Subscribe registers the given handler to be called on any future
|
// Subscribe registers the given handler to be called on any future
|
||||||
// configuration changes.
|
// configuration changes.
|
||||||
func (w *ConfigWrapper) Subscribe(h Handler) {
|
func (w *Wrapper) Subscribe(h Handler) {
|
||||||
w.sMut.Lock()
|
w.sMut.Lock()
|
||||||
w.subs = append(w.subs, h)
|
w.subs = append(w.subs, h)
|
||||||
w.sMut.Unlock()
|
w.sMut.Unlock()
|
||||||
}
|
}
|
||||||
|
|
||||||
// Raw returns the currently wrapped Configuration object.
|
// Raw returns the currently wrapped Configuration object.
|
||||||
func (w *ConfigWrapper) Raw() Configuration {
|
func (w *Wrapper) Raw() Configuration {
|
||||||
return w.cfg
|
return w.cfg
|
||||||
}
|
}
|
||||||
|
|
||||||
// Replace swaps the current configuration object for the given one.
|
// Replace swaps the current configuration object for the given one.
|
||||||
func (w *ConfigWrapper) Replace(cfg Configuration) {
|
func (w *Wrapper) Replace(cfg Configuration) {
|
||||||
w.mut.Lock()
|
w.mut.Lock()
|
||||||
defer w.mut.Unlock()
|
defer w.mut.Unlock()
|
||||||
|
|
||||||
@@ -127,7 +127,7 @@ func (w *ConfigWrapper) Replace(cfg Configuration) {
|
|||||||
|
|
||||||
// Devices returns a map of devices. Device structures should not be changed,
|
// Devices returns a map of devices. Device structures should not be changed,
|
||||||
// other than for the purpose of updating via SetDevice().
|
// other than for the purpose of updating via SetDevice().
|
||||||
func (w *ConfigWrapper) Devices() map[protocol.DeviceID]DeviceConfiguration {
|
func (w *Wrapper) Devices() map[protocol.DeviceID]DeviceConfiguration {
|
||||||
w.mut.Lock()
|
w.mut.Lock()
|
||||||
defer w.mut.Unlock()
|
defer w.mut.Unlock()
|
||||||
if w.deviceMap == nil {
|
if w.deviceMap == nil {
|
||||||
@@ -141,7 +141,7 @@ func (w *ConfigWrapper) Devices() map[protocol.DeviceID]DeviceConfiguration {
|
|||||||
|
|
||||||
// SetDevice adds a new device to the configuration, or overwrites an existing
|
// SetDevice adds a new device to the configuration, or overwrites an existing
|
||||||
// device with the same ID.
|
// device with the same ID.
|
||||||
func (w *ConfigWrapper) SetDevice(dev DeviceConfiguration) {
|
func (w *Wrapper) SetDevice(dev DeviceConfiguration) {
|
||||||
w.mut.Lock()
|
w.mut.Lock()
|
||||||
defer w.mut.Unlock()
|
defer w.mut.Unlock()
|
||||||
|
|
||||||
@@ -161,7 +161,7 @@ func (w *ConfigWrapper) SetDevice(dev DeviceConfiguration) {
|
|||||||
|
|
||||||
// Devices returns a map of folders. Folder structures should not be changed,
|
// Devices returns a map of folders. Folder structures should not be changed,
|
||||||
// other than for the purpose of updating via SetFolder().
|
// other than for the purpose of updating via SetFolder().
|
||||||
func (w *ConfigWrapper) Folders() map[string]FolderConfiguration {
|
func (w *Wrapper) Folders() map[string]FolderConfiguration {
|
||||||
w.mut.Lock()
|
w.mut.Lock()
|
||||||
defer w.mut.Unlock()
|
defer w.mut.Unlock()
|
||||||
if w.folderMap == nil {
|
if w.folderMap == nil {
|
||||||
@@ -181,7 +181,7 @@ func (w *ConfigWrapper) Folders() map[string]FolderConfiguration {
|
|||||||
|
|
||||||
// SetFolder adds a new folder to the configuration, or overwrites an existing
|
// SetFolder adds a new folder to the configuration, or overwrites an existing
|
||||||
// folder with the same ID.
|
// folder with the same ID.
|
||||||
func (w *ConfigWrapper) SetFolder(fld FolderConfiguration) {
|
func (w *Wrapper) SetFolder(fld FolderConfiguration) {
|
||||||
w.mut.Lock()
|
w.mut.Lock()
|
||||||
defer w.mut.Unlock()
|
defer w.mut.Unlock()
|
||||||
|
|
||||||
@@ -200,14 +200,14 @@ func (w *ConfigWrapper) SetFolder(fld FolderConfiguration) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Options returns the current options configuration object.
|
// Options returns the current options configuration object.
|
||||||
func (w *ConfigWrapper) Options() OptionsConfiguration {
|
func (w *Wrapper) Options() OptionsConfiguration {
|
||||||
w.mut.Lock()
|
w.mut.Lock()
|
||||||
defer w.mut.Unlock()
|
defer w.mut.Unlock()
|
||||||
return w.cfg.Options
|
return w.cfg.Options
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetOptions replaces the current options configuration object.
|
// SetOptions replaces the current options configuration object.
|
||||||
func (w *ConfigWrapper) SetOptions(opts OptionsConfiguration) {
|
func (w *Wrapper) SetOptions(opts OptionsConfiguration) {
|
||||||
w.mut.Lock()
|
w.mut.Lock()
|
||||||
defer w.mut.Unlock()
|
defer w.mut.Unlock()
|
||||||
w.cfg.Options = opts
|
w.cfg.Options = opts
|
||||||
@@ -215,14 +215,14 @@ func (w *ConfigWrapper) SetOptions(opts OptionsConfiguration) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// GUI returns the current GUI configuration object.
|
// GUI returns the current GUI configuration object.
|
||||||
func (w *ConfigWrapper) GUI() GUIConfiguration {
|
func (w *Wrapper) GUI() GUIConfiguration {
|
||||||
w.mut.Lock()
|
w.mut.Lock()
|
||||||
defer w.mut.Unlock()
|
defer w.mut.Unlock()
|
||||||
return w.cfg.GUI
|
return w.cfg.GUI
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetGUI replaces the current GUI configuration object.
|
// SetGUI replaces the current GUI configuration object.
|
||||||
func (w *ConfigWrapper) SetGUI(gui GUIConfiguration) {
|
func (w *Wrapper) SetGUI(gui GUIConfiguration) {
|
||||||
w.mut.Lock()
|
w.mut.Lock()
|
||||||
defer w.mut.Unlock()
|
defer w.mut.Unlock()
|
||||||
w.cfg.GUI = gui
|
w.cfg.GUI = gui
|
||||||
@@ -230,7 +230,7 @@ func (w *ConfigWrapper) SetGUI(gui GUIConfiguration) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// InvalidateFolder sets the invalid marker on the given folder.
|
// InvalidateFolder sets the invalid marker on the given folder.
|
||||||
func (w *ConfigWrapper) InvalidateFolder(id string, err string) {
|
func (w *Wrapper) InvalidateFolder(id string, err string) {
|
||||||
w.mut.Lock()
|
w.mut.Lock()
|
||||||
defer w.mut.Unlock()
|
defer w.mut.Unlock()
|
||||||
|
|
||||||
@@ -246,7 +246,7 @@ func (w *ConfigWrapper) InvalidateFolder(id string, err string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Save writes the configuration to disk, and generates a ConfigSaved event.
|
// Save writes the configuration to disk, and generates a ConfigSaved event.
|
||||||
func (w *ConfigWrapper) Save() error {
|
func (w *Wrapper) Save() error {
|
||||||
fd, err := ioutil.TempFile(filepath.Dir(w.path), "cfg")
|
fd, err := ioutil.TempFile(filepath.Dir(w.path), "cfg")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
|||||||
@@ -86,7 +86,7 @@ const BufferSize = 64
|
|||||||
|
|
||||||
type Logger struct {
|
type Logger struct {
|
||||||
subs map[int]*Subscription
|
subs map[int]*Subscription
|
||||||
nextId int
|
nextID int
|
||||||
mutex sync.Mutex
|
mutex sync.Mutex
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -120,15 +120,15 @@ func NewLogger() *Logger {
|
|||||||
func (l *Logger) Log(t EventType, data interface{}) {
|
func (l *Logger) Log(t EventType, data interface{}) {
|
||||||
l.mutex.Lock()
|
l.mutex.Lock()
|
||||||
if debug {
|
if debug {
|
||||||
dl.Debugln("log", l.nextId, t.String(), data)
|
dl.Debugln("log", l.nextID, t.String(), data)
|
||||||
}
|
}
|
||||||
e := Event{
|
e := Event{
|
||||||
ID: l.nextId,
|
ID: l.nextID,
|
||||||
Time: time.Now(),
|
Time: time.Now(),
|
||||||
Type: t,
|
Type: t,
|
||||||
Data: data,
|
Data: data,
|
||||||
}
|
}
|
||||||
l.nextId++
|
l.nextID++
|
||||||
for _, s := range l.subs {
|
for _, s := range l.subs {
|
||||||
if s.mask&t != 0 {
|
if s.mask&t != 0 {
|
||||||
select {
|
select {
|
||||||
@@ -148,10 +148,10 @@ func (l *Logger) Subscribe(mask EventType) *Subscription {
|
|||||||
}
|
}
|
||||||
s := &Subscription{
|
s := &Subscription{
|
||||||
mask: mask,
|
mask: mask,
|
||||||
id: l.nextId,
|
id: l.nextID,
|
||||||
events: make(chan Event, BufferSize),
|
events: make(chan Event, BufferSize),
|
||||||
}
|
}
|
||||||
l.nextId++
|
l.nextID++
|
||||||
l.subs[s.id] = s
|
l.subs[s.id] = s
|
||||||
l.mutex.Unlock()
|
l.mutex.Unlock()
|
||||||
return s
|
return s
|
||||||
|
|||||||
@@ -126,7 +126,7 @@ type BlockFinder struct {
|
|||||||
mut sync.RWMutex
|
mut sync.RWMutex
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewBlockFinder(db *leveldb.DB, cfg *config.ConfigWrapper) *BlockFinder {
|
func NewBlockFinder(db *leveldb.DB, cfg *config.Wrapper) *BlockFinder {
|
||||||
if blockFinder != nil {
|
if blockFinder != nil {
|
||||||
return blockFinder
|
return blockFinder
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ func TestCache(t *testing.T) {
|
|||||||
|
|
||||||
res, ok := c.get("nonexistent")
|
res, ok := c.get("nonexistent")
|
||||||
if res != false || ok != false {
|
if res != false || ok != false {
|
||||||
t.Error("res %v, ok %v for nonexistent item", res, ok)
|
t.Errorf("res %v, ok %v for nonexistent item", res, ok)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set and check some items
|
// Set and check some items
|
||||||
|
|||||||
@@ -169,9 +169,8 @@ func parseIgnoreFile(fd io.Reader, currentFile string, seen map[string]bool) (*M
|
|||||||
includes, err := loadIgnoreFile(includeFile, seen)
|
includes, err := loadIgnoreFile(includeFile, seen)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
} else {
|
|
||||||
exps.patterns = append(exps.patterns, includes.patterns...)
|
|
||||||
}
|
}
|
||||||
|
exps.patterns = append(exps.patterns, includes.patterns...)
|
||||||
} else {
|
} else {
|
||||||
// Path name or pattern, add it so it matches files both in
|
// Path name or pattern, add it so it matches files both in
|
||||||
// current directory and subdirs.
|
// current directory and subdirs.
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ func newDeviceActivity() *deviceActivity {
|
|||||||
|
|
||||||
func (m *deviceActivity) leastBusy(availability []protocol.DeviceID) protocol.DeviceID {
|
func (m *deviceActivity) leastBusy(availability []protocol.DeviceID) protocol.DeviceID {
|
||||||
m.mut.Lock()
|
m.mut.Lock()
|
||||||
var low int = 2<<30 - 1
|
low := 2<<30 - 1
|
||||||
var selected protocol.DeviceID
|
var selected protocol.DeviceID
|
||||||
for _, device := range availability {
|
for _, device := range availability {
|
||||||
if usage := m.act[device]; usage < low {
|
if usage := m.act[device]; usage < low {
|
||||||
|
|||||||
@@ -22,9 +22,9 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func TestDeviceActivity(t *testing.T) {
|
func TestDeviceActivity(t *testing.T) {
|
||||||
n0 := protocol.DeviceID{1, 2, 3, 4}
|
n0 := protocol.DeviceID([32]byte{1, 2, 3, 4})
|
||||||
n1 := protocol.DeviceID{5, 6, 7, 8}
|
n1 := protocol.DeviceID([32]byte{5, 6, 7, 8})
|
||||||
n2 := protocol.DeviceID{9, 10, 11, 12}
|
n2 := protocol.DeviceID([32]byte{9, 10, 11, 12})
|
||||||
devices := []protocol.DeviceID{n0, n1, n2}
|
devices := []protocol.DeviceID{n0, n1, n2}
|
||||||
na := newDeviceActivity()
|
na := newDeviceActivity()
|
||||||
|
|
||||||
|
|||||||
@@ -82,7 +82,7 @@ type service interface {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type Model struct {
|
type Model struct {
|
||||||
cfg *config.ConfigWrapper
|
cfg *config.Wrapper
|
||||||
db *leveldb.DB
|
db *leveldb.DB
|
||||||
finder *files.BlockFinder
|
finder *files.BlockFinder
|
||||||
progressEmitter *ProgressEmitter
|
progressEmitter *ProgressEmitter
|
||||||
@@ -123,7 +123,7 @@ var (
|
|||||||
// NewModel creates and starts a new model. The model starts in read-only mode,
|
// NewModel creates and starts a new model. The model starts in read-only mode,
|
||||||
// where it sends index information to connected peers and responds to requests
|
// where it sends index information to connected peers and responds to requests
|
||||||
// for file data without altering the local folder in any way.
|
// for file data without altering the local folder in any way.
|
||||||
func NewModel(cfg *config.ConfigWrapper, deviceName, clientName, clientVersion string, db *leveldb.DB) *Model {
|
func NewModel(cfg *config.Wrapper, deviceName, clientName, clientVersion string, db *leveldb.DB) *Model {
|
||||||
m := &Model{
|
m := &Model{
|
||||||
cfg: cfg,
|
cfg: cfg,
|
||||||
db: db,
|
db: db,
|
||||||
@@ -862,11 +862,11 @@ func (m *Model) deviceStatRef(deviceID protocol.DeviceID) *stats.DeviceStatistic
|
|||||||
|
|
||||||
if sr, ok := m.deviceStatRefs[deviceID]; ok {
|
if sr, ok := m.deviceStatRefs[deviceID]; ok {
|
||||||
return sr
|
return sr
|
||||||
} else {
|
|
||||||
sr = stats.NewDeviceStatisticsReference(m.db, deviceID)
|
|
||||||
m.deviceStatRefs[deviceID] = sr
|
|
||||||
return sr
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sr := stats.NewDeviceStatisticsReference(m.db, deviceID)
|
||||||
|
m.deviceStatRefs[deviceID] = sr
|
||||||
|
return sr
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *Model) deviceWasSeen(deviceID protocol.DeviceID) {
|
func (m *Model) deviceWasSeen(deviceID protocol.DeviceID) {
|
||||||
|
|||||||
@@ -38,7 +38,7 @@ type ProgressEmitter struct {
|
|||||||
|
|
||||||
// Creates a new progress emitter which emits DownloadProgress events every
|
// Creates a new progress emitter which emits DownloadProgress events every
|
||||||
// interval.
|
// interval.
|
||||||
func NewProgressEmitter(cfg *config.ConfigWrapper) *ProgressEmitter {
|
func NewProgressEmitter(cfg *config.Wrapper) *ProgressEmitter {
|
||||||
t := &ProgressEmitter{
|
t := &ProgressEmitter{
|
||||||
stop: make(chan struct{}),
|
stop: make(chan struct{}),
|
||||||
registry: make(map[string]*sharedPullerState),
|
registry: make(map[string]*sharedPullerState),
|
||||||
|
|||||||
@@ -201,7 +201,7 @@ func (w *Walker) walkAndHashFiles(fchan chan protocol.FileInfo) filepath.WalkFun
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var flags uint32 = protocol.FlagDirectory
|
flags := uint32(protocol.FlagDirectory)
|
||||||
if w.IgnorePerms {
|
if w.IgnorePerms {
|
||||||
flags |= protocol.FlagNoPermBits | 0777
|
flags |= protocol.FlagNoPermBits | 0777
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -190,16 +190,16 @@ func TestVerify(t *testing.T) {
|
|||||||
|
|
||||||
type fileList []protocol.FileInfo
|
type fileList []protocol.FileInfo
|
||||||
|
|
||||||
func (f fileList) Len() int {
|
func (l fileList) Len() int {
|
||||||
return len(f)
|
return len(l)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f fileList) Less(a, b int) bool {
|
func (l fileList) Less(a, b int) bool {
|
||||||
return f[a].Name < f[b].Name
|
return l[a].Name < l[b].Name
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f fileList) Swap(a, b int) {
|
func (l fileList) Swap(a, b int) {
|
||||||
f[a], f[b] = f[b], f[a]
|
l[a], l[b] = l[b], l[a]
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l fileList) testfiles() testfileList {
|
func (l fileList) testfiles() testfileList {
|
||||||
|
|||||||
@@ -48,7 +48,7 @@ func init() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// A wrapper around actual implementations
|
// A wrapper around actual implementations
|
||||||
func UpgradeTo(rel Release) error {
|
func To(rel Release) error {
|
||||||
select {
|
select {
|
||||||
case <-upgradeUnlocked:
|
case <-upgradeUnlocked:
|
||||||
path, err := osext.Executable()
|
path, err := osext.Executable()
|
||||||
|
|||||||
@@ -86,15 +86,15 @@ func LatestRelease(prerelease bool) (Release, error) {
|
|||||||
if prerelease {
|
if prerelease {
|
||||||
// We are a beta version. Use the latest.
|
// We are a beta version. Use the latest.
|
||||||
return rels[0], nil
|
return rels[0], nil
|
||||||
} else {
|
|
||||||
// We are a regular release. Only consider non-prerelease versions for upgrade.
|
|
||||||
for _, rel := range rels {
|
|
||||||
if !rel.Prerelease {
|
|
||||||
return rel, nil
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return Release{}, ErrVersionUnknown
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// We are a regular release. Only consider non-prerelease versions for upgrade.
|
||||||
|
for _, rel := range rels {
|
||||||
|
if !rel.Prerelease {
|
||||||
|
return rel, nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return Release{}, ErrVersionUnknown
|
||||||
}
|
}
|
||||||
|
|
||||||
func readTarGZ(url string, dir string) (string, error) {
|
func readTarGZ(url string, dir string) (string, error) {
|
||||||
|
|||||||
@@ -101,8 +101,8 @@ type upnpRoot struct {
|
|||||||
|
|
||||||
// Discover discovers UPnP InternetGatewayDevices.
|
// Discover discovers UPnP InternetGatewayDevices.
|
||||||
// The order in which the devices appear in the result list is not deterministic.
|
// The order in which the devices appear in the result list is not deterministic.
|
||||||
func Discover() []*IGD {
|
func Discover() []IGD {
|
||||||
result := make([]*IGD, 0)
|
var result []IGD
|
||||||
l.Infoln("Starting UPnP discovery...")
|
l.Infoln("Starting UPnP discovery...")
|
||||||
|
|
||||||
timeout := 3
|
timeout := 3
|
||||||
@@ -137,7 +137,7 @@ func Discover() []*IGD {
|
|||||||
|
|
||||||
// Search for UPnP InternetGatewayDevices for <timeout> seconds, ignoring responses from any devices listed in knownDevices.
|
// Search for UPnP InternetGatewayDevices for <timeout> seconds, ignoring responses from any devices listed in knownDevices.
|
||||||
// The order in which the devices appear in the result list is not deterministic
|
// The order in which the devices appear in the result list is not deterministic
|
||||||
func discover(deviceType string, timeout int, knownDevices []*IGD) []*IGD {
|
func discover(deviceType string, timeout int, knownDevices []IGD) []IGD {
|
||||||
ssdp := &net.UDPAddr{IP: []byte{239, 255, 255, 250}, Port: 1900}
|
ssdp := &net.UDPAddr{IP: []byte{239, 255, 255, 250}, Port: 1900}
|
||||||
|
|
||||||
tpl := `M-SEARCH * HTTP/1.1
|
tpl := `M-SEARCH * HTTP/1.1
|
||||||
@@ -155,8 +155,8 @@ Mx: %d
|
|||||||
l.Debugln("Starting discovery of device type " + deviceType + "...")
|
l.Debugln("Starting discovery of device type " + deviceType + "...")
|
||||||
}
|
}
|
||||||
|
|
||||||
results := make([]*IGD, 0)
|
var results []IGD
|
||||||
resultChannel := make(chan *IGD, 8)
|
resultChannel := make(chan IGD, 8)
|
||||||
|
|
||||||
socket, err := net.ListenUDP("udp4", &net.UDPAddr{})
|
socket, err := net.ListenUDP("udp4", &net.UDPAddr{})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -231,7 +231,7 @@ Mx: %d
|
|||||||
return results
|
return results
|
||||||
}
|
}
|
||||||
|
|
||||||
func handleSearchResponse(deviceType string, knownDevices []*IGD, resp []byte, length int, resultChannel chan<- *IGD, resultWaitGroup *sync.WaitGroup) {
|
func handleSearchResponse(deviceType string, knownDevices []IGD, resp []byte, length int, resultChannel chan<- IGD, resultWaitGroup *sync.WaitGroup) {
|
||||||
defer resultWaitGroup.Done() // Signal when we've finished processing
|
defer resultWaitGroup.Done() // Signal when we've finished processing
|
||||||
|
|
||||||
if debug {
|
if debug {
|
||||||
@@ -321,7 +321,7 @@ func handleSearchResponse(deviceType string, knownDevices []*IGD, resp []byte, l
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
igd := &IGD{
|
igd := IGD{
|
||||||
uuid: deviceUUID,
|
uuid: deviceUUID,
|
||||||
friendlyName: upnpRoot.Device.FriendlyName,
|
friendlyName: upnpRoot.Device.FriendlyName,
|
||||||
url: deviceDescriptionURL,
|
url: deviceDescriptionURL,
|
||||||
@@ -352,7 +352,7 @@ func localIP(url *url.URL) (string, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func getChildDevices(d upnpDevice, deviceType string) []upnpDevice {
|
func getChildDevices(d upnpDevice, deviceType string) []upnpDevice {
|
||||||
result := make([]upnpDevice, 0)
|
var result []upnpDevice
|
||||||
for _, dev := range d.Devices {
|
for _, dev := range d.Devices {
|
||||||
if dev.DeviceType == deviceType {
|
if dev.DeviceType == deviceType {
|
||||||
result = append(result, dev)
|
result = append(result, dev)
|
||||||
@@ -362,7 +362,7 @@ func getChildDevices(d upnpDevice, deviceType string) []upnpDevice {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func getChildServices(d upnpDevice, serviceType string) []upnpService {
|
func getChildServices(d upnpDevice, serviceType string) []upnpService {
|
||||||
result := make([]upnpService, 0)
|
var result []upnpService
|
||||||
for _, svc := range d.Services {
|
for _, svc := range d.Services {
|
||||||
if svc.ServiceType == serviceType {
|
if svc.ServiceType == serviceType {
|
||||||
result = append(result, svc)
|
result = append(result, svc)
|
||||||
@@ -372,7 +372,7 @@ func getChildServices(d upnpDevice, serviceType string) []upnpService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func getServiceDescriptions(rootURL string, device upnpDevice) ([]IGDService, error) {
|
func getServiceDescriptions(rootURL string, device upnpDevice) ([]IGDService, error) {
|
||||||
result := make([]IGDService, 0)
|
var result []IGDService
|
||||||
|
|
||||||
if device.DeviceType == "urn:schemas-upnp-org:device:InternetGatewayDevice:1" {
|
if device.DeviceType == "urn:schemas-upnp-org:device:InternetGatewayDevice:1" {
|
||||||
descriptions := getIGDServices(rootURL, device,
|
descriptions := getIGDServices(rootURL, device,
|
||||||
@@ -400,7 +400,7 @@ func getServiceDescriptions(rootURL string, device upnpDevice) ([]IGDService, er
|
|||||||
}
|
}
|
||||||
|
|
||||||
func getIGDServices(rootURL string, device upnpDevice, wanDeviceURN string, wanConnectionURN string, serviceURNs []string) []IGDService {
|
func getIGDServices(rootURL string, device upnpDevice, wanDeviceURN string, wanConnectionURN string, serviceURNs []string) []IGDService {
|
||||||
result := make([]IGDService, 0)
|
var result []IGDService
|
||||||
|
|
||||||
devices := getChildDevices(device, wanDeviceURN)
|
devices := getChildDevices(device, wanDeviceURN)
|
||||||
|
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func TestExternalIPParsing(t *testing.T) {
|
func TestExternalIPParsing(t *testing.T) {
|
||||||
soap_response :=
|
soapResponse :=
|
||||||
[]byte(`<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" s:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
|
[]byte(`<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" s:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
|
||||||
<s:Body>
|
<s:Body>
|
||||||
<u:GetExternalIPAddressResponse xmlns:u="urn:schemas-upnp-org:service:WANIPConnection:1">
|
<u:GetExternalIPAddressResponse xmlns:u="urn:schemas-upnp-org:service:WANIPConnection:1">
|
||||||
@@ -31,7 +31,7 @@ func TestExternalIPParsing(t *testing.T) {
|
|||||||
</s:Envelope>`)
|
</s:Envelope>`)
|
||||||
|
|
||||||
envelope := &soapGetExternalIPAddressResponseEnvelope{}
|
envelope := &soapGetExternalIPAddressResponseEnvelope{}
|
||||||
err := xml.Unmarshal(soap_response, envelope)
|
err := xml.Unmarshal(soapResponse, envelope)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Error(err)
|
t.Error(err)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -62,9 +62,8 @@ func (v Simple) Archive(filePath string) error {
|
|||||||
l.Debugln("not archiving nonexistent file", filePath)
|
l.Debugln("not archiving nonexistent file", filePath)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
} else {
|
|
||||||
return err
|
|
||||||
}
|
}
|
||||||
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
versionsDir := filepath.Join(v.folderPath, ".stversions")
|
versionsDir := filepath.Join(v.folderPath, ".stversions")
|
||||||
|
|||||||
@@ -294,9 +294,8 @@ func (v Staggered) Archive(filePath string) error {
|
|||||||
l.Debugln("not archiving nonexistent file", filePath)
|
l.Debugln("not archiving nonexistent file", filePath)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
} else {
|
|
||||||
return err
|
|
||||||
}
|
}
|
||||||
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if _, err := os.Stat(v.versionsPath); err != nil {
|
if _, err := os.Stat(v.versionsPath); err != nil {
|
||||||
|
|||||||
Reference in New Issue
Block a user