all: Implement suture v4-api (#6947)

This commit is contained in:
Simon Frei
2020-11-17 13:19:04 +01:00
committed by GitHub
parent e8fc465ea8
commit 9524b51708
65 changed files with 617 additions and 693 deletions
+30 -23
View File
@@ -8,6 +8,7 @@ package main
import (
"bytes"
"context"
"crypto/tls"
"flag"
"fmt"
@@ -41,6 +42,7 @@ import (
"github.com/syncthing/syncthing/lib/syncthing"
"github.com/syncthing/syncthing/lib/tlsutil"
"github.com/syncthing/syncthing/lib/upgrade"
"github.com/syncthing/syncthing/lib/util"
"github.com/pkg/errors"
)
@@ -321,7 +323,7 @@ func main() {
}
if err != nil {
l.Warnln("Command line options:", err)
os.Exit(syncthing.ExitError.AsInt())
os.Exit(util.ExitError.AsInt())
}
if options.logFile == "default" || options.logFile == "" {
@@ -358,7 +360,7 @@ func main() {
)
if err != nil {
l.Warnln("Error reading device ID:", err)
os.Exit(syncthing.ExitError.AsInt())
os.Exit(util.ExitError.AsInt())
}
fmt.Println(protocol.NewDeviceID(cert.Certificate[0]))
@@ -368,7 +370,7 @@ func main() {
if options.browserOnly {
if err := openGUI(protocol.EmptyDeviceID); err != nil {
l.Warnln("Failed to open web UI:", err)
os.Exit(syncthing.ExitError.AsInt())
os.Exit(util.ExitError.AsInt())
}
return
}
@@ -376,7 +378,7 @@ func main() {
if options.generateDir != "" {
if err := generate(options.generateDir); err != nil {
l.Warnln("Failed to generate config and keys:", err)
os.Exit(syncthing.ExitError.AsInt())
os.Exit(util.ExitError.AsInt())
}
return
}
@@ -384,14 +386,14 @@ func main() {
// Ensure that our home directory exists.
if err := ensureDir(locations.GetBaseDir(locations.ConfigBaseDir), 0700); err != nil {
l.Warnln("Failure on home directory:", err)
os.Exit(syncthing.ExitError.AsInt())
os.Exit(util.ExitError.AsInt())
}
if options.upgradeTo != "" {
err := upgrade.ToURL(options.upgradeTo)
if err != nil {
l.Warnln("Error while Upgrading:", err)
os.Exit(syncthing.ExitError.AsInt())
os.Exit(util.ExitError.AsInt())
}
l.Infoln("Upgraded from", options.upgradeTo)
return
@@ -422,13 +424,13 @@ func main() {
os.Exit(exitCodeForUpgrade(err))
}
l.Infof("Upgraded to %q", release.Tag)
os.Exit(syncthing.ExitUpgrade.AsInt())
os.Exit(util.ExitUpgrade.AsInt())
}
if options.resetDatabase {
if err := resetDB(); err != nil {
l.Warnln("Resetting database:", err)
os.Exit(syncthing.ExitError.AsInt())
os.Exit(util.ExitError.AsInt())
}
l.Infoln("Successfully reset database - it will be rebuilt after next start.")
return
@@ -601,13 +603,14 @@ func syncthingMain(runtimeOptions RuntimeOptions) {
}
evLogger := events.NewLogger()
go evLogger.Serve()
defer evLogger.Stop()
ctx, cancel := context.WithCancel(context.Background())
go evLogger.Serve(ctx)
defer cancel()
cfg, err := syncthing.LoadConfigAtStartup(locations.Get(locations.ConfigFile), cert, evLogger, runtimeOptions.allowNewerConfig, noDefaultFolder)
if err != nil {
l.Warnln("Failed to initialize config:", err)
os.Exit(syncthing.ExitError.AsInt())
os.Exit(util.ExitError.AsInt())
}
// Candidate builds should auto upgrade. Make sure the option is set,
@@ -653,7 +656,7 @@ func syncthingMain(runtimeOptions RuntimeOptions) {
}
} else {
l.Infof("Upgraded to %q, exiting now.", release.Tag)
os.Exit(syncthing.ExitUpgrade.AsInt())
os.Exit(util.ExitUpgrade.AsInt())
}
}
@@ -694,18 +697,18 @@ func syncthingMain(runtimeOptions RuntimeOptions) {
f, err := os.Create(fmt.Sprintf("cpu-%d.pprof", os.Getpid()))
if err != nil {
l.Warnln("Creating profile:", err)
os.Exit(syncthing.ExitError.AsInt())
os.Exit(util.ExitError.AsInt())
}
if err := pprof.StartCPUProfile(f); err != nil {
l.Warnln("Starting profile:", err)
os.Exit(syncthing.ExitError.AsInt())
os.Exit(util.ExitError.AsInt())
}
}
go standbyMonitor(app, cfg)
if err := app.Start(); err != nil {
os.Exit(syncthing.ExitError.AsInt())
os.Exit(util.ExitError.AsInt())
}
cleanConfigDirectory()
@@ -718,6 +721,10 @@ func syncthingMain(runtimeOptions RuntimeOptions) {
status := app.Wait()
if status == util.ExitError {
l.Warnln("Syncthing stopped with error:", app.Error())
}
if runtimeOptions.cpuProfile {
pprof.StopCPUProfile()
}
@@ -733,7 +740,7 @@ func setupSignalHandling(app *syncthing.App) {
signal.Notify(restartSign, sigHup)
go func() {
<-restartSign
app.Stop(syncthing.ExitRestart)
app.Stop(util.ExitRestart)
}()
// Exit with "success" code (no restart) on INT/TERM
@@ -742,7 +749,7 @@ func setupSignalHandling(app *syncthing.App) {
signal.Notify(stopSign, os.Interrupt, sigTerm)
go func() {
<-stopSign
app.Stop(syncthing.ExitSuccess)
app.Stop(util.ExitSuccess)
}()
}
@@ -779,7 +786,7 @@ func auditWriter(auditFile string) io.Writer {
fd, err = os.OpenFile(auditFile, auditFlags, 0600)
if err != nil {
l.Warnln("Audit:", err)
os.Exit(syncthing.ExitError.AsInt())
os.Exit(util.ExitError.AsInt())
}
auditDest = auditFile
}
@@ -829,7 +836,7 @@ func standbyMonitor(app *syncthing.App, cfg config.Wrapper) {
// things a moment to stabilize.
time.Sleep(restartDelay)
app.Stop(syncthing.ExitRestart)
app.Stop(util.ExitRestart)
return
}
now = time.Now()
@@ -899,7 +906,7 @@ func autoUpgrade(cfg config.Wrapper, app *syncthing.App, evLogger events.Logger)
sub.Unsubscribe()
l.Warnf("Automatically upgraded to version %q. Restarting in 1 minute.", rel.Tag)
time.Sleep(time.Minute)
app.Stop(syncthing.ExitUpgrade)
app.Stop(util.ExitUpgrade)
return
}
}
@@ -987,13 +994,13 @@ func setPauseState(cfg config.Wrapper, paused bool) {
}
if _, err := cfg.Replace(raw); err != nil {
l.Warnln("Cannot adjust paused state:", err)
os.Exit(syncthing.ExitError.AsInt())
os.Exit(util.ExitError.AsInt())
}
}
func exitCodeForUpgrade(err error) int {
if _, ok := err.(*errNoUpgrade); ok {
return syncthing.ExitNoUpgradeAvailable.AsInt()
return util.ExitNoUpgradeAvailable.AsInt()
}
return syncthing.ExitError.AsInt()
return util.ExitError.AsInt()
}
+5 -5
View File
@@ -26,7 +26,7 @@ import (
"github.com/syncthing/syncthing/lib/osutil"
"github.com/syncthing/syncthing/lib/protocol"
"github.com/syncthing/syncthing/lib/sync"
"github.com/syncthing/syncthing/lib/syncthing"
"github.com/syncthing/syncthing/lib/util"
)
var (
@@ -99,7 +99,7 @@ func monitorMain(runtimeOptions RuntimeOptions) {
if t := time.Since(restarts[0]); t < loopThreshold {
l.Warnf("%d restarts in %v; not retrying further", countRestarts, t)
os.Exit(syncthing.ExitError.AsInt())
os.Exit(util.ExitError.AsInt())
}
copy(restarts[0:], restarts[1:])
@@ -169,7 +169,7 @@ func monitorMain(runtimeOptions RuntimeOptions) {
if err == nil {
// Successful exit indicates an intentional shutdown
os.Exit(syncthing.ExitSuccess.AsInt())
os.Exit(util.ExitSuccess.AsInt())
}
if exiterr, ok := err.(*exec.ExitError); ok {
@@ -177,7 +177,7 @@ func monitorMain(runtimeOptions RuntimeOptions) {
if stopped || runtimeOptions.noRestart {
os.Exit(exitCode)
}
if exitCode == syncthing.ExitUpgrade.AsInt() {
if exitCode == util.ExitUpgrade.AsInt() {
// Restart the monitor process to release the .old
// binary as part of the upgrade process.
l.Infoln("Restarting monitor...")
@@ -189,7 +189,7 @@ func monitorMain(runtimeOptions RuntimeOptions) {
}
if runtimeOptions.noRestart {
os.Exit(syncthing.ExitError.AsInt())
os.Exit(util.ExitError.AsInt())
}
l.Infoln("Syncthing exited:", err)