Skip to content

Commit f17abdf

Browse files
committed
Core: download to tmp file first.
1 parent e792831 commit f17abdf

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

Core/Downloader/HttpClient.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,9 @@ bool HttpClient::downloadAs(string url, string filepath)
8181
// forward all data to this func
8282
curl_easy_setopt(m_curl, CURLOPT_WRITEFUNCTION, &HttpClient::writeToFile);
8383

84+
// try to write a temp file instead of the real file
85+
string tmpFile = filepath + ".tmp";
86+
8487
// open the file
8588
FILE * file = fopen(filepath.c_str(), "wb");
8689
if (file)
@@ -93,6 +96,9 @@ bool HttpClient::downloadAs(string url, string filepath)
9396

9497
fclose(file);
9598

99+
// rename it to real filename // TODO: handle exceptions (interrupt or bad request)
100+
rename(tmpFile.c_str(), filepath.c_str());
101+
96102
return res == CURLE_OK;
97103
}
98104

0 commit comments

Comments
 (0)