]> git.saurik.com Git - apt.git/blobdiff - apt-pkg/acquire-method.cc
fileutl: empty file support: Avoid fstat() on -1 fd and check result
[apt.git] / apt-pkg / acquire-method.cc
index cfa93e95c01c474534a6f02515d7300f907563a7..39d5e61f2acb1ab10d4009f9bad60bfa26672fa5 100644 (file)
@@ -80,9 +80,20 @@ void pkgAcqMethod::Fail(bool Transient)
 {
    string Err = "Undetermined Error";
    if (_error->empty() == false)
 {
    string Err = "Undetermined Error";
    if (_error->empty() == false)
-      _error->PopMessage(Err);   
-   _error->Discard();
-   Fail(Err,Transient);
+   {
+      Err.clear();
+      while (_error->empty() == false)
+      {
+        std::string msg;
+        if (_error->PopMessage(msg))
+        {
+           if (Err.empty() == false)
+              Err.append("\n");
+           Err.append(msg);
+        }
+      }
+   }
+   Fail(Err, Transient);
 }
                                                                        /*}}}*/
 // AcqMethod::Fail - A fetch has failed                                        /*{{{*/
 }
                                                                        /*}}}*/
 // AcqMethod::Fail - A fetch has failed                                        /*{{{*/
@@ -145,13 +156,13 @@ void pkgAcqMethod::URIStart(FetchResult &Res)
    std::cout << "200 URI Start\n"
             << "URI: " << Queue->Uri << "\n";
    if (Res.Size != 0)
    std::cout << "200 URI Start\n"
             << "URI: " << Queue->Uri << "\n";
    if (Res.Size != 0)
-      std::cout << "Size: " << Res.Size << "\n";
+      std::cout << "Size: " << std::to_string(Res.Size) << "\n";
 
    if (Res.LastModified != 0)
 
    if (Res.LastModified != 0)
-      std::cout << "Last-Modified: " << TimeRFC1123(Res.LastModified) << "\n";
+      std::cout << "Last-Modified: " << TimeRFC1123(Res.LastModified, true) << "\n";
 
    if (Res.ResumePoint != 0)
 
    if (Res.ResumePoint != 0)
-      std::cout << "Resume-Point: " << Res.ResumePoint << "\n";
+      std::cout << "Resume-Point: " << std::to_string(Res.ResumePoint) << "\n";
 
    if (UsedMirror.empty() == false)
       std::cout << "UsedMirror: " << UsedMirror << "\n";
 
    if (UsedMirror.empty() == false)
       std::cout << "UsedMirror: " << UsedMirror << "\n";
@@ -184,10 +195,10 @@ void pkgAcqMethod::URIDone(FetchResult &Res, FetchResult *Alt)
       std::cout << "Filename: " << Res.Filename << "\n";
 
    if (Res.Size != 0)
       std::cout << "Filename: " << Res.Filename << "\n";
 
    if (Res.Size != 0)
-      std::cout << "Size: " << Res.Size << "\n";
+      std::cout << "Size: " << std::to_string(Res.Size) << "\n";
 
    if (Res.LastModified != 0)
 
    if (Res.LastModified != 0)
-      std::cout << "Last-Modified: " << TimeRFC1123(Res.LastModified) << "\n";
+      std::cout << "Last-Modified: " << TimeRFC1123(Res.LastModified, true) << "\n";
 
    printHashStringList(&Res.Hashes);
 
 
    printHashStringList(&Res.Hashes);
 
@@ -202,7 +213,7 @@ void pkgAcqMethod::URIDone(FetchResult &Res, FetchResult *Alt)
    }
 
    if (Res.ResumePoint != 0)
    }
 
    if (Res.ResumePoint != 0)
-      std::cout << "Resume-Point: " << Res.ResumePoint << "\n";
+      std::cout << "Resume-Point: " << std::to_string(Res.ResumePoint) << "\n";
 
    if (Res.IMSHit == true)
       std::cout << "IMS-Hit: true\n";
 
    if (Res.IMSHit == true)
       std::cout << "IMS-Hit: true\n";
