[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Bug#781509: apt-transport-https: reports uninitialized size → W: Size of file [FILE] is not what the server reported



Control: reassign 777565 apt-transport-https
Control: forcemerge -1 777565

(hopefully that worked this time around)

So, thinking about this some more we can get away with a (smaller) diff
fixing these two interconnected problems. It isn't really nice, but its
short and that is what counts now and it at least catches the essence of
both suggested patches.


Best regards

David Kalnischkies
commit 70c374f18a69661006fc0472018efe833e03fa90
Author: David Kalnischkies <david@kalnischkies.de>
Date:   Tue Apr 7 14:34:04 2015 +0200

    properly handle expected filesize in https
    
    The worker expects that the methods tell him when they start or finish
    downloading a file. Various information pieces are passed along in this report
    including the (expected) filesize. https is using a "global" struct for
    reporting which made it 'reuse' incorrect values in some cases like a
    non-existent InRelease fallbacking to Release{,.gpg} resulting in an incorrect
    size-mismatch warning scaring and desensitizing users as well as being subject
    to a race between the write_data and progress callbacks generating incorrect
    progress reporting and potentially the same error message.
    
    Other branches as well as the bugreports contain 'better' fixes making the
    struct local and other sensible changes, but are larger as a result, so in
    this version we opted for short diff with minimal effect above else instead.
    
    Closes: 777565, 781509
    Thanks: Robert Edmonds and Anders Kaseorg for initial patchs

diff --git a/methods/https.cc b/methods/https.cc
index 3a5981b..cb11159 100644
--- a/methods/https.cc
+++ b/methods/https.cc
@@ -68,6 +68,8 @@ HttpsMethod::parse_header(void *buffer, size_t size, size_t nmemb, void *userp)
 
       me->File->Truncate(me->Server->StartPos);
       me->File->Seek(me->Server->StartPos);
+
+      me->Res.Size = me->Server->Size;
    }
    else if (me->Server->HeaderLine(line) == false)
       return 0;
@@ -97,17 +99,6 @@ HttpsMethod::write_data(void *buffer, size_t size, size_t nmemb, void *userp)
    return buffer_size;
 }
 
-int
-HttpsMethod::progress_callback(void *clientp, double dltotal, double /*dlnow*/,
-                             double /*ultotal*/, double /*ulnow*/)
-{
-   HttpsMethod *me = (HttpsMethod *)clientp;
-   if(dltotal > 0 && me->Res.Size == 0) {
-      me->Res.Size = (unsigned long long)dltotal;
-   }
-   return 0;
-}
-
 // HttpsServerState::HttpsServerState - Constructor			/*{{{*/
 HttpsServerState::HttpsServerState(URI Srv,HttpsMethod * /*Owner*/) : ServerState(Srv, NULL)
 {
@@ -201,10 +192,8 @@ bool HttpsMethod::Fetch(FetchItem *Itm)
    curl_easy_setopt(curl, CURLOPT_WRITEHEADER, this);
    curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_data);
    curl_easy_setopt(curl, CURLOPT_WRITEDATA, this);
-   curl_easy_setopt(curl, CURLOPT_PROGRESSFUNCTION, progress_callback);
-   curl_easy_setopt(curl, CURLOPT_PROGRESSDATA, this);
    // options
-   curl_easy_setopt(curl, CURLOPT_NOPROGRESS, false);
+   curl_easy_setopt(curl, CURLOPT_NOPROGRESS, true);
    curl_easy_setopt(curl, CURLOPT_FILETIME, true);
    // only allow curl to handle https, not the other stuff it supports
    curl_easy_setopt(curl, CURLOPT_PROTOCOLS, CURLPROTO_HTTPS);
@@ -357,6 +346,7 @@ bool HttpsMethod::Fetch(FetchItem *Itm)
    // go for it - if the file exists, append on it
    File = new FileFd(Itm->DestFile, FileFd::WriteAny);
    Server = new HttpsServerState(Itm->Uri, this);
+   Res = FetchResult();
 
    // keep apt updated
    Res.Filename = Itm->DestFile;

Attachment: signature.asc
Description: Digital signature


Reply to: