mirror of
https://github.com/syncthing/syncthing.git
synced 2024-11-16 02:18:44 -07:00
Various style fixes
This commit is contained in:
parent
12d69e25dd
commit
9d07aa006d
@ -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)
|
||||||
|
@ -105,7 +105,7 @@ var (
|
|||||||
cfg *config.ConfigWrapper
|
cfg *config.ConfigWrapper
|
||||||
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 {
|
||||||
@ -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
|
||||||
|
@ -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 {
|
||||||
|
@ -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
|
||||||
|
@ -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 {
|
||||||
|
@ -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) {
|
||||||
|
@ -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) {
|
||||||
|
@ -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 {
|
||||||
|
Loading…
Reference in New Issue
Block a user