Skip to content

Commit 6287df1

Browse files
Fix agent not able to install esptool after 1.6.0 (#986)
* fix link * drop test on old tool not used anymore, and introduce again `arduino-fwuploader` * add tests to install esptool to verify #980 * implement properly rename function to fix extraction issue with esptool * fix test * Update v2/pkgs/tools_test.go Co-authored-by: MatteoPologruto <109663225+MatteoPologruto@users.noreply.github.com> --------- Co-authored-by: MatteoPologruto <109663225+MatteoPologruto@users.noreply.github.com>
1 parent 46fbb34 commit 6287df1

File tree

7 files changed

+32
-126
lines changed

7 files changed

+32
-126
lines changed

main_test.go

+13
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,18 @@ func TestInstallToolV2(t *testing.T) {
116116
Signature: &bossacSignature,
117117
}
118118

119+
esptoolURL := "https://github.com/earlephilhower/esp-quick-toolchain/releases/download/2.5.0-3/x86_64-linux-gnu.esptool-f80ae31.tar.gz"
120+
esptoolChecksum := "SHA-256:bded1dca953377838b6086a9bcd40a1dc5286ba5f69f2372c22a1d1819baad24"
121+
esptoolSignature := "852b58871419ce5e5633ecfaa72c0f0fa890ceb51164b362b8133bc0e3e003a21cec48935b8cdc078f4031219cbf17fb7edd9d7c9ca8ed85492911c9ca6353c9aa4691eb91fda99563a6bd49aeca0d9981fb05ec76e45c6024f8a6822862ad1e34ddc652fbbf4fa909887a255d4f087398ec386577efcec523c21203be3d10fc9e9b0f990a7536875a77dc2bc5cbffea7734b62238e31719111b718bacccebffc9be689545540e81d23b81caa66214376f58a0d6a45cf7efc5d3af62ab932b371628162fffe403906f41d5534921e5be081c5ac2ecc9db5caec03a105cc44b00ce19a95ad079843501eb8182e0717ce327867380c0e39d2b48698547fc1d0d66"
122+
esptoolInstallURLOK := tools.ToolPayload{
123+
Name: "esptool",
124+
Version: "2.5.0-3-20ed2b9",
125+
Packager: "esp8266",
126+
URL: &esptoolURL,
127+
Checksum: &esptoolChecksum,
128+
Signature: &esptoolSignature,
129+
}
130+
119131
wrongSignature := "wr0ngs1gn4tur3"
120132
bossacInstallWrongSig := tools.ToolPayload{
121133
Name: "bossac",
@@ -147,6 +159,7 @@ func TestInstallToolV2(t *testing.T) {
147159
{bossacInstallWrongSig, http.StatusInternalServerError, "verification error"},
148160
{bossacInstallWrongCheck, http.StatusInternalServerError, "checksum of downloaded file doesn't match"},
149161
{bossacInstallNoURL, http.StatusOK, "ok"},
162+
{esptoolInstallURLOK, http.StatusOK, "ok"},
150163
}
151164

152165
for _, test := range tests {

tools/download_test.go

-1
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,6 @@ func TestDownload(t *testing.T) {
120120
{"rp2040tools", "1.0.6", []string{"elf2uf2", "picotool", "pioasm", "rp2040load"}},
121121
{"esptool_py", "4.5.1", []string{"esptool"}},
122122
{"arduino-fwuploader", "2.2.2", []string{"arduino-fwuploader"}},
123-
{"fwupdater", "0.1.12", []string{"firmwares", "FirmwareUploader"}}, // old legacy tool
124123
}
125124
// prepare the test environment
126125
tempDir := t.TempDir()

tools/testdata/test_tool_index.json

-55
Original file line numberDiff line numberDiff line change
@@ -514,61 +514,6 @@
514514
"size": "6829396"
515515
}
516516
]
517-
},
518-
{
519-
"name": "fwupdater",
520-
"version": "0.1.12",
521-
"systems": [
522-
{
523-
"host": "i686-linux-gnu",
524-
"url": "http://downloads.arduino.cc/tools/FirmwareUploader_0.1.12_Linux_32bit.tar.bz2",
525-
"archiveFileName": "FirmwareUploader_0.1.12_Linux_32bit.tar.bz2",
526-
"checksum": "SHA-256:2fec2bdfd20ad4950bc9ba37108dc2a7c152f569174279c0697efe1f5a0db781",
527-
"size": "26097546"
528-
},
529-
{
530-
"host": "x86_64-pc-linux-gnu",
531-
"url": "http://downloads.arduino.cc/tools/FirmwareUploader_0.1.12_Linux_64bit.tar.bz2",
532-
"archiveFileName": "FirmwareUploader_0.1.12_Linux_64bit.tar.bz2",
533-
"checksum": "SHA-256:ce57d0afef30cb7d3513f5da326346c99d6bf4923bbc2200634086811f3fb31e",
534-
"size": "26073327"
535-
},
536-
{
537-
"host": "i686-mingw32",
538-
"url": "http://downloads.arduino.cc/tools/FirmwareUploader_0.1.12_Windows_32bit.zip",
539-
"archiveFileName": "FirmwareUploader_0.1.12_Windows_32bit.zip",
540-
"checksum": "SHA-256:558568b453caa1c821def8cc6d34555d0c910eb7e7e871de3ae1c39ae6f01bdd",
541-
"size": "25743641"
542-
},
543-
{
544-
"host": "x86_64-mingw32",
545-
"url": "http://downloads.arduino.cc/tools/FirmwareUploader_0.1.12_Windows_64bit.zip",
546-
"archiveFileName": "FirmwareUploader_0.1.12_Windows_64bit.zip",
547-
"checksum": "SHA-256:ec16de33620985434280c92c3c322257b89bb67adf8fd4d5dd5f9467ea1e9e40",
548-
"size": "25851428"
549-
},
550-
{
551-
"host": "i386-apple-darwin11",
552-
"url": "http://downloads.arduino.cc/tools/FirmwareUploader_0.1.12_macOS_64bit.tar.bz2",
553-
"archiveFileName": "FirmwareUploader_0.1.12_macOS_64bit.tar.bz2",
554-
"checksum": "SHA-256:a470361b57f86ddfcaecd274d844af51ee1d23a71cd6c26e30fcef2152d1a03f",
555-
"size": "25792860"
556-
},
557-
{
558-
"host": "arm-linux-gnueabihf",
559-
"url": "http://downloads.arduino.cc/tools/FirmwareUploader_0.1.12_Linux_ARM.tar.bz2",
560-
"archiveFileName": "FirmwareUploader_0.1.12_Linux_ARM.tar.bz2",
561-
"checksum": "SHA-256:855fa0a9b942c3ee18906efc510bdfe30bf3334ff28ffbb476e648ff30033847",
562-
"size": "25936245"
563-
},
564-
{
565-
"host": "aarch64-linux-gnu",
566-
"url": "http://downloads.arduino.cc/tools/FirmwareUploader_0.1.12_Linux_ARM64.tar.bz2",
567-
"archiveFileName": "FirmwareUploader_0.1.12_Linux_ARM64.tar.bz2",
568-
"checksum": "SHA-256:691461e64fe075e9a79801347c2bd895fb72f8f2c45a7cd49056c6ad9efe8fc4",
569-
"size": "25967430"
570-
}
571-
]
572517
}
573518
]
574519
}

