]> git.saurik.com Git - apt.git/blobdiff - apt-pkg/deb/debsrcrecords.cc
fix skipping of already downloaded files and add some FIXMEs
[apt.git] / apt-pkg / deb / debsrcrecords.cc
index ce55ccd1f03e298b8f9e1fba8a3130bc5e22f61b..c620c229840543dd8034ecfabaaa95973221f7f0 100644 (file)
@@ -17,6 +17,7 @@
 #include <apt-pkg/strutl.h>
 #include <apt-pkg/configuration.h>
 #include <apt-pkg/aptconfiguration.h>
+#include <apt-pkg/hashes.h>
 
 using std::max;
                                                                        /*}}}*/
@@ -114,64 +115,89 @@ bool debSrcRecordParser::BuildDepends(std::vector<pkgSrcRecords::Parser::BuildDe
 bool debSrcRecordParser::Files(std::vector<pkgSrcRecords::File> &List)
 {
    List.erase(List.begin(),List.end());
+
+   // FIXME: build string dynamically from 
+   //            Hashes::SupportedHashes
+   const char *hash_field[] = { "Checksums-Sha512", 
+                            "Checksums-Sha256",
+                            "Checksums-Sha1",
+                            "Files", // historic name
+                            NULL,
+   };
+
+   // FIXME: use string from Hashes::SupportedHashes
+   // FIXME2: this is case senstivie
+   const char *hash_type[] = { "SHA512", 
+                            "SHA256",
+                            "SHA1",
+                            "MD5Sum",
+                            NULL,
+   };
    
-   string Files = Sect.FindS("Files");
-   if (Files.empty() == true)
-      return false;
-
-   // Stash the / terminated directory prefix
-   string Base = Sect.FindS("Directory");
-   if (Base.empty() == false && Base[Base.length()-1] != '/')
-      Base += '/';
-
-   std::vector<std::string> const compExts = APT::Configuration::getCompressorExtensions();
-
-   // Iterate over the entire list grabbing each triplet
-   const char *C = Files.c_str();
-   while (*C != 0)
-   {   
-      pkgSrcRecords::File F;
-      string Size;
-      
-      // Parse each of the elements
-      if (ParseQuoteWord(C,F.MD5Hash) == false ||
-         ParseQuoteWord(C,Size) == false ||
-         ParseQuoteWord(C,F.Path) == false)
-        return _error->Error("Error parsing file record");
-      
-      // Parse the size and append the directory
-      F.Size = atoi(Size.c_str());
-      F.Path = Base + F.Path;
-      
-      // Try to guess what sort of file it is we are getting.
-      string::size_type Pos = F.Path.length()-1;
-      while (1)
-      {
-        string::size_type Tmp = F.Path.rfind('.',Pos);
-        if (Tmp == string::npos)
-           break;
-        if (F.Type == "tar") {
-           // source v3 has extension 'debian.tar.*' instead of 'diff.*'
-           if (string(F.Path, Tmp+1, Pos-Tmp) == "debian")
-              F.Type = "diff";
-           break;
-        }
-        F.Type = string(F.Path,Tmp+1,Pos-Tmp);
-        
-        if (std::find(compExts.begin(), compExts.end(), std::string(".").append(F.Type)) != compExts.end() ||
-            F.Type == "tar")
-        {
-           Pos = Tmp-1;
-           continue;
-        }
+   for (int i=0; hash_field[i] != NULL; i++)
+   {
+
+      string Files = Sect.FindS(hash_field[i]);
+      if (Files.empty() == true)
+         continue;
+
+      // Stash the / terminated directory prefix
+      string Base = Sect.FindS("Directory");
+      if (Base.empty() == false && Base[Base.length()-1] != '/')
+         Base += '/';
+
+      std::vector<std::string> const compExts = APT::Configuration::getCompressorExtensions();
+
+      // Iterate over the entire list grabbing each triplet
+      const char *C = Files.c_str();
+      while (*C != 0)
+      {   
+         pkgSrcRecords::File F;
+         string Size;
+         
+         // Parse each of the elements
+         std::string RawHash;
+         if (ParseQuoteWord(C, RawHash) == false ||
+             ParseQuoteWord(C, Size) == false ||
+             ParseQuoteWord(C, F.Path) == false)
+            return _error->Error("Error parsing '%s' record", hash_field[i]);
+         // assign full hash string
+         F.Hash = HashString(hash_type[i], RawHash).toStr();
+         
+         // Parse the size and append the directory
+         F.Size = atoi(Size.c_str());
+         F.Path = Base + F.Path;
+         
+         // Try to guess what sort of file it is we are getting.
+         string::size_type Pos = F.Path.length()-1;
+         while (1)
+         {
+            string::size_type Tmp = F.Path.rfind('.',Pos);
+            if (Tmp == string::npos)
+               break;
+            if (F.Type == "tar") {
+               // source v3 has extension 'debian.tar.*' instead of 'diff.*'
+               if (string(F.Path, Tmp+1, Pos-Tmp) == "debian")
+                  F.Type = "diff";
+               break;
+            }
+            F.Type = string(F.Path,Tmp+1,Pos-Tmp);
+            
+            if (std::find(compExts.begin(), compExts.end(), std::string(".").append(F.Type)) != compExts.end() ||
+                F.Type == "tar")
+            {
+               Pos = Tmp-1;
+               continue;
+            }
         
-        break;
-      }
+            break;
+         }
       
-      List.push_back(F);
+         List.push_back(F);
+      }
+      break;
    }
-   
-   return true;
+   return (List.size() > 0);
 }
                                                                        /*}}}*/
 // SrcRecordParser::~SrcRecordParser - Destructor                      /*{{{*/