make expected-size a maximum-size check as this is what we want at this point
authorMichael Vogt <mvo@ubuntu.com>
Tue, 7 Oct 2014 15:47:30 +0000 (17:47 +0200)
committerMichael Vogt <mvo@ubuntu.com>
Tue, 7 Oct 2014 15:47:30 +0000 (17:47 +0200)
apt-pkg/acquire-method.cc
apt-pkg/acquire-method.h
apt-pkg/acquire-worker.cc
methods/ftp.cc
methods/ftp.h
methods/http.cc
methods/https.cc
methods/server.cc
methods/server.h
test/integration/test-apt-update-expected-size

index 330854e..9c05582 100644 (file)
@@ -373,7 +373,7 @@ int pkgAcqMethod::Run(bool Single)
                  Tmp->ExpectedHashes.push_back(HashString(*t, hash));
            }
             char *End;
-            Tmp->ExpectedSize = strtoll(LookupTag(Message, "Expected-Size", "0").c_str(), &End, 10);
+            Tmp->MaximumSize = strtoll(LookupTag(Message, "Maximum-Size", "0").c_str(), &End, 10);
            Tmp->Next = 0;
            
            // Append it to the list
index 2e4e828..675c4f8 100644 (file)
@@ -48,7 +48,10 @@ class pkgAcqMethod
       bool IndexFile;
       bool FailIgnore;
       HashStringList ExpectedHashes;
-      unsigned long long ExpectedSize;
+      // a maximum size we will download, this can be the exact filesize
+      // for when we know it or a arbitrary limit when we don't know the
+      // filesize (like a InRelease file)
+      unsigned long long MaximumSize;
    };
    
    struct FetchResult
index 8bd1618..ffa84eb 100644 (file)
@@ -526,9 +526,6 @@ bool pkgAcquire::Worker::QueueItem(pkgAcquire::Queue::QItem *Item)
    if (OutFd == -1)
       return false;
    
-   string ExpectedSize;
-   strprintf(ExpectedSize, "%llu", Item->Owner->FileSize);
-
    string Message = "600 URI Acquire\n";
    Message.reserve(300);
    Message += "URI: " + Item->URI;
@@ -536,7 +533,12 @@ bool pkgAcquire::Worker::QueueItem(pkgAcquire::Queue::QItem *Item)
    HashStringList const hsl = Item->Owner->HashSums();
    for (HashStringList::const_iterator hs = hsl.begin(); hs != hsl.end(); ++hs)
       Message += "\nExpected-" + hs->HashType() + ": " + hs->HashValue();
-   Message += "\nExpected-Size: " + ExpectedSize;
+   if(Item->Owner->FileSize > 0)
+   {
+      string MaximumSize;
+      strprintf(MaximumSize, "%llu", Item->Owner->FileSize);
+      Message += "\nMaximum-Size: " + MaximumSize;
+   }
    Message += Item->Owner->Custom600Headers();
    Message += "\n\n";
    
index 75ace1c..bc84dda 100644 (file)
@@ -849,7 +849,7 @@ bool FTPConn::Finalize()
 /* This opens a data connection, sends REST and RETR and then
    transfers the file over. */
 bool FTPConn::Get(const char *Path,FileFd &To,unsigned long long Resume,
-                 Hashes &Hash,bool &Missing, unsigned long long ExpectedSize)
+                 Hashes &Hash,bool &Missing, unsigned long long MaximumSize)
 {
    Missing = false;
    if (CreateDataFd() == false)
@@ -924,9 +924,9 @@ bool FTPConn::Get(const char *Path,FileFd &To,unsigned long long Resume,
         return false;
       }
 
-      if (ExpectedSize > 0 && To.Tell() > ExpectedSize)
+      if (MaximumSize > 0 && To.Tell() > MaximumSize)
          return _error->Error("Writing more data than expected (%llu > %llu)",
-                              To.Tell(), ExpectedSize);
+                              To.Tell(), MaximumSize);
    }
 
    // All done
@@ -1067,7 +1067,7 @@ bool FtpMethod::Fetch(FetchItem *Itm)
       FailFd = Fd.Fd();
       
       bool Missing;
