k3s/pkg/datadir/datadir.go

31 lines
523 B
Go
Raw Normal View History

2019-01-09 16:54:15 +00:00
package datadir
import (
"os"
"github.com/pkg/errors"
"github.com/rancher/norman/pkg/resolvehome"
)
const (
DefaultDataDir = "/var/lib/rancher/k3s"
DefaultHomeDataDir = "${HOME}/.rancher/k3s"
)
2019-01-09 16:54:15 +00:00
func Resolve(dataDir string) (string, error) {
if dataDir == "" {
if os.Getuid() == 0 {
dataDir = DefaultDataDir
2019-01-09 16:54:15 +00:00
} else {
dataDir = DefaultHomeDataDir
2019-01-09 16:54:15 +00:00
}
}
dataDir, err := resolvehome.Resolve(dataDir)
if err != nil {
return "", errors.Wrapf(err, "resolving %s", dataDir)
}
return dataDir, nil
}