Add new Debug::RunScripts option
[ntk/apt.git] / apt-pkg / deb / deblistparser.cc
index 7777d65..a1bcfb7 100644 (file)
@@ -104,44 +104,49 @@ string debListParser::Version()
    return Section.FindS("Version");
 }
                                                                        /*}}}*/
-// ListParser::NewVersion - Fill in the version structure              /*{{{*/
-// ---------------------------------------------------------------------
-/* */
-bool debListParser::NewVersion(pkgCache::VerIterator &Ver)
+unsigned char debListParser::ParseMultiArch(bool const showErrors)     /*{{{*/
 {
-   // Parse the section
-   Ver->Section = UniqFindTagWrite("Section");
-
-   // Parse multi-arch
+   unsigned char MA;
    string const MultiArch = Section.FindS("Multi-Arch");
    if (MultiArch.empty() == true)
-      Ver->MultiArch = pkgCache::Version::None;
+      MA = pkgCache::Version::None;
    else if (MultiArch == "same") {
-      // Parse multi-arch
       if (ArchitectureAll() == true)
       {
-        /* Arch all packages can't be Multi-Arch: same */
-        _error->Warning("Architecture: all package '%s' can't be Multi-Arch: same",
-                       Section.FindS("Package").c_str());
-        Ver->MultiArch = pkgCache::Version::None;
+        if (showErrors == true)
+           _error->Warning("Architecture: all package '%s' can't be Multi-Arch: same",
+                 Section.FindS("Package").c_str());
+        MA = pkgCache::Version::None;
       }
       else
-        Ver->MultiArch = pkgCache::Version::Same;
+        MA = pkgCache::Version::Same;
    }
    else if (MultiArch == "foreign")
-      Ver->MultiArch = pkgCache::Version::Foreign;
+      MA = pkgCache::Version::Foreign;
    else if (MultiArch == "allowed")
-      Ver->MultiArch = pkgCache::Version::Allowed;
+      MA = pkgCache::Version::Allowed;
    else
    {
-      _error->Warning("Unknown Multi-Arch type '%s' for package '%s'",
-                       MultiArch.c_str(), Section.FindS("Package").c_str());
-      Ver->MultiArch = pkgCache::Version::None;
+      if (showErrors == true)
+        _error->Warning("Unknown Multi-Arch type '%s' for package '%s'",
+              MultiArch.c_str(), Section.FindS("Package").c_str());
+      MA = pkgCache::Version::None;
    }
 
    if (ArchitectureAll() == true)
-      Ver->MultiArch |= pkgCache::Version::All;
+      MA |= pkgCache::Version::All;
 
+   return MA;
+}
+                                                                       /*}}}*/
+// ListParser::NewVersion - Fill in the version structure              /*{{{*/
+// ---------------------------------------------------------------------
+/* */
+bool debListParser::NewVersion(pkgCache::VerIterator &Ver)
+{
+   // Parse the section
+   Ver->Section = UniqFindTagWrite("Section");
+   Ver->MultiArch = ParseMultiArch(true);
    // Archive Size
    Ver->Size = Section.FindULL("Size");
    // Unpacked Size (in K)
@@ -933,3 +938,24 @@ 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)
+{
+   if (pkgCacheGenerator::ListParser::SameVersion(Hash, Ver) == false)
+      return false;
+   // status file has no (Download)Size, but all others are fair game
+   // 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)
+      return false;
+   // available everywhere, but easier to check here than to include in VersionHash
+   unsigned char MultiArch = ParseMultiArch(false);
+   if (MultiArch != Ver->MultiArch)
+      return false;
+   // for all practical proposes (we can check): same version
+   return true;
+}
+                                                                       /*}}}*/
+#endif