]> git.saurik.com Git - apt.git/blobdiff - apt-pkg/deb/dpkgpm.cc
* apt-pkg/deb/dpkgpm.cc:
[apt.git] / apt-pkg / deb / dpkgpm.cc
index 4dc0baa5049c552290bb8300c05c4d259dcccd92..4c473c1c2d93d282a25956d7a7eae560cbe9bfd3 100644 (file)
@@ -123,6 +123,18 @@ ionice(int PID)
    return ExecWait(Process, "ionice");
 }
 
+// dpkgChrootDirectory - chrooting for dpkg if needed                  /*{{{*/
+static void dpkgChrootDirectory()
+{
+   std::string const chrootDir = _config->FindDir("DPkg::Chroot-Directory");
+   if (chrootDir == "/")
+      return;
+   std::cerr << "Chrooting into " << chrootDir << std::endl;
+   if (chroot(chrootDir.c_str()) != 0)
+      _exit(100);
+}
+                                                                       /*}}}*/
+
 // DPkgPM::pkgDPkgPM - Constructor                                     /*{{{*/
 // ---------------------------------------------------------------------
 /* */
@@ -328,15 +340,7 @@ bool pkgDPkgPM::RunScriptsWithPkgs(const char *Cnf)
         SetCloseExec(STDIN_FILENO,false);      
         SetCloseExec(STDERR_FILENO,false);
 
-        if (_config->FindDir("DPkg::Chroot-Directory","/") != "/") 
-        {
-           std::cerr << "Chrooting into " 
-                     << _config->FindDir("DPkg::Chroot-Directory") 
-                     << std::endl;
-           if (chroot(_config->FindDir("DPkg::Chroot-Directory","/").c_str()) != 0)
-              _exit(100);
-        }
-
+        dpkgChrootDirectory();
         const char *Args[4];
         Args[0] = "/bin/sh";
         Args[1] = "-c";
@@ -858,6 +862,12 @@ bool pkgDPkgPM::Go(int OutStatusFd)
    pid_t dpkgAssertMultiArch = ExecFork();
    if (dpkgAssertMultiArch == 0)
    {
+      dpkgChrootDirectory();
+      // redirect everything to the ultimate sink as we only need the exit-status
+      int const nullfd = open("/dev/null", O_RDONLY);
+      dup2(nullfd, STDIN_FILENO);
+      dup2(nullfd, STDOUT_FILENO);
+      dup2(nullfd, STDERR_FILENO);
       execv(Args[0], (char**) &Args[0]);
       _error->WarningE("dpkgGo", "Can't detect if dpkg supports multi-arch!");
       _exit(2);
@@ -1085,7 +1095,14 @@ bool pkgDPkgPM::Go(int OutStatusFd)
            }
            else
            {
-              char * const fullname = strdup(I->Pkg.FullName(false).c_str());
+              pkgCache::VerIterator PkgVer;
+              std::string name = I->Pkg.Name();
+              if (Op == Item::Remove || Op == Item::Purge)
+                 PkgVer = I->Pkg.CurrentVer();
+              else
+                 PkgVer = Cache[I->Pkg].InstVerIter(Cache);
+              name.append(":").append(PkgVer.Arch());
+              char * const fullname = strdup(name.c_str());
               Packages.push_back(fullname);
               ADDARG(fullname);
            }
@@ -1190,14 +1207,7 @@ bool pkgDPkgPM::Go(int OutStatusFd)
         }
         close(fd[0]); // close the read end of the pipe
 
-        if (_config->FindDir("DPkg::Chroot-Directory","/") != "/") 
-        {
-           std::cerr << "Chrooting into " 
-                     << _config->FindDir("DPkg::Chroot-Directory") 
-                     << std::endl;
-           if (chroot(_config->FindDir("DPkg::Chroot-Directory","/").c_str()) != 0)
-              _exit(100);
-        }
+        dpkgChrootDirectory();
 
         if (chdir(_config->FindDir("DPkg::Run-Directory","/").c_str()) != 0)
            _exit(100);