Use executable dir instead of working dir

master
HimbeerserverDE 2021-08-28 13:23:07 +02:00
parent 1b364826ed
commit eab858ba6b
No known key found for this signature in database
GPG Key ID: 1A651504791E6A8B
2 changed files with 17 additions and 3 deletions

View File

@ -2,6 +2,8 @@ package main
import (
"database/sql"
"os"
"path/filepath"
"time"
_ "github.com/mattn/go-sqlite3"
@ -122,8 +124,13 @@ func (a authSQLite3) updateTimestamp(name string) {
}
func (a *authSQLite3) init() error {
var err error
a.db, err = sql.Open("sqlite3", "auth.sqlite")
executable, err := os.Executable()
if err != nil {
return err
}
path := filepath.Dir(executable) + "/auth.sqlite"
a.db, err = sql.Open("sqlite3", path)
if err != nil {
return err
}

View File

@ -4,6 +4,7 @@ import (
"encoding/json"
"log"
"os"
"path/filepath"
)
const latestSerializeVer = 0x1c
@ -48,7 +49,13 @@ func loadConfig() error {
conf.AuthBackend = defaultAuthBackend
conf.BindAddr = defaultBindAddr
f, err := os.OpenFile("config.json", os.O_RDWR|os.O_CREATE, 0666)
executable, err := os.Executable()
if err != nil {
return err
}
path := filepath.Dir(executable) + "/config.json"
f, err := os.OpenFile(path, os.O_RDWR|os.O_CREATE, 0666)
if err != nil {
conf = oldConf
return err