From 61fbe8fc8ccb2fc2be92b0547afa250b3df44035 Mon Sep 17 00:00:00 2001 From: Abe Estrada Date: Mon, 5 Mar 2018 17:00:07 -0700 Subject: [PATCH 1/2] Prepend environment path to database path This fixes an error when the `ENV_SHIORI_DB` is defined, it doesn't open a database file because the database file name isn't on the `databasePath` variable. --- main.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.go b/main.go index cdff383..f71bf17 100644 --- a/main.go +++ b/main.go @@ -12,7 +12,7 @@ import ( func main() { databasePath := "shiori.db" if value, found := os.LookupEnv("ENV_SHIORI_DB"); found { - databasePath = value + databasePath = value + "/" + databasePath } sqliteDB, err := db.OpenSQLiteDatabase(databasePath) From c79b117ddb5cf0161be7724e1b272ae5ffd6f4fc Mon Sep 17 00:00:00 2001 From: Radhi Fadlillah Date: Fri, 9 Mar 2018 21:15:45 +0700 Subject: [PATCH 2/2] Add filename if ENV_SHIORI_DB is directory --- main.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/main.go b/main.go index f71bf17..1369076 100644 --- a/main.go +++ b/main.go @@ -3,6 +3,7 @@ package main import ( "os" + fp "path/filepath" "github.com/RadhiFadlillah/shiori/cmd" db "github.com/RadhiFadlillah/shiori/database" @@ -12,7 +13,12 @@ import ( func main() { databasePath := "shiori.db" if value, found := os.LookupEnv("ENV_SHIORI_DB"); found { - databasePath = value + "/" + databasePath + // If ENV_SHIORI_DB is directory, append "shiori.db" as filename + if f1, err := os.Stat(value); err == nil && f1.IsDir() { + value = fp.Join(value, "shiori.db") + } + + databasePath = value } sqliteDB, err := db.OpenSQLiteDatabase(databasePath)