mirror of
https://github.com/1f349/dendrite.git
synced 2024-11-22 11:41:38 +00:00
Parse URIs correctly
This commit is contained in:
parent
a6f995eb45
commit
2411007c4b
@ -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
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user