mirror of
https://github.com/dnote/dnote
synced 2026-03-14 22:45:50 +01:00
* Create platform specific directory definitions * Fix CLI integration test * Rename dirs to paths and get config path * Namespace * Fix initialization of dirs * Simplify and change description * Simplify * Fix build flag * Bump sqlite version * Bump xgo
49 lines
968 B
Go
49 lines
968 B
Go
// Package dirs provides base directory definitions for the system
|
|
package dirs
|
|
|
|
import (
|
|
"os"
|
|
"os/user"
|
|
|
|
"github.com/pkg/errors"
|
|
)
|
|
|
|
var (
|
|
// Home is the home directory of the user
|
|
Home string
|
|
// ConfigHome is the full path to the directory in which user-specific
|
|
// configurations should be written.
|
|
ConfigHome string
|
|
// DataHome is the full path to the directory in which user-specific data
|
|
// files should be written.
|
|
DataHome string
|
|
// CacheHome is the full path to the directory in which user-specific
|
|
// non-essential cached data should be writte
|
|
CacheHome string
|
|
)
|
|
|
|
func init() {
|
|
Reload()
|
|
}
|
|
|
|
// Reload reloads the directory definitions
|
|
func Reload() {
|
|
initDirs()
|
|
}
|
|
|
|
func getHomeDir() string {
|
|
usr, err := user.Current()
|
|
if err != nil {
|
|
panic(errors.Wrap(err, "getting home dir"))
|
|
}
|
|
|
|
return usr.HomeDir
|
|
}
|
|
|
|
func readPath(envName, defaultPath string) string {
|
|
if dir := os.Getenv(envName); dir != "" {
|
|
return dir
|
|
}
|
|
|
|
return defaultPath
|
|
}
|