(ctx context.Context, f1, f2 fs.File, fname string)
| 325 | } |
| 326 | |
| 327 | func (c *Comparer) compareFiles(ctx context.Context, f1, f2 fs.File, fname string) error { |
| 328 | if c.DiffCommand == "" { |
| 329 | return nil |
| 330 | } |
| 331 | |
| 332 | oldName := "/dev/null" |
| 333 | newName := "/dev/null" |
| 334 | |
| 335 | if f1 != nil { |
| 336 | oldName = filepath.Join("old", fname) |
| 337 | oldFile := filepath.Join(c.tmpDir, oldName) |
| 338 | |
| 339 | if err := downloadFile(ctx, f1, oldFile); err != nil { |
| 340 | return errors.Wrap(err, "error downloading old file") |
| 341 | } |
| 342 | |
| 343 | defer os.Remove(oldFile) //nolint:errcheck |
| 344 | } |
| 345 | |
| 346 | if f2 != nil { |
| 347 | newName = filepath.Join("new", fname) |
| 348 | newFile := filepath.Join(c.tmpDir, newName) |
| 349 | |
| 350 | if err := downloadFile(ctx, f2, newFile); err != nil { |
| 351 | return errors.Wrap(err, "error downloading new file") |
| 352 | } |
| 353 | defer os.Remove(newFile) //nolint:errcheck |
| 354 | } |
| 355 | |
| 356 | var args []string |
| 357 | |
| 358 | args = append(args, c.DiffArguments...) |
| 359 | args = append(args, oldName, newName) |
| 360 | |
| 361 | cmd := exec.CommandContext(ctx, c.DiffCommand, args...) //nolint:gosec |
| 362 | cmd.Dir = c.tmpDir |
| 363 | cmd.Stdout = c.out |
| 364 | cmd.Stderr = c.out |
| 365 | cmd.Run() //nolint:errcheck |
| 366 | |
| 367 | return nil |
| 368 | } |
| 369 | |
| 370 | func downloadFile(ctx context.Context, f fs.File, fname string) error { |
| 371 | if err := os.MkdirAll(filepath.Dir(fname), dirMode); err != nil { |
no test coverage detected