Skip to content

Commit

Permalink
lib/syncthing: Expose backend instead of lowlevel (syncthing#6224)
Browse files Browse the repository at this point in the history
  • Loading branch information
imsodin authored and calmh committed Dec 12, 2019
1 parent 82ed8e7 commit 8140350
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 12 deletions.
4 changes: 2 additions & 2 deletions cmd/syncthing/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
Expand Down
5 changes: 3 additions & 2 deletions lib/syncthing/syncthing.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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,
Expand Down
3 changes: 2 additions & 1 deletion lib/syncthing/syncthing_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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")
Expand Down
9 changes: 2 additions & 7 deletions lib/syncthing/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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))
}

0 comments on commit 8140350

Please sign in to comment.