]> git.saurik.com Git - apt.git/blobdiff - methods/server.cc
test if TMPDIR is accessible before using
[apt.git] / methods / server.cc
index 1b6511c59dc0525bc0b4e8ae116594a9c4bda42c..c4689ff122ffb5f2c051e37dee0d48dcdf7415d4 100644 (file)
@@ -44,7 +44,8 @@ time_t ServerMethod::FailTime = 0;
 // ---------------------------------------------------------------------
 /* Returns 0 if things are OK, 1 if an IO error occurred and 2 if a header
    parse error occurred */
 // ---------------------------------------------------------------------
 /* Returns 0 if things are OK, 1 if an IO error occurred and 2 if a header
    parse error occurred */
-ServerState::RunHeadersResult ServerState::RunHeaders(FileFd * const File)
+ServerState::RunHeadersResult ServerState::RunHeaders(FileFd * const File,
+                                                      const std::string &Uri)
 {
    State = Header;
    
 {
    State = Header;
    
@@ -66,7 +67,7 @@ ServerState::RunHeadersResult ServerState::RunHeaders(FileFd * const File)
         continue;
 
       if (Owner->Debug == true)
         continue;
 
       if (Owner->Debug == true)
-        clog << Data;
+        clog << "Answer for: " << Uri << endl << Data;
       
       for (string::const_iterator I = Data.begin(); I < Data.end(); ++I)
       {
       
       for (string::const_iterator I = Data.begin(); I < Data.end(); ++I)
       {
@@ -323,10 +324,10 @@ ServerMethod::DealWithHeaders(FetchResult &Res)
       failure */
    if (Server->Result < 200 || Server->Result >= 300)
    {
       failure */
    if (Server->Result < 200 || Server->Result >= 300)
    {
-      char err[255];
-      snprintf(err,sizeof(err)-1,"HttpError%i",Server->Result);
+      std::string err;
+      strprintf(err, "HttpError%u", Server->Result);
       SetFailReason(err);
       SetFailReason(err);
-      _error->Error("%u %s",Server->Result,Server->Code);
+      _error->Error("%u %s", Server->Result, Server->Code);
       if (Server->HaveContent == true)
         return ERROR_WITH_CONTENT_PAGE;
       return ERROR_UNRECOVERABLE;
       if (Server->HaveContent == true)
         return ERROR_WITH_CONTENT_PAGE;
       return ERROR_UNRECOVERABLE;
@@ -485,7 +486,7 @@ int ServerMethod::Loop()
       Fetch(0);
       
       // Fetch the next URL header data from the server.
       Fetch(0);
       
       // Fetch the next URL header data from the server.
-      switch (Server->RunHeaders(File))
+      switch (Server->RunHeaders(File, Queue->Uri))
       {
         case ServerState::RUN_HEADERS_OK:
         break;
       {
         case ServerState::RUN_HEADERS_OK:
         break;
@@ -533,8 +534,10 @@ int ServerMethod::Loop()
            bool Result = true;
 
             // ensure we don't fetch too much
            bool Result = true;
 
             // ensure we don't fetch too much
-            if (Queue->ExpectedSize > 0)
-               Server->ExpectedSize = Queue->ExpectedSize;
+            // we could do "Server->MaximumSize = Queue->MaximumSize" here
+            // but that would break the clever pipeline messup detection
+            // so instead we use the size of the biggest item in the queue
+            Server->MaximumSize = FindMaximumObjectSizeInQueue();
 
             if (Server->HaveContent)
               Result = Server->RunData(File);
 
             if (Server->HaveContent)
               Result = Server->RunData(File);
@@ -609,7 +612,10 @@ int ServerMethod::Loop()
                  QueueBack = Queue;
               }
               else
                  QueueBack = Queue;
               }
               else
+               {
+                  Server->Close();
                  Fail(true);
                  Fail(true);
+               }
            }
            break;
         }
            }
            break;
         }
@@ -702,5 +708,15 @@ int ServerMethod::Loop()
    }
    
    return 0;
    }
    
    return 0;
+}
+                                                                       /*}}}*/
+                                                                       /*{{{*/
+unsigned long long
+ServerMethod::FindMaximumObjectSizeInQueue() const 
+{
+   unsigned long long MaxSizeInQueue = 0;
+   for (FetchItem *I = Queue; I != 0 && I != QueueBack; I = I->Next)
+      MaxSizeInQueue = std::max(MaxSizeInQueue, I->MaximumSize);
+   return MaxSizeInQueue;
 }
                                                                        /*}}}*/
 }
                                                                        /*}}}*/