Skip to content

Commit e5690c5

Browse files
committed
make tools.install extract in the proper folder
1 parent e8cd9cd commit e5690c5

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

v2/pkgs/tools.go

+15-3
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"os/user"
99
"path/filepath"
1010
"runtime"
11+
"strings"
1112

1213
"github.com/arduino/arduino-create-agent/gen/tools"
1314
"github.com/codeclysm/extract"
@@ -110,7 +111,7 @@ func (c *Tools) Install(ctx context.Context, payload *tools.ToolPayload) error {
110111
for _, tool := range packager.Tools {
111112
if tool.Name == payload.Name &&
112113
tool.Version == payload.Version {
113-
return c.install(ctx, tool)
114+
return c.install(ctx, payload.Packager, tool)
114115
}
115116
}
116117
}
@@ -121,7 +122,7 @@ func (c *Tools) Install(ctx context.Context, payload *tools.ToolPayload) error {
121122
payload.Packager, payload.Name, payload.Version))
122123
}
123124

124-
func (c *Tools) install(ctx context.Context, tool Tool) error {
125+
func (c *Tools) install(ctx context.Context, packager string, tool Tool) error {
125126
i := findSystem(tool)
126127

127128
// Download
@@ -132,7 +133,7 @@ func (c *Tools) install(ctx context.Context, tool Tool) error {
132133
}
133134
defer res.Body.Close()
134135

135-
err = extract.Archive(ctx, res.Body, c.Folder, nil)
136+
err = extract.Archive(ctx, res.Body, c.Folder, rename(packager, tool.Name, tool.Version))
136137
if err != nil {
137138
return err
138139
}
@@ -144,6 +145,17 @@ func (c *Tools) Remove(ctx context.Context, payload *tools.ToolPayload) error {
144145
return nil
145146
}
146147

148+
func rename(packager, name, version string) extract.Renamer {
149+
base := filepath.Join(packager, name, version)
150+
return func(path string) string {
151+
parts := strings.Split(path, string(filepath.Separator))
152+
path = strings.Join(parts[1:], string(filepath.Separator))
153+
path = filepath.Join(base, path)
154+
fmt.Println("path", path)
155+
return path
156+
}
157+
}
158+
147159
func findSystem(tool Tool) int {
148160
var systems = map[string]string{
149161
"linuxamd64": "x86_64-linux-gnu",

0 commit comments

Comments
 (0)