1
0
mirror of https://github.com/osmarks/mycorrhiza.git synced 2024-12-04 18:19:54 +00:00

Fix config path resolver

This commit is contained in:
handlerug 2021-04-28 17:12:36 +07:00
parent 989ed43455
commit 5bbfc6e049
No known key found for this signature in database
GPG Key ID: 38009F0605051491
2 changed files with 13 additions and 18 deletions

View File

@ -2,24 +2,23 @@ package files
import (
"errors"
"github.com/adrg/xdg"
"github.com/bouncepaw/mycorrhiza/util"
"log"
"path/filepath"
"strings"
"github.com/adrg/xdg"
"github.com/bouncepaw/mycorrhiza/util"
)
var paths struct {
tokensJSON string
registrationCredentialsJSON string
fixedCredentialsJSON string
configINI string
}
func TokensJSON() string { return paths.tokensJSON }
func RegistrationCredentialsJSON() string { return paths.registrationCredentialsJSON }
func FixedCredentialsJSON() string { return paths.fixedCredentialsJSON }
func ConfigINI() string { return paths.configINI }
// CalculatePaths looks for all external paths and stores them. Tries its best to find any errors. It is safe it to call it multiple times in order to save new paths.
func CalculatePaths() error {
@ -38,13 +37,7 @@ func CalculatePaths() error {
if dir, err := fixedCredentialsPath(); err != nil {
return err
} else {
paths.tokensJSON = dir
}
if dir, err := configPath(); err != nil {
return err
} else {
paths.configINI = dir
paths.fixedCredentialsJSON = dir
}
return nil
@ -79,11 +72,11 @@ func registrationCredentialsPath() (string, error) {
}
func fixedCredentialsPath() (string, error) {
path, err := filepath.Abs(util.FixedCredentialsPath)
return path, err
}
var err error
var path = ""
func configPath() (string, error) {
path, err := filepath.Abs(util.ConfigFilePath)
if len(util.FixedCredentialsPath) > 0 {
path, err = filepath.Abs(util.FixedCredentialsPath)
}
return path, err
}

View File

@ -179,11 +179,13 @@ Crawl-delay: 5`))
func main() {
parseCliArgs()
// It is ok if the path is ""
util.ReadConfigFile(util.ConfigFilePath)
if err := files.CalculatePaths(); err != nil {
log.Fatal(err)
}
// It is ok if the path is ""
util.ReadConfigFile(files.ConfigINI())
log.Println("Running MycorrhizaWiki")
if err := os.Chdir(WikiDir); err != nil {