diff options
author | dec05eba <dec05eba@protonmail.com> | 2017-12-12 19:46:57 +0100 |
---|---|---|
committer | dec05eba <dec05eba@protonmail.com> | 2017-12-12 19:49:29 +0100 |
commit | f2c70dfaba8d6481e86646080c51b6874d95f14e (patch) | |
tree | 1ee19bdd5f951b86f2b481c94f969a473a5e57fc /src/curl.cpp | |
parent | f3b7b7d34b3bf2b1be18914577c96b66dead379a (diff) |
Lazily create directories that are needed
Directories such as:
~/.sibs
~/.sibs/archive
~/.sibs/lib
And directories for each specific library.
Also fix bug in getFileContent and fileOverwrite if file already exists
Diffstat (limited to 'src/curl.cpp')
-rw-r--r-- | src/curl.cpp | 18 |
1 files changed, 15 insertions, 3 deletions
diff --git a/src/curl.cpp b/src/curl.cpp index f39cab8..e141e78 100644 --- a/src/curl.cpp +++ b/src/curl.cpp @@ -70,10 +70,24 @@ namespace sibs curl_easy_setopt(curl_handle, CURLOPT_WRITEDATA, file); printf("Downloading from url: %s\n", url); CURLcode curlResponse = curl_easy_perform(curl_handle); + + long httpCode = 0; + curl_easy_getinfo(curl_handle, CURLINFO_RESPONSE_CODE, &httpCode); curl_easy_cleanup(curl_handle); fclose(file); - if(curlResponse != CURLE_OK) + if(httpCode == 200 && curlResponse == CURLE_OK) + return Result<bool>::Ok(true); + + if(httpCode != 200) + { + string errMsg = "Failed to download file from url: "; + errMsg += url; + errMsg += "\nReason: Expected http response code 200 (OK), got: "; + errMsg += to_string(httpCode); + return Result<bool>::Err(errMsg); + } + else { string errMsg = "Failed to download file from url: "; errMsg += url; @@ -81,7 +95,5 @@ namespace sibs errMsg += curl_easy_strerror(curlResponse); return Result<bool>::Err(errMsg); } - - return Result<bool>::Ok(true); } }
\ No newline at end of file |