]> git.saurik.com Git - apt.git/commitdiff
first iteration that adds support for checksums-{sha512,sha256}
authorMichael Vogt <michael.vogt@ubuntu.com>
Mon, 14 Jan 2013 06:09:51 +0000 (07:09 +0100)
committerMichael Vogt <michael.vogt@ubuntu.com>
Mon, 14 Jan 2013 06:09:51 +0000 (07:09 +0100)
apt-pkg/deb/debsrcrecords.cc
apt-pkg/srcrecords.h
cmdline/apt-get.cc

index ce55ccd1f03e298b8f9e1fba8a3130bc5e22f61b..45cc0ae82200d0bcb5b370c160fa9d1b1143c862 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,84 @@ bool debSrcRecordParser::BuildDepends(std::vector<pkgSrcRecords::Parser::BuildDe
 bool debSrcRecordParser::Files(std::vector<pkgSrcRecords::File> &List)
 {
    List.erase(List.begin(),List.end());
+
+   const char *hash_field[] = { "Checksums-Sha512", 
+                            "Checksums-Sha256",
+                            "Checksums-Sha1",
+                            "Files", // historic name
+                            NULL,
+   };
+   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                      /*{{{*/
index ed69d0d72d470cfa9dfe18406c394c432c1b6bf3..7cb490079113198d42e741b5296f1e0a4528a36a 100644 (file)
@@ -31,7 +31,7 @@ class pkgSrcRecords
    // Describes a single file
    struct File
    {
-      std::string MD5Hash;
+      std::string Hash;
       unsigned long Size;
       std::string Path;
       std::string Type;
index 1bb981b20566624355eebc21d6e95158ee1f37e4..68e7f829c7f50dd6b4edaaefeefacb530c0fb1fd 100644 (file)
@@ -2555,15 +2555,12 @@ bool DoSource(CommandLine &CmdL)
         if(queued.find(Last->Index().ArchiveURI(I->Path)) != queued.end())
            continue;
         queued.insert(Last->Index().ArchiveURI(I->Path));
-           
+
         // check if we have a file with that md5 sum already localy
-        if(!I->MD5Hash.empty() && FileExists(flNotDir(I->Path)))  
+        if(!I->Hash.empty() && FileExists(flNotDir(I->Path)))  
         {
-           FileFd Fd(flNotDir(I->Path), FileFd::ReadOnly);
-           MD5Summation sum;
-           sum.AddFD(Fd.Fd(), Fd.Size());
-           Fd.Close();
-           if((string)sum.Result() == I->MD5Hash) 
+            HashString hash_string = HashString(I->Hash);
+            if(hash_string.VerifyFile(I->Path))
            {
               ioprintf(c1out,_("Skipping already downloaded file '%s'\n"),
                        flNotDir(I->Path).c_str());
@@ -2572,7 +2569,7 @@ bool DoSource(CommandLine &CmdL)
         }
 
         new pkgAcqFile(&Fetcher,Last->Index().ArchiveURI(I->Path),
-                       I->MD5Hash,I->Size,
+                       I->Hash,I->Size,
                        Last->Index().SourceInfo(*Last,*I),Src);
       }
    }