From c1553e72c6728572b06dc32395a994d5bfdc8e23 Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Thu, 17 Sep 2015 13:46:11 +0200 Subject: switch 'apt-mark hold' from Pkg to Ver based operation Users hold a package foo (at version X) or try to prevent the installation of foo (usually based on the information they know about version X), even if we say that we "hold a package". Conceptionally we also need to know about which architecture we are talking and that is an information bound to a version (as a package can change architecture over time). We internally did this lookup from Pkg to Ver already, we just move this to a central place where the user has a change to influence it now. Git-Dch: Ignore --- cmdline/apt-mark.cc | 49 ++++++++++++++++++------------------------------- 1 file changed, 18 insertions(+), 31 deletions(-) (limited to 'cmdline') diff --git a/cmdline/apt-mark.cc b/cmdline/apt-mark.cc index d9a93fa05..ef3a0d72f 100644 --- a/cmdline/apt-mark.cc +++ b/cmdline/apt-mark.cc @@ -174,25 +174,25 @@ static bool DoHold(CommandLine &CmdL) if (unlikely(Cache == NULL)) return false; - APT::PackageList pkgset = APT::PackageList::FromCommandLine(CacheFile, CmdL.FileList + 1); + APT::VersionVector pkgset = APT::VersionVector::FromCommandLine(CacheFile, CmdL.FileList + 1, APT::CacheSetHelper::INSTCAND); if (pkgset.empty() == true) return _error->Error(_("No packages found")); bool const MarkHold = strcasecmp(CmdL.FileList[0],"hold") == 0; auto const part = std::stable_partition(pkgset.begin(), pkgset.end(), - [](pkgCache::PkgIterator const &P) { return P->SelectedState == pkgCache::State::Hold; }); + [](pkgCache::VerIterator const &V) { return V.ParentPkg()->SelectedState == pkgCache::State::Hold; }); auto const doneBegin = MarkHold ? pkgset.begin() : part; auto const doneEnd = MarkHold ? part : pkgset.end(); auto const changeBegin = MarkHold ? part : pkgset.begin(); auto const changeEnd = MarkHold ? pkgset.end() : part; - std::for_each(doneBegin, doneEnd, [&MarkHold](pkgCache::PkgIterator const &P) { + std::for_each(doneBegin, doneEnd, [&MarkHold](pkgCache::VerIterator const &V) { if (MarkHold == true) - ioprintf(c1out, _("%s was already set on hold.\n"), P.FullName(true).c_str()); + ioprintf(c1out, _("%s was already set on hold.\n"), V.ParentPkg().FullName(true).c_str()); else - ioprintf(c1out, _("%s was already not hold.\n"), P.FullName(true).c_str()); + ioprintf(c1out, _("%s was already not hold.\n"), V.ParentPkg().FullName(true).c_str()); }); if (doneBegin == pkgset.begin() && doneEnd == pkgset.end()) @@ -200,11 +200,11 @@ static bool DoHold(CommandLine &CmdL) if (_config->FindB("APT::Mark::Simulate", false) == true) { - std::for_each(changeBegin, changeEnd, [&MarkHold](pkgCache::PkgIterator const &P) { + std::for_each(changeBegin, changeEnd, [&MarkHold](pkgCache::VerIterator const &V) { if (MarkHold == false) - ioprintf(c1out, _("%s set on hold.\n"), P.FullName(true).c_str()); + ioprintf(c1out, _("%s set on hold.\n"), V.ParentPkg().FullName(true).c_str()); else - ioprintf(c1out, _("Canceled hold on %s.\n"), P.FullName(true).c_str()); + ioprintf(c1out, _("Canceled hold on %s.\n"), V.ParentPkg().FullName(true).c_str()); }); return true; } @@ -237,9 +237,9 @@ static bool DoHold(CommandLine &CmdL) } } - APT::PackageList keepoffset; + APT::VersionVector keepoffset; std::copy_if(changeBegin, changeEnd, std::back_inserter(keepoffset), - [](pkgCache::PkgIterator const &P) { return P->CurrentVer == 0; }); + [](pkgCache::VerIterator const &V) { return V.ParentPkg()->CurrentVer == 0; }); if (keepoffset.empty() == false) { @@ -269,16 +269,9 @@ static bool DoHold(CommandLine &CmdL) } FILE* dpkg = fdopen(external[1], "w"); - for (APT::PackageList::iterator Pkg = keepoffset.begin(); Pkg != keepoffset.end(); ++Pkg) - { - char const * Arch; - if (Pkg->VersionList != 0) - Arch = Pkg.VersionList().Arch(); - else - Arch = Pkg.Arch(); + for (auto const &V: keepoffset) fprintf(dpkg, "Package: %s\nVersion: 0~\nArchitecture: %s\nMaintainer: Dummy Example \n" - "Description: dummy package record\n A record is needed to put a package on hold, so here it is.\n\n", Pkg.Name(), Arch); - } + "Description: dummy package record\n A record is needed to put a package on hold, so here it is.\n\n", V.ParentPkg().Name(), V.Arch()); fclose(dpkg); keepoffset.clear(); @@ -320,29 +313,23 @@ static bool DoHold(CommandLine &CmdL) bool const dpkgMultiArch = _system->MultiArchSupported(); FILE* dpkg = fdopen(external[1], "w"); - for (auto Pkg = changeBegin; Pkg != changeEnd; ++Pkg) + for (auto Ver = changeBegin; Ver != changeEnd; ++Ver) { + pkgCache::PkgIterator P = Ver.ParentPkg(); if (dpkgMultiArch == false) - fprintf(dpkg, "%s", Pkg.FullName(true).c_str()); + fprintf(dpkg, "%s", P.FullName(true).c_str()); else - { - if (Pkg->CurrentVer != 0) - fprintf(dpkg, "%s:%s", Pkg.Name(), Pkg.CurrentVer().Arch()); - else if (Pkg.VersionList().end() == false) - fprintf(dpkg, "%s:%s", Pkg.Name(), Pkg.VersionList().Arch()); - else - fprintf(dpkg, "%s", Pkg.FullName(false).c_str()); - } + fprintf(dpkg, "%s:%s", P.Name(), Ver.Arch()); if (MarkHold == true) { fprintf(dpkg, " hold\n"); - ioprintf(c1out,_("%s set on hold.\n"), Pkg.FullName(true).c_str()); + ioprintf(c1out,_("%s set on hold.\n"), P.FullName(true).c_str()); } else { fprintf(dpkg, " install\n"); - ioprintf(c1out,_("Canceled hold on %s.\n"), Pkg.FullName(true).c_str()); + ioprintf(c1out,_("Canceled hold on %s.\n"), P.FullName(true).c_str()); } } fclose(dpkg); -- cgit v1.2.3