]> git.saurik.com Git - apt.git/blobdiff - apt-pkg/deb/deblistparser.cc
support dpkg debug mode in APT::StateChanges
[apt.git] / apt-pkg / deb / deblistparser.cc
index 6ab0d0393ca610d0f49b5766d1133339a6efd16f..f7f64debdda1de3b75dd1c68ede503e24765e720 100644 (file)
@@ -42,7 +42,7 @@ static const debListParser::WordList PrioList[] = {
    {"standard",pkgCache::State::Standard},
    {"optional",pkgCache::State::Optional},
    {"extra",pkgCache::State::Extra},
-   {NULL, 0}};
+   {"", 0}};
 
 // ListParser::debListParser - Constructor                             /*{{{*/
 // ---------------------------------------------------------------------
@@ -72,9 +72,9 @@ string debListParser::Package() {
 // ListParser::Architecture - Return the package arch                  /*{{{*/
 // ---------------------------------------------------------------------
 /* This will return the Architecture of the package this section describes */
-string debListParser::Architecture() {
+APT::StringView debListParser::Architecture() {
    auto const Arch = Section.Find("Architecture");
-   return Arch.empty() ? "none" : Arch.to_string();
+   return Arch.empty() ? "none" : Arch;
 }
                                                                        /*}}}*/
 // ListParser::ArchitectureAll                                         /*{{{*/
@@ -89,9 +89,9 @@ bool debListParser::ArchitectureAll() {
 /* This is to return the string describing the version in debian form,
    epoch:upstream-release. If this returns the blank string then the 
    entry is assumed to only describe package properties */
-string debListParser::Version()
+APT::StringView debListParser::Version()
 {
-   return Section.Find("Version").to_string();
+   return Section.Find("Version");
 }
                                                                        /*}}}*/
 unsigned char debListParser::ParseMultiArch(bool const showErrors)     /*{{{*/
@@ -144,7 +144,7 @@ bool debListParser::NewVersion(pkgCache::VerIterator &Ver)
       Ver->Section = idx;
    }
    // Parse the source package name
-   pkgCache::GrpIterator const G = Ver.ParentPkg().Group();
+   pkgCache::GrpIterator G = Ver.ParentPkg().Group();
    Ver->SourcePkgName = G->Name;
    Ver->SourceVerStr = Ver->VerStr;
    if (Section.Find("Source",Start,Stop) == true)
@@ -154,24 +154,25 @@ bool debListParser::NewVersion(pkgCache::VerIterator &Ver)
 
       if (Space != NULL)
       {
-        Stop = Space;
         const char * const Open = (const char * const) memchr(Space, '(', Stop - Space);
         if (likely(Open != NULL))
         {
            const char * const Close = (const char * const) memchr(Open, ')', Stop - Open);
            if (likely(Close != NULL))
            {
-              std::string const version(Open + 1, (Close - Open) - 1);
+              APT::StringView const version(Open + 1, (Close - Open) - 1);
               if (version != Ver.VerStr())
               {
                  map_stringitem_t const idx = StoreString(pkgCacheGenerator::VERSIONNUMBER, version);
+                 G = Ver.ParentPkg().Group();
                  Ver->SourceVerStr = idx;
               }
            }
         }
+        Stop = Space;
       }
 
-      std::string const pkgname(Start, Stop - Start);
+      APT::StringView const pkgname(Start, Stop - Start);
       if (pkgname != G.Name())
       {
         for (pkgCache::PkgIterator P = G.PackageList(); P.end() == false; P = G.NextPkg(P))
@@ -190,6 +191,7 @@ bool debListParser::NewVersion(pkgCache::VerIterator &Ver)
         if (V.end() == true)
         {
            map_stringitem_t const idx = StoreString(pkgCacheGenerator::PKGNAME, pkgname);
+           G = Ver.ParentPkg().Group();
            Ver->SourcePkgName = idx;
         }
       }
@@ -235,35 +237,24 @@ bool debListParser::NewVersion(pkgCache::VerIterator &Ver)
    return true;
 }
                                                                        /*}}}*/
-// ListParser::Description - Return the description string             /*{{{*/
-// ---------------------------------------------------------------------
-/* This is to return the string describing the package in debian
-   form. If this returns the blank string then the entry is assumed to
-   only describe package properties */
-string debListParser::Description(std::string const &lang)
-{
-   return Description(StringView(lang)).to_string();
-}
-
-StringView debListParser::Description(StringView lang)
-{
-   if (lang.empty())
-      return Section.Find("Description");
-   else
-      return Section.Find(string("Description-").append(lang.data(), lang.size()));
-}
-                                                                       /*}}}*/
 // ListParser::AvailableDescriptionLanguages                           /*{{{*/
 std::vector<std::string> debListParser::AvailableDescriptionLanguages()
 {
    std::vector<std::string> const understood = APT::Configuration::getLanguages();
    std::vector<std::string> avail;
+   static constexpr int prefixLen = 12;
+   static constexpr int avgLanguageLen = 5;
+   std::string tagname;
+
+   tagname.reserve(prefixLen + avgLanguageLen);
+   tagname.assign("Description-");
    if (Section.Exists("Description") == true)
       avail.push_back("");
    for (std::vector<std::string>::const_iterator lang = understood.begin(); lang != understood.end(); ++lang)
    {
-      std::string const tagname = "Description-" + *lang;
-      if (Section.Exists(tagname.c_str()) == true)
+      tagname.resize(prefixLen);
+      tagname.append(*lang);
+      if (Section.Exists(tagname) == true)
         avail.push_back(*lang);
    }
    return avail;
@@ -277,10 +268,10 @@ std::vector<std::string> debListParser::AvailableDescriptionLanguages()
  */
 MD5SumValue debListParser::Description_md5()
 {
-   auto const value = Section.Find("Description-md5");
+   StringView const value = Section.Find("Description-md5");
    if (value.empty() == true)
    {
-      StringView desc = Description(StringView("", 0));
+      StringView const desc = Section.Find("Description");
       if (desc == "\n")
         return MD5SumValue();
 
@@ -366,8 +357,12 @@ unsigned short debListParser::VersionHash()
            continue;
         *J++ = tolower_ascii(*Start);
 
-        if ((*Start == '<' || *Start == '>') && Start[1] != *Start && Start[1] != '=')
-           *J++ = '=';
+        /* Normalize <= to < and >= to >. This is the wrong way around, but
+         * more efficient that the right way. And since we're only hashing
+         * it does not matter which way we normalize. */
+        if ((*Start == '<' || *Start == '>') && Start[1] == '=') {
+           Start++;
+        }
       }
 
       Result = AddCRC16(Result,S,J - S);
@@ -416,7 +411,7 @@ bool debStatusListParser::ParseStatus(pkgCache::PkgIterator &Pkg,
                           {"hold",pkgCache::State::Hold},
                           {"deinstall",pkgCache::State::DeInstall},
                           {"purge",pkgCache::State::Purge},
-                          {NULL, 0}};
+                          {"", 0}};
    if (GrabWord(StringView(Start,I-Start),WantList,Pkg->SelectedState) == false)
       return _error->Error("Malformed 1st word in the Status line");
 
@@ -432,7 +427,7 @@ bool debStatusListParser::ParseStatus(pkgCache::PkgIterator &Pkg,
                           {"reinstreq",pkgCache::State::ReInstReq},
                           {"hold",pkgCache::State::HoldInst},
                           {"hold-reinstreq",pkgCache::State::HoldReInstReq},
-                          {NULL, 0}};
+                          {"", 0}};
    if (GrabWord(StringView(Start,I-Start),FlagList,Pkg->InstState) == false)
       return _error->Error("Malformed 2nd word in the Status line");
 
@@ -452,7 +447,7 @@ bool debStatusListParser::ParseStatus(pkgCache::PkgIterator &Pkg,
                             {"triggers-awaited",pkgCache::State::TriggersAwaited},
                             {"triggers-pending",pkgCache::State::TriggersPending},
                             {"installed",pkgCache::State::Installed},
-                            {NULL, 0}};
+                            {"", 0}};
    if (GrabWord(StringView(Start,I-Start),StatusList,Pkg->CurrentState) == false)
       return _error->Error("Malformed 3rd word in the Status line");
 
