@@ -3,13 +3,16 @@ package context
33
44import (
55 gocontext "context"
6+ "errors"
67 "fmt"
78 "math/rand"
9+ "net/url"
810 "os"
911 "os/signal"
1012 "path/filepath"
1113 "runtime"
1214 "runtime/pprof"
15+ "strconv"
1316 "strings"
1417 "sync"
1518 "time"
@@ -19,6 +22,7 @@ import (
1922 "github.com/aptly-dev/aptly/console"
2023 "github.com/aptly-dev/aptly/database"
2124 "github.com/aptly-dev/aptly/database/goleveldb"
25+ "github.com/aptly-dev/aptly/database/ssdb"
2226 "github.com/aptly-dev/aptly/deb"
2327 "github.com/aptly-dev/aptly/files"
2428 "github.com/aptly-dev/aptly/http"
@@ -27,6 +31,7 @@ import (
2731 "github.com/aptly-dev/aptly/swift"
2832 "github.com/aptly-dev/aptly/task"
2933 "github.com/aptly-dev/aptly/utils"
34+ "github.com/seefan/gossdb/v2/conf"
3035 "github.com/smira/commander"
3136 "github.com/smira/flag"
3237)
@@ -287,7 +292,32 @@ func (context *AptlyContext) _database() (database.Storage, error) {
287292 if context .database == nil {
288293 var err error
289294
290- context .database , err = goleveldb .NewDB (context .dbPath ())
295+ if context .config ().DatabaseBackend .Type == "leveldb" {
296+ if context .config ().DatabaseBackend .DbPath != "" {
297+ dbPath := filepath .Join (context .config ().RootDir , context .config ().DatabaseBackend .DbPath )
298+ context .database , err = goleveldb .NewDB (dbPath )
299+ } else {
300+ return nil , errors .New ("leveldb databaseBackend config invalid" )
301+ }
302+ } else if context .config ().DatabaseBackend .Type == "ssdb" {
303+ var cfg conf.Config
304+ u , e := url .Parse (context .config ().DatabaseBackend .URL )
305+
306+ if e != nil {
307+ return nil , e
308+ }
309+ cfg .Port , e = strconv .Atoi (u .Port ())
310+ cfg .Host = strings .Split (u .Host , ":" )[0 ]
311+ if e != nil {
312+ return nil , e
313+ }
314+ password , _ := u .User .Password ()
315+ cfg .Password = password
316+ context .database , err = ssdb .NewOpenDB (& cfg )
317+ } else {
318+ context .database , err = goleveldb .NewDB (context .dbPath ())
319+ }
320+
291321 if err != nil {
292322 return nil , fmt .Errorf ("can't instantiate database: %s" , err )
293323 }
0 commit comments