(repo, data string)
| 498 | } |
| 499 | |
| 500 | func replaceData(repo, data string) error { |
| 501 | // If the path is absolute we assume it is the full path to the |
| 502 | // testdata. If it is relative, we assume it refers to one of the |
| 503 | // test data sets. |
| 504 | if !filepath.IsAbs(data) { |
| 505 | ds, err := GetTestDataPath() |
| 506 | if err != nil { |
| 507 | return err |
| 508 | } |
| 509 | data = filepath.Join(ds, data) |
| 510 | } |
| 511 | // Walk the data directory and copy over all files. We have special |
| 512 | // handling of the Kptfile to make sure we don't lose the Upstream data. |
| 513 | if err := filepath.Walk(data, func(path string, info os.FileInfo, err error) error { |
| 514 | if err != nil { |
| 515 | return err |
| 516 | } |
| 517 | rel, err := filepath.Rel(data, path) |
| 518 | if err != nil { |
| 519 | return err |
| 520 | } |
| 521 | |
| 522 | _, err = os.Stat(filepath.Join(repo, rel)) |
| 523 | if err != nil && !os.IsNotExist(err) { |
| 524 | return err |
| 525 | } |
| 526 | |
| 527 | // If the file/directory doesn't exist in the repo folder, we just |
| 528 | // copy it over. |
| 529 | if os.IsNotExist(err) { |
| 530 | if info.IsDir() { |
| 531 | err := os.Mkdir(filepath.Join(repo, rel), 0700) |
| 532 | if err != nil { |
| 533 | return err |
| 534 | } |
| 535 | } else { |
| 536 | err := copyutil.SyncFile(path, filepath.Join(repo, rel)) |
| 537 | if err != nil { |
| 538 | return err |
| 539 | } |
| 540 | } |
| 541 | return nil |
| 542 | } |
| 543 | |
| 544 | // If it is a directory and we know it already exists, we don't need |
| 545 | // to do anything. |
| 546 | if info.IsDir() { |
| 547 | return nil |
| 548 | } |
| 549 | |
| 550 | // For Kptfiles we need to keep the Upstream section even if we replace |
| 551 | // the file. |
| 552 | if rel == "Kptfile" { |
| 553 | dataKptfile, err := kptfileutil.ReadFile(filepath.Dir(path)) |
| 554 | if err != nil { |
| 555 | return err |
| 556 | } |
| 557 | repoKptfileDir := filepath.Dir(filepath.Join(repo, rel)) |
no test coverage detected