| 374 | } |
| 375 | |
| 376 | static std::string get_cached_ref(const fs::path & repo_path) { |
| 377 | fs::path refs_path = repo_path / "refs"; |
| 378 | if (!fs::is_directory(refs_path)) { |
| 379 | return {}; |
| 380 | } |
| 381 | std::string fallback; |
| 382 | |
| 383 | for (const auto & entry : fs::directory_iterator(refs_path)) { |
| 384 | if (!entry.is_regular_file()) { |
| 385 | continue; |
| 386 | } |
| 387 | std::ifstream f(entry.path()); |
| 388 | std::string commit; |
| 389 | if (!f || !std::getline(f, commit) || commit.empty()) { |
| 390 | continue; |
| 391 | } |
| 392 | if (!is_valid_commit(commit)) { |
| 393 | LOG_WRN("%s: skip invalid commit: %s\n", __func__, commit.c_str()); |
| 394 | continue; |
| 395 | } |
| 396 | if (entry.path().filename() == "main") { |
| 397 | return commit; |
| 398 | } |
| 399 | if (fallback.empty()) { |
| 400 | fallback = commit; |
| 401 | } |
| 402 | } |
| 403 | return fallback; |
| 404 | } |
| 405 | |
| 406 | hf_files get_cached_files(const std::string & repo_id) { |
| 407 | fs::path cache_dir = get_cache_directory(); |
no test coverage detected