ggml : improve error handling for search path existence checks (#17653)
* Improve error handling for search path existence checks Refactor existence checks for search paths using std::error_code to handle potential errors. * Improve cache file existence check with error code Update fs::exists to use std::error_code for error handling. * Simplify existence check for search paths Simplify existence check for search paths * Fix logging path in error message for posix_stat * Update ggml/src/ggml-backend-reg.cpp Co-authored-by: Aman Gupta <amangupta052@gmail.com> * Adapt to the coding standard --------- Co-authored-by: Aman Gupta <amangupta052@gmail.com>
This commit is contained in:
parent
444f00b0ec
commit
7b43f55753
|
|
@ -534,8 +534,12 @@ static ggml_backend_reg_t ggml_backend_load_best(const char * name, bool silent,
|
||||||
fs::path best_path;
|
fs::path best_path;
|
||||||
|
|
||||||
for (const auto & search_path : search_paths) {
|
for (const auto & search_path : search_paths) {
|
||||||
if (!fs::exists(search_path)) {
|
if (std::error_code ec; !fs::exists(search_path, ec)) {
|
||||||
|
if (ec) {
|
||||||
|
GGML_LOG_DEBUG("%s: posix_stat(%s) failure, error-message: %s\n", __func__, path_str(search_path).c_str(), ec.message().c_str());
|
||||||
|
} else {
|
||||||
GGML_LOG_DEBUG("%s: search path %s does not exist\n", __func__, path_str(search_path).c_str());
|
GGML_LOG_DEBUG("%s: search path %s does not exist\n", __func__, path_str(search_path).c_str());
|
||||||
|
}
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
fs::directory_iterator dir_it(search_path, fs::directory_options::skip_permission_denied);
|
fs::directory_iterator dir_it(search_path, fs::directory_options::skip_permission_denied);
|
||||||
|
|
@ -575,8 +579,12 @@ static ggml_backend_reg_t ggml_backend_load_best(const char * name, bool silent,
|
||||||
for (const auto & search_path : search_paths) {
|
for (const auto & search_path : search_paths) {
|
||||||
fs::path filename = backend_filename_prefix().native() + name_path.native() + backend_filename_extension().native();
|
fs::path filename = backend_filename_prefix().native() + name_path.native() + backend_filename_extension().native();
|
||||||
fs::path path = search_path / filename;
|
fs::path path = search_path / filename;
|
||||||
if (fs::exists(path)) {
|
if (std::error_code ec; fs::exists(path, ec)) {
|
||||||
return get_reg().load_backend(path, silent);
|
return get_reg().load_backend(path, silent);
|
||||||
|
} else {
|
||||||
|
if (ec) {
|
||||||
|
GGML_LOG_DEBUG("%s: posix_stat(%s) failure, error-message: %s\n", __func__, path_str(path).c_str(), ec.message().c_str());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
|
|
||||||
|
|
@ -1257,7 +1257,8 @@ bool rpc_server::get_cached_file(uint64_t hash, std::vector<uint8_t> & data) {
|
||||||
char hash_str[17];
|
char hash_str[17];
|
||||||
snprintf(hash_str, sizeof(hash_str), "%016" PRIx64, hash);
|
snprintf(hash_str, sizeof(hash_str), "%016" PRIx64, hash);
|
||||||
fs::path cache_file = fs::path(cache_dir) / hash_str;
|
fs::path cache_file = fs::path(cache_dir) / hash_str;
|
||||||
if (!fs::exists(cache_file)) {
|
std::error_code ec;
|
||||||
|
if (!fs::exists(cache_file, ec)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
std::ifstream ifs(cache_file, std::ios::binary);
|
std::ifstream ifs(cache_file, std::ios::binary);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue