Loader FS and empty env fix

This commit is contained in:
Katrina Verey
2021-03-24 17:40:59 -07:00
parent e77c284924
commit 3255c73c71
12 changed files with 100 additions and 44 deletions

View File

@@ -41,24 +41,6 @@ const (
NoPluginHomeSentinal = "/No/non-builtin/plugins!"
)
func EnabledPluginConfig(b types.BuiltinPluginLoadingOptions) *types.PluginConfig {
return MakePluginConfig(types.PluginRestrictionsNone, b)
}
func DisabledPluginConfig() *types.PluginConfig {
return MakePluginConfig(
types.PluginRestrictionsBuiltinsOnly,
types.BploUseStaticallyLinked)
}
func MakePluginConfig(pr types.PluginRestrictions,
b types.BuiltinPluginLoadingOptions) *types.PluginConfig {
return &types.PluginConfig{
PluginRestrictions: pr,
BpLoadingOptions: b,
}
}
type NotedFunc struct {
Note string
F func() string
@@ -79,9 +61,11 @@ func DefaultAbsPluginHome(fSys filesys.FileSystem) (string, error) {
{
Note: "homed in $" + XdgConfigHomeEnv,
F: func() string {
return filepath.Join(
os.Getenv(XdgConfigHomeEnv),
ProgramName, RelPluginHome)
if root := os.Getenv(XdgConfigHomeEnv); root != "" {
return filepath.Join(root, ProgramName, RelPluginHome)
}
// do not look in "kustomize/plugin" if XdgConfigHomeEnv is unset
return ""
},
},
{
@@ -110,11 +94,14 @@ func FirstDirThatExistsElseError(
pathFuncs []NotedFunc) (string, error) {
var nope []types.Pair
for _, dt := range pathFuncs {
dir := dt.F()
if fSys.Exists(dir) {
return dir, nil
if dir := dt.F(); dir != "" {
if fSys.Exists(dir) {
return dir, nil
}
nope = append(nope, types.Pair{Key: dt.Note, Value: dir})
} else {
nope = append(nope, types.Pair{Key: dt.Note, Value: "<no value>"})
}
nope = append(nope, types.Pair{Key: dt.Note, Value: dir})
}
return "", types.NewErrUnableToFind(what, nope)
}