diff mbox

Bug#614298: multiarch: apt-get remove of foreign-arch package removes wrong one

Message ID 20110306043901.GB14374@virgil.dodds.net
State New
Headers show

Commit Message

Steve Langasek March 6, 2011, 4:39 a.m. UTC
tags 614298 patch
thanks

Hi David,

Please find attached a tentative patch for this issue.  It's not exactly the
most elegant, but it seemed to be the best we can do without changing the
libapt ABI.  If you prefer a different solution, please let me know and I
can give it a try.
diff mbox

Patch

=== modified file 'apt-pkg/deb/dpkgpm.cc'
--- apt-pkg/deb/dpkgpm.cc	2011-02-03 13:22:32 +0000
+++ apt-pkg/deb/dpkgpm.cc	2011-03-06 04:30:47 +0000
@@ -881,7 +881,10 @@ 
 
       // Generate the argument list
       const char *Args[MaxArgs + 50];
-      
+      // keep track of allocated strings for multiarch package names
+      char *Packages[MaxArgs + 50];
+      unsigned int pkgcount = 0;
+
       // Now check if we are within the MaxArgs limit
       //
       // this code below is problematic, because it may happen that
@@ -989,13 +992,22 @@ 
       }      
       else
       {
+	 string const nativeArch = _config->Find("APT::Architecture");
 	 for (;I != J && Size < MaxArgBytes; I++)
 	 {
 	    if((*I).Pkg.end() == true)
 	       continue;
 	    if (I->Op == Item::Configure && disappearedPkgs.find(I->Pkg.Name()) != disappearedPkgs.end())
 	       continue;
-	    Args[n++] = I->Pkg.Name();
+	    if (I->Pkg.Arch() == nativeArch || !strcmp(I->Pkg.Arch(), "all"))
+	       Args[n++] = I->Pkg.Name();
+	    else
+            {
+	       string const PkgDesc = I->Pkg.Name() + string(":") + string(I->Pkg.Arch());
+	       Packages[pkgcount] = new char[PkgDesc.size()+1];
+	       strncpy(Packages[pkgcount++],PkgDesc.c_str(),PkgDesc.size()+1);
+	       Args[n++] = Packages[pkgcount-1];
+            }
 	    Size += strlen(Args[n-1]);
 	 }	 
       }      
@@ -1145,6 +1157,11 @@ 
       sigemptyset(&sigmask);
       sigprocmask(SIG_BLOCK,&sigmask,&original_sigmask);
 
+      /* clean up the temporary allocation for multiarch package names in
+         the parent, so we don't leak memory when we return. */
+      for (unsigned int i = 0; i < pkgcount; i++)
+	 delete [] Packages[i];
+
       // the result of the waitpid call
       int res;
       int select_ret;

=== modified file 'debian/changelog'
--- debian/changelog	2011-02-24 18:39:12 +0000
+++ debian/changelog	2011-03-06 04:30:47 +0000
@@ -1,10 +1,16 @@ 
 apt (0.8.11.6) UNRELEASED; urgency=low
 
+  [ Christian Perrier ]
   * Fix error in French translation of manpages (apt_preferences(5)).
     Merci, RĂ©mi Vanicat. Closes: #613689
   * Complete French manpage translation
   * Italian translation update (Milo Casagrande). Closes: #614395
 
+  [ Steve Langasek ]
+  * apt-pkg/deb/dpkgpm.cc: make sure that for multiarch packages, we're
+    passing the full qualified package name to dpkg for removals.
+    Closes: #614298
+
  -- Christian Perrier <bubulle@debian.org>  Fri, 18 Feb 2011 05:53:49 +0100
 
 apt (0.8.11.5) unstable; urgency=low