| 331 | } |
| 332 | |
| 333 | int YALMData::from_directory(const std::string& dirname, bool lock_model_weights) { |
| 334 | std::vector<std::string> files; |
| 335 | DIR* dir = opendir(dirname.c_str()); |
| 336 | if (dir == nullptr) { |
| 337 | std::cout << "failed to open directory" << std::endl; |
| 338 | return -1; |
| 339 | } |
| 340 | |
| 341 | // Collect all files |
| 342 | struct dirent* entry; |
| 343 | while ((entry = readdir(dir)) != nullptr) { |
| 344 | std::string filename = entry->d_name; |
| 345 | // Skip . and .. directory entries |
| 346 | if (filename != "." && filename != "..") { |
| 347 | files.push_back(dirname + "/" + filename); |
| 348 | } |
| 349 | } |
| 350 | closedir(dir); |
| 351 | |
| 352 | if (files.empty()) { |
| 353 | std::cout << "no files found" << std::endl; |
| 354 | return -1; |
| 355 | } |
| 356 | |
| 357 | // Sort files to ensure consistent ordering |
| 358 | std::sort(files.begin(), files.end()); |
| 359 | |
| 360 | // Read first file with metadata |
| 361 | if (update_from_file(files[0], true, lock_model_weights) != 0) { |
| 362 | std::cout << "failed to read metadata" << std::endl; |
| 363 | return -1; |
| 364 | } |
| 365 | |
| 366 | std::cout << "read metadata " << metadata << std::endl; |
| 367 | |
| 368 | // Read remaining files without metadata |
| 369 | for (size_t i = 1; i < files.size(); i++) { |
| 370 | if (update_from_file(files[i], false, lock_model_weights) != 0) { |
| 371 | std::cout << "failed to read file " << files[i] << std::endl; |
| 372 | return -1; |
| 373 | } |
| 374 | } |
| 375 | |
| 376 | return 0; |
| 377 | } |
nothing calls this directly
no outgoing calls
no test coverage detected