]> git.saurik.com Git - apt.git/commitdiff
Version 3 for DPkg::Pre-Install-Pkgs with MultiArch info
authorDavid Kalnischkies <kalnischkies@gmail.com>
Wed, 26 Jun 2013 15:37:57 +0000 (17:37 +0200)
committerDavid Kalnischkies <kalnischkies@gmail.com>
Thu, 11 Jul 2013 16:34:21 +0000 (18:34 +0200)
Adds on top of Version 2 to all displayed version numbers the
architecture as well as the MultiArch flag for consumption by the hooks.

Most of the time the architecture will be the same for both versions
displayed, but packages might change from "all" to "any" (or back)
between versions so we can't display the architecture for packages.

Pseudo-Format for Version 3:
<name> <version> <arch> <m-a-flag> <compare> <version> <arch> <m-a-flag>

Examples:
stuff - - none < 1 amd64 none **CONFIGURE**
libsame 1 i386 same < 2 i386 same **CONFIGURE**
stuff 2 i386 none > 1 i386 none **CONFIGURE**
libsame 2 i386 same > - - none **REMOVE**
toolkit 1 all foreign > - - none **REMOVE**

Closes: #712116
apt-pkg/cacheiterators.h
apt-pkg/deb/dpkgpm.cc
apt-pkg/deb/dpkgpm.h
apt-pkg/pkgcache.cc
doc/apt.conf.5.xml
test/integration/test-bug-712116-dpkg-pre-install-pkgs-hook-multiarch [new file with mode: 0755]

index 179a0e963a0eef27ed006cc31e25b09d8fe81c5f..886d84838ab7b8f99b1d3b03933b8611557e3028 100644 (file)
@@ -220,6 +220,7 @@ class pkgCache::VerIterator : public Iterator<Version, VerIterator> {
        inline VerFileIterator FileList() const;
        bool Downloadable() const;
        inline const char *PriorityType() const {return Owner->Priority(S->Priority);};
+       const char *MultiArchType() const;
        std::string RelStr() const;
 
        bool Automatic() const;
index 3bc31dc3733d0c81968e34d0b9c6f56176d5e00b..fb04735353c85af96b62f20b2c54d4b1b85d8cc2 100644 (file)
@@ -238,15 +238,23 @@ bool pkgDPkgPM::Remove(PkgIterator Pkg,bool Purge)
    return true;
 }
                                                                        /*}}}*/