-      if (Server->Get(File,Fd,Res.ResumePoint,Hash,Missing,Itm->ExpectedSize) == false)
+      if (Server->Get(File,Fd,Res.ResumePoint,Hash,Missing,Itm->MaximumSize) == false)
       {
         Fd.Close();
 
index 416a919..a31ebc9 100644 (file)
@@ -62,7 +62,7 @@ class FTPConn
    bool Size(const char *Path,unsigned long long &Size);
    bool ModTime(const char *Path, time_t &Time);
    bool Get(const char *Path,FileFd &To,unsigned long long Resume,
-           Hashes &MD5,bool &Missing, unsigned long long ExpectedSize);
+           Hashes &MD5,bool &Missing, unsigned long long MaximumSize);
    
    FTPConn(URI Srv);
    ~FTPConn();
index b076e59..f8faa0c 100644 (file)
@@ -655,10 +655,10 @@ bool HttpServerState::Go(bool ToFile, FileFd * const File)
         return _error->Errno("write",_("Error writing to output file"));
    }
 
-   if (ExpectedSize > 0 && File && File->Tell() > ExpectedSize)
+   if (MaximumSize > 0 && File && File->Tell() > MaximumSize)
    {
       return _error->Error("Writing more data than expected (%llu > %llu)",
-                           File->Tell(), ExpectedSize);
+                           File->Tell(), MaximumSize);
    }
 
    // Handle commands from APT
index a4794e7..787e4a5 100644 (file)
@@ -82,9 +82,9 @@ HttpsMethod::write_data(void *buffer, size_t size, size_t nmemb, void *userp)
    if(me->File->Write(buffer, size*nmemb) != true)
       return false;
 
-   if(me->Queue->ExpectedSize > 0 && me->File->Tell() > me->Queue->ExpectedSize)
+   if(me->Queue->MaximumSize > 0 && me->File->Tell() > me->Queue->MaximumSize)
       return _error->Error("Writing more data than expected (%llu > %llu)",
-                           me->TotalWritten, me->Queue->ExpectedSize);
+                           me->TotalWritten, me->Queue->MaximumSize);
 
    return size*nmemb;
 }
index 2237379..82f9b47 100644 (file)
@@ -534,8 +534,8 @@ int ServerMethod::Loop()
            bool Result = true;
 
             // ensure we don't fetch too much
-            if (Queue->ExpectedSize > 0)
-               Server->ExpectedSize = Queue->ExpectedSize;
+            if (Queue->MaximumSize > 0)
+               Server->MaximumSize = Queue->MaximumSize;
 
             if (Server->HaveContent)
               Result = Server->RunData(File);
index 0134a95..3093e00 100644 (file)
@@ -49,7 +49,7 @@ struct ServerState
    URI Proxy;
    unsigned long TimeOut;
 
-   unsigned long long ExpectedSize;
+   unsigned long long MaximumSize;
 
    protected:
    ServerMethod *Owner;
@@ -75,7 +75,7 @@ struct ServerState
    bool Comp(URI Other) const {return Other.Host == ServerName.Host && Other.Port == ServerName.Port;};
    virtual void Reset() {Major = 0; Minor = 0; Result = 0; Code[0] = '\0'; Size = 0;
                 StartPos = 0; Encoding = Closes; time(&Date); HaveContent = false;
-                State = Header; Persistent = false; Pipeline = true; ExpectedSize = 0;};
+                State = Header; Persistent = false; Pipeline = true; MaximumSize = 0;};
    virtual bool WriteResponse(std::string const &Data) = 0;
 
    /** \brief Transfer the data from the socket */
index 7281233..c1eecc0 100755 (executable)
@@ -15,6 +15,13 @@ changetowebserver
 # normal update works fine
 testsuccess aptget update
 
+# make InRelease really big
+mv aptarchive/dists/unstable/InRelease aptarchive/dists/unstable/InRelease.good
+dd if=/dev/zero of=aptarchive/dists/unstable/InRelease bs=1M count=2
+touch -d '+1hour' aptarchive/dists/unstable/InRelease
+aptget update -o acquire::MaxReleaseFileSize=$((1*1000*1000))
+
+
 # append junk at the end of the Packages.gz/Packages
 SIZE="$(stat --printf=%s aptarchive/dists/unstable/main/binary-i386/Packages)"
 echo "1234567890" >> aptarchive/dists/unstable/main/binary-i386/Packages.gz