Skip to content

Commit 6948adc

Browse files
authored
ggml : use noexcept overload for is_regular_file in backend registration (ggml-org#19452)
using noexcept std::filesystem::directory_entry::is_regular_file overload prevents abnormal termination upon throwing an error (as caused by symlinks to non-existent folders on linux) Resolves: ggml-org#18560
1 parent 854b09f commit 6948adc

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

ggml/src/ggml-backend-reg.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -471,9 +471,10 @@ static ggml_backend_reg_t ggml_backend_load_best(const char * name, bool silent,
471471

472472
int best_score = 0;
473473
fs::path best_path;
474+
std::error_code ec;
474475

475476
for (const auto & search_path : search_paths) {
476-
if (std::error_code ec; !fs::exists(search_path, ec)) {
477+
if (!fs::exists(search_path, ec)) {
477478
if (ec) {
478479
GGML_LOG_DEBUG("%s: posix_stat(%s) failure, error-message: %s\n", __func__, path_str(search_path).c_str(), ec.message().c_str());
479480
} else {
@@ -483,7 +484,7 @@ static ggml_backend_reg_t ggml_backend_load_best(const char * name, bool silent,
483484
}
484485
fs::directory_iterator dir_it(search_path, fs::directory_options::skip_permission_denied);
485486
for (const auto & entry : dir_it) {
486-
if (entry.is_regular_file()) {
487+
if (entry.is_regular_file(ec)) {
487488
auto filename = entry.path().filename();
488489
auto ext = entry.path().extension();
489490
if (filename.native().find(file_prefix) == 0 && ext == file_extension) {

0 commit comments

Comments
 (0)