Skip to content

Commit 0593ee0

Browse files
committed
implement properly rename function to fix extraction issue with esptool
1 parent 17aec33 commit 0593ee0

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

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

0 commit comments

Comments
 (0)