| 561 | using migrate_files = std::vector<migrate_file>; |
| 562 | |
| 563 | static bool collect_file(const fs::path & old_cache, |
| 564 | const std::string & owner, |
| 565 | const std::string & repo, |
| 566 | const std::string & path, |
| 567 | const std::string & sha256, |
| 568 | const hf_files & files, |
| 569 | migrate_files & to_migrate) { |
| 570 | |
| 571 | const hf_file * file = nullptr; |
| 572 | |
| 573 | for (const auto & f : files) { |
| 574 | if (f.path == path) { |
| 575 | file = &f; |
| 576 | break; |
| 577 | } |
| 578 | } |
| 579 | |
| 580 | std::string old_filename = make_old_cache_filename(owner, repo, path); |
| 581 | fs::path old_path = old_cache / old_filename; |
| 582 | fs::path etag_path = old_path.string() + ".etag"; |
| 583 | |
| 584 | if (!fs::exists(old_path)) { |
| 585 | if (file && fs::exists(file->final_path)) { |
| 586 | return true; |
| 587 | } |
| 588 | LOG_WRN("%s: %s not found in old cache or HF cache\n", __func__, old_filename.c_str()); |
| 589 | return false; |
| 590 | } |
| 591 | |
| 592 | if (!file) { |
| 593 | LOG_WRN("%s: %s not found in current repo\n", __func__, old_filename.c_str()); |
| 594 | return false; |
| 595 | } |
| 596 | |
| 597 | if (!sha256.empty() && !file->oid.empty() && sha256 != file->oid) { |
| 598 | LOG_WRN("%s: %s is not up to date (sha256 mismatch)\n", __func__, old_filename.c_str()); |
| 599 | return false; |
| 600 | } |
| 601 | |
| 602 | if (file->size > 0) { |
| 603 | size_t size = fs::file_size(old_path); |
| 604 | if (size != file->size) { |
| 605 | LOG_WRN("%s: %s has wrong size %zu (expected %zu)\n", __func__, old_filename.c_str(), size, file->size); |
| 606 | return false; |
| 607 | } |
| 608 | } |
| 609 | |
| 610 | to_migrate.push_back({path, sha256, file->size, old_path, etag_path, file}); |
| 611 | return true; |
| 612 | } |
| 613 | |
| 614 | static bool collect_files(const fs::path & old_cache, |
| 615 | const std::string & owner, |
no test coverage detected