]> git.ipfire.org Git - pakfire.git/commitdiff
downloader: Log download information
authorMichael Tremer <michael.tremer@ipfire.org>
Thu, 11 Mar 2021 21:41:37 +0000 (21:41 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Thu, 11 Mar 2021 21:41:37 +0000 (21:41 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/libpakfire/downloader.c

index c6f42fc3ac8dd892adefbcbfef4e9542763f9bab..8426af0c4fa05f4484e904f15cf799aeea9630e2 100644 (file)
@@ -22,6 +22,7 @@
 #include <stdlib.h>
 #include <sys/queue.h>
 #include <unistd.h>
+#include <utime.h>
 
 #include <curl/curl.h>
 
@@ -316,13 +317,66 @@ ERROR:
        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) {
@@ -331,6 +385,14 @@ static int pakfire_transfer_done(struct pakfire_downloader* downloader,
                return r;
        }
 
+       // Filetime
+       curl_easy_getinfo(h, CURLINFO_FILETIME_T, &times.modtime);
+       r = utime(transfer->path, &times);
+       if (r) {
+               ERROR(downloader->pakfire, "Could not set mtime of %s: %s\n",
+                       transfer->path, strerror(errno));
+       }
+
        return 0;
 }