-// DPkgPM::SendV2Pkgs - Send version 2 package info                    /*{{{*/
+// DPkgPM::SendPkgInfo - Send info for install-pkgs hook               /*{{{*/
 // ---------------------------------------------------------------------
 /* This is part of the helper script communication interface, it sends
    very complete information down to the other end of the pipe.*/
 bool pkgDPkgPM::SendV2Pkgs(FILE *F)
 {
-   fprintf(F,"VERSION 2\n");
-   
-   /* Write out all of the configuration directives by walking the 
+   return SendPkgsInfo(F, 2);
+}
+bool pkgDPkgPM::SendPkgsInfo(FILE * const F, unsigned int const &Version)
+{
+   // This version of APT supports only v3, so don't sent higher versions
+   if (Version <= 3)
+      fprintf(F,"VERSION %u\n", Version);
+   else
+      fprintf(F,"VERSION 3\n");
+
+   /* Write out all of the configuration directives by walking the
       configuration tree */
    const Configuration::Item *Top = _config->Tree(0);
    for (; Top != 0;)
@@ -280,30 +288,51 @@ bool pkgDPkgPM::SendV2Pkgs(FILE *F)
       pkgDepCache::StateCache &S = Cache[I->Pkg];
       
       fprintf(F,"%s ",I->Pkg.Name());
-      // Current version
-      if (I->Pkg->CurrentVer == 0)
-        fprintf(F,"- ");
+
+      // Current version which we are going to replace
+      pkgCache::VerIterator CurVer = I->Pkg.CurrentVer();
+      if (CurVer.end() == true && (I->Op == Item::Remove || I->Op == Item::Purge))
+        CurVer = FindNowVersion(I->Pkg);
+
+      else if (CurVer.end() == true)
+      {
+        if (Version <= 2)
+           fprintf(F, "- ");
+        else
+           fprintf(F, "- - none ");
+      }
       else
-        fprintf(F,"%s ",I->Pkg.CurrentVer().VerStr());
-      
-      // Show the compare operator
-      // Target version
+      {
+        fprintf(F, "%s ", CurVer.VerStr());
+        if (Version >= 3)
+           fprintf(F, "%s %s ", CurVer.Arch(), CurVer.MultiArchType());
+      }
+
+      // Show the compare operator between current and install version
       if (S.InstallVer != 0)
       {
+        pkgCache::VerIterator const InstVer = S.InstVerIter(Cache);
         int Comp = 2;
-        if (I->Pkg->CurrentVer != 0)
-           Comp = S.InstVerIter(Cache).CompareVer(I->Pkg.CurrentVer());
+        if (CurVer.end() == false)
+           Comp = InstVer.CompareVer(CurVer);
         if (Comp < 0)
            fprintf(F,"> ");
-        if (Comp == 0)
+        else if (Comp == 0)
            fprintf(F,"= ");
-        if (Comp > 0)
+        else if (Comp > 0)
            fprintf(F,"< ");
-        fprintf(F,"%s ",S.InstVerIter(Cache).VerStr());
+        fprintf(F, "%s ", InstVer.VerStr());
+        if (Version >= 3)
+           fprintf(F, "%s %s ", InstVer.Arch(), InstVer.MultiArchType());
       }
       else
-        fprintf(F,"> - ");
-      
+      {
+        if (Version <= 2)
+           fprintf(F, "> - ");
+        else
+           fprintf(F, "> - - none ");
+      }
+
       // Show the filename/operation
       if (I->Op == Item::Install)
       {
@@ -313,9 +342,9 @@ bool pkgDPkgPM::SendV2Pkgs(FILE *F)
         else
            fprintf(F,"%s\n",I->File.c_str());
       }      
-      if (I->Op == Item::Configure)
+      else if (I->Op == Item::Configure)
         fprintf(F,"**CONFIGURE**\n");
-      if (I->Op == Item::Remove ||
+      else if (I->Op == Item::Remove ||
          I->Op == Item::Purge)
         fprintf(F,"**REMOVE**\n");
       
@@ -404,7 +433,7 @@ bool pkgDPkgPM::RunScriptsWithPkgs(const char *Cnf)
         }
       }
       else
-        SendV2Pkgs(F);
+        SendPkgsInfo(F, Version);
 
       fclose(F);
       
index aab39f633a9a1e4c3a5018102d939899deadb98c..c31d56f8ea995c4563ecb090df5bc75bc86015d7 100644 (file)
@@ -14,6 +14,7 @@
 #include <vector>
 #include <map>
 #include <stdio.h>
+#include <apt-pkg/macros.h>
 
 #ifndef APT_8_CLEANER_HEADERS
 using std::vector;
@@ -79,7 +80,8 @@ class pkgDPkgPM : public pkgPackageManager
 
    // Helpers
    bool RunScriptsWithPkgs(const char *Cnf);
-   bool SendV2Pkgs(FILE *F);
+   __deprecated bool SendV2Pkgs(FILE *F);
+   bool SendPkgsInfo(FILE * const F, unsigned int const &Version);
    void WriteHistoryTag(std::string const &tag, std::string value);
 
    // apport integration
index d7725563b07c8979df8eb9e23a0d73cb33faed47..52e814c0b9b69ac3b34e4c43a958a3aa0712d4f0 100644 (file)
@@ -924,6 +924,18 @@ string pkgCache::VerIterator::RelStr() const
    return Res;
 }
                                                                        /*}}}*/
