]> git.saurik.com Git - apt.git/blobdiff - ftparchive/writer.cc
merged from http://bzr.debian.org/bzr/apt/apt/debian-experimental2
[apt.git] / ftparchive / writer.cc
index eb8938b9594708bc69335fc3216a5b5740c55dba..27e53faf81f90a6b3a318f94aa5cdcda6d4a0951 100644 (file)
    ##################################################################### */
                                                                        /*}}}*/
 // Include Files                                                       /*{{{*/
-#include "writer.h"
-    
-#include <apti18n.h>
+#include <config.h>
+
 #include <apt-pkg/strutl.h>
 #include <apt-pkg/error.h>
 #include <apt-pkg/configuration.h>
 #include <apt-pkg/aptconfiguration.h>
 #include <apt-pkg/md5.h>
-#include <apt-pkg/sha1.h>
-#include <apt-pkg/sha2.h>
+#include <apt-pkg/hashes.h>
 #include <apt-pkg/deblistparser.h>
 
 #include <sys/types.h>
 #include <iostream>
 #include <sstream>
 #include <memory>
-    
+
+#include "writer.h"
 #include "cachedb.h"
 #include "apt-ftparchive.h"
 #include "multicompress.h"
+
+#include <apti18n.h>
                                                                        /*}}}*/
 using namespace std;
 FTWScanner *FTWScanner::Owner;
@@ -64,6 +65,7 @@ FTWScanner::FTWScanner(string const &Arch): Arch(Arch)
    DoMD5 = _config->FindB("APT::FTPArchive::MD5",true);
    DoSHA1 = _config->FindB("APT::FTPArchive::SHA1",true);
    DoSHA256 = _config->FindB("APT::FTPArchive::SHA256",true);
+   DoSHA512 = _config->FindB("APT::FTPArchive::SHA512",true);
 }
                                                                        /*}}}*/
 // FTWScanner::Scanner - FTW Scanner                                   /*{{{*/
@@ -246,8 +248,8 @@ bool FTWScanner::LoadFileList(string const &Dir, string const &File)
 // ---------------------------------------------------------------------
 /* */
 bool FTWScanner::Delink(string &FileName,const char *OriginalPath,
-                       unsigned long &DeLinkBytes,
-                       off_t const &FileSize)
+                       unsigned long long &DeLinkBytes,
+                       unsigned long long const &FileSize)
 {
    // See if this isn't an internaly prefix'd file name.
    if (InternalPrefix.empty() == false &&
@@ -377,7 +379,7 @@ bool PackagesWriter::DoPackage(string FileName)
       return false;
    }
 
-   off_t FileSize = Db.GetFileSize();
+   unsigned long long FileSize = Db.GetFileSize();
    if (Delink(FileName,OriginalPath,Stats.DeLinkBytes,FileSize) == false)
       return false;
    
@@ -413,7 +415,7 @@ bool PackagesWriter::DoPackage(string FileName)
    }
 
    char Size[40];
-   sprintf(Size,"%lu", (unsigned long) FileSize);
+   sprintf(Size,"%llu", (unsigned long long) FileSize);
    
    // Strip the DirStrip prefix from the FileName and add the PathPrefix
    string NewFileName;
@@ -494,7 +496,7 @@ bool PackagesWriter::DoPackage(string FileName)
    }
 
    for (map<string,string>::const_iterator I = OverItem->FieldOverride.begin(); 
-        I != OverItem->FieldOverride.end(); I++) 
+        I != OverItem->FieldOverride.end(); ++I)
       SetTFRewriteData(Changes[End++],I->first.c_str(),I->second.c_str());
 
    SetTFRewriteData(Changes[End++], 0, 0);
@@ -610,7 +612,7 @@ bool SourcesWriter::DoPackage(string FileName)
    if (St.st_size > 128*1024)
       return _error->Error("DSC file '%s' is too large!",FileName.c_str());
          
