From 8140350094ae6a3a39d040bd19b9b65fc9eecbbd Mon Sep 17 00:00:00 2001 From: Simon Frei Date: Thu, 12 Dec 2019 16:50:09 +0100 Subject: [PATCH] lib/syncthing: Expose backend instead of lowlevel (#6224) --- cmd/syncthing/main.go | 4 ++-- lib/syncthing/syncthing.go | 5 +++-- lib/syncthing/syncthing_test.go | 3 ++- lib/syncthing/utils.go | 9 ++------- 4 files changed, 9 insertions(+), 12 deletions(-) diff --git a/cmd/syncthing/main.go b/cmd/syncthing/main.go index 965632d99..37872fcf2 100644 --- a/cmd/syncthing/main.go +++ b/cmd/syncthing/main.go @@ -486,7 +486,7 @@ func checkUpgrade() upgrade.Release { func performUpgrade(release upgrade.Release) { // Use leveldb database locks to protect against concurrent upgrades - _, err := syncthing.OpenGoleveldb(locations.Get(locations.Database), config.TuningAuto) + _, err := syncthing.OpenDBBackend(locations.Get(locations.Database), config.TuningAuto) if err == nil { err = upgrade.To(release) if err != nil { @@ -578,7 +578,7 @@ func syncthingMain(runtimeOptions RuntimeOptions) { } dbFile := locations.Get(locations.Database) - ldb, err := syncthing.OpenGoleveldb(dbFile, cfg.Options().DatabaseTuning) + ldb, err := syncthing.OpenDBBackend(dbFile, cfg.Options().DatabaseTuning) if err != nil { l.Warnln("Error opening database:", err) os.Exit(1) diff --git a/lib/syncthing/syncthing.go b/lib/syncthing/syncthing.go index ba105925b..99fc23132 100644 --- a/lib/syncthing/syncthing.go +++ b/lib/syncthing/syncthing.go @@ -23,6 +23,7 @@ import ( "github.com/syncthing/syncthing/lib/config" "github.com/syncthing/syncthing/lib/connections" "github.com/syncthing/syncthing/lib/db" + "github.com/syncthing/syncthing/lib/db/backend" "github.com/syncthing/syncthing/lib/discover" "github.com/syncthing/syncthing/lib/events" "github.com/syncthing/syncthing/lib/locations" @@ -84,10 +85,10 @@ type App struct { stopped chan struct{} } -func New(cfg config.Wrapper, ll *db.Lowlevel, evLogger events.Logger, cert tls.Certificate, opts Options) *App { +func New(cfg config.Wrapper, dbBackend backend.Backend, evLogger events.Logger, cert tls.Certificate, opts Options) *App { a := &App{ cfg: cfg, - ll: ll, + ll: db.NewLowlevel(dbBackend), evLogger: evLogger, opts: opts, cert: cert, diff --git a/lib/syncthing/syncthing_test.go b/lib/syncthing/syncthing_test.go index 46508e338..d1de4f021 100644 --- a/lib/syncthing/syncthing_test.go +++ b/lib/syncthing/syncthing_test.go @@ -14,6 +14,7 @@ import ( "time" "github.com/syncthing/syncthing/lib/config" + "github.com/syncthing/syncthing/lib/db/backend" "github.com/syncthing/syncthing/lib/events" "github.com/syncthing/syncthing/lib/protocol" "github.com/syncthing/syncthing/lib/tlsutil" @@ -77,7 +78,7 @@ func TestStartupFail(t *testing.T) { }, events.NoopLogger) defer os.Remove(cfg.ConfigPath()) - app := New(cfg, nil, events.NoopLogger, cert, Options{}) + app := New(cfg, backend.OpenMemory(), events.NoopLogger, cert, Options{}) startErr := app.Start() if startErr == nil { t.Fatal("Expected an error from Start, got nil") diff --git a/lib/syncthing/utils.go b/lib/syncthing/utils.go index 841a483e6..18c1725dd 100644 --- a/lib/syncthing/utils.go +++ b/lib/syncthing/utils.go @@ -16,7 +16,6 @@ import ( "github.com/pkg/errors" "github.com/syncthing/syncthing/lib/config" - "github.com/syncthing/syncthing/lib/db" "github.com/syncthing/syncthing/lib/db/backend" "github.com/syncthing/syncthing/lib/events" "github.com/syncthing/syncthing/lib/fs" @@ -124,10 +123,6 @@ func copyFile(src, dst string) error { return nil } -func OpenGoleveldb(path string, tuning config.Tuning) (*db.Lowlevel, error) { - ldb, err := backend.Open(path, backend.Tuning(tuning)) - if err != nil { - return nil, err - } - return db.NewLowlevel(ldb), nil +func OpenDBBackend(path string, tuning config.Tuning) (backend.Backend, error) { + return backend.Open(path, backend.Tuning(tuning)) }