]> git.saurik.com Git - apt.git/blobdiff - apt-pkg/deb/deblistparser.cc
just-in-time creation for (implicit) Provides
[apt.git] / apt-pkg / deb / deblistparser.cc
index 502bd1a5132d887369517351a3b3e0e61e0da3a5..87aa99c6ebd233149493e7376c97a7b6d63209e2 100644 (file)
@@ -50,7 +50,7 @@ static debListParser::WordList PrioList[] = {
 /* Provide an architecture and only this one and "all" will be accepted
    in Step(), if no Architecture is given we will accept every arch
    we would accept in general with checkArchitecture() */
-debListParser::debListParser(FileFd *File, string const &Arch) : Tags(File),
+debListParser::debListParser(FileFd *File, string const &Arch) :  d(NULL), Tags(File),
                                Arch(Arch) {
    if (Arch == "native")
       this->Arch = _config->Find("APT::Architecture");
@@ -207,23 +207,22 @@ bool debListParser::NewVersion(pkgCache::VerIterator &Ver)
         Ver->Priority = pkgCache::State::Extra;
    }
 
-   if (ParseDepends(Ver,"Depends",pkgCache::Dep::Depends) == false)
-      return false;
    if (ParseDepends(Ver,"Pre-Depends",pkgCache::Dep::PreDepends) == false)
       return false;
-   if (ParseDepends(Ver,"Suggests",pkgCache::Dep::Suggests) == false)
-      return false;
-   if (ParseDepends(Ver,"Recommends",pkgCache::Dep::Recommends) == false)
+   if (ParseDepends(Ver,"Depends",pkgCache::Dep::Depends) == false)
       return false;
    if (ParseDepends(Ver,"Conflicts",pkgCache::Dep::Conflicts) == false)
       return false;
    if (ParseDepends(Ver,"Breaks",pkgCache::Dep::DpkgBreaks) == false)
       return false;
+   if (ParseDepends(Ver,"Recommends",pkgCache::Dep::Recommends) == false)
+      return false;
+   if (ParseDepends(Ver,"Suggests",pkgCache::Dep::Suggests) == false)
+      return false;
    if (ParseDepends(Ver,"Replaces",pkgCache::Dep::Replaces) == false)
       return false;
    if (ParseDepends(Ver,"Enhances",pkgCache::Dep::Enhances) == false)
       return false;
-
    // Obsolete.
    if (ParseDepends(Ver,"Optional",pkgCache::Dep::Suggests) == false)
       return false;
@@ -372,13 +371,9 @@ unsigned short debListParser::VersionHash()
 /* Status lines are of the form,
      Status: want flag status
    want = unknown, install, hold, deinstall, purge
-   flag = ok, reinstreq, hold, hold-reinstreq
-   status = not-installed, unpacked, half-configured,
-            half-installed, config-files, post-inst-failed, 
-            removal-failed, installed
-   
-   Some of the above are obsolete (I think?) flag = hold-* and 
-   status = post-inst-failed, removal-failed at least.
+   flag = ok, reinstreq
+   status = not-installed, config-files, half-installed, unpacked,
+            half-configured, triggers-awaited, triggers-pending, installed
  */
 bool debListParser::ParseStatus(pkgCache::PkgIterator &Pkg,
                                pkgCache::VerIterator &Ver)
@@ -435,15 +430,13 @@ bool debListParser::ParseStatus(pkgCache::PkgIterator &Pkg,
 
    // Process the flag field
    WordList StatusList[] = {{"not-installed",pkgCache::State::NotInstalled},
+                            {"config-files",pkgCache::State::ConfigFiles},
+                            {"half-installed",pkgCache::State::HalfInstalled},
                             {"unpacked",pkgCache::State::UnPacked},
                             {"half-configured",pkgCache::State::HalfConfigured},
-                            {"installed",pkgCache::State::Installed},
-                            {"half-installed",pkgCache::State::HalfInstalled},
-                            {"config-files",pkgCache::State::ConfigFiles},
                             {"triggers-awaited",pkgCache::State::TriggersAwaited},
                             {"triggers-pending",pkgCache::State::TriggersPending},
-                            {"post-inst-failed",pkgCache::State::HalfConfigured},
-                            {"removal-failed",pkgCache::State::HalfInstalled},
+                            {"installed",pkgCache::State::Installed},
                             {NULL, 0}};
    if (GrabWord(string(Start,I-Start),StatusList,Pkg->CurrentState) == false)
       return _error->Error("Malformed 3rd word in the Status line");
@@ -669,72 +662,94 @@ const char *debListParser::ParseDepends(const char *Start,const char *Stop,
 
    if (ParseRestrictionsList == true)
    {
-      // Parse a restrictions list
-      if (I != Stop && *I == '<')
+      // Parse a restrictions formula which is in disjunctive normal form:
+      // (foo AND bar) OR (blub AND bla)
+
+      std::vector<string> const profiles = APT::Configuration::getBuildProfiles();
+
+      // if the next character is a restriction list, then by default the
+      // dependency does not apply and the conditions have to be checked
+      // if the next character is not a restriction list, then by default the
+      // dependency applies
+      bool applies1 = (*I != '<');
+      while (I != Stop)
       {
+        if (*I != '<')
+            break;
+
         ++I;
         // malformed
         if (unlikely(I == Stop))
            return 0;
 
-        std::vector<string> const profiles = APT::Configuration::getBuildProfiles();
-
         const char *End = I;
-        bool Found = false;
-        bool NegRestriction = false;
-        while (I != Stop)
-        {
-           // look for whitespace or ending '>'
-           for (;End != Stop && !isspace(*End) && *End != '>'; ++End);
 
-           if (unlikely(End == Stop))
-              return 0;
-
-           if (*I == '!')
+        // if of the prior restriction list is already fulfilled, then
+        // we can just skip to the end of the current list
+        if (applies1) {
+           for (;End != Stop && *End != '>'; ++End);
+           I = ++End;
+           // skip whitespace
+           for (;I != Stop && isspace(*I) != 0; I++);
+        } else {
+           bool applies2 = true;
+           // all the conditions inside a restriction list have to be
+           // met so once we find one that is not met, we can skip to
+           // the end of this list
+           while (I != Stop)
            {
-              NegRestriction = true;
-              ++I;
-           }
+              // look for whitespace or ending '>'
+              // End now points to the character after the current term
+              for (;End != Stop && !isspace(*End) && *End != '>'; ++End);
 
-           std::string restriction(I, End);
+              if (unlikely(End == Stop))
+                 return 0;
 
-           std::string prefix = "profile.";
-           // only support for "profile" prefix, ignore others
-           if (restriction.size() > prefix.size() &&
-                 restriction.substr(0, prefix.size()) == prefix)
-           {
-              // get the name of the profile
-              restriction = restriction.substr(prefix.size());
+              bool NegRestriction = false;
+              if (*I == '!')
+              {
+                 NegRestriction = true;
+                 ++I;
+              }
+
+              std::string restriction(I, End);
 
               if (restriction.empty() == false && profiles.empty() == false &&
-                    std::find(profiles.begin(), profiles.end(), restriction) != profiles.end())
+                 std::find(profiles.begin(), profiles.end(), restriction) != profiles.end())
               {
-                 Found = true;
-                 if (I[-1] != '!')
-                    NegRestriction = false;
-                 // we found a match, so fast-forward to the end of the wildcards
-                 for (; End != Stop && *End != '>'; ++End);
+                 if (NegRestriction) {
+                    applies2 = false;
+                    // since one of the terms does not apply we don't have to check the others
+                    for (; End != Stop && *End != '>'; ++End);
+                 }
+              } else {
+                 if (!NegRestriction) {
+                    applies2 = false;
+                    // since one of the terms does not apply we don't have to check the others
+                    for (; End != Stop && *End != '>'; ++End);
+                 }
+              }
+
+              if (*End++ == '>') {
+                 I = End;
+                 // skip whitespace
+                 for (;I != Stop && isspace(*I) != 0; I++);
+                 break;
               }
-           }
 
-           if (*End++ == '>') {
               I = End;
-              break;
+              // skip whitespace
+              for (;I != Stop && isspace(*I) != 0; I++);
+           }
+           if (applies2) {
+              applies1 = true;
            }
-
-           I = End;
-           for (;I != Stop && isspace(*I) != 0; I++);
         }
-
-        if (NegRestriction == true)
-           Found = !Found;
-
-        if (Found == false)
-           Package = ""; /* not for this restriction */
       }
 
-      // Skip whitespace
-      for (;I != Stop && isspace(*I) != 0; I++);
+      if (applies1 == false) {
+        Package = ""; //not for this restriction
+      }
    }
 
    if (I != Stop && *I == '|')
@@ -788,7 +803,7 @@ bool debListParser::ParseDepends(pkgCache::VerIterator &Ver,
         if (NewDepends(Ver,Package,"none",Version,Op,Type) == false)
            return false;
       }
-      else if (MultiArchEnabled == true && found != string::npos &&
+      else if (found != string::npos &&
               strcmp(Package.c_str() + found, ":any") != 0)
       {
         string Arch = Package.substr(found+1, string::npos);
@@ -797,7 +812,7 @@ bool debListParser::ParseDepends(pkgCache::VerIterator &Ver,
         // … but this is probably the best thing to do.
         if (Arch == "native")
            Arch = _config->Find("APT::Architecture");
-        if (NewDepends(Ver,Package,Arch,Version,Op,Type) == false)
+        if (NewDepends(Ver,Package,Arch,Version,Op | pkgCache::Dep::ArchSpecific,Type) == false)
            return false;
       }
       else
@@ -835,15 +850,21 @@ bool debListParser::ParseProvides(pkgCache::VerIterator &Ver)
       while (1)
       {
         Start = ParseDepends(Start,Stop,Package,Version,Op);
+        const size_t archfound = Package.rfind(':');
         if (Start == 0)
            return _error->Error("Problem parsing Provides line");
         if (Op != pkgCache::Dep::NoOp && Op != pkgCache::Dep::Equals) {
            _error->Warning("Ignoring Provides line with non-equal DepCompareOp for package %s", Package.c_str());
+        } else if (archfound != string::npos) {
+           string OtherArch = Package.substr(archfound+1, string::npos);
+           Package = Package.substr(0, archfound);
+           if (NewProvides(Ver, Package, OtherArch, Version, pkgCache::Flag::ArchSpecific) == false)
+              return false;
         } else if ((Ver->MultiArch & pkgCache::Version::Foreign) == pkgCache::Version::Foreign) {
-           if (NewProvidesAllArch(Ver, Package, Version) == false)
+           if (NewProvidesAllArch(Ver, Package, Version, 0) == false)
               return false;
         } else {
-           if (NewProvides(Ver, Package, Arch, Version) == false)
+           if (NewProvides(Ver, Package, Arch, Version, 0) == false)
               return false;
         }
 
@@ -855,26 +876,14 @@ bool debListParser::ParseProvides(pkgCache::VerIterator &Ver)
    if ((Ver->MultiArch & pkgCache::Version::Allowed) == pkgCache::Version::Allowed)
    {
       string const Package = string(Ver.ParentPkg().Name()).append(":").append("any");
-      return NewProvidesAllArch(Ver, Package, Ver.VerStr());
+      return NewProvidesAllArch(Ver, Package, Ver.VerStr(), pkgCache::Flag::MultiArchImplicit);
    }
    else if ((Ver->MultiArch & pkgCache::Version::Foreign) == pkgCache::Version::Foreign)
-      return NewProvidesAllArch(Ver, Ver.ParentPkg().Name(), Ver.VerStr());
+      return NewProvidesAllArch(Ver, Ver.ParentPkg().Name(), Ver.VerStr(), pkgCache::Flag::MultiArchImplicit);
 
    return true;
 }
                                                                        /*}}}*/
-// ListParser::NewProvides - add provides for all architectures                /*{{{*/
-bool debListParser::NewProvidesAllArch(pkgCache::VerIterator &Ver, string const &Package,
-                               string const &Version) {
-   for (std::vector<string>::const_iterator a = Architectures.begin();
-       a != Architectures.end(); ++a)
-   {
-      if (NewProvides(Ver, Package, *a, Version) == false)
-        return false;
-   }
-   return true;
-}
-                                                                       /*}}}*/
 // ListParser::GrabWord - Matches a word and returns                   /*{{{*/
 // ---------------------------------------------------------------------
 /* Looks for a word in a list of words - for ParseStatus */
@@ -927,43 +936,6 @@ bool debListParser::Step()
    return false;
 }
                                                                        /*}}}*/
-// ListParser::LoadReleaseInfo - Load the release information          /*{{{*/
-// ---------------------------------------------------------------------
-/* */
-bool debListParser::LoadReleaseInfo(pkgCache::PkgFileIterator &FileI,
-                                   FileFd &File, string component)
-{
-   // apt-secure does no longer download individual (per-section) Release
-   // file. to provide Component pinning we use the section name now
-   map_stringitem_t const storage = StoreString(pkgCacheGenerator::MIXED, component);
-   FileI->Component = storage;
-
-   pkgTagFile TagFile(&File, File.Size());
-   pkgTagSection Section;
-   if (_error->PendingError() == true || TagFile.Step(Section) == false)
-      return false;
-
-   std::string data;
-   #define APT_INRELEASE(TYPE, TAG, STORE) \
-   data = Section.FindS(TAG); \
-   if (data.empty() == false) \
-   { \
-      map_stringitem_t const storage = StoreString(pkgCacheGenerator::TYPE, data); \
-      STORE = storage; \
-   }
-   APT_INRELEASE(MIXED, "Suite", FileI->Archive)
-   APT_INRELEASE(MIXED, "Component", FileI->Component)
-   APT_INRELEASE(VERSIONNUMBER, "Version", FileI->Version)
-   APT_INRELEASE(MIXED, "Origin", FileI->Origin)
-   APT_INRELEASE(MIXED, "Codename", FileI->Codename)
-   APT_INRELEASE(MIXED, "Label", FileI->Label)
-   #undef APT_INRELEASE
-   Section.FindFlag("NotAutomatic", FileI->Flags, pkgCache::Flag::NotAutomatic);
-   Section.FindFlag("ButAutomaticUpgrades", FileI->Flags, pkgCache::Flag::ButAutomaticUpgrades);
-
-   return !_error->PendingError();
-}
-                                                                       /*}}}*/
 // ListParser::GetPrio - Convert the priority from a string            /*{{{*/
 // ---------------------------------------------------------------------
 /* */
@@ -976,7 +948,6 @@ unsigned char debListParser::GetPrio(string Str)
    return Out;
 }
                                                                        /*}}}*/
-#if (APT_PKG_MAJOR >= 4 && APT_PKG_MINOR >= 13)
 bool debListParser::SameVersion(unsigned short const Hash,             /*{{{*/
       pkgCache::VerIterator const &Ver)
 {
@@ -996,8 +967,6 @@ bool debListParser::SameVersion(unsigned short const Hash,          /*{{{*/
    return true;
 }
                                                                        /*}}}*/
-#endif
-
 
 debDebFileParser::debDebFileParser(FileFd *File, std::string const &DebFile)
    : debListParser(File, ""), DebFile(DebFile)
@@ -1010,7 +979,7 @@ bool debDebFileParser::UsePackage(pkgCache::PkgIterator &Pkg,
    bool res = debListParser::UsePackage(Pkg, Ver);
    // we use the full file path as a provides so that the file is found
    // by its name
-   if(NewProvidesAllArch(Ver, DebFile, Ver.VerStr()) == false)
+   if(NewProvidesAllArch(Ver, DebFile, Ver.VerStr(), 0) == false)
       return false;
    return res;
 }