File tree Expand file tree Collapse file tree 1 file changed +9
-5
lines changed
Expand file tree Collapse file tree 1 file changed +9
-5
lines changed Original file line number Diff line number Diff 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
272273func 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
You can’t perform that action at this time.
0 commit comments