Skip to content

Commit

Permalink
fix: component windows extension (#1567)
Browse files Browse the repository at this point in the history
  • Loading branch information
jon-stewart authored Feb 28, 2024
1 parent 9019e41 commit 851f7c1
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 5 deletions.
16 changes: 14 additions & 2 deletions lwcomponent/catalog.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,13 @@ func (c *Catalog) Stage(
}

func (c *Catalog) Verify(component *CDKComponent) (err error) {
data, err := os.ReadFile(filepath.Join(component.stage.Directory(), component.Name))
path := filepath.Join(component.stage.Directory(), component.Name)

if operatingSystem == "windows" {
path = fmt.Sprintf("%s.exe", path)
}

data, err := os.ReadFile(path)
if err != nil {
return
}
Expand Down Expand Up @@ -215,9 +221,15 @@ func (c *Catalog) Install(component *CDKComponent) (err error) {
return
}

path := filepath.Join(component.stage.Directory(), component.Name)

if operatingSystem == "windows" {
path = fmt.Sprintf("%s.exe", path)
}

if component.ApiInfo != nil &&
(component.ApiInfo.ComponentType == BinaryType || component.ApiInfo.ComponentType == CommandType) {
if err := os.Chmod(filepath.Join(componentDir, component.Name), 0744); err != nil {
if err := os.Chmod(path, 0744); err != nil {
return errors.Wrap(err, "unable to make component executable")
}
}
Expand Down
8 changes: 7 additions & 1 deletion lwcomponent/host_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,13 @@ func (h *HostInfo) Validate() (err error) {
return errors.New(fmt.Sprintf("missing file '%s'", componentName))
}

if !file.FileExists(filepath.Join(h.Dir, componentName)) {
path := filepath.Join(h.Dir, componentName)

if operatingSystem == "windows" {
path = fmt.Sprintf("%s.exe", path)
}

if !file.FileExists(path) {
return errors.New(fmt.Sprintf("missing file '%s'", componentName))
}

Expand Down
11 changes: 9 additions & 2 deletions lwcomponent/staging.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"archive/tar"
"compress/gzip"
"encoding/base64"
"fmt"
"io"
"net/url"
"os"
Expand Down Expand Up @@ -174,8 +175,14 @@ func (s *stageTarGz) Validate() (err error) {
return errors.Errorf("missing file '%s'", s.name)
}

if !file.FileExists(filepath.Join(s.dir, s.name)) {
return errors.Errorf("missing file '%s'", s.name)
path := filepath.Join(s.dir, s.name)

if operatingSystem == "windows" {
path = fmt.Sprintf("%s.exe", path)
}

if !file.FileExists(path) {
return errors.Errorf("missing file '%s'", path)
}

return
Expand Down

0 comments on commit 851f7c1

Please sign in to comment.