Skip to content

Commit

Permalink
Change default database to home dir
Browse files Browse the repository at this point in the history
  • Loading branch information
RadhiFadlillah committed Mar 12, 2018
1 parent 4684300 commit 6bab302
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,10 @@ Use "shiori [command] --help" for more information about a command.

## Advanced

By default, `shiori` will create database in the location where you run it. For example, if you run `shiori`. To set the database to a specific location, you can set the environment variable `ENV_SHIORI_DB` to your desired path.
By default, `shiori` will create database in `$HOME/.shiori.db`. If you want to set the database to another location, you can set the environment variable `ENV_SHIORI_DB` to your desired path :

- If `ENV_SHIORI_DB` points to a directory, it will create `.shiori.db` file inside that directory, so the final path for database is `$ENV_SHIORI_DB/.shiori.db`.
- Else, it will create a new database file in the specified path.

## Usage with Docker

Expand Down
16 changes: 13 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package main

import (
"os"
"os/user"
fp "path/filepath"

"github.com/RadhiFadlillah/shiori/cmd"
Expand All @@ -11,11 +12,11 @@ import (
)

func main() {
databasePath := "shiori.db"
databasePath := fp.Join(getHomeDir(), ".shiori.db")
if value, found := os.LookupEnv("ENV_SHIORI_DB"); found {
// If ENV_SHIORI_DB is directory, append "shiori.db" as filename
// 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")
value = fp.Join(value, ".shiori.db")
}

databasePath = value
Expand All @@ -28,6 +29,15 @@ func main() {
cmd.Execute()
}

func getHomeDir() string {
user, err := user.Current()
if err != nil {
return ""
}

return user.HomeDir
}

func checkError(err error) {
if err != nil {
panic(err)
Expand Down

0 comments on commit 6bab302

Please sign in to comment.