sanity check the startup directory

This commit is contained in:
2020-07-26 01:29:27 -04:00
parent 158212a8f9
commit 8ceb66454d
2 changed files with 15 additions and 2 deletions

15
gui.go
View File

@ -38,8 +38,9 @@ func NewGUI() *GUI {
// Start launches a new syndie-gui application
func (client *GUI) Start(path string) {
sanityCheckStartupDir(path)
client.db = newDatabase()
client.db.openDB(path)
client.db.openDB(path + "/db/bolt.db")
client.db.reload()
a := app.New()
@ -98,3 +99,15 @@ func (client *GUI) fetch(fetch bool) {
func (client *GUI) applyOptions() {
client.pagination = 25
}
func sanityCheckStartupDir(path string) {
var err error
_, err = os.Stat(path)
if os.IsNotExist(err) {
os.Mkdir(path, 0777)
_, err = os.Stat(path + "/db/")
if os.IsNotExist(err) {
os.Mkdir(path+"/db/", 0777)
}
}
}

View File

@ -11,5 +11,5 @@ func main() {
if err != nil {
panic("Error obtaining current user")
}
client.Start(usr.HomeDir + "/.syndie/db/bolt.db")
client.Start(usr.HomeDir + "/.syndie")
}