Skip to content

Commit

Permalink
Core: download to tmp file first.
Browse files Browse the repository at this point in the history
  • Loading branch information
hivivo committed Jan 30, 2014
1 parent e792831 commit f17abdf
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions Core/Downloader/HttpClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,9 @@ bool HttpClient::downloadAs(string url, string filepath)
// forward all data to this func
curl_easy_setopt(m_curl, CURLOPT_WRITEFUNCTION, &HttpClient::writeToFile);

// try to write a temp file instead of the real file
string tmpFile = filepath + ".tmp";

// open the file
FILE * file = fopen(filepath.c_str(), "wb");
if (file)
Expand All @@ -93,6 +96,9 @@ bool HttpClient::downloadAs(string url, string filepath)

fclose(file);

// rename it to real filename // TODO: handle exceptions (interrupt or bad request)
rename(tmpFile.c_str(), filepath.c_str());

return res == CURLE_OK;
}

Expand Down

0 comments on commit f17abdf

Please sign in to comment.