]> git.saurik.com Git - apt.git/commitdiff
replace "filesize - 1" trick in http with proper 416 handling
authorDavid Kalnischkies <kalnischkies@gmail.com>
Mon, 16 Sep 2013 22:41:58 +0000 (00:41 +0200)
committerDavid Kalnischkies <kalnischkies@gmail.com>
Tue, 1 Oct 2013 09:06:23 +0000 (11:06 +0200)
Our http client requests the "filesize - 1" for the small edgecase of
handling a file which was completely downloaded, but not yet moved to
the correct place as we get 416 errors in that case, but as we can
handle 416 returns now we just special-case the situation of requesting
the exact filesize and handle it as a 200 without content instead.

methods/http.cc

index 2a8b7f0fccdfc883c9ef853ef825b205d604316d..5f0dc03d91142f3c880e6538a6d7f675548a3512 100644 (file)
@@ -750,7 +750,7 @@ void HttpMethod::SendReq(FetchItem *Itm,CircleBuf &Out)
    if (stat(Itm->DestFile.c_str(),&SBuf) >= 0 && SBuf.st_size > 0)
    {
       // In this case we send an if-range query with a range header
    if (stat(Itm->DestFile.c_str(),&SBuf) >= 0 && SBuf.st_size > 0)
    {
       // In this case we send an if-range query with a range header
-      sprintf(Buf,"Range: bytes=%lli-\r\nIf-Range: %s\r\n",(long long)SBuf.st_size - 1,
+      sprintf(Buf,"Range: bytes=%lli-\r\nIf-Range: %s\r\n",(long long)SBuf.st_size,
              TimeRFC1123(SBuf.st_mtime).c_str());
       Req += Buf;
    }
              TimeRFC1123(SBuf.st_mtime).c_str());
       Req += Buf;
    }
@@ -1004,11 +1004,24 @@ HttpMethod::DealWithHeaders(FetchResult &Res,ServerState *Srv)
       /* else pass through for error message */
    }
    // retry after an invalid range response without partial data
       /* else pass through for error message */
    }
    // retry after an invalid range response without partial data
-   else if (Srv->Result == 416 && FileExists(Queue->DestFile) == true &&
-        unlink(Queue->DestFile.c_str()) == 0)
+   else if (Srv->Result == 416)
    {
    {
-      NextURI = Queue->Uri;
-      return TRY_AGAIN_OR_REDIRECT;
+      struct stat SBuf;
+      if (stat(Queue->DestFile.c_str(),&SBuf) >= 0 && SBuf.st_size > 0)
+      {
+        if ((unsigned long long)SBuf.st_size == Srv->Size)
+        {
+           // the file is completely downloaded, but was not moved
+           Srv->StartPos = Srv->Size;
+           Srv->Result = 200;
+           Srv->HaveContent = false;
+        }
+        else if (unlink(Queue->DestFile.c_str()) == 0)
+        {
+           NextURI = Queue->Uri;
+           return TRY_AGAIN_OR_REDIRECT;
+        }
+      }
    }
  
    /* We have a reply we dont handle. This should indicate a perm server
    }
  
    /* We have a reply we dont handle. This should indicate a perm server
@@ -1246,7 +1259,9 @@ int HttpMethod::Loop()
            URIStart(Res);
 
            // Run the data
            URIStart(Res);
 
            // Run the data
-           bool Result =  Server->RunData();
+           bool Result = true;
+            if (Server->HaveContent)
+              Result = Server->RunData();
 
            /* If the server is sending back sizeless responses then fill in
               the size now */
 
            /* If the server is sending back sizeless responses then fill in
               the size now */