Skip to content

Deploy fix on downloadtool #361

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Apr 23, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions v2/pkgs/indexes.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package pkgs

import (
"context"
b64 "encoding/base64"
"encoding/json"
"io/ioutil"
"net/url"
Expand Down Expand Up @@ -31,7 +32,7 @@ func (c *Indexes) Add(ctx context.Context, payload *indexes.IndexPayload) (*inde
}

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

// Get reads the index file from the Indexes Folder, unmarshaling it
func (c *Indexes) Get(ctx context.Context, uri string) (index Index, err error) {
filename := url.PathEscape(uri)
filename := b64.StdEncoding.EncodeToString([]byte(url.PathEscape(uri)))
path := filepath.Join(c.Folder, filename)
data, err := ioutil.ReadFile(path)
if err != nil {
Expand All @@ -74,17 +75,20 @@ func (c *Indexes) List(context.Context) ([]string, error) {
_ = os.MkdirAll(c.Folder, 0755)
// Read files
files, err := ioutil.ReadDir(c.Folder)

if err != nil {
return nil, err
}

res := []string{}
for _, file := range files {
// Select only files that begin with http
if !strings.HasPrefix(file.Name(), "http") {
decodedFileName, _ := b64.URLEncoding.DecodeString(file.Name())
fileName:=string(decodedFileName)
if !strings.HasPrefix(fileName, "http") {
continue
}
path, err := url.PathUnescape(file.Name())
path, err := url.PathUnescape(fileName)
if err != nil {
c.Log.Warn(err)
}
Expand All @@ -96,7 +100,7 @@ func (c *Indexes) List(context.Context) ([]string, error) {

// Remove deletes the index file from the Indexes Folder
func (c *Indexes) Remove(ctx context.Context, payload *indexes.IndexPayload) (*indexes.Operation, error) {
filename := url.PathEscape(payload.URL)
filename := b64.StdEncoding.EncodeToString([]byte(url.PathEscape(payload.URL)))
err := os.RemoveAll(filepath.Join(c.Folder, filename))
if err != nil {
return nil, err
Expand Down
8 changes: 4 additions & 4 deletions v2/pkgs/tools.go
Original file line number Diff line number Diff line change
Expand Up @@ -212,10 +212,9 @@ func (c *Tools) Remove(ctx context.Context, payload *tools.ToolPayload) (*tools.

func rename(base string) extract.Renamer {
return func(path string) string {
parts := strings.Split(path, string(filepath.Separator))
path = strings.Join(parts[1:], string(filepath.Separator))
parts := strings.Split(filepath.ToSlash(path), "/")
path = strings.Join(parts[1:], "/")
path = filepath.Join(base, path)

return path
}
}
Expand Down Expand Up @@ -258,8 +257,9 @@ func writeInstalled(folder, path string) error {

parts := strings.Split(path, string(filepath.Separator))
tool := parts[len(parts)-2]

toolWithVersion := fmt.Sprint(tool, "-", parts[len(parts)-1])
installed[tool] = filepath.Join(folder, path)
installed[toolWithVersion] = filepath.Join(folder, path)

data, err = json.Marshal(installed)
if err != nil {
Expand Down