| 404 | } |
| 405 | |
| 406 | hf_files get_cached_files(const std::string & repo_id) { |
| 407 | fs::path cache_dir = get_cache_directory(); |
| 408 | if (!fs::exists(cache_dir)) { |
| 409 | return {}; |
| 410 | } |
| 411 | |
| 412 | if (!repo_id.empty() && !is_valid_repo_id(repo_id)) { |
| 413 | LOG_WRN("%s: invalid repository: %s\n", __func__, repo_id.c_str()); |
| 414 | return {}; |
| 415 | } |
| 416 | |
| 417 | hf_files files; |
| 418 | |
| 419 | for (const auto & repo : fs::directory_iterator(cache_dir)) { |
| 420 | if (!repo.is_directory()) { |
| 421 | continue; |
| 422 | } |
| 423 | fs::path snapshots_path = repo.path() / "snapshots"; |
| 424 | |
| 425 | if (!fs::exists(snapshots_path)) { |
| 426 | continue; |
| 427 | } |
| 428 | std::string _repo_id = folder_name_to_repo(repo.path().filename().string()); |
| 429 | |
| 430 | if (!is_valid_repo_id(_repo_id)) { |
| 431 | continue; |
| 432 | } |
| 433 | if (!repo_id.empty() && _repo_id != repo_id) { |
| 434 | continue; |
| 435 | } |
| 436 | std::string commit = get_cached_ref(repo.path()); |
| 437 | fs::path commit_path = snapshots_path / commit; |
| 438 | |
| 439 | if (commit.empty() || !fs::is_directory(commit_path)) { |
| 440 | continue; |
| 441 | } |
| 442 | for (const auto & entry : fs::recursive_directory_iterator(commit_path)) { |
| 443 | if (!entry.is_regular_file() && !entry.is_symlink()) { |
| 444 | continue; |
| 445 | } |
| 446 | fs::path path = entry.path().lexically_relative(commit_path); |
| 447 | |
| 448 | if (!path.empty()) { |
| 449 | hf_file file; |
| 450 | file.repo_id = _repo_id; |
| 451 | file.path = path.generic_string(); |
| 452 | file.local_path = entry.path().string(); |
| 453 | file.final_path = file.local_path; |
| 454 | files.push_back(std::move(file)); |
| 455 | } |
| 456 | } |
| 457 | } |
| 458 | |
| 459 | return files; |
| 460 | } |
| 461 | |
| 462 | std::string finalize_file(const hf_file & file) { |
| 463 | static std::atomic<bool> symlinks_disabled{false}; |
no test coverage detected