Skip to content

Commit 1e8425a

Browse files
committed
llama-run: Fix model download on Windows
* fix SSL error (SSL peer certificate or SSH remote key was not OK) * fix program crash on std::filesystem::rename
1 parent 86587da commit 1e8425a

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

tools/run/run.cpp

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -373,7 +373,7 @@ class File {
373373
return out;
374374
}
375375

376-
~File() {
376+
void close() {
377377
if (fd >= 0) {
378378
# ifdef _WIN32
379379
if (hFile != INVALID_HANDLE_VALUE) {
@@ -388,6 +388,13 @@ class File {
388388
if (file) {
389389
fclose(file);
390390
}
391+
392+
fd = -1;
393+
file = nullptr;
394+
}
395+
396+
~File() {
397+
close();
391398
}
392399

393400
private:
@@ -439,6 +446,8 @@ class HttpClient {
439446
return 1;
440447
}
441448
if (!output_file.empty()) {
449+
// Explicitly close file in order to release lock
450+
out.close();
442451
std::filesystem::rename(output_file_partial, output_file);
443452
}
444453

@@ -507,6 +516,9 @@ class HttpClient {
507516
curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
508517
curl_easy_setopt(curl, CURLOPT_DEFAULT_PROTOCOL, "https");
509518
curl_easy_setopt(curl, CURLOPT_FAILONERROR, 1L);
519+
#ifdef _WIN32
520+
curl_easy_setopt(curl, CURLOPT_SSL_OPTIONS, CURLSSLOPT_NATIVE_CA);
521+
#endif
510522
return curl_easy_perform(curl);
511523
}
512524

0 commit comments

Comments
 (0)