mirror of
https://github.com/k3s-io/k3s.git
synced 2024-06-07 19:41:36 +00:00
31 lines
523 B
Go
31 lines
523 B
Go
package datadir
|
|
|
|
import (
|
|
"os"
|
|
|
|
"github.com/pkg/errors"
|
|
"github.com/rancher/norman/pkg/resolvehome"
|
|
)
|
|
|
|
const (
|
|
DefaultDataDir = "/var/lib/rancher/k3s"
|
|
DefaultHomeDataDir = "${HOME}/.rancher/k3s"
|
|
)
|
|
|
|
func Resolve(dataDir string) (string, error) {
|
|
if dataDir == "" {
|
|
if os.Getuid() == 0 {
|
|
dataDir = DefaultDataDir
|
|
} else {
|
|
dataDir = DefaultHomeDataDir
|
|
}
|
|
}
|
|
|
|
dataDir, err := resolvehome.Resolve(dataDir)
|
|
if err != nil {
|
|
return "", errors.Wrapf(err, "resolving %s", dataDir)
|
|
}
|
|
|
|
return dataDir, nil
|
|
}
|