()
| 210 | } |
| 211 | |
| 212 | func (b *BuildTool) checkAndFix() error { |
| 213 | var ( |
| 214 | folderName string |
| 215 | archiveName string |
| 216 | location string |
| 217 | ) |
| 218 | |
| 219 | // Determine folder name and location based on tool type |
| 220 | toolsDir := filepath.Join(b.ctx.Downloads(), "tools") |
| 221 | if len(b.Paths) > 0 { |
| 222 | // Archive with paths: extract to subdirectory. |
| 223 | folderName = strings.Split(b.Paths[0], "/")[0] |
| 224 | location = filepath.Join(toolsDir, folderName) |
| 225 | |
| 226 | // Use archive name as download file name if specified. |
| 227 | archiveName = filepath.Base(b.Url) |
| 228 | if b.Archive != "" { |
| 229 | archiveName = b.Archive |
| 230 | } |
| 231 | } else { |
| 232 | // Single-file tool: use directly from /downloads/ |
| 233 | if b.Archive != "" { |
| 234 | archiveName = b.Archive |
| 235 | location = filepath.Join(b.ctx.Downloads(), b.Archive) |
| 236 | } else { |
| 237 | archiveName = filepath.Base(b.Url) |
| 238 | location = filepath.Join(b.ctx.Downloads(), filepath.Base(b.Url)) |
| 239 | } |
| 240 | folderName = "" // Empty indicates single-file, no subdirectory needed. |
| 241 | } |
| 242 | |
| 243 | // Check and repair resource. |
| 244 | repair := fileio.NewRepair(b.Url, b.ctx.Downloads(), archiveName, folderName, toolsDir, b.SHA256) |
| 245 | if err := repair.CheckAndRepair(b.ctx); err != nil { |
| 246 | return err |
| 247 | } |
| 248 | |
| 249 | // Only print if tool was just downloaded (didn't exist before). |
| 250 | if !fileio.PathExists(location) { |
| 251 | // Print download & extract info. |
| 252 | color.PrintPass("tool: %s", fileio.Base(b.Url)) |
| 253 | color.PrintHint("Location: %s", location) |
| 254 | } |
| 255 | |
| 256 | return nil |
| 257 | } |
| 258 | |
| 259 | type BuildTools struct { |
| 260 | BuildTools []BuildTool `toml:"build_tools"` |
no test coverage detected