From b24f30fdad741cf0178d29f008519b5349f52e9a Mon Sep 17 00:00:00 2001 From: Pierrick HYMBERT Date: Sun, 17 Mar 2024 16:52:38 +0100 Subject: [PATCH] common: llama_load_model_from_url delete previous file before downloading --- common/common.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/common/common.cpp b/common/common.cpp index 3ecd4e5cd..2f5d965d6 100644 --- a/common/common.cpp +++ b/common/common.cpp @@ -1750,6 +1750,14 @@ struct llama_model * llama_load_model_from_url(const char * model_url, const cha if (!file_exists || strcmp(etag, headers.etag) != 0 || strcmp(last_modified, headers.last_modified) != 0) { char path_model_temporary[LLAMA_CURL_MAX_PATH_LENGTH] = {0}; snprintf(path_model_temporary, sizeof(path_model_temporary), "%s.downloadInProgress", path_model); + if (file_exists) { + fprintf(stderr, "%s: deleting previous downloaded model file: %s\n", __func__, path_model); + if (remove(path_model) != 0) { + curl_easy_cleanup(curl); + fprintf(stderr, "%s: unable to delete file: %s\n", __func__, path_model); + return NULL; + } + } // Set the output file auto * outfile = fopen(path_model_temporary, "wb");