File tree 1 file changed +9
-5
lines changed
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.
269
269
return & tools.Operation {Status : "ok" }, nil
270
270
}
271
271
272
+ // rename function is used to rename the path of the extracted files
272
273
func rename (base string ) extract.Renamer {
274
+ // "Rename" the given path adding the "base" and removing the root folder in "path" (if present).
273
275
return func (path string ) string {
274
276
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 )
278
281
}
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 )
281
285
}
282
286
}
283
287
You can’t perform that action at this time.
0 commit comments