Skip to content

Commit

Permalink
implement properly rename function to fix extraction issue with esptool
Browse files Browse the repository at this point in the history
  • Loading branch information
umbynos committed Aug 5, 2024
1 parent be1ee90 commit 51c71f2
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions v2/pkgs/tools.go
Original file line number Diff line number Diff line change
Expand Up @@ -269,15 +269,20 @@ func (t *Tools) Remove(ctx context.Context, payload *tools.ToolPayload) (*tools.
return &tools.Operation{Status: "ok"}, nil
}

// rename function is used to rename the path of the extracted files
func rename(base string) extract.Renamer {
// "Rename" the given path adding the "base" and removing the root folder in "path" (if present).
return func(path string) string {
parts := strings.Split(filepath.ToSlash(path), "/")
newPath := strings.Join(parts[1:], "/")
if newPath == "" {
newPath = filepath.Join(newPath, path)
if len(parts) <= 1 {
// The path does not contain a root folder. This might happen for tool packages (zip files)
// that have an invalid structure. Do not try to remove the root folder in these cases.
return filepath.Join(base, path)
} else {

Check failure on line 281 in v2/pkgs/tools.go

View workflow job for this annotation

GitHub Actions / check-style (./)

if block ends with a return statement, so drop this else and outdent its block
// Removes the first part of the path (the root folder).
path = strings.Join(parts[1:], "/")
return filepath.Join(base, path)
}
path = filepath.Join(base, newPath)
return path
}
}

Expand Down

0 comments on commit 51c71f2

Please sign in to comment.