@@ -213,10 +224,10 @@ void pkgAcqMethod::URIDone(FetchResult &Res, FetchResult *Alt)
         std::cout << "Alt-Filename: " << Alt->Filename << "\n";
 
       if (Alt->Size != 0)
         std::cout << "Alt-Filename: " << Alt->Filename << "\n";
 
       if (Alt->Size != 0)
-        std::cout << "Alt-Size: " << Alt->Size << "\n";
+        std::cout << "Alt-Size: " << std::to_string(Alt->Size) << "\n";
 
       if (Alt->LastModified != 0)
 
       if (Alt->LastModified != 0)
-        std::cout << "Alt-Last-Modified: " << TimeRFC1123(Alt->LastModified) << "\n";
+        std::cout << "Alt-Last-Modified: " << TimeRFC1123(Alt->LastModified, true) << "\n";
 
       printHashStringList(&Alt->Hashes);
 
 
       printHashStringList(&Alt->Hashes);
 
@@ -376,7 +387,10 @@ int pkgAcqMethod::Run(bool Single)
                  Tmp->ExpectedHashes.push_back(HashString(*t, hash));
            }
             char *End;
                  Tmp->ExpectedHashes.push_back(HashString(*t, hash));
            }
             char *End;
-            Tmp->MaximumSize = strtoll(LookupTag(Message, "Maximum-Size", "0").c_str(), &End, 10);
+           if (Tmp->ExpectedHashes.FileSize() > 0)
+              Tmp->MaximumSize = Tmp->ExpectedHashes.FileSize();
+           else
+              Tmp->MaximumSize = strtoll(LookupTag(Message, "Maximum-Size", "0").c_str(), &End, 10);
            Tmp->Next = 0;
            
            // Append it to the list
            Tmp->Next = 0;
            
            // Append it to the list
@@ -385,14 +399,14 @@ int pkgAcqMethod::Run(bool Single)
            *I = Tmp;
            if (QueueBack == 0)
               QueueBack = Tmp;
            *I = Tmp;
            if (QueueBack == 0)
               QueueBack = Tmp;
-           
+
            // Notify that this item is to be fetched.
            // Notify that this item is to be fetched.
-           if (Fetch(Tmp) == false)
+           if (URIAcquire(Message, Tmp) == false)
               Fail();
               Fail();
-           
-           break;                                           
-        }   
-      }      
+
+           break;
+        }
+      }
    }
 
    Exit();
    }
 
    Exit();
@@ -400,8 +414,6 @@ int pkgAcqMethod::Run(bool Single)
 }
                                                                        /*}}}*/
 // AcqMethod::PrintStatus - privately really send a log/status message /*{{{*/
 }
                                                                        /*}}}*/
 // AcqMethod::PrintStatus - privately really send a log/status message /*{{{*/
-// ---------------------------------------------------------------------
-/* */
 void pkgAcqMethod::PrintStatus(char const * const header, const char* Format,
                               va_list &args) const
 {
 void pkgAcqMethod::PrintStatus(char const * const header, const char* Format,
                               va_list &args) const
 {
@@ -456,7 +468,7 @@ void pkgAcqMethod::Redirect(const string &NewURI)
 // ---------------------------------------------------------------------
 /* */
 pkgAcqMethod::FetchResult::FetchResult() : LastModified(0),
 // ---------------------------------------------------------------------
 /* */
 pkgAcqMethod::FetchResult::FetchResult() : LastModified(0),
-                                   IMSHit(false), Size(0), ResumePoint(0)
+                                   IMSHit(false), Size(0), ResumePoint(0), d(NULL)
 {
 }
                                                                        /*}}}*/
 {
 }
                                                                        /*}}}*/
@@ -477,3 +489,12 @@ void pkgAcqMethod::Dequeue() {                                             /*{{{*/
    delete Tmp;
 }
                                                                        /*}}}*/
    delete Tmp;
 }
                                                                        /*}}}*/
+pkgAcqMethod::~pkgAcqMethod() {}
+
+pkgAcqMethod::FetchItem::FetchItem() :
+   Next(nullptr), DestFileFd(-1), LastModified(0), IndexFile(false),
+   FailIgnore(false), MaximumSize(0), d(nullptr)
+{}
+pkgAcqMethod::FetchItem::~FetchItem() {}
+
+pkgAcqMethod::FetchResult::~FetchResult() {}