Files
nabarr/cmd/nabarr/config.go
l3uddz fbcce0a55b fix(rss): support prowlarr feeds (#31)
* fix(rss): support thetvdb attribute for prowlarr support

* refactor(rss): allow queue of rss items with tmdb in for sonarr

* fix(test): set test item title based on the pvr type

* refactor(build): windows arm64 builds
2021-09-13 17:55:11 +01:00

47 lines
977 B
Go

//go:build !windows
package main
import (
"github.com/kirsle/configdir"
"golang.org/x/sys/unix"
"os"
"path/filepath"
)
func defaultConfigPath() string {
// get binary path
bp := getBinaryPath()
if dirIsWriteable(bp) == nil {
return bp
}
// binary path is not write-able, use alternative path
cp := configdir.LocalConfig("nabarr")
if _, err := os.Stat(cp); os.IsNotExist(err) {
if e := os.MkdirAll(cp, os.ModePerm); e != nil {
panic("failed to create nabarr config directory")
}
}
return cp
}
func getBinaryPath() string {
// get current binary path
dir, err := filepath.Abs(filepath.Dir(os.Args[0]))
if err != nil {
// get current working dir
if dir, err = os.Getwd(); err != nil {
panic("failed to determine current binary location")
}
}
return dir
}
func dirIsWriteable(dir string) error {
// credits: https://stackoverflow.com/questions/20026320/how-to-tell-if-folder-exists-and-is-writable
return unix.Access(dir, unix.W_OK)
}