]> git.saurik.com Git - apt.git/blobdiff - apt-pkg/deb/debmetaindex.cc
rework hashsum verification in the acquire system
[apt.git] / apt-pkg / deb / debmetaindex.cc
index b597b6f3c281898e990fb6ead38d1530f61e0592..eb5e78e3bbca5a668ee8d7a331c3f24b9cd65caa 100644 (file)
@@ -1,4 +1,3 @@
-// ijones, walters
 #include <config.h>
 
 #include <apt-pkg/debmetaindex.h>
 #include <config.h>
 
 #include <apt-pkg/debmetaindex.h>
@@ -10,8 +9,15 @@
 #include <apt-pkg/aptconfiguration.h>
 #include <apt-pkg/indexrecords.h>
 #include <apt-pkg/sourcelist.h>
 #include <apt-pkg/aptconfiguration.h>
 #include <apt-pkg/indexrecords.h>
 #include <apt-pkg/sourcelist.h>
-#include <apt-pkg/error.h>
-
+#include <apt-pkg/hashes.h>
+#include <apt-pkg/macros.h>
+#include <apt-pkg/metaindex.h>
+
+#include <string.h>
+#include <map>
+#include <string>
+#include <utility>
+#include <vector>
 #include <set>
 #include <algorithm>
 
 #include <set>
 #include <algorithm>
 
@@ -72,6 +78,20 @@ string debReleaseIndex::MetaIndexURI(const char *Type) const
    return Res;
 }
 
    return Res;
 }
 
