Ensure we have a Policy in CacheFile.BuildDepCache()
[ntk/apt.git] / apt-pkg / indexcopy.cc
index f53989b..854ba1b 100644 (file)
 #include <apt-pkg/configuration.h>
 #include <apt-pkg/tagfile.h>
 #include <apt-pkg/indexrecords.h>
-#include <apt-pkg/md5.h>
 #include <apt-pkg/cdrom.h>
+#include <apt-pkg/gpgv.h>
+#include <apt-pkg/hashes.h>
 
 #include <iostream>
 #include <sstream>
 #include <unistd.h>
 #include <sys/stat.h>
-#include <sys/types.h>
-#include <fcntl.h>
 #include <stdio.h>
 #include <stdlib.h>
+#include <string.h>
 
 #include "indexcopy.h"
 #include <apti18n.h>
@@ -65,7 +65,7 @@ bool IndexCopy::CopyPackages(string CDROM,string Name,vector<string> &List,
       for (std::vector<APT::Configuration::Compressor>::const_iterator c = compressor.begin();
           c != compressor.end(); ++c)
       {
-        if (stat(std::string(file + c->Extension).c_str(), &Buf) != 0)
+        if (stat((file + c->Extension).c_str(), &Buf) != 0)
            continue;
         found = true;
         break;
@@ -106,9 +106,9 @@ bool IndexCopy::CopyPackages(string CDROM,string Name,vector<string> &List,
       } else {
          Target.Open(TargetF,FileFd::WriteAtomic);
       }
-      FILE *TargetFl = fdopen(dup(Target.Fd()),"w");
       if (_error->PendingError() == true)
         return false;
+      FILE *TargetFl = fdopen(dup(Target.Fd()),"w");
       if (TargetFl == 0)
         return _error->Errno("fdopen","Failed to reopen fd");
       
@@ -141,7 +141,6 @@ bool IndexCopy::CopyPackages(string CDROM,string Name,vector<string> &List,
            File = OrigPath + ChopDirs(File,Chop);
         
         // See if the file exists
-        bool Mangled = false;
         if (NoStat == false || Hits < 10)
         {
            // Attempt to fix broken structure
@@ -161,9 +160,10 @@ bool IndexCopy::CopyPackages(string CDROM,string Name,vector<string> &List,
            
            // Get the size
            struct stat Buf;
-           if (stat(string(CDROM + Prefix + File).c_str(),&Buf) != 0 || 
+           if (stat((CDROM + Prefix + File).c_str(),&Buf) != 0 || 
                Buf.st_size == 0)
            {
+              bool Mangled = false;
               // Attempt to fix busted symlink support for one instance
               string OrigFile = File;
               string::size_type Start = File.find("binary-");
@@ -175,7 +175,7 @@ bool IndexCopy::CopyPackages(string CDROM,string Name,vector<string> &List,
               }
               
               if (Mangled == false ||
-                  stat(string(CDROM + Prefix + File).c_str(),&Buf) != 0)
+                  stat((CDROM + Prefix + File).c_str(),&Buf) != 0)
               {
                  if (Debug == true)
                     clog << "Missed(2): " << OrigFile << endl;
@@ -286,7 +286,7 @@ bool IndexCopy::ReconstructPrefix(string &Prefix,string OrigPath,string CD,
    while (1)
    {
       struct stat Buf;
-      if (stat(string(CD + MyPrefix + File).c_str(),&Buf) != 0)
+      if (stat((CD + MyPrefix + File).c_str(),&Buf) != 0)
       {
         if (Debug == true)
            cout << "Failed, " << CD + MyPrefix + File << endl;
@@ -315,7 +315,7 @@ bool IndexCopy::ReconstructChop(unsigned long &Chop,string Dir,string File)
    while (1)
    {
       struct stat Buf;
-      if (stat(string(Dir + File).c_str(),&Buf) != 0)
+      if (stat((Dir + File).c_str(),&Buf) != 0)
       {
         File = ChopDirs(File,1);
         Depth++;
@@ -436,8 +436,8 @@ bool PackageCopy::GetFile(string &File,unsigned long long &Size)
 /* */
 bool PackageCopy::RewriteEntry(FILE *Target,string File)
 {
-   TFRewriteData Changes[] = {{"Filename",File.c_str()},
-                              {}};
+   TFRewriteData Changes[] = {{ "Filename", File.c_str(), NULL },
+                              { NULL, NULL, NULL }};
    
    if (TFRewrite(Target,*Section,TFRewritePackageOrder,Changes) == false)
       return false;
@@ -482,8 +482,8 @@ bool SourceCopy::GetFile(string &File,unsigned long long &Size)
 bool SourceCopy::RewriteEntry(FILE *Target,string File)
 {
    string Dir(File,0,File.rfind('/'));
-   TFRewriteData Changes[] = {{"Directory",Dir.c_str()},
-                              {}};
+   TFRewriteData Changes[] = {{ "Directory", Dir.c_str(), NULL },
+                              { NULL, NULL, NULL }};
    
    if (TFRewrite(Target,*Section,TFRewriteSourceOrder,Changes) == false)
       return false;
@@ -544,16 +544,14 @@ bool SigVerify::CopyMetaIndex(string CDROM, string CDName,                /*{{{*/
       FileFd Rel;
       Target.Open(TargetF,FileFd::WriteAtomic);
       Rel.Open(prefix + file,FileFd::ReadOnly);
-      if (_error->PendingError() == true)
-        return false;
       if (CopyFile(Rel,Target) == false)
-        return false;
-   
+        return _error->Error("Copying of '%s' for '%s' from '%s' failed", file.c_str(), CDName.c_str(), prefix.c_str());
+
       return true;
 }
                                                                        /*}}}*/
 bool SigVerify::CopyAndVerify(string CDROM,string Name,vector<string> &SigList,        /*{{{*/
-                             vector<string> PkgList,vector<string> SrcList)
+                             vector<string> /*PkgList*/,vector<string> /*SrcList*/)
 {
    if (SigList.empty() == true)
       return true;
@@ -603,6 +601,7 @@ bool SigVerify::CopyAndVerify(string CDROM,string Name,vector<string> &SigList,
                         (useInRelease ? inrelease.c_str() : releasegpg.c_str()));
         // something went wrong, don't copy the Release.gpg
         // FIXME: delete any existing gpg file?
+        delete MetaIndex;
         continue;
       }
 
@@ -642,6 +641,16 @@ bool SigVerify::CopyAndVerify(string CDROM,string Name,vector<string> &SigList,
    return true;
 }
                                                                        /*}}}*/
+// SigVerify::RunGPGV - deprecated wrapper calling ExecGPGV            /*{{{*/
+APT_NORETURN bool SigVerify::RunGPGV(std::string const &File, std::string const &FileOut,
+      int const &statusfd, int fd[2]) {
+   ExecGPGV(File, FileOut, statusfd, fd);
+}
+APT_NORETURN bool SigVerify::RunGPGV(std::string const &File, std::string const &FileOut,
+      int const &statusfd) {
+   ExecGPGV(File, FileOut, statusfd);
+}
+                                                                       /*}}}*/
 bool TranslationsCopy::CopyTranslations(string CDROM,string Name,      /*{{{*/
                                vector<string> &List, pkgCdromStatus *log)
 {
@@ -665,7 +674,7 @@ bool TranslationsCopy::CopyTranslations(string CDROM,string Name,   /*{{{*/
       for (std::vector<APT::Configuration::Compressor>::const_iterator c = compressor.begin();
           c != compressor.end(); ++c)
       {
-        if (stat(std::string(file + c->Extension).c_str(), &Buf) != 0)
+        if (stat((file + c->Extension).c_str(), &Buf) != 0)
            continue;
         found = true;
         break;
@@ -681,9 +690,7 @@ bool TranslationsCopy::CopyTranslations(string CDROM,string Name,   /*{{{*/
    unsigned int WrongSize = 0;
    unsigned int Packages = 0;
    for (vector<string>::iterator I = List.begin(); I != List.end(); ++I)
-   {      
-      string OrigPath = string(*I,CDROM.length());
-
+   {
       // Open the package file
       FileFd Pkg(*I, FileFd::ReadOnly, FileFd::Auto);
       off_t const FileSize = Pkg.Size();
@@ -706,9 +713,9 @@ bool TranslationsCopy::CopyTranslations(string CDROM,string Name,   /*{{{*/
       } else {
         Target.Open(TargetF,FileFd::WriteAtomic);
       }
-      FILE *TargetFl = fdopen(dup(Target.Fd()),"w");
       if (_error->PendingError() == true)
         return false;
+      FILE *TargetFl = fdopen(dup(Target.Fd()),"w");
       if (TargetFl == 0)
         return _error->Errno("fdopen","Failed to reopen fd");