diff options
author | Kegan Dougal <kegan@matrix.org> | 2020-05-28 12:28:21 +0100 |
---|---|---|
committer | Kegan Dougal <kegan@matrix.org> | 2020-05-28 12:28:21 +0100 |
commit | 2411007c4bab8b5c851f3e1e9552cd7a69bbcd9b (patch) | |
tree | a079cbdfcb89d6f4f85437b8da9c127ab4da53ab /serverkeyapi | |
parent | a6f995eb45f0d012f79aa66f727cb6260455b334 (diff) |
Parse URIs correctly
Diffstat (limited to 'serverkeyapi')
-rw-r--r-- | serverkeyapi/storage/sqlite3/keydb.go | 16 |
1 files changed, 15 insertions, 1 deletions
diff --git a/serverkeyapi/storage/sqlite3/keydb.go b/serverkeyapi/storage/sqlite3/keydb.go index d1dc61c9..1ad6e7e8 100644 --- a/serverkeyapi/storage/sqlite3/keydb.go +++ b/serverkeyapi/storage/sqlite3/keydb.go @@ -17,6 +17,8 @@ package sqlite3 import ( "context" + "errors" + "net/url" "time" "golang.org/x/crypto/ed25519" @@ -44,7 +46,19 @@ func NewDatabase( serverKey ed25519.PublicKey, serverKeyID gomatrixserverlib.KeyID, ) (*Database, error) { - db, err := sqlutil.Open(internal.SQLiteDriverName(), dataSourceName, nil) + uri, err := url.Parse(dataSourceName) + if err != nil { + return nil, err + } + var cs string + if uri.Opaque != "" { // file:filename.db + cs = uri.Opaque + } else if uri.Path != "" { // file:///path/to/filename.db + cs = uri.Path + } else { + return nil, errors.New("no filename or path in connect string") + } + db, err := sqlutil.Open(internal.SQLiteDriverName(), cs, nil) if err != nil { return nil, err } |