+std::string debReleaseIndex::LocalFileName() const
+{
+   // see if we have a InRelease file
+   std::string PathInRelease =  MetaIndexFile("InRelease");
+   if (FileExists(PathInRelease))
+      return PathInRelease;
+
+   // and if not return the normal one
+   if (FileExists(PathInRelease))
+      return MetaIndexFile("Release");
+
+   return "";
+}
+
 string debReleaseIndex::IndexURISuffix(const char *Type, string const &Section, string const &Arch) const
 {
    string Res ="";
 string debReleaseIndex::IndexURISuffix(const char *Type, string const &Section, string const &Arch) const
 {
    string Res ="";
@@ -164,19 +184,21 @@ debReleaseIndex::~debReleaseIndex() {
                        delete *S;
 }
 
                        delete *S;
 }
 
-vector <struct IndexTarget *>* debReleaseIndex::ComputeIndexTargets() const {
-       vector <struct IndexTarget *>* IndexTargets = new vector <IndexTarget *>;
+vector <IndexTarget *>* debReleaseIndex::ComputeIndexTargets() const {
+       vector <IndexTarget *>* IndexTargets = new vector <IndexTarget *>;
 
        map<string, vector<debSectionEntry const*> >::const_iterator const src = ArchEntries.find("source");
        if (src != ArchEntries.end()) {
                vector<debSectionEntry const*> const SectionEntries = src->second;
                for (vector<debSectionEntry const*>::const_iterator I = SectionEntries.begin();
                     I != SectionEntries.end(); ++I) {
 
        map<string, vector<debSectionEntry const*> >::const_iterator const src = ArchEntries.find("source");
        if (src != ArchEntries.end()) {
                vector<debSectionEntry const*> const SectionEntries = src->second;
                for (vector<debSectionEntry const*>::const_iterator I = SectionEntries.begin();
                     I != SectionEntries.end(); ++I) {
-                       IndexTarget * Target = new IndexTarget();
-                       Target->ShortDesc = "Sources";
-                       Target->MetaKey = SourceIndexURISuffix(Target->ShortDesc.c_str(), (*I)->Section);
-                       Target->URI = SourceIndexURI(Target->ShortDesc.c_str(), (*I)->Section);
-                       Target->Description = Info (Target->ShortDesc.c_str(), (*I)->Section);
+                       char const * const ShortDesc = "Sources";
+                       IndexTarget * const Target = new IndexTarget(
+                             SourceIndexURISuffix(ShortDesc, (*I)->Section),
+                             ShortDesc,
+                             Info(ShortDesc, (*I)->Section),
+                             SourceIndexURI(ShortDesc, (*I)->Section)
+                             );
                        IndexTargets->push_back (Target);
                }
        }
                        IndexTargets->push_back (Target);
                }
        }
@@ -192,11 +214,13 @@ vector <struct IndexTarget *>* debReleaseIndex::ComputeIndexTargets() const {
                        continue;
                for (vector <const debSectionEntry *>::const_iterator I = a->second.begin();
                     I != a->second.end(); ++I) {
                        continue;
                for (vector <const debSectionEntry *>::const_iterator I = a->second.begin();
                     I != a->second.end(); ++I) {
-                       IndexTarget * Target = new IndexTarget();
-                       Target->ShortDesc = "Packages";
-                       Target->MetaKey = IndexURISuffix(Target->ShortDesc.c_str(), (*I)->Section, a->first);
-                       Target->URI = IndexURI(Target->ShortDesc.c_str(), (*I)->Section, a->first);
-                       Target->Description = Info (Target->ShortDesc.c_str(), (*I)->Section, a->first);
+                       char const * const ShortDesc = "Packages";
+                       IndexTarget * const Target = new IndexTarget(
+                             IndexURISuffix(ShortDesc, (*I)->Section, a->first),
+                             ShortDesc,
+                             Info (ShortDesc, (*I)->Section, a->first),
+                             IndexURI(ShortDesc, (*I)->Section, a->first)
+                             );
                        IndexTargets->push_back (Target);
                        sections.insert((*I)->Section);
                }
                        IndexTargets->push_back (Target);
                        sections.insert((*I)->Section);
                }
@@ -215,11 +239,13 @@ vector <struct IndexTarget *>* debReleaseIndex::ComputeIndexTargets() const {
             s != sections.end(); ++s) {
                for (std::vector<std::string>::const_iterator l = lang.begin();
                     l != lang.end(); ++l) {
             s != sections.end(); ++s) {
                for (std::vector<std::string>::const_iterator l = lang.begin();
                     l != lang.end(); ++l) {
-                       IndexTarget * Target = new OptionalIndexTarget();
-                       Target->ShortDesc = "Translation-" + *l;
-                       Target->MetaKey = TranslationIndexURISuffix(l->c_str(), *s);
-                       Target->URI = TranslationIndexURI(l->c_str(), *s);
-                       Target->Description = Info (Target->ShortDesc.c_str(), *s);
+                       std::string const ShortDesc = "Translation-" + *l;
+                       IndexTarget * const Target = new OptionalIndexTarget(
+                             TranslationIndexURISuffix(l->c_str(), *s),
+                             ShortDesc,
+                             Info (ShortDesc.c_str(), *s),
+                             TranslationIndexURI(l->c_str(), *s)
+                             );
                        IndexTargets->push_back(Target);
                }
        }
                        IndexTargets->push_back(Target);
                }
        }
@@ -229,41 +255,25 @@ vector <struct IndexTarget *>* debReleaseIndex::ComputeIndexTargets() const {
                                                                        /*}}}*/
 bool debReleaseIndex::GetIndexes(pkgAcquire *Owner, bool const &GetAll) const
 {
                                                                        /*}}}*/
 bool debReleaseIndex::GetIndexes(pkgAcquire *Owner, bool const &GetAll) const
 {
-   bool const tryInRelease = _config->FindB("Acquire::TryInRelease", true);
+   indexRecords * const iR = new indexRecords(Dist);
+   if (Trusted == ALWAYS_TRUSTED)
+      iR->SetTrusted(true);
+   else if (Trusted == NEVER_TRUSTED)
+      iR->SetTrusted(false);
 
    // special case for --print-uris
 
    // special case for --print-uris
-   if (GetAll) {
-      vector <struct IndexTarget *> *targets = ComputeIndexTargets();
-      for (vector <struct IndexTarget*>::const_iterator Target = targets->begin(); Target != targets->end(); ++Target) {
-        new pkgAcqIndex(Owner, (*Target)->URI, (*Target)->Description,
-                        (*Target)->ShortDesc, HashString());
-      }
-      delete targets;
-
-      // this is normally created in pkgAcqMetaSig, but if we run
-      // in --print-uris mode, we add it here
-      if (tryInRelease == false)
-        new pkgAcqMetaIndex(Owner, MetaIndexURI("Release"),
-              MetaIndexInfo("Release"), "Release",
-              MetaIndexURI("Release.gpg"),
-              ComputeIndexTargets(),
-              new indexRecords (Dist));
+   vector <IndexTarget *> const * const targets = ComputeIndexTargets();
+#define APT_TARGET(X) IndexTarget("", X, MetaIndexInfo(X), MetaIndexURI(X))
+   pkgAcqMetaBase * const TransactionManager = new pkgAcqMetaClearSig(Owner,
+        APT_TARGET("InRelease"), APT_TARGET("Release"), APT_TARGET("Release.gpg"),
+        targets, iR);
+#undef APT_TARGET
+   if (GetAll)
+   {
+      for (vector <IndexTarget*>::const_iterator Target = targets->begin(); Target != targets->end(); ++Target)
+        new pkgAcqIndex(Owner, TransactionManager, *Target);
    }
 
    }
 
-   if (tryInRelease == true)
-      new pkgAcqMetaClearSig(Owner, MetaIndexURI("InRelease"),
-           MetaIndexInfo("InRelease"), "InRelease",
-           MetaIndexURI("Release"), MetaIndexInfo("Release"), "Release",
-           MetaIndexURI("Release.gpg"), MetaIndexInfo("Release.gpg"), "Release.gpg",
-           ComputeIndexTargets(),
-           new indexRecords (Dist));
-   else
-      new pkgAcqMetaSig(Owner, MetaIndexURI("Release.gpg"),
-           MetaIndexInfo("Release.gpg"), "Release.gpg",
-           MetaIndexURI("Release"), MetaIndexInfo("Release"), "Release",
-           ComputeIndexTargets(),
-           new indexRecords (Dist));
-
    return true;
 }
 
    return true;
 }
 
@@ -366,7 +376,7 @@ debReleaseIndex::debSectionEntry::debSectionEntry (string const &Section,
                bool const &IsSrc): Section(Section), IsSrc(IsSrc)
 {}
 
                bool const &IsSrc): Section(Section), IsSrc(IsSrc)
 {}
 
-class debSLTypeDebian : public pkgSourceList::Type
+class APT_HIDDEN debSLTypeDebian : public pkgSourceList::Type
 {
    protected:
 
 {
    protected:
 
@@ -376,9 +386,12 @@ class debSLTypeDebian : public pkgSourceList::Type
    {
       // parse arch=, arch+= and arch-= settings
       map<string, string>::const_iterator arch = Options.find("arch");
    {
       // parse arch=, arch+= and arch-= settings
       map<string, string>::const_iterator arch = Options.find("arch");
-      vector<string> Archs =
-               (arch != Options.end()) ? VectorizeString(arch->second, ',') :
-                               APT::Configuration::getArchitectures();
+      vector<string> Archs;
+      if (arch != Options.end())
+        Archs = VectorizeString(arch->second, ',');
+      else
+        Archs = APT::Configuration::getArchitectures();
+
       if ((arch = Options.find("arch+")) != Options.end())
       {
         std::vector<std::string> const plusArch = VectorizeString(arch->second, ',');
       if ((arch = Options.find("arch+")) != Options.end())
       {
         std::vector<std::string> const plusArch = VectorizeString(arch->second, ',');
@@ -449,7 +462,16 @@ class debSLTypeDebian : public pkgSourceList::Type
    }
 };
 
    }
 };
 
-class debSLTypeDeb : public debSLTypeDebian
+debDebFileMetaIndex::debDebFileMetaIndex(std::string const &DebFile)
+   : metaIndex(DebFile, "local-uri", "deb-dist"), DebFile(DebFile)
+{
+   DebIndex = new debDebPkgFileIndex(DebFile);
+   Indexes = new vector<pkgIndexFile *>();
+   Indexes->push_back(DebIndex);
+}
+
+
+class APT_HIDDEN debSLTypeDeb : public debSLTypeDebian
 {
    public:
 
 {
    public:
 
@@ -467,7 +489,7 @@ class debSLTypeDeb : public debSLTypeDebian
    }   
 };
 
    }   
 };
 
-class debSLTypeDebSrc : public debSLTypeDebian
+class APT_HIDDEN debSLTypeDebSrc : public debSLTypeDebian
 {
    public:
 
 {
    public:
 
@@ -485,5 +507,26 @@ class debSLTypeDebSrc : public debSLTypeDebian
    }   
 };
 
    }   
 };
 
-debSLTypeDeb _apt_DebType;
-debSLTypeDebSrc _apt_DebSrcType;
+class APT_HIDDEN debSLTypeDebFile : public pkgSourceList::Type
+{
+   public:
+
+   bool CreateItem(vector<metaIndex *> &List, string const &URI,
+                  string const &/*Dist*/, string const &/*Section*/,
+                  std::map<string, string> const &/*Options*/) const
+   {
+      metaIndex *mi = new debDebFileMetaIndex(URI);
+      List.push_back(mi);
+      return true;
+   }
+   
+   debSLTypeDebFile()
+   {
+      Name = "deb-file";
+      Label = "Debian Deb File";
+   }   
+};
+
+APT_HIDDEN debSLTypeDeb _apt_DebType;
+APT_HIDDEN debSLTypeDebSrc _apt_DebSrcType;
+APT_HIDDEN debSLTypeDebFile _apt_DebFileType;