Skip to content

Commit

Permalink
backend: config: Change default plugins dir
Browse files Browse the repository at this point in the history
This fix prevents the development app (when running npm run
dev-only-app) from watching the .plugins directory locally, which causes
an endless loop of refreshes to the app. To do this, we ensure that
.plugins is not set as the plugins dir by default.

Fixes: #1937

Signed-off-by: Evangelos Skopelitis <[email protected]>
  • Loading branch information
skoeva committed May 7, 2024
1 parent ce248d6 commit e0b66e5
Showing 1 changed file with 3 additions and 22 deletions.
25 changes: 3 additions & 22 deletions backend/pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,26 +172,17 @@ func flagset() *flag.FlagSet {

// Gets the default plugins-dir depending on platform.
func defaultPluginDir() string {
// These are the folders we use for the default plugin-dir.
// - the passed in pluginDir if it's not empty.
// - "./.plugins" if it exists.
// This is the folder we use for the default plugin-dir:
// - ~/.config/Headlamp/plugins exists or it can be made
// - "./.plugins" if the ~/.config/Headlamp/plugins can't be made.
// Windows: %APPDATA%\Headlamp\Config\plugins
// (for example, C:\Users\USERNAME\AppData\Roaming\Headlamp\Config\plugins)
pluginDirDefault := "./.plugins"

if folderExists(pluginDirDefault) {
return pluginDirDefault
}

// https://www.npmjs.com/package/env-paths
// https://pkg.go.dev/os#UserConfigDir
userConfigDir, err := os.UserConfigDir()
if err != nil {
logger.Log(logger.LevelError, nil, err, "getting user config dir")

return pluginDirDefault
return ""
}

pluginsConfigDir := filepath.Join(userConfigDir, "Headlamp", "plugins")
Expand All @@ -207,22 +198,12 @@ func defaultPluginDir() string {
if err != nil {
logger.Log(logger.LevelError, nil, err, "creating plugins directory")

return pluginDirDefault
return ""
}

return pluginsConfigDir
}

// folderExists(path) returns true if the folder exists.
func folderExists(path string) bool {
info, err := os.Stat(path)
if os.IsNotExist(err) {
return false
}

return info.IsDir()
}

func GetDefaultKubeConfigPath() string {
user, err := user.Current()
if err != nil {
Expand Down

0 comments on commit e0b66e5

Please sign in to comment.