+// VerIterator::MultiArchType - string representing MultiArch flag     /*{{{*/
+const char * pkgCache::VerIterator::MultiArchType() const
+{
+   if ((S->MultiArch & pkgCache::Version::Same) == pkgCache::Version::Same)
+      return "same";
+   else if ((S->MultiArch & pkgCache::Version::Foreign) == pkgCache::Version::Foreign)
+      return "foreign";
+   else if ((S->MultiArch & pkgCache::Version::Allowed) == pkgCache::Version::Allowed)
+      return "allowed";
+   return "none";
+}
+                                                                       /*}}}*/
 // PkgFileIterator::IsOk - Checks if the cache is in sync with the file        /*{{{*/
 // ---------------------------------------------------------------------
 /* This stats the file and compares its stats with the ones that were
index 3cf3136d39a00ec7b74488a0bc2925cb99c4b410..9973fe42be54e99b3d6e511ea492fb6033641c23 100644 (file)
@@ -688,11 +688,17 @@ DPkg::Pre-Install-Pkgs {"/usr/sbin/dpkg-preconfigure --apt";};
      will abort. APT will pass the filenames of all .deb files it is going to
      install to the commands, one per line on standard input.</para>
 
-     <para>Version 2 of this protocol dumps more information, including the 
+     <para>Version 2 of this protocol dumps more information, including the
      protocol version, the APT configuration space and the packages, files
-     and versions being changed. Version 2 is enabled by setting 
-     <literal>DPkg::Tools::options::cmd::Version</literal> to 2. <literal>cmd</literal> is a
-     command given to <literal>Pre-Install-Pkgs</literal>.</para></listitem>
+     and versions being changed. Version 3 adds the architecture and <literal>MultiArch</literal>
+     flag to each version being dumped.</para>
+
+     <para>The version of the protocol to be used for the command
+     <literal><replaceable>cmd</replaceable></literal> can be chosen by setting
+     <literal>DPkg::Tools::options::<replaceable>cmd</replaceable>::Version</literal>
+     accordingly, the default being version 1. If APT isn't supporting the requested
+     version it will send the information in the highest version it has support for instead.
+     </para></listitem>
      </varlistentry>
 
      <varlistentry><term><option>Run-Directory</option></term>
diff --git a/test/integration/test-bug-712116-dpkg-pre-install-pkgs-hook-multiarch b/test/integration/test-bug-712116-dpkg-pre-install-pkgs-hook-multiarch
new file mode 100755 (executable)
index 0000000..aee44f7
--- /dev/null
@@ -0,0 +1,95 @@
+#!/bin/sh
+set -e
+
+TESTDIR=$(readlink -f $(dirname $0))
+. $TESTDIR/framework
+setupenvironment
+configarchitecture 'amd64' 'i386'
+
+buildsimplenativepackage 'toolkit' 'all' '1' 'stable' 'Multi-Arch: foreign'
+buildsimplenativepackage 'toolkit' 'amd64' '2' 'unstable' 'Multi-Arch: foreign'
+buildsimplenativepackage 'libsame' 'i386,amd64' '1' 'stable' 'Multi-Arch: same'
+buildsimplenativepackage 'libsame' 'i386,amd64' '2' 'unstable' 'Multi-Arch: same'
+buildsimplenativepackage 'stuff' 'i386,amd64' '1' 'stable' 'Depends: libsame (= 1), toolkit (= 1)'
+buildsimplenativepackage 'stuff' 'i386,amd64' '2' 'unstable' 'Depends: libsame (= 2), toolkit (= 2)'
+
+setupaptarchive
+
+hook='pre-install-pkgs'
+
+enablehookversion() {
+       echo "#!/bin/sh
+while read line; do
+       if echo \"\$line\" | grep -Fq '**'; then
+               echo \"\$line\"
+       fi
+done > ${hook}-v${1}.list" > ${hook}-v${1}.sh
+       chmod +x ${hook}-v${1}.sh
+       echo "dpkg::${hook}:: \"./${hook}-v${1}.sh --foo -bar\";
+DPkg::Tools::options::\"./${hook}-v${1}.sh\"::Version \"$1\";" > rootdir/etc/apt/apt.conf.d/hook-v$1
+}
+
+enablehookversion 2
+enablehookversion 3
+
+observehook() {
+       rm -f ${hook}-v2.list ${hook}-v3.list
+       msgtest 'Observe hooks while' "$*"
+       aptget "$@" -y --force-yes >/dev/null 2>&1 && msgpass || msgfail
+}
+
+observehook install stuff -t stable
+testfileequal "${hook}-v2.list" 'libsame - < 1 **CONFIGURE**
+toolkit - < 1 **CONFIGURE**
+stuff - < 1 **CONFIGURE**'
+testfileequal "${hook}-v3.list" 'libsame - - none < 1 amd64 same **CONFIGURE**
+toolkit - - none < 1 all foreign **CONFIGURE**
+stuff - - none < 1 amd64 none **CONFIGURE**'
+
+observehook install stuff -t unstable
+testfileequal "${hook}-v2.list" 'libsame 1 < 2 **CONFIGURE**
+toolkit 1 < 2 **CONFIGURE**
+stuff 1 < 2 **CONFIGURE**'
+testfileequal "${hook}-v3.list" 'libsame 1 amd64 same < 2 amd64 same **CONFIGURE**
+toolkit 1 all foreign < 2 amd64 foreign **CONFIGURE**
+stuff 1 amd64 none < 2 amd64 none **CONFIGURE**'
+
+observehook install stuff:i386 -t unstable
+testfileequal "${hook}-v2.list" 'stuff 2 > - **REMOVE**
+libsame - < 2 **CONFIGURE**
+stuff - < 2 **CONFIGURE**'
+testfileequal "${hook}-v3.list" 'stuff 2 amd64 none > - - none **REMOVE**
+libsame - - none < 2 i386 same **CONFIGURE**
+stuff - - none < 2 i386 none **CONFIGURE**'
+
+observehook remove libsame
+testfileequal "${hook}-v2.list" 'libsame 2 > - **REMOVE**'
+testfileequal "${hook}-v3.list" 'libsame 2 amd64 same > - - none **REMOVE**'
+
+observehook install stuff:i386/stable libsame:i386/stable toolkit/stable
+testfileequal "${hook}-v2.list" 'libsame 2 > 1 **CONFIGURE**
+toolkit 2 > 1 **CONFIGURE**
+stuff 2 > 1 **CONFIGURE**'
+testfileequal "${hook}-v3.list" 'libsame 2 i386 same > 1 i386 same **CONFIGURE**
+toolkit 2 amd64 foreign > 1 all foreign **CONFIGURE**
+stuff 2 i386 none > 1 i386 none **CONFIGURE**'
+
+observehook install 'libsame:*'
+testfileequal "${hook}-v2.list" 'libsame 1 < 2 **CONFIGURE**
+libsame - < 2 **CONFIGURE**
+toolkit 1 < 2 **CONFIGURE**
+stuff 1 < 2 **CONFIGURE**'
+testfileequal "${hook}-v3.list" 'libsame 1 i386 same < 2 i386 same **CONFIGURE**
+libsame - - none < 2 amd64 same **CONFIGURE**
+toolkit 1 all foreign < 2 amd64 foreign **CONFIGURE**
+stuff 1 i386 none < 2 i386 none **CONFIGURE**'
+
+observehook purge stuff:i386 'libsame:*' toolkit
+testfileequal "${hook}-v2.list" 'libsame 2 > - **REMOVE**
+stuff 2 > - **REMOVE**
+libsame 2 > - **REMOVE**
+toolkit 2 > - **REMOVE**'
+testfileequal "${hook}-v3.list" 'libsame 2 amd64 same > - - none **REMOVE**
+stuff 2 i386 none > - - none **REMOVE**
+libsame 2 i386 same > - - none **REMOVE**
+toolkit 2 amd64 foreign > - - none **REMOVE**'