diff options
-rw-r--r-- | apt-pkg/aptconfiguration.cc | 65 | ||||
-rw-r--r-- | apt-pkg/contrib/configuration.cc | 10 | ||||
-rw-r--r-- | apt-pkg/deb/dpkgpm.cc | 82 | ||||
-rw-r--r-- | apt-pkg/depcache.cc | 39 | ||||
-rw-r--r-- | debian/changelog | 37 | ||||
-rw-r--r-- | methods/http.cc | 14 | ||||
-rw-r--r-- | methods/https.cc | 13 | ||||
-rwxr-xr-x | test/integration/test-bug-657695-resolver-breaks-on-virtuals | 51 | ||||
-rwxr-xr-x | test/integration/test-ordering-ignore-not-matching-breaks | 56 | ||||
-rwxr-xr-x | test/integration/test-ubuntu-bug-859188-multiarch-reinstall | 28 | ||||
-rw-r--r-- | test/libapt/configuration_test.cc | 9 |
11 files changed, 362 insertions, 42 deletions
diff --git a/apt-pkg/aptconfiguration.cc b/apt-pkg/aptconfiguration.cc index c7da4cf35..b5ad74831 100644 --- a/apt-pkg/aptconfiguration.cc +++ b/apt-pkg/aptconfiguration.cc @@ -20,6 +20,7 @@ #include <sys/types.h> #include <dirent.h> #include <stdio.h> +#include <fcntl.h> #include <algorithm> #include <string> @@ -328,13 +329,60 @@ std::vector<std::string> const Configuration::getArchitectures(bool const &Cache // FIXME: It is a bit unclean to have debian specific code here… if (archs.empty() == true) { archs.push_back(arch); - string dpkgcall = _config->Find("Dir::Bin::dpkg", "dpkg"); - std::vector<string> const dpkgoptions = _config->FindVector("DPkg::options"); - for (std::vector<string>::const_iterator o = dpkgoptions.begin(); - o != dpkgoptions.end(); ++o) - dpkgcall.append(" ").append(*o); - dpkgcall.append(" --print-foreign-architectures 2> /dev/null"); - FILE *dpkg = popen(dpkgcall.c_str(), "r"); + + // Generate the base argument list for dpkg + std::vector<const char *> Args; + string Tmp = _config->Find("Dir::Bin::dpkg","dpkg"); + { + string const dpkgChrootDir = _config->FindDir("DPkg::Chroot-Directory", "/"); + size_t dpkgChrootLen = dpkgChrootDir.length(); + if (dpkgChrootDir != "/" && Tmp.find(dpkgChrootDir) == 0) { + if (dpkgChrootDir[dpkgChrootLen - 1] == '/') + --dpkgChrootLen; + Tmp = Tmp.substr(dpkgChrootLen); + } + } + Args.push_back(Tmp.c_str()); + + // Stick in any custom dpkg options + ::Configuration::Item const *Opts = _config->Tree("DPkg::Options"); + if (Opts != 0) { + Opts = Opts->Child; + for (; Opts != 0; Opts = Opts->Next) + { + if (Opts->Value.empty() == true) + continue; + Args.push_back(Opts->Value.c_str()); + } + } + + Args.push_back("--print-foreign-architectures"); + Args.push_back(NULL); + + int external[2] = {-1, -1}; + if (pipe(external) != 0) + { + _error->WarningE("getArchitecture", "Can't create IPC pipe for dpkg --print-foreign-architectures"); + return archs; + } + + pid_t dpkgMultiArch = ExecFork(); + if (dpkgMultiArch == 0) { + close(external[0]); + std::string const chrootDir = _config->FindDir("DPkg::Chroot-Directory"); + if (chrootDir != "/" && chroot(chrootDir.c_str()) != 0) + _error->WarningE("getArchitecture", "Couldn't chroot into %s for dpkg --print-foreign-architectures", chrootDir.c_str()); + int const nullfd = open("/dev/null", O_RDONLY); + dup2(nullfd, STDIN_FILENO); + dup2(external[1], STDOUT_FILENO); + dup2(nullfd, STDERR_FILENO); + execv(Args[0], (char**) &Args[0]); + _error->WarningE("getArchitecture", "Can't detect foreign architectures supported by dpkg!"); + _exit(100); + } + close(external[1]); + + FILE *dpkg = fdopen(external[0], "r"); char buf[1024]; if(dpkg != NULL) { while (fgets(buf, sizeof(buf), dpkg) != NULL) { @@ -349,8 +397,9 @@ std::vector<std::string> const Configuration::getArchitectures(bool const &Cache arch = strtok(NULL, " "); } } - pclose(dpkg); + fclose(dpkg); } + ExecWait(dpkgMultiArch, "dpkg --print-foreign-architectures", true); return archs; } diff --git a/apt-pkg/contrib/configuration.cc b/apt-pkg/contrib/configuration.cc index 0949ec223..36866a35a 100644 --- a/apt-pkg/contrib/configuration.cc +++ b/apt-pkg/contrib/configuration.cc @@ -185,8 +185,14 @@ string Configuration::FindFile(const char *Name,const char *Default) const } string val = Itm->Value; - while (Itm->Parent != 0 && Itm->Parent->Value.empty() == false) - { + while (Itm->Parent != 0) + { + if (Itm->Parent->Value.empty() == true) + { + Itm = Itm->Parent; + continue; + } + // Absolute if (val.length() >= 1 && val[0] == '/') break; diff --git a/apt-pkg/deb/dpkgpm.cc b/apt-pkg/deb/dpkgpm.cc index 82b127c2f..d28461dab 100644 --- a/apt-pkg/deb/dpkgpm.cc +++ b/apt-pkg/deb/dpkgpm.cc @@ -122,6 +122,45 @@ 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); +} + /*}}}*/ + + +// FindNowVersion - Helper to find a Version in "now" state /*{{{*/ +// --------------------------------------------------------------------- +/* This is helpful when a package is no longer installed but has residual + * config files + */ +static +pkgCache::VerIterator FindNowVersion(const pkgCache::PkgIterator &Pkg) +{ + pkgCache::VerIterator Ver; + for (Ver = Pkg.VersionList(); Ver.end() == false; Ver++) + { + pkgCache::VerFileIterator Vf = Ver.FileList(); + pkgCache::PkgFileIterator F = Vf.File(); + for (F = Vf.File(); F.end() == false; F++) + { + if (F && F.Archive()) + { + if (strcmp(F.Archive(), "now")) + return Ver; + } + } + } + return Ver; +} + /*}}}*/ + // DPkgPM::pkgDPkgPM - Constructor /*{{{*/ // --------------------------------------------------------------------- /* */ @@ -327,15 +366,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"; @@ -831,7 +862,17 @@ bool pkgDPkgPM::Go(int OutStatusFd) // Generate the base argument list for dpkg std::vector<const char *> Args; unsigned long StartSize = 0; - string const Tmp = _config->Find("Dir::Bin::dpkg","dpkg"); + string Tmp = _config->Find("Dir::Bin::dpkg","dpkg"); + { + string const dpkgChrootDir = _config->FindDir("DPkg::Chroot-Directory", "/"); + size_t dpkgChrootLen = dpkgChrootDir.length(); + if (dpkgChrootDir != "/" && Tmp.find(dpkgChrootDir) == 0) + { + if (dpkgChrootDir[dpkgChrootLen - 1] == '/') + --dpkgChrootLen; + Tmp = Tmp.substr(dpkgChrootLen); + } + } Args.push_back(Tmp.c_str()); StartSize += Tmp.length(); @@ -857,6 +898,7 @@ 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); @@ -1091,11 +1133,18 @@ bool pkgDPkgPM::Go(int OutStatusFd) { pkgCache::VerIterator PkgVer; std::string name = I->Pkg.Name(); - if (Op == Item::Remove || Op == Item::Purge) + if (Op == Item::Remove || Op == Item::Purge) + { PkgVer = I->Pkg.CurrentVer(); + if(PkgVer.end() == true) + PkgVer = FindNowVersion(I->Pkg); + } else PkgVer = Cache[I->Pkg].InstVerIter(Cache); - name.append(":").append(PkgVer.Arch()); + if (PkgVer.end() == false) + name.append(":").append(PkgVer.Arch()); + else + _error->Warning("Can not find PkgVer for '%s'", name.c_str()); char * const fullname = strdup(name.c_str()); Packages.push_back(fullname); ADDARG(fullname); @@ -1201,14 +1250,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); diff --git a/apt-pkg/depcache.cc b/apt-pkg/depcache.cc index 7aaf1c61b..fdfd1c713 100644 --- a/apt-pkg/depcache.cc +++ b/apt-pkg/depcache.cc @@ -1241,19 +1241,36 @@ void pkgDepCache::SetReInstall(PkgIterator const &Pkg,bool To) if (unlikely(Pkg.end() == true)) return; + APT::PackageList pkglist; + if (Pkg->CurrentVer != 0 && + (Pkg.CurrentVer()-> MultiArch & pkgCache::Version::Same) == pkgCache::Version::Same) + { + pkgCache::GrpIterator Grp = Pkg.Group(); + for (pkgCache::PkgIterator P = Grp.PackageList(); P.end() == false; P = Grp.NextPkg(P)) + { + if (P->CurrentVer != 0) + pkglist.insert(P); + } + } + else + pkglist.insert(Pkg); + ActionGroup group(*this); - RemoveSizes(Pkg); - RemoveStates(Pkg); - - StateCache &P = PkgState[Pkg->ID]; - if (To == true) - P.iFlags |= ReInstall; - else - P.iFlags &= ~ReInstall; - - AddStates(Pkg); - AddSizes(Pkg); + for (APT::PackageList::const_iterator Pkg = pkglist.begin(); Pkg != pkglist.end(); ++Pkg) + { + RemoveSizes(Pkg); + RemoveStates(Pkg); + + StateCache &P = PkgState[Pkg->ID]; + if (To == true) + P.iFlags |= ReInstall; + else + P.iFlags &= ~ReInstall; + + AddStates(Pkg); + AddSizes(Pkg); + } } /*}}}*/ // DepCache::SetCandidateVersion - Change the candidate version /*{{{*/ diff --git a/debian/changelog b/debian/changelog index 128c9b0d5..4d086c569 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,40 @@ +apt (0.8.16~exp12ubuntu2) precise; urgency=low + + [ David Kalnischkies ] + * apt-pkg/deb/dpkgpm.cc: + - chroot if needed before dpkg --assert-multi-arch + - ensure that dpkg binary doesn't have the chroot-directory prefixed + * apt-pkg/depcache.cc: + - if a M-A:same package is marked for reinstall, mark all it's installed + silbings for reinstallation as well (LP: #859188) + * apt-pkg/contrib/configuration.cc: + - do not stop parent transversal in FindDir if the value is empty + * methods/http{s,}.cc: + - if a file without an extension is requested send an 'Accept: text/*' + header to avoid that the server chooses unsupported compressed files + in a content-negotation attempt (Closes: #657560) + * apt-pkg/aptconfiguration.cc: + - chroot if needed before calling dpkg --print-foreign-architectures + + [ Steve Langasek ] + * cmdline/apt-get.cc: + - for cross-build-dependencies M-A: none should be DEB_HOST_ARCH, + not DEB_BUILD_ARCH (Closes: #646288) + + [ Colin Watson ] + * apt-pkg/algorithms.cc: + - don't break out of the main-resolver loop for Breaks to deal with all + of them in a single iteration (Closes: #657695, LP: #922485) + - use a signed int instead of short for score calculation as upgrades + become so big now that it can overflow (Closes: #657732, LP: #917173) + + [ Michael Vogt ] + * apt-pkg/deb/dpkgpm.cc: + - fix crash when a package is in removed but residual config state + (LP: #923807) + + -- Michael Vogt <michael.vogt@ubuntu.com> Mon, 30 Jan 2012 21:03:12 +0100 + apt (0.8.16~exp12ubuntu1) precise; urgency=low [ Michael Vogt ] diff --git a/methods/http.cc b/methods/http.cc index b8ed43cd2..2721b1224 100644 --- a/methods/http.cc +++ b/methods/http.cc @@ -716,7 +716,19 @@ void HttpMethod::SendReq(FetchItem *Itm,CircleBuf &Out) } } - + // If we ask for uncompressed files servers might respond with content- + // negotation which lets us end up with compressed files we do not support, + // see 657029, 657560 and co, so if we have no extension on the request + // ask for text only. As a sidenote: If there is nothing to negotate servers + // seem to be nice and ignore it. + if (_config->FindB("Acquire::http::SendAccept", true) == true) + { + size_t const filepos = Itm->Uri.find_last_of('/'); + string const file = Itm->Uri.substr(filepos + 1); + if (flExtension(file) == file) + strcat(Buf,"Accept: text/*\r\n"); + } + string Req = Buf; // Check for a partial file diff --git a/methods/https.cc b/methods/https.cc index 6de18b8e0..4f2d581d2 100644 --- a/methods/https.cc +++ b/methods/https.cc @@ -242,6 +242,19 @@ bool HttpsMethod::Fetch(FetchItem *Itm) // error handling curl_easy_setopt(curl, CURLOPT_ERRORBUFFER, curl_errorstr); + // If we ask for uncompressed files servers might respond with content- + // negotation which lets us end up with compressed files we do not support, + // see 657029, 657560 and co, so if we have no extension on the request + // ask for text only. As a sidenote: If there is nothing to negotate servers + // seem to be nice and ignore it. + if (_config->FindB("Acquire::https::SendAccept", _config->FindB("Acquire::http::SendAccept", true)) == true) + { + size_t const filepos = Itm->Uri.find_last_of('/'); + string const file = Itm->Uri.substr(filepos + 1); + if (flExtension(file) == file) + headers = curl_slist_append(headers, "Accept: text/*"); + } + // if we have the file send an if-range query with a range header if (stat(Itm->DestFile.c_str(),&SBuf) >= 0 && SBuf.st_size > 0) { diff --git a/test/integration/test-bug-657695-resolver-breaks-on-virtuals b/test/integration/test-bug-657695-resolver-breaks-on-virtuals new file mode 100755 index 000000000..e9b27cfcd --- /dev/null +++ b/test/integration/test-bug-657695-resolver-breaks-on-virtuals @@ -0,0 +1,51 @@ +#!/bin/sh +set -e + +TESTDIR=$(readlink -f $(dirname $0)) +. $TESTDIR/framework +setupenvironment +configarchitecture 'amd64' + +insertinstalledpackage 'xserver-xorg-core' 'amd64' '2:1.7.6-2ubuntu7.10' +for i in $(seq 1 50); do + insertinstalledpackage "xserver-xorg-video-driver$i" 'amd64' '1.0' 'Provides: xserver-xorg-video-6' +done + +insertpackage 'unstable' 'xserver-xorg-core' 'amd64' '2:1.11.3-0ubuntu9' 'Breaks: xserver-xorg-video-6' + + +setupaptarchive + +testequal 'Reading package lists... +Building dependency tree... +The following packages will be REMOVED: + xserver-xorg-video-driver1 xserver-xorg-video-driver10 + xserver-xorg-video-driver11 xserver-xorg-video-driver12 + xserver-xorg-video-driver13 xserver-xorg-video-driver14 + xserver-xorg-video-driver15 xserver-xorg-video-driver16 + xserver-xorg-video-driver17 xserver-xorg-video-driver18 + xserver-xorg-video-driver19 xserver-xorg-video-driver2 + xserver-xorg-video-driver20 xserver-xorg-video-driver21 + xserver-xorg-video-driver22 xserver-xorg-video-driver23 + xserver-xorg-video-driver24 xserver-xorg-video-driver25 + xserver-xorg-video-driver26 xserver-xorg-video-driver27 + xserver-xorg-video-driver28 xserver-xorg-video-driver29 + xserver-xorg-video-driver3 xserver-xorg-video-driver30 + xserver-xorg-video-driver31 xserver-xorg-video-driver32 + xserver-xorg-video-driver33 xserver-xorg-video-driver34 + xserver-xorg-video-driver35 xserver-xorg-video-driver36 + xserver-xorg-video-driver37 xserver-xorg-video-driver38 + xserver-xorg-video-driver39 xserver-xorg-video-driver4 + xserver-xorg-video-driver40 xserver-xorg-video-driver41 + xserver-xorg-video-driver42 xserver-xorg-video-driver43 + xserver-xorg-video-driver44 xserver-xorg-video-driver45 + xserver-xorg-video-driver46 xserver-xorg-video-driver47 + xserver-xorg-video-driver48 xserver-xorg-video-driver49 + xserver-xorg-video-driver5 xserver-xorg-video-driver50 + xserver-xorg-video-driver6 xserver-xorg-video-driver7 + xserver-xorg-video-driver8 xserver-xorg-video-driver9 +The following packages will be upgraded: + xserver-xorg-core +1 upgraded, 0 newly installed, 50 to remove and 0 not upgraded. +After this operation, 2150 kB disk space will be freed. +E: Trivial Only specified but this is not a trivial operation.' aptget dist-upgrade --trivial-only diff --git a/test/integration/test-ordering-ignore-not-matching-breaks b/test/integration/test-ordering-ignore-not-matching-breaks new file mode 100755 index 000000000..c9fca4edf --- /dev/null +++ b/test/integration/test-ordering-ignore-not-matching-breaks @@ -0,0 +1,56 @@ +#!/bin/sh +set -e + +TESTDIR=$(readlink -f $(dirname $0)) +. $TESTDIR/framework +setupenvironment +configarchitecture 'amd64' 'i386' + +insertpackage 'unstable-mp' 'crda' 'i386,amd64' '1.1.1-1ubuntu4mp' 'Provides: wireless-crda +Multi-Arch: foreign' +insertpackage 'unstable-m' 'crda' 'i386,amd64' '1.1.1-1ubuntu4m' 'Multi-Arch: foreign' +insertpackage 'unstable-p' 'crda' 'i386,amd64' '1.1.1-1ubuntu4p' 'Provides: wireless-crda' +insertpackage 'unstable' 'wireless-crda' 'i386,amd64' '1.16' + + +insertinstalledpackage 'wireless-crda' 'amd64' '1.14' + +setupaptarchive + +testequal 'Reading package lists... +Building dependency tree... +The following NEW packages will be installed: + crda +0 upgraded, 1 newly installed, 0 to remove and 1 not upgraded. +Inst crda (1.1.1-1ubuntu4m unstable-m [amd64]) +Conf crda (1.1.1-1ubuntu4m unstable-m [amd64])' aptget install crda -s -t unstable-m + +testequal 'Reading package lists... +Building dependency tree... +The following NEW packages will be installed: + crda +0 upgraded, 1 newly installed, 0 to remove and 1 not upgraded. +Inst crda (1.1.1-1ubuntu4p unstable-p [amd64]) +Conf crda (1.1.1-1ubuntu4p unstable-p [amd64])' aptget install crda -s -t unstable-p + +testequal 'Reading package lists... +Building dependency tree... +The following NEW packages will be installed: + crda +0 upgraded, 1 newly installed, 0 to remove and 1 not upgraded. +Inst crda (1.1.1-1ubuntu4mp unstable-mp [amd64]) +Conf crda (1.1.1-1ubuntu4mp unstable-mp [amd64])' aptget install crda -s -t unstable-mp + +rm rootdir/var/lib/dpkg/status +insertinstalledpackage 'crda' 'amd64' '1.1.1-1ubuntu4mp' 'Provides: wireless-crda +Conflicts: wireless-crda (<< 1.15) +Replaces: wireless-crda ( << 1.15) +Multi-arch: foreign' + +testequal 'Reading package lists... +Building dependency tree... +The following NEW packages will be installed: + wireless-crda +0 upgraded, 1 newly installed, 0 to remove and 1 not upgraded. +Inst wireless-crda (1.16 unstable [amd64]) +Conf wireless-crda (1.16 unstable [amd64])' aptget install wireless-crda -s -t unstable diff --git a/test/integration/test-ubuntu-bug-859188-multiarch-reinstall b/test/integration/test-ubuntu-bug-859188-multiarch-reinstall new file mode 100755 index 000000000..0fdf97485 --- /dev/null +++ b/test/integration/test-ubuntu-bug-859188-multiarch-reinstall @@ -0,0 +1,28 @@ +#!/bin/sh +set -e + +TESTDIR=$(readlink -f $(dirname $0)) +. $TESTDIR/framework +setupenvironment +configarchitecture 'amd64' 'i386' 'armel' + +buildsimplenativepackage 'libsame' 'amd64,i386,armel' '1.0' 'unstable' 'Multi-Arch: same' + +# FIXME: hack around dpkg's current inability to handle multiarch, a clean install would be better… +insertinstalledpackage 'libsame' 'amd64,i386' '1.0' 'Multi-Arch: same' +sed -e 's#/installed#/unstable#' -e 's#Installed-Size: 42#Installed-Size: 1#' -i rootdir/var/lib/dpkg/status + +setupaptarchive + +REINSTALL='Reading package lists... +Building dependency tree... +0 upgraded, 0 newly installed, 2 reinstalled, 0 to remove and 0 not upgraded. +Inst libsame [1.0] (1.0 unstable [amd64]) +Inst libsame:i386 [1.0] (1.0 unstable [i386]) +Conf libsame (1.0 unstable [amd64]) +Conf libsame:i386 (1.0 unstable [i386])' + +testequal "$REINSTALL" aptget install --reinstall libsame -s +testequal "$REINSTALL" aptget install --reinstall libsame:amd64 -s +testequal "$REINSTALL" aptget install --reinstall libsame:i386 -s +testequal "$REINSTALL" aptget install --reinstall libsame:amd64 libsame:i386 -s diff --git a/test/libapt/configuration_test.cc b/test/libapt/configuration_test.cc index 5b23d17fb..9a3e2c118 100644 --- a/test/libapt/configuration_test.cc +++ b/test/libapt/configuration_test.cc @@ -71,6 +71,15 @@ int main(int argc,const char *argv[]) { equals(Cnf.Find("APT2::Version", "33"), "33"); equals(Cnf.FindI("APT2::Version", 33), 33); + equals(Cnf.FindFile("Dir::State"), ""); + equals(Cnf.FindFile("Dir::Aptitude::State"), ""); + Cnf.Set("Dir", "/srv/sid"); + equals(Cnf.FindFile("Dir::State"), ""); + Cnf.Set("Dir::State", "var/lib/apt"); + Cnf.Set("Dir::Aptitude::State", "var/lib/aptitude"); + equals(Cnf.FindFile("Dir::State"), "/srv/sid/var/lib/apt"); + equals(Cnf.FindFile("Dir::Aptitude::State"), "/srv/sid/var/lib/aptitude"); + //FIXME: Test for configuration file parsing; // currently only integration/ tests test them implicitly |