#include <stdlib.h>
#include <sys/queue.h>
#include <unistd.h>
+#include <utime.h>
#include <curl/curl.h>
return NULL;
}
+static const char* curl_http_version(long v) {
+ switch (v) {
+ case CURL_HTTP_VERSION_2_0:
+ return "HTTP/2.0";
+
+ case CURL_HTTP_VERSION_1_1:
+ return "HTTP/1.1";
+
+ case CURL_HTTP_VERSION_1_0:
+ return "HTTP/1.0";
+ }
+
+ return "unknown";
+}
+
static int pakfire_transfer_done(struct pakfire_downloader* downloader,
struct pakfire_transfer* transfer, CURLMsg* msg) {
+ CURL* h = transfer->handle;
+
int r;
+ const char* url;
+ long response_code;
+ long http_version;
+ struct utimbuf times;
+ double total_time;
+ curl_off_t download_size;
+ curl_off_t speed;
DEBUG(downloader->pakfire, "cURL transfer done: %d - %s\n",
msg->data.result, curl_easy_strerror(msg->data.result));
+ // Effective URL
+ curl_easy_getinfo(h, CURLINFO_EFFECTIVE_URL, &url);
+ if (url)
+ DEBUG(downloader->pakfire, " Effective URL: %s\n", url);
+
+ // Response code
+ curl_easy_getinfo(h, CURLINFO_RESPONSE_CODE, &response_code);
+ if (response_code)
+ DEBUG(downloader->pakfire, " Response code: %ld\n", response_code);
+
+ // HTTP Version
+ curl_easy_getinfo(h, CURLINFO_HTTP_VERSION, &http_version);
+ if (http_version)
+ DEBUG(downloader->pakfire, " HTTP Version: %s\n", curl_http_version(http_version));
+
+ // Total Times
+ curl_easy_getinfo(h, CURLINFO_TOTAL_TIME, &total_time);
+ DEBUG(downloader->pakfire, " Total Time: %.2fs\n", total_time);
+
+ // Download Size
+ curl_easy_getinfo(h, CURLINFO_SIZE_DOWNLOAD_T, &download_size);
+ if (download_size)
+ DEBUG(downloader->pakfire, " Download Size: %ld bytes\n", download_size);
+
+ // Download Speed
+ curl_easy_getinfo(h, CURLINFO_SPEED_DOWNLOAD_T, &speed);
+ if (speed)
+ DEBUG(downloader->pakfire, " Download Speed: %ld bps\n", speed);
+
// Move the temporary file to its destination
r = link(transfer->tempfile, transfer->path);
if (r) {
return r;
}
+ // Filetime
+ curl_easy_getinfo(h, CURLINFO_FILETIME_T, ×.modtime);
+ r = utime(transfer->path, ×);
+ if (r) {
+ ERROR(downloader->pakfire, "Could not set mtime of %s: %s\n",
+ transfer->path, strerror(errno));
+ }
+
return 0;
}