@@ -591,9 +586,9 @@ const char *debListParser::ParseDepends(const char *Start,const char *Stop,
       string const arch = _config->Find("APT::Architecture");
       size_t const found = Package.rfind(':');
       if (found != StringView::npos &&
-         (Package.compare(found, Package.size(), ":any") == 0 ||
-          Package.compare(found, Package.size(), ":native") == 0||
-          Package.compare(found +1, Package.size(), arch) == 0))
+         (Package.substr(found) == ":any" ||
+          Package.substr(found) == ":native" ||
+          Package.substr(found +1) == arch))
         Package = Package.substr(0,found);
    }
 
@@ -662,7 +657,7 @@ const char *debListParser::ParseDepends(const char *Start,const char *Stop,
               ++I;
            }
 
-           std::string arch(I, End);
+           std::string const arch(I, End);
            if (arch.empty() == false && matchesArch(arch.c_str()) == true)
            {
               Found = true;
@@ -744,8 +739,7 @@ const char *debListParser::ParseDepends(const char *Start,const char *Stop,
                  ++I;
               }
 
-              std::string restriction(I, End);
-
+              std::string const restriction(I, End);
               if (restriction.empty() == false && profiles.empty() == false &&
                  std::find(profiles.begin(), profiles.end(), restriction) != profiles.end())
               {
@@ -802,11 +796,11 @@ const char *debListParser::ParseDepends(const char *Start,const char *Stop,
 /* This is the higher level depends parser. It takes a tag and generates
    a complete depends tree for the given version. */
 bool debListParser::ParseDepends(pkgCache::VerIterator &Ver,
-                                const char *Tag,unsigned int Type)
+                                StringView Tag,unsigned int Type)
 {
    const char *Start;
    const char *Stop;
-   if (Section.Find(Tag,Start,Stop) == false)
+   if (Section.Find(Tag,Start,Stop) == false || Start == Stop)
       return true;
 
    string const pkgArch = Ver.Arch();
@@ -819,7 +813,7 @@ bool debListParser::ParseDepends(pkgCache::VerIterator &Ver,
 
       Start = ParseDepends(Start, Stop, Package, Version, Op, false, false, false);
       if (Start == 0)
-        return _error->Error("Problem parsing dependency %s",Tag);
+        return _error->Error("Problem parsing dependency %.*s",(int)Tag.length(), Tag.data());
       size_t const found = Package.rfind(':');
 
       if (found == string::npos)
@@ -827,7 +821,7 @@ bool debListParser::ParseDepends(pkgCache::VerIterator &Ver,
         if (NewDepends(Ver,Package,pkgArch,Version,Op,Type) == false)
            return false;
       }
-      else if (Package.compare(found, Package.npos, ":any") == 0)
+      else if (Package.substr(found) == ":any")
       {
         if (NewDepends(Ver,Package,"any",Version,Op,Type) == false)
            return false;
@@ -836,12 +830,13 @@ bool debListParser::ParseDepends(pkgCache::VerIterator &Ver,
       {
         // Such dependencies are not supposed to be accepted …
         // … but this is probably the best thing to do anyway
-        std::string Pkg;
         if (Package.substr(found + 1) == "native")
-           Pkg = Package.substr(0, found).to_string() + ':' + Ver.Cache()->NativeArch();
-        else
-           Pkg = Package.to_string();
-        if (NewDepends(Ver, Pkg, "any", Version, Op | pkgCache::Dep::ArchSpecific, Type) == false)
+        {
+           std::string const Pkg = Package.substr(0, found).to_string() + ':' + Ver.Cache()->NativeArch();
+           if (NewDepends(Ver, Pkg, "any", Version, Op | pkgCache::Dep::ArchSpecific, Type) == false)
+              return false;
+        }
+        else if (NewDepends(Ver, Package, "any", Version, Op | pkgCache::Dep::ArchSpecific, Type) == false)
            return false;
       }
 
@@ -900,8 +895,12 @@ bool debListParser::ParseProvides(pkgCache::VerIterator &Ver)
               return false;
         } else if ((Ver->MultiArch & pkgCache::Version::Foreign) == pkgCache::Version::Foreign) {
            if (APT::Configuration::checkArchitecture(Arch))
+           {
               if (NewProvidesAllArch(Ver, Package, Version, 0) == false)
                  return false;
+           }
+           else if (NewProvides(Ver, Package, Arch, Version, 0) == false)
+              return false;
         } else {
            if ((Ver->MultiArch & pkgCache::Version::Allowed) == pkgCache::Version::Allowed)
            {
@@ -956,12 +955,12 @@ bool debListParser::ParseProvides(pkgCache::VerIterator &Ver)
 // ListParser::GrabWord - Matches a word and returns                   /*{{{*/
 // ---------------------------------------------------------------------
 /* Looks for a word in a list of words - for ParseStatus */
-bool debListParser::GrabWord(StringView Word,const WordList *List,unsigned char &Out)
+bool debListParser::GrabWord(StringView Word, WordList const *List, unsigned char &Out)
 {
-   for (unsigned int C = 0; List[C].Str != 0; C++)
+   for (unsigned int C = 0; List[C].Str.empty() == false; C++)
    {
-      if (Word.length() == strlen(List[C].Str) &&
-         strncasecmp(Word.data(),List[C].Str,Word.length()) == 0)
+      if (Word.length() == List[C].Str.length() &&
+         strncasecmp(Word.data(), List[C].Str.data(), Word.length()) == 0)
       {
         Out = List[C].Val;
         return true;
@@ -1000,7 +999,7 @@ bool debListParser::SameVersion(unsigned short const Hash,         /*{{{*/
    // status file is parsed last, so the first version we encounter is
    // probably also the version we have downloaded
    unsigned long long const Size = Section.FindULL("Size");
-   if (Size != 0 && Size != Ver->Size)
+   if (Size != 0 && Ver->Size != 0 && Size != Ver->Size)
       return false;
    // available everywhere, but easier to check here than to include in VersionHash
    unsigned char MultiArch = ParseMultiArch(false);