Skip to content

Fix Duplicate tool bug #346

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 2 commits into from
Apr 3, 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
11 changes: 8 additions & 3 deletions v2/pkgs/indexes.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"net/url"
"os"
"path/filepath"
"strings"

"github.com/arduino/arduino-create-agent/gen/indexes"
"github.com/sirupsen/logrus"
Expand Down Expand Up @@ -77,13 +78,17 @@ func (c *Indexes) List(context.Context) ([]string, error) {
return nil, err
}

res := make([]string, len(files))
for i, file := range files {
res := []string{}
for _, file := range files {
// Select only files that begin with http
if !strings.HasPrefix(file.Name(), "http") {
continue
}
path, err := url.PathUnescape(file.Name())
if err != nil {
c.Log.Warn(err)
}
res[i] = path
res = append(res, path)
}

return res, nil
Expand Down
4 changes: 4 additions & 0 deletions v2/pkgs/indexes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"net/http"
"net/http/httptest"
"os"
"path/filepath"
"strings"
"testing"

Expand All @@ -28,6 +29,9 @@ func TestIndexes(t *testing.T) {
}
defer os.RemoveAll(tmp)

// Create extraneous folder in temp folder
os.MkdirAll(filepath.Join(tmp, "arduino"), 0755)

service := pkgs.Indexes{
Folder: tmp,
}
Expand Down
7 changes: 7 additions & 0 deletions v2/pkgs/tools.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,8 +169,15 @@ func (c *Tools) install(ctx context.Context, path, url, checksum string) (*tools
var buffer bytes.Buffer
reader := io.TeeReader(res.Body, &buffer)

// Cleanup
err = os.RemoveAll(filepath.Join(c.Folder, path))
if err != nil {
return nil, err
}

err = extract.Archive(ctx, reader, c.Folder, rename(path))
if err != nil {
os.RemoveAll(path)
return nil, err
}

Expand Down
10 changes: 10 additions & 0 deletions v2/pkgs/tools_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,16 @@ func TestTools(t *testing.T) {
t.Fatalf("expected %d == %d (%s)", len(installed), 1, "len(installed)")
}

// Install the tool again
_, err = service.Install(ctx, &tools.ToolPayload{
Packager: "arduino",
Name: "avrdude",
Version: "6.0.1-arduino2",
})
if err != nil {
t.Fatal(err)
}

// Remove tool
_, err = service.Remove(ctx, &tools.ToolPayload{
Packager: "arduino",
Expand Down