Skip to content

Commit fca3237

Browse files
authored
Merge pull request #361 from arduino/devel
Deploy fix on downloadtool
2 parents 5c199c1 + cb014fd commit fca3237

File tree

2 files changed

+13
-9
lines changed

2 files changed

+13
-9
lines changed

v2/pkgs/indexes.go

+9-5
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package pkgs
22

33
import (
44
"context"
5+
b64 "encoding/base64"
56
"encoding/json"
67
"io/ioutil"
78
"net/url"
@@ -31,7 +32,7 @@ func (c *Indexes) Add(ctx context.Context, payload *indexes.IndexPayload) (*inde
3132
}
3233

3334
// Download tmp file
34-
filename := url.PathEscape(payload.URL)
35+
filename := b64.StdEncoding.EncodeToString([]byte(url.PathEscape(payload.URL)))
3536
path := filepath.Join(c.Folder, filename+".tmp")
3637
d, err := downloader.Download(path, indexURL.String())
3738
if err != nil {
@@ -53,7 +54,7 @@ func (c *Indexes) Add(ctx context.Context, payload *indexes.IndexPayload) (*inde
5354

5455
// Get reads the index file from the Indexes Folder, unmarshaling it
5556
func (c *Indexes) Get(ctx context.Context, uri string) (index Index, err error) {
56-
filename := url.PathEscape(uri)
57+
filename := b64.StdEncoding.EncodeToString([]byte(url.PathEscape(uri)))
5758
path := filepath.Join(c.Folder, filename)
5859
data, err := ioutil.ReadFile(path)
5960
if err != nil {
@@ -74,17 +75,20 @@ func (c *Indexes) List(context.Context) ([]string, error) {
7475
_ = os.MkdirAll(c.Folder, 0755)
7576
// Read files
7677
files, err := ioutil.ReadDir(c.Folder)
78+
7779
if err != nil {
7880
return nil, err
7981
}
8082

8183
res := []string{}
8284
for _, file := range files {
8385
// Select only files that begin with http
84-
if !strings.HasPrefix(file.Name(), "http") {
86+
decodedFileName, _ := b64.URLEncoding.DecodeString(file.Name())
87+
fileName:=string(decodedFileName)
88+
if !strings.HasPrefix(fileName, "http") {
8589
continue
8690
}
87-
path, err := url.PathUnescape(file.Name())
91+
path, err := url.PathUnescape(fileName)
8892
if err != nil {
8993
c.Log.Warn(err)
9094
}
@@ -96,7 +100,7 @@ func (c *Indexes) List(context.Context) ([]string, error) {
96100

97101
// Remove deletes the index file from the Indexes Folder
98102
func (c *Indexes) Remove(ctx context.Context, payload *indexes.IndexPayload) (*indexes.Operation, error) {
99-
filename := url.PathEscape(payload.URL)
103+
filename := b64.StdEncoding.EncodeToString([]byte(url.PathEscape(payload.URL)))
100104
err := os.RemoveAll(filepath.Join(c.Folder, filename))
101105
if err != nil {
102106
return nil, err

v2/pkgs/tools.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -212,10 +212,9 @@ func (c *Tools) Remove(ctx context.Context, payload *tools.ToolPayload) (*tools.
212212

213213
func rename(base string) extract.Renamer {
214214
return func(path string) string {
215-
parts := strings.Split(path, string(filepath.Separator))
216-
path = strings.Join(parts[1:], string(filepath.Separator))
215+
parts := strings.Split(filepath.ToSlash(path), "/")
216+
path = strings.Join(parts[1:], "/")
217217
path = filepath.Join(base, path)
218-
219218
return path
220219
}
221220
}
@@ -258,8 +257,9 @@ func writeInstalled(folder, path string) error {
258257

259258
parts := strings.Split(path, string(filepath.Separator))
260259
tool := parts[len(parts)-2]
261-
260+
toolWithVersion := fmt.Sprint(tool, "-", parts[len(parts)-1])
262261
installed[tool] = filepath.Join(folder, path)
262+
installed[toolWithVersion] = filepath.Join(folder, path)
263263

264264
data, err = json.Marshal(installed)
265265
if err != nil {

0 commit comments

Comments
 (0)