2019-01-09 16:54:15 +00:00
|
|
|
package datadir
|
|
|
|
|
|
|
|
import (
|
|
|
|
"os"
|
|
|
|
|
|
|
|
"github.com/pkg/errors"
|
|
|
|
"github.com/rancher/norman/pkg/resolvehome"
|
|
|
|
)
|
|
|
|
|
2019-01-26 04:53:53 +00:00
|
|
|
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 {
|
2019-01-26 04:53:53 +00:00
|
|
|
dataDir = DefaultDataDir
|
2019-01-09 16:54:15 +00:00
|
|
|
} else {
|
2019-01-26 04:53:53 +00:00
|
|
|
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
|
|
|
|
}
|