Skip to content

Commit

Permalink
Fixes for plugins on Windows
Browse files Browse the repository at this point in the history
os.ExpandEnv does not work on Windows, and HOME is also set to
an empty-string, so HOMEPATH must be substituted in.

Signed-off-by: Alex Ellis (OpenFaaS Ltd) <alexellis2@gmail.com>
  • Loading branch information
alexellis committed Jan 25, 2024
1 parent 31db71d commit 8383725
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
8 changes: 7 additions & 1 deletion commands/faas.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"log"
"os"
"path"
"runtime"
"strings"
"syscall"

Expand Down Expand Up @@ -137,7 +138,12 @@ func runFaas(cmd *cobra.Command, args []string) {

func getPlugins() ([]string, error) {
plugins := []string{}
pluginHome := os.ExpandEnv("$HOME/.openfaas/plugins")
var pluginHome string
if runtime.GOOS == "windows" {
pluginHome = os.Expand("$HOMEPATH/.openfaas/plugins", os.Getenv)
} else {
pluginHome = os.ExpandEnv("$HOME/.openfaas/plugins")
}

if _, err := os.Stat(pluginHome); err != nil && os.IsNotExist(err) {
return plugins, nil
Expand Down
11 changes: 9 additions & 2 deletions commands/plugin_get.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,17 @@ func runPluginGetCmd(cmd *cobra.Command, args []string) error {
fmt.Printf("Fetching plugin: %s\n", pluginName)
}

pluginDir := os.ExpandEnv("$HOME/.openfaas/plugins")
var pluginDir string
if runtime.GOOS == "windows" {
pluginDir = os.Expand("$HOMEPATH/.openfaas/plugins", os.Getenv)
} else {
pluginDir = os.ExpandEnv("$HOME/.openfaas/plugins")
}

if _, err := os.Stat(pluginDir); os.IsNotExist(err) {
os.MkdirAll(pluginDir, 0755)
if err := os.MkdirAll(pluginDir, 0755); err != nil && os.ErrExist != err {
return fmt.Errorf("failed to create plugin directory %s: %w", pluginDir, err)
}
}

tmpTar := path.Join(os.TempDir(), pluginName+".tar")
Expand Down

0 comments on commit 8383725

Please sign in to comment.