v2/pkgs/pkgs.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ type System struct {
5050
Checksum string `json:"checksum"`
5151
}
5252

53-
// Source: https://github.com/arduino/arduino-cli/blob/master/arduino/cores/tools.go#L129-L142
53+
// Source: https://github.com/arduino/arduino-cli/blob/master/internal/arduino/cores/tools.go#L129-L142
5454
var (
5555
regexpLinuxArm = regexp.MustCompile("arm.*-linux-gnueabihf")
5656
regexpLinuxArm64 = regexp.MustCompile("(aarch64|arm64)-linux-gnu")
@@ -66,7 +66,7 @@ var (
6666
regexpFreeBSD64 = regexp.MustCompile("amd64-freebsd[0-9]*")
6767
)
6868

69-
// Source: https://github.com/arduino/arduino-cli/blob/master/arduino/cores/tools.go#L144-L176
69+
// Source: https://github.com/arduino/arduino-cli/blob/master/internal/arduino/cores/tools.go#L144-L176
7070
func (s *System) isExactMatchWith(osName, osArch string) bool {
7171
if s.Host == "all" {
7272
return true
@@ -101,7 +101,7 @@ func (s *System) isExactMatchWith(osName, osArch string) bool {
101101
return false
102102
}
103103

104-
// Source: https://github.com/arduino/arduino-cli/blob/master/arduino/cores/tools.go#L178-L198
104+
// Source: https://github.com/arduino/arduino-cli/blob/master/internal/arduino/cores/tools.go#L178-L198
105105
func (s *System) isCompatibleWith(osName, osArch string) (bool, int) {
106106
if s.isExactMatchWith(osName, osArch) {
107107
return true, 1000
@@ -125,7 +125,7 @@ func (s *System) isCompatibleWith(osName, osArch string) (bool, int) {
125125
}
126126

127127
// GetFlavourCompatibleWith returns the downloadable resource (System) compatible with the specified OS/Arch
128-
// Source: https://github.com/arduino/arduino-cli/blob/master/arduino/cores/tools.go#L206-L216
128+
// Source: https://github.com/arduino/arduino-cli/blob/master/internal/arduino/cores/tools.go#L206-L216
129129
func (t *Tool) GetFlavourCompatibleWith(osName, osArch string) System {
130130
var correctSystem System
131131
maxSimilarity := -1

v2/pkgs/testdata/test_tool_index.json

-55
Original file line numberDiff line numberDiff line change
@@ -514,61 +514,6 @@
514514
"size": "6829396"
515515
}
516516
]
517-
},
518-
{
519-
"name": "fwupdater",
520-
"version": "0.1.12",
521-
"systems": [
522-
{
523-
"host": "i686-linux-gnu",
524-
"url": "http://downloads.arduino.cc/tools/FirmwareUploader_0.1.12_Linux_32bit.tar.bz2",
525-
"archiveFileName": "FirmwareUploader_0.1.12_Linux_32bit.tar.bz2",
526-
"checksum": "SHA-256:2fec2bdfd20ad4950bc9ba37108dc2a7c152f569174279c0697efe1f5a0db781",
527-
"size": "26097546"
528-
},
529-
{
530-
"host": "x86_64-pc-linux-gnu",
531-
"url": "http://downloads.arduino.cc/tools/FirmwareUploader_0.1.12_Linux_64bit.tar.bz2",
532-
"archiveFileName": "FirmwareUploader_0.1.12_Linux_64bit.tar.bz2",
533-
"checksum": "SHA-256:ce57d0afef30cb7d3513f5da326346c99d6bf4923bbc2200634086811f3fb31e",
534-
"size": "26073327"
535-
},
536-
{
537-
"host": "i686-mingw32",
538-
"url": "http://downloads.arduino.cc/tools/FirmwareUploader_0.1.12_Windows_32bit.zip",
539-
"archiveFileName": "FirmwareUploader_0.1.12_Windows_32bit.zip",
540-
"checksum": "SHA-256:558568b453caa1c821def8cc6d34555d0c910eb7e7e871de3ae1c39ae6f01bdd",
541-
"size": "25743641"
542-
},
543-
{
544-
"host": "x86_64-mingw32",
545-
"url": "http://downloads.arduino.cc/tools/FirmwareUploader_0.1.12_Windows_64bit.zip",
546-
"archiveFileName": "FirmwareUploader_0.1.12_Windows_64bit.zip",
547-
"checksum": "SHA-256:ec16de33620985434280c92c3c322257b89bb67adf8fd4d5dd5f9467ea1e9e40",
548-
"size": "25851428"
549-
},
550-
{
551-
"host": "i386-apple-darwin11",
552-
"url": "http://downloads.arduino.cc/tools/FirmwareUploader_0.1.12_macOS_64bit.tar.bz2",
553-
"archiveFileName": "FirmwareUploader_0.1.12_macOS_64bit.tar.bz2",
554-
"checksum": "SHA-256:a470361b57f86ddfcaecd274d844af51ee1d23a71cd6c26e30fcef2152d1a03f",
555-
"size": "25792860"
556-
},
557-
{
558-
"host": "arm-linux-gnueabihf",
559-
"url": "http://downloads.arduino.cc/tools/FirmwareUploader_0.1.12_Linux_ARM.tar.bz2",
560-
"archiveFileName": "FirmwareUploader_0.1.12_Linux_ARM.tar.bz2",
561-
"checksum": "SHA-256:855fa0a9b942c3ee18906efc510bdfe30bf3334ff28ffbb476e648ff30033847",
562-
"size": "25936245"
563-
},
564-
{
565-
"host": "aarch64-linux-gnu",
566-
"url": "http://downloads.arduino.cc/tools/FirmwareUploader_0.1.12_Linux_ARM64.tar.bz2",
567-
"archiveFileName": "FirmwareUploader_0.1.12_Linux_ARM64.tar.bz2",
568-
"checksum": "SHA-256:691461e64fe075e9a79801347c2bd895fb72f8f2c45a7cd49056c6ad9efe8fc4",
569-
"size": "25967430"
570-
}
571-
]
572517
}
573518
]
574519
}

v2/pkgs/tools.go

+9-5
Original file line numberDiff line numberDiff line change
@@ -269,15 +269,19 @@ func (t *Tools) Remove(ctx context.Context, payload *tools.ToolPayload) (*tools.
269269
return &tools.Operation{Status: "ok"}, nil
270270
}
271271

272+
// rename function is used to rename the path of the extracted files
272273
func rename(base string) extract.Renamer {
274+
// "Rename" the given path adding the "base" and removing the root folder in "path" (if present).
273275
return func(path string) string {
274276
parts := strings.Split(filepath.ToSlash(path), "/")
275-
newPath := strings.Join(parts[1:], "/")
276-
if newPath == "" {
277-
newPath = filepath.Join(newPath, path)
277+
if len(parts) <= 1 {
278+
// The path does not contain a root folder. This might happen for tool packages (zip files)
279+
// that have an invalid structure. Do not try to remove the root folder in these cases.
280+
return filepath.Join(base, path)
278281
}
279-
path = filepath.Join(base, newPath)
280-
return path
282+
// Removes the first part of the path (the root folder).
283+
path = strings.Join(parts[1:], "/")
284+
return filepath.Join(base, path)
281285
}
282286
}
283287

v2/pkgs/tools_test.go

+6-6
Original file line numberDiff line numberDiff line change
@@ -230,9 +230,9 @@ func TestInstall(t *testing.T) {
230230
{Name: "dfu-util", Version: "0.10.0-arduino1", Packager: "arduino-test", URL: nil, Checksum: nil, Signature: nil},
231231
{Name: "rp2040tools", Version: "1.0.6", Packager: "arduino-test", URL: nil, Checksum: nil, Signature: nil},
232232
{Name: "esptool_py", Version: "4.5.1", Packager: "arduino-test", URL: nil, Checksum: nil, Signature: nil},
233-
// At the moment we don't install these ones because they are packaged in a different way: they do not have a top level dir, causing the rename funcion to behave incorrectly
234-
// {Name: "fwupdater", Version: "0.1.12", Packager: "arduino-test", URL: nil, Checksum: nil, Signature: nil},
235-
// {Name: "arduino-fwuploader", Version: "2.2.2", Packager: "arduino-test", URL: nil, Checksum: nil, Signature: nil},
233+
{Name: "arduino-fwuploader", Version: "2.2.2", Packager: "arduino-test", URL: nil, Checksum: nil, Signature: nil},
234+
// test download of a tool not present in index. the same archive is downloaded on linux/win/mac See https://github.com/arduino/arduino-create-agent/issues/980
235+
{Name: "esptool", Version: "2.5.0-3-20ed2b9", Packager: "esp8266", URL: strpoint("https://github.com/earlephilhower/esp-quick-toolchain/releases/download/2.5.0-3/x86_64-linux-gnu.esptool-f80ae31.tar.gz"), Checksum: strpoint("SHA-256:bded1dca953377838b6086a9bcd40a1dc5286ba5f69f2372c22a1d1819baad24"), Signature: strpoint("852b58871419ce5e5633ecfaa72c0f0fa890ceb51164b362b8133bc0e3e003a21cec48935b8cdc078f4031219cbf17fb7edd9d7c9ca8ed85492911c9ca6353c9aa4691eb91fda99563a6bd49aeca0d9981fb05ec76e45c6024f8a6822862ad1e34ddc652fbbf4fa909887a255d4f087398ec386577efcec523c21203be3d10fc9e9b0f990a7536875a77dc2bc5cbffea7734b62238e31719111b718bacccebffc9be689545540e81d23b81caa66214376f58a0d6a45cf7efc5d3af62ab932b371628162fffe403906f41d5534921e5be081c5ac2ecc9db5caec03a105cc44b00ce19a95ad079843501eb8182e0717ce327867380c0e39d2b48698547fc1d0d66")},
236236
}
237237

238238
expectedFiles := map[string][]string{
@@ -244,8 +244,8 @@ func TestInstall(t *testing.T) {
244244
"dfu-util-0.10.0-arduino1": {"dfu-prefix", "dfu-suffix", "dfu-util"},
245245
"rp2040tools-1.0.6": {"elf2uf2", "picotool", "pioasm", "rp2040load"},
246246
"esptool_py-4.5.1": {"esptool"},
247-
// "fwupdater-0.1.12": {"firmwares", "FirmwareUploader"}, // old legacy tool
248-
// "arduino-fwuploader-2.2.2": {"arduino-fwuploader"},
247+
"arduino-fwuploader-2.2.2": {"arduino-fwuploader"},
248+
// "esptool-2.5.0-3-20ed2b9": {"esptool"}, // we don't check if there is esptool in the archive because it's the same archive even on windows (no extension)
249249
}
250250
for _, tc := range testCases {
251251
t.Run(tc.Name+"-"+tc.Version, func(t *testing.T) {
@@ -254,7 +254,7 @@ func TestInstall(t *testing.T) {
254254
require.NoError(t, err)
255255

256256
// Check that the tool has been downloaded
257-
toolDir := paths.New(tmp).Join("arduino-test", tc.Name, tc.Version)
257+
toolDir := paths.New(tmp).Join(tc.Packager, tc.Name, tc.Version)
258258
require.DirExists(t, toolDir.String())
259259

260260
// Check that the files have been created

0 commit comments

Comments
 (0)