-   if (BufSize < (unsigned)St.st_size+1)
+   if (BufSize < (unsigned long long)St.st_size+1)
    {
       BufSize = St.st_size+1;
       Buffer = (char *)realloc(Buffer,St.st_size+1);
@@ -830,7 +832,7 @@ bool SourcesWriter::DoPackage(string FileName)
       SetTFRewriteData(Changes[End++], "Maintainer", NewMaint.c_str());
    
    for (map<string,string>::const_iterator I = SOverItem->FieldOverride.begin(); 
-        I != SOverItem->FieldOverride.end(); I++) 
+        I != SOverItem->FieldOverride.end(); ++I)
       SetTFRewriteData(Changes[End++],I->first.c_str(),I->second.c_str());
 
    SetTFRewriteData(Changes[End++], 0, 0);
@@ -1039,33 +1041,18 @@ bool ReleaseWriter::DoPackage(string FileName)
 
    CheckSums[NewFileName].size = fd.Size();
 
+   Hashes hs;
+   hs.AddFD(fd.Fd(), 0, DoMD5, DoSHA1, DoSHA256, DoSHA512);
    if (DoMD5 == true)
-   {
-      MD5Summation MD5;
-      MD5.AddFD(fd.Fd(), fd.Size());
-      CheckSums[NewFileName].MD5 = MD5.Result();
-      fd.Seek(0);
-   }
+      CheckSums[NewFileName].MD5 = hs.MD5.Result();
    if (DoSHA1 == true)
-   {
-      SHA1Summation SHA1;
-      SHA1.AddFD(fd.Fd(), fd.Size());
-      CheckSums[NewFileName].SHA1 = SHA1.Result();
-      fd.Seek(0);
-   }
+      CheckSums[NewFileName].SHA1 = hs.SHA1.Result();
    if (DoSHA256 == true)
-   {
-      SHA256Summation SHA256;
-      SHA256.AddFD(fd.Fd(), fd.Size());
-      CheckSums[NewFileName].SHA256 = SHA256.Result();
-   }
-
-   SHA256Summation SHA512;
-   SHA256.AddFD(fd.Fd(), fd.Size());
-   CheckSums[NewFileName].SHA512 = SHA512.Result();
-
+      CheckSums[NewFileName].SHA256 = hs.SHA256.Result();
+   if (DoSHA512 == true)
+      CheckSums[NewFileName].SHA512 = hs.SHA512.Result();
    fd.Close();
-   
+
    return true;
 }
 
@@ -1080,7 +1067,7 @@ void ReleaseWriter::Finish()
       for(map<string,struct CheckSum>::const_iterator I = CheckSums.begin();
          I != CheckSums.end(); ++I)
       {
-        fprintf(Output, " %s %16ld %s\n",
+        fprintf(Output, " %s %16llu %s\n",
                 (*I).second.MD5.c_str(),
                 (*I).second.size,
                 (*I).first.c_str());
@@ -1092,7 +1079,7 @@ void ReleaseWriter::Finish()
       for(map<string,struct CheckSum>::const_iterator I = CheckSums.begin();
          I != CheckSums.end(); ++I)
       {
-        fprintf(Output, " %s %16ld %s\n",
+        fprintf(Output, " %s %16llu %s\n",
                 (*I).second.SHA1.c_str(),
                 (*I).second.size,
                 (*I).first.c_str());
@@ -1104,7 +1091,7 @@ void ReleaseWriter::Finish()
       for(map<string,struct CheckSum>::const_iterator I = CheckSums.begin();
          I != CheckSums.end(); ++I)
       {
-        fprintf(Output, " %s %16ld %s\n",
+        fprintf(Output, " %s %16llu %s\n",
                 (*I).second.SHA256.c_str(),
                 (*I).second.size,
                 (*I).first.c_str());
@@ -1116,7 +1103,7 @@ void ReleaseWriter::Finish()
        I != CheckSums.end();
        ++I)
    {
-      fprintf(Output, " %s %32ld %s\n",
+      fprintf(Output, " %s %16llu %s\n",
               (*I).second.SHA512.c_str(),
               (*I).second.size,
               (*I).first.c_str());