From 304731b8f23e03d15d1c2d6f66e1bf5f26ac0ca2 Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Sat, 17 Aug 2013 10:11:40 +0200 Subject: [ABI-Break] remove the PACKAGE_MATCHER_ABI_COMPAT defines --- apt-private/private-list.cc | 8 -------- 1 file changed, 8 deletions(-) (limited to 'apt-private') diff --git a/apt-private/private-list.cc b/apt-private/private-list.cc index c3a21aafc..bbf4607f9 100644 --- a/apt-private/private-list.cc +++ b/apt-private/private-list.cc @@ -53,9 +53,6 @@ struct PackageSortAlphabetic } }; -#ifdef PACKAGE_MATCHER_ABI_COMPAT -#define PackageMatcher PackageNameMatchesFnmatch -#endif class PackageNameMatcher : public Matcher { public: @@ -64,16 +61,11 @@ class PackageNameMatcher : public Matcher for(int i=0; patterns[i] != NULL; i++) { std::string pattern = patterns[i]; -#ifdef PACKAGE_MATCHER_ABI_COMPAT - APT::CacheFilter::PackageNameMatchesFnmatch *cachefilter = NULL; - cachefilter = new APT::CacheFilter::PackageNameMatchesFnmatch(pattern); -#else APT::CacheFilter::PackageMatcher *cachefilter = NULL; if(_config->FindB("APT::Cmd::UseRegexp", false) == true) cachefilter = new APT::CacheFilter::PackageNameMatchesRegEx(pattern); else cachefilter = new APT::CacheFilter::PackageNameMatchesFnmatch(pattern); -#endif filters.push_back(cachefilter); } } -- cgit v1.2.3 From 96c6cab1fd5a5de19fbd552b42e1dd1c08417946 Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Wed, 16 Apr 2014 17:41:11 +0200 Subject: calculate Percent as part of pkgAcquireStatus to provide a weighted percent for both items and bytes --- apt-private/acqprogress.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'apt-private') diff --git a/apt-private/acqprogress.cc b/apt-private/acqprogress.cc index fe7a45e12..adec37405 100644 --- a/apt-private/acqprogress.cc +++ b/apt-private/acqprogress.cc @@ -170,7 +170,7 @@ bool AcqTextStatus::Pulse(pkgAcquire *Owner) ScreenWidth = sizeof(Buffer)-1; // Put in the percent done - sprintf(S,"%.0f%%",((CurrentBytes + CurrentItems)*100.0)/(TotalBytes+TotalItems)); + sprintf(S,"%.0f%%", Percent); bool Shown = false; for (pkgAcquire::Worker *I = Owner->WorkersBegin(); I != 0; -- cgit v1.2.3 From 0d29b9d4368284782862c7b507c47002b79ddb27 Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Sat, 26 Apr 2014 00:00:51 +0200 Subject: WIP local deb install --- apt-private/private-install.cc | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) (limited to 'apt-private') diff --git a/apt-private/private-install.cc b/apt-private/private-install.cc index 107ed398e..40165af31 100644 --- a/apt-private/private-install.cc +++ b/apt-private/private-install.cc @@ -19,6 +19,10 @@ #include #include #include +#include + +// FIXME: include of deb specific header +#include #include #include @@ -669,10 +673,23 @@ bool DoCacheManipulationFromCommandLine(CommandLine &CmdL, CacheFile &Cache, bool DoInstall(CommandLine &CmdL) { CacheFile Cache; + // first check for local pkgs and add them to the cache + for (const char **I = CmdL.FileList; *I != 0; I++) + { + if(FileExists(*I)) + { + // FIMXE: direct usage of .deb specific stuff + metaIndex *mi = new debDebFileMetaIndex(*I); + pkgSourceList *sources = Cache.GetSourceList(); + sources->Add(mi); + } + } + + // then open the cache if (Cache.OpenForInstall() == false || Cache.CheckDeps(CmdL.FileSize() != 1) == false) return false; - + std::map verset; if(!DoCacheManipulationFromCommandLine(CmdL, Cache, verset)) -- cgit v1.2.3 From eafc5435878d4013262131e5506c52d77b8a4bd4 Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Mon, 28 Apr 2014 14:50:11 +0200 Subject: avoid deb specific code in private-install --- apt-private/private-install.cc | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) (limited to 'apt-private') diff --git a/apt-private/private-install.cc b/apt-private/private-install.cc index 40165af31..4a68bb9d1 100644 --- a/apt-private/private-install.cc +++ b/apt-private/private-install.cc @@ -21,9 +21,6 @@ #include #include -// FIXME: include of deb specific header -#include - #include #include #include @@ -33,6 +30,7 @@ #include #include #include +#include #include #include @@ -678,10 +676,19 @@ bool DoInstall(CommandLine &CmdL) { if(FileExists(*I)) { - // FIMXE: direct usage of .deb specific stuff - metaIndex *mi = new debDebFileMetaIndex(*I); - pkgSourceList *sources = Cache.GetSourceList(); - sources->Add(mi); + // FIXME: make this more elegant + std::string TypeStr = flExtension(*I) + "-file"; + pkgSourceList::Type *Type = pkgSourceList::Type::GetType(TypeStr.c_str()); + if(Type != 0) + { + std::vector List; + std::map Options; + if(Type->CreateItem(List, *I, "", "", Options)) + { + pkgSourceList *sources = Cache.GetSourceList(); + sources->Add(List[0]); + } + } } } -- cgit v1.2.3 From 94f6611592b4b77ac257ec37445776ac2845f682 Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Wed, 7 May 2014 16:23:37 +0200 Subject: rename pkgSourceList::Add() to pkgSourceList::AddMetaIndex() --- apt-private/private-install.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'apt-private') diff --git a/apt-private/private-install.cc b/apt-private/private-install.cc index 4a68bb9d1..e7606a1d1 100644 --- a/apt-private/private-install.cc +++ b/apt-private/private-install.cc @@ -686,7 +686,7 @@ bool DoInstall(CommandLine &CmdL) if(Type->CreateItem(List, *I, "", "", Options)) { pkgSourceList *sources = Cache.GetSourceList(); - sources->Add(List[0]); + sources->AddMetaIndex(List[0]); } } } -- cgit v1.2.3 From aaf677da5b62d3d0fdeb26f9b4c63fed544b63cd Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Wed, 7 May 2014 16:41:25 +0200 Subject: move pkgSourceList::AddMetaIndex() into a private subclass until we decide about a good API --- apt-private/private-cachefile.h | 23 +++++++++++++++++++++++ apt-private/private-install.cc | 4 +++- 2 files changed, 26 insertions(+), 1 deletion(-) (limited to 'apt-private') diff --git a/apt-private/private-cachefile.h b/apt-private/private-cachefile.h index dce7e0a3a..1fddabfbd 100644 --- a/apt-private/private-cachefile.h +++ b/apt-private/private-cachefile.h @@ -6,7 +6,20 @@ #include #include #include +#include +#include +// FIXME: we need to find a way to export this +class APT_PUBLIC SourceList : public pkgSourceList +{ + + public: + // Add custom metaIndex (e.g. local files) + void AddMetaIndex(metaIndex *mi) { + SrcList.push_back(mi); + } + +}; // class CacheFile - Cover class for some dependency cache functions /*{{{*/ // --------------------------------------------------------------------- @@ -28,6 +41,16 @@ class APT_PUBLIC CacheFile : public pkgCacheFile return false; return true; } + // FIXME: this can go once the "libapt-pkg" pkgSourceList has a way + // to add custom metaIndexes (or custom local files or so) + bool BuildSourceList(OpProgress */*Progress*/ = NULL) { + if (SrcList != NULL) + return true; + SrcList = new SourceList(); + if (SrcList->ReadMainList() == false) + return _error->Error(_("The list of sources could not be read.")); + return true; + } bool Open(bool WithLock = true) { OpTextProgress Prog(*_config); diff --git a/apt-private/private-install.cc b/apt-private/private-install.cc index e7606a1d1..35649fcdb 100644 --- a/apt-private/private-install.cc +++ b/apt-private/private-install.cc @@ -685,7 +685,9 @@ bool DoInstall(CommandLine &CmdL) std::map Options; if(Type->CreateItem(List, *I, "", "", Options)) { - pkgSourceList *sources = Cache.GetSourceList(); + // we have our own CacheFile that gives us a SourceList + // with superpowerz + SourceList *sources = (SourceList*)Cache.GetSourceList(); sources->AddMetaIndex(List[0]); } } -- cgit v1.2.3 From b58f28d4c4a06ef0a67cf3b6fe57aa08e7bc6b7e Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Wed, 7 May 2014 21:39:53 +0200 Subject: fix some compile errors in the now enabled #if (APT_PKG_MAJOR >= 4 && APT_PKG_MINOR < 13) --- apt-private/private-install.cc | 1 + 1 file changed, 1 insertion(+) (limited to 'apt-private') diff --git a/apt-private/private-install.cc b/apt-private/private-install.cc index 35649fcdb..d9e485462 100644 --- a/apt-private/private-install.cc +++ b/apt-private/private-install.cc @@ -20,6 +20,7 @@ #include #include #include +#include #include #include -- cgit v1.2.3 From 722c387941f8d313fe18b61828fb82a0bbca5dad Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Thu, 8 May 2014 14:31:10 +0200 Subject: apt-private/acqprogress.cc: do not show file size on IMSHit, it wasn't fetched, so why bother --- apt-private/acqprogress.cc | 2 -- 1 file changed, 2 deletions(-) (limited to 'apt-private') diff --git a/apt-private/acqprogress.cc b/apt-private/acqprogress.cc index ee6c4536f..4bcfd8f00 100644 --- a/apt-private/acqprogress.cc +++ b/apt-private/acqprogress.cc @@ -64,8 +64,6 @@ void AcqTextStatus::IMSHit(pkgAcquire::ItemDesc &Itm) cout << '\r' << BlankLine << '\r'; cout << _("Hit ") << Itm.Description; - if (Itm.Owner->FileSize != 0) - cout << " [" << SizeToStr(Itm.Owner->FileSize) << "B]"; cout << endl; Update = true; } -- cgit v1.2.3 From 0c8171d7c52a46a719382ee7ed67451213f608ec Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Fri, 9 May 2014 01:22:50 +0200 Subject: =?UTF-8?q?tests:=20be=20able=20to=20disable=20"Fetched=20?= =?UTF-8?q?=E2=80=A6"=20statistics=20message?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The line contains everchanging execution statistics which is harmful for testcases as they need to filter out such lines, but this is hard so we can just add an option to disable them instead and be done. Git-Dch: Ignore --- apt-private/acqprogress.cc | 3 +++ 1 file changed, 3 insertions(+) (limited to 'apt-private') diff --git a/apt-private/acqprogress.cc b/apt-private/acqprogress.cc index 4bcfd8f00..17a12799c 100644 --- a/apt-private/acqprogress.cc +++ b/apt-private/acqprogress.cc @@ -140,6 +140,9 @@ void AcqTextStatus::Stop() if (Quiet <= 0) cout << '\r' << BlankLine << '\r' << flush; + if (_config->FindB("quiet::NoStatistic", false) == true) + return; + if (FetchedBytes != 0 && _error->PendingError() == false) ioprintf(cout,_("Fetched %sB in %s (%sB/s)\n"), SizeToStr(FetchedBytes).c_str(), -- cgit v1.2.3 From 8f418981337503ff7abedd872f788b51bcdbc886 Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Tue, 22 Apr 2014 16:07:32 +0200 Subject: show upgradable packages after apt update Closes: 748389 --- apt-private/private-update.cc | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'apt-private') diff --git a/apt-private/private-update.cc b/apt-private/private-update.cc index da83d7741..fa827dea4 100644 --- a/apt-private/private-update.cc +++ b/apt-private/private-update.cc @@ -75,6 +75,24 @@ bool DoUpdate(CommandLine &CmdL) return false; } + // show basic stats (if the user whishes) + if (_config->FindB("APT::Cmd::Show-Update-Stats", false) == true) + { + int upgradable = 0; + Cache.Open(); + for (pkgCache::PkgIterator I = Cache->PkgBegin(); I.end() != true; ++I) + { + pkgDepCache::StateCache &state = Cache[I]; + if (I->CurrentVer != 0 && state.Upgradable()) + upgradable++; + } + const char *msg = ngettext( + "%i package can be upgraded. Run 'apt list --upgradable' to see it.\n", + "%i packages can be upgraded. Run 'apt list --upgradable' to see them.\n", + upgradable); + ioprintf(c1out, msg, upgradable); + } + return true; } /*}}}*/ -- cgit v1.2.3 From d287a035e07030be13f72265d4d0812086c323f5 Mon Sep 17 00:00:00 2001 From: Sebastian Schmidt Date: Sat, 17 May 2014 06:57:47 +0200 Subject: fix screen width detection for apt/apt-get lists 3163087b moved SigWinch(int) from apt-get.cc to private-output.cc without moving #include , making SigWinch a nop. Closes: 748430, 747942 --- apt-private/private-output.cc | 1 + 1 file changed, 1 insertion(+) (limited to 'apt-private') diff --git a/apt-private/private-output.cc b/apt-private/private-output.cc index 7f3eef6c2..32f27a3dd 100644 --- a/apt-private/private-output.cc +++ b/apt-private/private-output.cc @@ -23,6 +23,7 @@ #include #include #include +#include #include /*}}}*/ -- cgit v1.2.3 From 58377ceb4b62e8f50ddae8f17ce1511e4bf79a18 Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Fri, 30 May 2014 13:42:36 +0200 Subject: if Resolver fails, do not continue even if not broken This can happen if the request is already a well-formed request all by itself (e.g. the package has no dependencies), but the resolver found a reason to not accept it as solution. Our edsp 'dump' solver e.g. shouldn't be able to trigger install, which it does otherwise. --- apt-private/private-install.cc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'apt-private') diff --git a/apt-private/private-install.cc b/apt-private/private-install.cc index 107ed398e..f15ccc398 100644 --- a/apt-private/private-install.cc +++ b/apt-private/private-install.cc @@ -617,7 +617,8 @@ bool DoCacheManipulationFromCommandLine(CommandLine &CmdL, CacheFile &Cache, if (Fix != NULL) { // Call the scored problem resolver - Fix->Resolve(true); + if (Fix->Resolve(true) == false && Cache->BrokenCount() == 0) + return false; } // Now we check the state of the packages, -- cgit v1.2.3 From a3f1d60cb75ab83f63a52a43c056a4752c8fdeb2 Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Fri, 30 May 2014 14:47:56 +0200 Subject: Show unauthenticated warning for source packages as well This will show the same unauthenticated warning for source packages as for binary packages and will not download a source package if it is unauthenticated. This can be overridden with --allow-unauthenticated Closes: #749795 --- apt-private/private-download.cc | 5 +++++ apt-private/private-download.h | 6 ++++++ 2 files changed, 11 insertions(+) (limited to 'apt-private') diff --git a/apt-private/private-download.cc b/apt-private/private-download.cc index a095f0c67..be7d23c31 100644 --- a/apt-private/private-download.cc +++ b/apt-private/private-download.cc @@ -28,6 +28,11 @@ bool CheckAuth(pkgAcquire& Fetcher, bool const PromptUser) if (UntrustedList == "") return true; + return AuthPrompt(UntrustedList, PromptUser); +} + +bool AuthPrompt(std::string UntrustedList, bool const PromptUser) +{ ShowList(c2out,_("WARNING: The following packages cannot be authenticated!"),UntrustedList,""); if (_config->FindB("APT::Get::AllowUnauthenticated",false) == true) diff --git a/apt-private/private-download.h b/apt-private/private-download.h index a108aa531..a90ac7eaa 100644 --- a/apt-private/private-download.h +++ b/apt-private/private-download.h @@ -5,7 +5,13 @@ class pkgAcquire; +// Check if all files in the fetcher are authenticated APT_PUBLIC bool CheckAuth(pkgAcquire& Fetcher, bool const PromptUser); + +// show a authentication warning prompt and return true if the system +// should continue +APT_PUBLIC bool AuthPrompt(std::string UntrustedList, bool const PromptUser); + APT_PUBLIC bool AcquireRun(pkgAcquire &Fetcher, int const PulseInterval, bool * const Failure, bool * const TransientNetworkFailure); #endif -- cgit v1.2.3 From 4d695011895d332685ebfaf21a79e8e4337e003e Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Mon, 9 Jun 2014 15:50:20 +0200 Subject: separate implementation from declaration of TryTo{Install,Remove} Git-Dch: Ignore --- apt-private/private-install.cc | 141 +++++++++++++++++++++++++++++++++++++ apt-private/private-install.h | 156 ++--------------------------------------- 2 files changed, 148 insertions(+), 149 deletions(-) (limited to 'apt-private') diff --git a/apt-private/private-install.cc b/apt-private/private-install.cc index f15ccc398..a365d4294 100644 --- a/apt-private/private-install.cc +++ b/apt-private/private-install.cc @@ -802,3 +802,144 @@ bool DoInstall(CommandLine &CmdL) return InstallPackages(Cache,false); } /*}}}*/ + +// TryToInstall - Mark a package for installation /*{{{*/ +void TryToInstall::operator() (pkgCache::VerIterator const &Ver) { + pkgCache::PkgIterator Pkg = Ver.ParentPkg(); + + Cache->GetDepCache()->SetCandidateVersion(Ver); + pkgDepCache::StateCache &State = (*Cache)[Pkg]; + + // Handle the no-upgrade case + if (_config->FindB("APT::Get::upgrade",true) == false && Pkg->CurrentVer != 0) + ioprintf(c1out,_("Skipping %s, it is already installed and upgrade is not set.\n"), + Pkg.FullName(true).c_str()); + // Ignore request for install if package would be new + else if (_config->FindB("APT::Get::Only-Upgrade", false) == true && Pkg->CurrentVer == 0) + ioprintf(c1out,_("Skipping %s, it is not installed and only upgrades are requested.\n"), + Pkg.FullName(true).c_str()); + else { + if (Fix != NULL) { + Fix->Clear(Pkg); + Fix->Protect(Pkg); + } + Cache->GetDepCache()->MarkInstall(Pkg,false); + + if (State.Install() == false) { + if (_config->FindB("APT::Get::ReInstall",false) == true) { + if (Pkg->CurrentVer == 0 || Pkg.CurrentVer().Downloadable() == false) + ioprintf(c1out,_("Reinstallation of %s is not possible, it cannot be downloaded.\n"), + Pkg.FullName(true).c_str()); + else + Cache->GetDepCache()->SetReInstall(Pkg, true); + } else + ioprintf(c1out,_("%s is already the newest version.\n"), + Pkg.FullName(true).c_str()); + } + + // Install it with autoinstalling enabled (if we not respect the minial + // required deps or the policy) + if (FixBroken == false) + doAutoInstallLater.insert(Pkg); + } + + // see if we need to fix the auto-mark flag + // e.g. apt-get install foo + // where foo is marked automatic + if (State.Install() == false && + (State.Flags & pkgCache::Flag::Auto) && + _config->FindB("APT::Get::ReInstall",false) == false && + _config->FindB("APT::Get::Only-Upgrade",false) == false && + _config->FindB("APT::Get::Download-Only",false) == false) + { + ioprintf(c1out,_("%s set to manually installed.\n"), + Pkg.FullName(true).c_str()); + Cache->GetDepCache()->MarkAuto(Pkg,false); + AutoMarkChanged++; + } +} + /*}}}*/ +bool TryToInstall::propergateReleaseCandiateSwitching(std::list > const &start, std::ostream &out)/*{{{*/ +{ + for (std::list >::const_iterator s = start.begin(); + s != start.end(); ++s) + Cache->GetDepCache()->SetCandidateVersion(s->first); + + bool Success = true; + // the Changed list contains: + // first: "new version" + // second: "what-caused the change" + std::list > Changed; + for (std::list >::const_iterator s = start.begin(); + s != start.end(); ++s) + { + Changed.push_back(std::make_pair(s->first, pkgCache::VerIterator(*Cache))); + // We continue here even if it failed to enhance the ShowBroken output + Success &= Cache->GetDepCache()->SetCandidateRelease(s->first, s->second, Changed); + } + for (std::list >::const_iterator c = Changed.begin(); + c != Changed.end(); ++c) + { + if (c->second.end() == true) + ioprintf(out, _("Selected version '%s' (%s) for '%s'\n"), + c->first.VerStr(), c->first.RelStr().c_str(), c->first.ParentPkg().FullName(true).c_str()); + else if (c->first.ParentPkg()->Group != c->second.ParentPkg()->Group) + { + pkgCache::VerIterator V = (*Cache)[c->first.ParentPkg()].CandidateVerIter(*Cache); + ioprintf(out, _("Selected version '%s' (%s) for '%s' because of '%s'\n"), V.VerStr(), + V.RelStr().c_str(), V.ParentPkg().FullName(true).c_str(), c->second.ParentPkg().FullName(true).c_str()); + } + } + return Success; +} + /*}}}*/ +void TryToInstall::doAutoInstall() { /*{{{*/ + for (APT::PackageSet::const_iterator P = doAutoInstallLater.begin(); + P != doAutoInstallLater.end(); ++P) { + pkgDepCache::StateCache &State = (*Cache)[P]; + if (State.InstBroken() == false && State.InstPolicyBroken() == false) + continue; + Cache->GetDepCache()->MarkInstall(P, true); + } + doAutoInstallLater.clear(); +} + /*}}}*/ +// TryToRemove - Mark a package for removal /*{{{*/ +void TryToRemove::operator() (pkgCache::VerIterator const &Ver) +{ + pkgCache::PkgIterator Pkg = Ver.ParentPkg(); + + if (Fix != NULL) + { + Fix->Clear(Pkg); + Fix->Protect(Pkg); + Fix->Remove(Pkg); + } + + if ((Pkg->CurrentVer == 0 && PurgePkgs == false) || + (PurgePkgs == true && Pkg->CurrentState == pkgCache::State::NotInstalled)) + { + pkgCache::GrpIterator Grp = Pkg.Group(); + pkgCache::PkgIterator P = Grp.PackageList(); + for (; P.end() != true; P = Grp.NextPkg(P)) + { + if (P == Pkg) + continue; + if (P->CurrentVer != 0 || (PurgePkgs == true && P->CurrentState != pkgCache::State::NotInstalled)) + { + // TRANSLATORS: Note, this is not an interactive question + ioprintf(c1out,_("Package '%s' is not installed, so not removed. Did you mean '%s'?\n"), + Pkg.FullName(true).c_str(), P.FullName(true).c_str()); + break; + } + } + if (P.end() == true) + ioprintf(c1out,_("Package '%s' is not installed, so not removed\n"),Pkg.FullName(true).c_str()); + + // MarkInstall refuses to install packages on hold + Pkg->SelectedState = pkgCache::State::Hold; + } + else + Cache->GetDepCache()->MarkDelete(Pkg, PurgePkgs); +} + /*}}}*/ diff --git a/apt-private/private-install.h b/apt-private/private-install.h index 5e18560c5..828163e40 100644 --- a/apt-private/private-install.h +++ b/apt-private/private-install.h @@ -3,28 +3,18 @@ #include #include -#include #include #include #include -#include -#include #include -#include - -#include -#include #include -#include #include #include - -#include - class CacheFile; class CommandLine; +class pkgProblemResolver; #define RAMFS_MAGIC 0x858458f6 @@ -39,7 +29,7 @@ APT_PUBLIC bool InstallPackages(CacheFile &Cache,bool ShwKept,bool Ask = true, // TryToInstall - Mark a package for installation /*{{{*/ -struct TryToInstall { +struct APT_PUBLIC TryToInstall { pkgCacheFile* Cache; pkgProblemResolver* Fix; bool FixBroken; @@ -49,109 +39,13 @@ struct TryToInstall { TryToInstall(pkgCacheFile &Cache, pkgProblemResolver *PM, bool const FixBroken) : Cache(&Cache), Fix(PM), FixBroken(FixBroken), AutoMarkChanged(0) {}; - void operator() (pkgCache::VerIterator const &Ver) { - pkgCache::PkgIterator Pkg = Ver.ParentPkg(); - - Cache->GetDepCache()->SetCandidateVersion(Ver); - pkgDepCache::StateCache &State = (*Cache)[Pkg]; - - // Handle the no-upgrade case - if (_config->FindB("APT::Get::upgrade",true) == false && Pkg->CurrentVer != 0) - ioprintf(c1out,_("Skipping %s, it is already installed and upgrade is not set.\n"), - Pkg.FullName(true).c_str()); - // Ignore request for install if package would be new - else if (_config->FindB("APT::Get::Only-Upgrade", false) == true && Pkg->CurrentVer == 0) - ioprintf(c1out,_("Skipping %s, it is not installed and only upgrades are requested.\n"), - Pkg.FullName(true).c_str()); - else { - if (Fix != NULL) { - Fix->Clear(Pkg); - Fix->Protect(Pkg); - } - Cache->GetDepCache()->MarkInstall(Pkg,false); - - if (State.Install() == false) { - if (_config->FindB("APT::Get::ReInstall",false) == true) { - if (Pkg->CurrentVer == 0 || Pkg.CurrentVer().Downloadable() == false) - ioprintf(c1out,_("Reinstallation of %s is not possible, it cannot be downloaded.\n"), - Pkg.FullName(true).c_str()); - else - Cache->GetDepCache()->SetReInstall(Pkg, true); - } else - ioprintf(c1out,_("%s is already the newest version.\n"), - Pkg.FullName(true).c_str()); - } - - // Install it with autoinstalling enabled (if we not respect the minial - // required deps or the policy) - if (FixBroken == false) - doAutoInstallLater.insert(Pkg); - } - - // see if we need to fix the auto-mark flag - // e.g. apt-get install foo - // where foo is marked automatic - if (State.Install() == false && - (State.Flags & pkgCache::Flag::Auto) && - _config->FindB("APT::Get::ReInstall",false) == false && - _config->FindB("APT::Get::Only-Upgrade",false) == false && - _config->FindB("APT::Get::Download-Only",false) == false) - { - ioprintf(c1out,_("%s set to manually installed.\n"), - Pkg.FullName(true).c_str()); - Cache->GetDepCache()->MarkAuto(Pkg,false); - AutoMarkChanged++; - } - } - - bool propergateReleaseCandiateSwitching(std::list > start, std::ostream &out) - { - for (std::list >::const_iterator s = start.begin(); - s != start.end(); ++s) - Cache->GetDepCache()->SetCandidateVersion(s->first); - - bool Success = true; - // the Changed list contains: - // first: "new version" - // second: "what-caused the change" - std::list > Changed; - for (std::list >::const_iterator s = start.begin(); - s != start.end(); ++s) - { - Changed.push_back(std::make_pair(s->first, pkgCache::VerIterator(*Cache))); - // We continue here even if it failed to enhance the ShowBroken output - Success &= Cache->GetDepCache()->SetCandidateRelease(s->first, s->second, Changed); - } - for (std::list >::const_iterator c = Changed.begin(); - c != Changed.end(); ++c) - { - if (c->second.end() == true) - ioprintf(out, _("Selected version '%s' (%s) for '%s'\n"), - c->first.VerStr(), c->first.RelStr().c_str(), c->first.ParentPkg().FullName(true).c_str()); - else if (c->first.ParentPkg()->Group != c->second.ParentPkg()->Group) - { - pkgCache::VerIterator V = (*Cache)[c->first.ParentPkg()].CandidateVerIter(*Cache); - ioprintf(out, _("Selected version '%s' (%s) for '%s' because of '%s'\n"), V.VerStr(), - V.RelStr().c_str(), V.ParentPkg().FullName(true).c_str(), c->second.ParentPkg().FullName(true).c_str()); - } - } - return Success; - } - - void doAutoInstall() { - for (APT::PackageSet::const_iterator P = doAutoInstallLater.begin(); - P != doAutoInstallLater.end(); ++P) { - pkgDepCache::StateCache &State = (*Cache)[P]; - if (State.InstBroken() == false && State.InstPolicyBroken() == false) - continue; - Cache->GetDepCache()->MarkInstall(P, true); - } - doAutoInstallLater.clear(); - } + void operator() (pkgCache::VerIterator const &Ver); + bool propergateReleaseCandiateSwitching(std::list > const &start, std::ostream &out); + void doAutoInstall(); }; /*}}}*/ // TryToRemove - Mark a package for removal /*{{{*/ -struct TryToRemove { +struct APT_PUBLIC TryToRemove { pkgCacheFile* Cache; pkgProblemResolver* Fix; bool PurgePkgs; @@ -159,43 +53,7 @@ struct TryToRemove { TryToRemove(pkgCacheFile &Cache, pkgProblemResolver *PM) : Cache(&Cache), Fix(PM), PurgePkgs(_config->FindB("APT::Get::Purge", false)) {}; - void operator() (pkgCache::VerIterator const &Ver) - { - pkgCache::PkgIterator Pkg = Ver.ParentPkg(); - - if (Fix != NULL) - { - Fix->Clear(Pkg); - Fix->Protect(Pkg); - Fix->Remove(Pkg); - } - - if ((Pkg->CurrentVer == 0 && PurgePkgs == false) || - (PurgePkgs == true && Pkg->CurrentState == pkgCache::State::NotInstalled)) - { - pkgCache::GrpIterator Grp = Pkg.Group(); - pkgCache::PkgIterator P = Grp.PackageList(); - for (; P.end() != true; P = Grp.NextPkg(P)) - { - if (P == Pkg) - continue; - if (P->CurrentVer != 0 || (PurgePkgs == true && P->CurrentState != pkgCache::State::NotInstalled)) - { - // TRANSLATORS: Note, this is not an interactive question - ioprintf(c1out,_("Package '%s' is not installed, so not removed. Did you mean '%s'?\n"), - Pkg.FullName(true).c_str(), P.FullName(true).c_str()); - break; - } - } - if (P.end() == true) - ioprintf(c1out,_("Package '%s' is not installed, so not removed\n"),Pkg.FullName(true).c_str()); - - // MarkInstall refuses to install packages on hold - Pkg->SelectedState = pkgCache::State::Hold; - } - else - Cache->GetDepCache()->MarkDelete(Pkg, PurgePkgs); - } + void operator() (pkgCache::VerIterator const &Ver); }; /*}}}*/ -- cgit v1.2.3 From 2847bed0b704bc636f169c5766da42180a084eac Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Tue, 10 Jun 2014 15:22:53 +0200 Subject: apt-private/private-output.cc: fix cppcheck output --- apt-private/private-output.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'apt-private') diff --git a/apt-private/private-output.cc b/apt-private/private-output.cc index 32f27a3dd..8f190a551 100644 --- a/apt-private/private-output.cc +++ b/apt-private/private-output.cc @@ -94,7 +94,7 @@ bool InitOutput() /*{{{*/ static std::string GetArchiveSuite(pkgCacheFile &/*CacheFile*/, pkgCache::VerIterator ver) /*{{{*/ { std::string suite = ""; - if (ver && ver.FileList() && ver.FileList()) + if (ver && ver.FileList()) { pkgCache::VerFileIterator VF = ver.FileList(); for (; VF.end() == false ; ++VF) -- cgit v1.2.3 From 24d05892fe96d52aaceef7af94d0e444e140067c Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Wed, 18 Jun 2014 08:25:16 +0200 Subject: Tell the user if no updates are available after apt update Thanks to Jakub Wilk for the suggestion. Closes: #751388 --- apt-private/private-update.cc | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'apt-private') diff --git a/apt-private/private-update.cc b/apt-private/private-update.cc index fa827dea4..a843d6f86 100644 --- a/apt-private/private-update.cc +++ b/apt-private/private-update.cc @@ -90,7 +90,10 @@ bool DoUpdate(CommandLine &CmdL) "%i package can be upgraded. Run 'apt list --upgradable' to see it.\n", "%i packages can be upgraded. Run 'apt list --upgradable' to see them.\n", upgradable); - ioprintf(c1out, msg, upgradable); + if (upgradable == 0) + c1out << _("All packages are up to date.") << std::endl; + else + ioprintf(c1out, msg, upgradable); } return true; -- cgit v1.2.3 From dab5f8745b8d6df1060490c8c5ac895832657a74 Mon Sep 17 00:00:00 2001 From: Fredrik Fornwall Date: Tue, 17 Jun 2014 11:33:00 +0200 Subject: use P_ instead of ngettext to compiling with --disable-nls Closes: 751857 --- apt-private/private-update.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'apt-private') diff --git a/apt-private/private-update.cc b/apt-private/private-update.cc index a843d6f86..0f2f7a8da 100644 --- a/apt-private/private-update.cc +++ b/apt-private/private-update.cc @@ -86,7 +86,7 @@ bool DoUpdate(CommandLine &CmdL) if (I->CurrentVer != 0 && state.Upgradable()) upgradable++; } - const char *msg = ngettext( + const char *msg = P_( "%i package can be upgraded. Run 'apt list --upgradable' to see it.\n", "%i packages can be upgraded. Run 'apt list --upgradable' to see them.\n", upgradable); -- cgit v1.2.3 From d39d7f885d61bfe296c131c83bdc042a2ab6b0d7 Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Tue, 17 Jun 2014 17:45:33 +0200 Subject: show our broken packages message in 'apt' solver --- apt-private/private-output.cc | 204 ++++++++++++++++++++++-------------------- apt-private/private-output.h | 3 +- 2 files changed, 110 insertions(+), 97 deletions(-) (limited to 'apt-private') diff --git a/apt-private/private-output.cc b/apt-private/private-output.cc index 8f190a551..158bd5c71 100644 --- a/apt-private/private-output.cc +++ b/apt-private/private-output.cc @@ -344,129 +344,141 @@ bool ShowList(ostream &out,string Title,string List,string VersionsList) Depends: libldap2 (>= 2.0.2-2) but it is not going to be installed Depends: libsasl7 but it is not going to be installed */ -void ShowBroken(ostream &out,CacheFile &Cache,bool Now) +static void ShowBrokenPackage(ostream &out, pkgCacheFile * const Cache, pkgCache::PkgIterator const &Pkg, bool const Now) { - if (Cache->BrokenCount() == 0) + if (Now == true) + { + if ((*Cache)[Pkg].NowBroken() == false) + return; + } + else + { + if ((*Cache)[Pkg].InstBroken() == false) + return; + } + + // Print out each package and the failed dependencies + out << " " << Pkg.FullName(true) << " :"; + unsigned const Indent = Pkg.FullName(true).size() + 3; + bool First = true; + pkgCache::VerIterator Ver; + + if (Now == true) + Ver = Pkg.CurrentVer(); + else + Ver = (*Cache)[Pkg].InstVerIter(*Cache); + + if (Ver.end() == true) + { + out << endl; return; + } - out << _("The following packages have unmet dependencies:") << endl; - for (unsigned J = 0; J < Cache->Head().PackageCount; J++) + for (pkgCache::DepIterator D = Ver.DependsList(); D.end() == false;) { - pkgCache::PkgIterator I(Cache,Cache.List[J]); - + // Compute a single dependency element (glob or) + pkgCache::DepIterator Start; + pkgCache::DepIterator End; + D.GlobOr(Start,End); // advances D + + if ((*Cache)->IsImportantDep(End) == false) + continue; + if (Now == true) { - if (Cache[I].NowBroken() == false) + if (((*Cache)[End] & pkgDepCache::DepGNow) == pkgDepCache::DepGNow) continue; } else { - if (Cache[I].InstBroken() == false) + if (((*Cache)[End] & pkgDepCache::DepGInstall) == pkgDepCache::DepGInstall) continue; } - - // Print out each package and the failed dependencies - out << " " << I.FullName(true) << " :"; - unsigned const Indent = I.FullName(true).size() + 3; - bool First = true; - pkgCache::VerIterator Ver; - - if (Now == true) - Ver = I.CurrentVer(); - else - Ver = Cache[I].InstVerIter(Cache); - - if (Ver.end() == true) - { - out << endl; - continue; - } - - for (pkgCache::DepIterator D = Ver.DependsList(); D.end() == false;) + + bool FirstOr = true; + while (1) { - // Compute a single dependency element (glob or) - pkgCache::DepIterator Start; - pkgCache::DepIterator End; - D.GlobOr(Start,End); // advances D + if (First == false) + for (unsigned J = 0; J != Indent; J++) + out << ' '; + First = false; - if (Cache->IsImportantDep(End) == false) - continue; - - if (Now == true) + if (FirstOr == false) { - if ((Cache[End] & pkgDepCache::DepGNow) == pkgDepCache::DepGNow) - continue; + for (unsigned J = 0; J != strlen(End.DepType()) + 3; J++) + out << ' '; } else + out << ' ' << End.DepType() << ": "; + FirstOr = false; + + out << Start.TargetPkg().FullName(true); + + // Show a quick summary of the version requirements + if (Start.TargetVer() != 0) + out << " (" << Start.CompType() << " " << Start.TargetVer() << ")"; + + /* Show a summary of the target package if possible. In the case + of virtual packages we show nothing */ + pkgCache::PkgIterator Targ = Start.TargetPkg(); + if (Targ->ProvidesList == 0) { - if ((Cache[End] & pkgDepCache::DepGInstall) == pkgDepCache::DepGInstall) - continue; - } - - bool FirstOr = true; - while (1) - { - if (First == false) - for (unsigned J = 0; J != Indent; J++) - out << ' '; - First = false; + out << ' '; + pkgCache::VerIterator Ver = (*Cache)[Targ].InstVerIter(*Cache); + if (Now == true) + Ver = Targ.CurrentVer(); - if (FirstOr == false) + if (Ver.end() == false) { - for (unsigned J = 0; J != strlen(End.DepType()) + 3; J++) - out << ' '; + if (Now == true) + ioprintf(out,_("but %s is installed"),Ver.VerStr()); + else + ioprintf(out,_("but %s is to be installed"),Ver.VerStr()); } else - out << ' ' << End.DepType() << ": "; - FirstOr = false; - - out << Start.TargetPkg().FullName(true); - - // Show a quick summary of the version requirements - if (Start.TargetVer() != 0) - out << " (" << Start.CompType() << " " << Start.TargetVer() << ")"; - - /* Show a summary of the target package if possible. In the case - of virtual packages we show nothing */ - pkgCache::PkgIterator Targ = Start.TargetPkg(); - if (Targ->ProvidesList == 0) { - out << ' '; - pkgCache::VerIterator Ver = Cache[Targ].InstVerIter(Cache); - if (Now == true) - Ver = Targ.CurrentVer(); - - if (Ver.end() == false) + if ((*Cache)[Targ].CandidateVerIter(*Cache).end() == true) { - if (Now == true) - ioprintf(out,_("but %s is installed"),Ver.VerStr()); + if (Targ->ProvidesList == 0) + out << _("but it is not installable"); else - ioprintf(out,_("but %s is to be installed"),Ver.VerStr()); - } + out << _("but it is a virtual package"); + } else - { - if (Cache[Targ].CandidateVerIter(Cache).end() == true) - { - if (Targ->ProvidesList == 0) - out << _("but it is not installable"); - else - out << _("but it is a virtual package"); - } - else - out << (Now?_("but it is not installed"):_("but it is not going to be installed")); - } + out << (Now?_("but it is not installed"):_("but it is not going to be installed")); } - - if (Start != End) - out << _(" or"); - out << endl; - - if (Start == End) - break; - ++Start; - } - } - } + } + + if (Start != End) + out << _(" or"); + out << endl; + + if (Start == End) + break; + ++Start; + } + } +} +void ShowBroken(ostream &out, CacheFile &Cache, bool const Now) +{ + if (Cache->BrokenCount() == 0) + return; + + out << _("The following packages have unmet dependencies:") << endl; + for (unsigned J = 0; J < Cache->Head().PackageCount; J++) + { + pkgCache::PkgIterator const I(Cache,Cache.List[J]); + ShowBrokenPackage(out, &Cache, I, Now); + } +} +void ShowBroken(ostream &out, pkgCacheFile &Cache, bool const Now) +{ + if (Cache->BrokenCount() == 0) + return; + + out << _("The following packages have unmet dependencies:") << endl; + for (pkgCache::PkgIterator Pkg = Cache->PkgBegin(); Pkg.end() == false; ++Pkg) + ShowBrokenPackage(out, &Cache, Pkg, Now); } /*}}}*/ // ShowNew - Show packages to newly install /*{{{*/ diff --git a/apt-private/private-output.h b/apt-private/private-output.h index 9633d0c37..6f3a964d7 100644 --- a/apt-private/private-output.h +++ b/apt-private/private-output.h @@ -28,7 +28,8 @@ void ListSingleVersion(pkgCacheFile &CacheFile, pkgRecords &records, // helper to describe global state -APT_PUBLIC void ShowBroken(std::ostream &out,CacheFile &Cache,bool Now); +APT_PUBLIC void ShowBroken(std::ostream &out, CacheFile &Cache, bool const Now); +APT_PUBLIC void ShowBroken(std::ostream &out, pkgCacheFile &Cache, bool const Now); APT_PUBLIC bool ShowList(std::ostream &out, std::string Title, std::string List, std::string VersionsList); -- cgit v1.2.3 From 172947cd7dc5c88c94c6ad269dc6c6be002ee958 Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Tue, 17 Jun 2014 19:05:53 +0200 Subject: do not call resolver twice on (dist-)upgrade --- apt-private/private-install.cc | 22 ++++++++++++++++------ apt-private/private-install.h | 4 ++-- apt-private/private-upgrade.cc | 12 ++---------- 3 files changed, 20 insertions(+), 18 deletions(-) (limited to 'apt-private') diff --git a/apt-private/private-install.cc b/apt-private/private-install.cc index a365d4294..e08cd8057 100644 --- a/apt-private/private-install.cc +++ b/apt-private/private-install.cc @@ -19,6 +19,7 @@ #include #include #include +#include #include #include @@ -524,15 +525,14 @@ static bool DoAutomaticRemove(CacheFile &Cache) static const unsigned short MOD_REMOVE = 1; static const unsigned short MOD_INSTALL = 2; -bool DoCacheManipulationFromCommandLine(CommandLine &CmdL, CacheFile &Cache) +bool DoCacheManipulationFromCommandLine(CommandLine &CmdL, CacheFile &Cache, int UpgradeMode) { std::map verset; - return DoCacheManipulationFromCommandLine(CmdL, Cache, verset); + return DoCacheManipulationFromCommandLine(CmdL, Cache, verset, UpgradeMode); } bool DoCacheManipulationFromCommandLine(CommandLine &CmdL, CacheFile &Cache, - std::map &verset) + std::map &verset, int UpgradeMode) { - // Enter the special broken fixing mode if the user specified arguments bool BrokenFix = false; if (Cache->BrokenCount() != 0) @@ -617,7 +617,17 @@ bool DoCacheManipulationFromCommandLine(CommandLine &CmdL, CacheFile &Cache, if (Fix != NULL) { // Call the scored problem resolver - if (Fix->Resolve(true) == false && Cache->BrokenCount() == 0) + bool resolver_fail = false; + if (UpgradeMode == 0) + { + if (strcmp(CmdL.FileList[0], "dist-upgrade") == 0 || strcmp(CmdL.FileList[0], "full-upgrade") == 0) + resolver_fail = APT::Upgrade::Upgrade(Cache, 0); + else + resolver_fail = Fix->Resolve(true); + } else + resolver_fail = APT::Upgrade::Upgrade(Cache, UpgradeMode); + + if (resolver_fail == false && Cache->BrokenCount() == 0) return false; } @@ -676,7 +686,7 @@ bool DoInstall(CommandLine &CmdL) std::map verset; - if(!DoCacheManipulationFromCommandLine(CmdL, Cache, verset)) + if(!DoCacheManipulationFromCommandLine(CmdL, Cache, verset, 0)) return false; /* Print out a list of packages that are going to be installed extra diff --git a/apt-private/private-install.h b/apt-private/private-install.h index 828163e40..8daa4a776 100644 --- a/apt-private/private-install.h +++ b/apt-private/private-install.h @@ -21,8 +21,8 @@ class pkgProblemResolver; APT_PUBLIC bool DoInstall(CommandLine &Cmd); bool DoCacheManipulationFromCommandLine(CommandLine &CmdL, CacheFile &Cache, - std::map &verset); -bool DoCacheManipulationFromCommandLine(CommandLine &CmdL, CacheFile &Cache); + std::map &verset, int UpgradeMode); +bool DoCacheManipulationFromCommandLine(CommandLine &CmdL, CacheFile &Cache, int UpgradeMode); APT_PUBLIC bool InstallPackages(CacheFile &Cache,bool ShwKept,bool Ask = true, bool Safety = true); diff --git a/apt-private/private-upgrade.cc b/apt-private/private-upgrade.cc index 68b2c5e00..31f067576 100644 --- a/apt-private/private-upgrade.cc +++ b/apt-private/private-upgrade.cc @@ -23,18 +23,10 @@ static bool UpgradeHelper(CommandLine &CmdL, int UpgradeFlags) return false; c0out << _("Calculating upgrade... ") << std::flush; - if (APT::Upgrade::Upgrade(Cache, UpgradeFlags) == false) - { - c0out << _("Failed") << std::endl; - ShowBroken(c1out,Cache,false); - return _error->Error(_("Internal error, Upgrade broke stuff")); - } + if(!DoCacheManipulationFromCommandLine(CmdL, Cache, UpgradeFlags)) + return false; c0out << _("Done") << std::endl; - // parse additional cmdline pkg manipulation switches - if(!DoCacheManipulationFromCommandLine(CmdL, Cache)) - return false; - return InstallPackages(Cache,true); } -- cgit v1.2.3 From 7d1b93d94083a3856efc821bacd9e91f80bbf760 Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Tue, 8 Jul 2014 16:06:56 +0200 Subject: Only show packages as upgradable if the have a CandidateVer != 0 Closes: #753297 --- apt-private/private-output.cc | 5 +++-- apt-private/private-update.cc | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) (limited to 'apt-private') diff --git a/apt-private/private-output.cc b/apt-private/private-output.cc index 158bd5c71..7f8922138 100644 --- a/apt-private/private-output.cc +++ b/apt-private/private-output.cc @@ -118,7 +118,7 @@ static std::string GetFlagsStr(pkgCacheFile &CacheFile, pkgCache::PkgIterator P) std::string flags_str; if (state.NowBroken()) flags_str = "B"; - if (P.CurrentVer() && state.Upgradable()) + if (P.CurrentVer() && state.Upgradable() && state.CandidateVer != NULL) flags_str = "g"; else if (P.CurrentVer() != NULL) flags_str = "i"; @@ -229,7 +229,8 @@ void ListSingleVersion(pkgCacheFile &CacheFile, pkgRecords &records, /*{{{*/ std::string CandidateVerStr = GetCandidateVersion(CacheFile, P); std::string InstalledVerStr = GetInstalledVersion(CacheFile, P); std::string StatusStr; - if(P.CurrentVer() == V && state.Upgradable()) { + if(P.CurrentVer() == V && state.Upgradable() && state.CandidateVer != NULL) + { strprintf(StatusStr, _("[installed,upgradable to: %s]"), CandidateVerStr.c_str()); } else if (P.CurrentVer() == V) { diff --git a/apt-private/private-update.cc b/apt-private/private-update.cc index 0f2f7a8da..860d84b86 100644 --- a/apt-private/private-update.cc +++ b/apt-private/private-update.cc @@ -83,7 +83,7 @@ bool DoUpdate(CommandLine &CmdL) for (pkgCache::PkgIterator I = Cache->PkgBegin(); I.end() != true; ++I) { pkgDepCache::StateCache &state = Cache[I]; - if (I->CurrentVer != 0 && state.Upgradable()) + if (I->CurrentVer != 0 && state.Upgradable() && state.CandidateVer != NULL) upgradable++; } const char *msg = P_( -- cgit v1.2.3 From cfefaf6c4a27bbd5bfdad67e482f4b01506f5bd5 Mon Sep 17 00:00:00 2001 From: Andreas Oberritter Date: Thu, 28 Aug 2014 15:04:20 -0700 Subject: The following command otherwise yields many blank lines: apt list -o APT::Cmd::use-format=true -o APT::Cmd::format=\${Package} And even worse when adding "-o APT::Cmd::All-Versions=true". Signed-off-by: Andreas Oberritter --- apt-private/private-list.cc | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'apt-private') diff --git a/apt-private/private-list.cc b/apt-private/private-list.cc index b69002103..f98456576 100644 --- a/apt-private/private-list.cc +++ b/apt-private/private-list.cc @@ -93,7 +93,6 @@ static void ListAllVersions(pkgCacheFile &CacheFile, pkgRecords &records,/*{{{*/ Ver.end() == false; ++Ver) { ListSingleVersion(CacheFile, records, Ver, outs, include_summary); - outs << "\n"; } } /*}}}*/ @@ -149,7 +148,7 @@ bool DoList(CommandLine &Cmd) // FIXME: SORT! and make sorting flexible (alphabetic, by pkg status) // output the sorted map for (K = output_map.begin(); K != output_map.end(); ++K) - std::cout << (*K).second << std::endl; + std::cout << (*K).second; // be nice and tell the user if there is more to see -- cgit v1.2.3 From 6763aaec8ddded31057733f53c63f15e6b949bd9 Mon Sep 17 00:00:00 2001 From: Andreas Oberritter Date: Tue, 2 Sep 2014 16:34:05 +0200 Subject: Avoid yielding blank lines with APT::Cmd::use-format=true --- apt-private/private-list.cc | 3 ++- apt-private/private-output.cc | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) (limited to 'apt-private') diff --git a/apt-private/private-list.cc b/apt-private/private-list.cc index f98456576..b69002103 100644 --- a/apt-private/private-list.cc +++ b/apt-private/private-list.cc @@ -93,6 +93,7 @@ static void ListAllVersions(pkgCacheFile &CacheFile, pkgRecords &records,/*{{{*/ Ver.end() == false; ++Ver) { ListSingleVersion(CacheFile, records, Ver, outs, include_summary); + outs << "\n"; } } /*}}}*/ @@ -148,7 +149,7 @@ bool DoList(CommandLine &Cmd) // FIXME: SORT! and make sorting flexible (alphabetic, by pkg status) // output the sorted map for (K = output_map.begin(); K != output_map.end(); ++K) - std::cout << (*K).second; + std::cout << (*K).second << std::endl; // be nice and tell the user if there is more to see diff --git a/apt-private/private-output.cc b/apt-private/private-output.cc index 7f8922138..8f1fb886e 100644 --- a/apt-private/private-output.cc +++ b/apt-private/private-output.cc @@ -220,7 +220,7 @@ void ListSingleVersion(pkgCacheFile &CacheFile, pkgRecords &records, /*{{{*/ output = SubstVar(output, "${Version}", GetVersion(CacheFile, V)); output = SubstVar(output, "${Description}", GetShortDescription(CacheFile, records, P)); output = SubstVar(output, "${Origin}", GetArchiveSuite(CacheFile, V)); - out << output << std::endl; + out << output; } else { // raring/linux-kernel version [upradable: new-version] // description -- cgit v1.2.3 From d059cc2668f284a7db77a15d1d742326d464e963 Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Fri, 5 Sep 2014 12:03:28 +0200 Subject: Fix incorrect upgradable listing in "apt list" (thanks to Michael Musenbrock) The "apt list" command was using only the pkgDepCache but not the pkgPolicy to figure out if a package is upgradable. This lead to incorrect display of upgradable package when the user used the policy to pin-down packages. Thanks to Michael Musenbrock for the initial patch. Closes: #753297 --- apt-private/private-cacheset.cc | 5 ++++- apt-private/private-output.cc | 5 ++++- 2 files changed, 8 insertions(+), 2 deletions(-) (limited to 'apt-private') diff --git a/apt-private/private-cacheset.cc b/apt-private/private-cacheset.cc index e37e7b227..159e1d8f1 100644 --- a/apt-private/private-cacheset.cc +++ b/apt-private/private-cacheset.cc @@ -55,7 +55,10 @@ bool GetLocalitySortedVersionSet(pkgCacheFile &CacheFile, } else if (_config->FindB("APT::Cmd::Upgradable") == true) { - if(P.CurrentVer() && state.Upgradable()) + pkgPolicy *policy = CacheFile.GetPolicy(); + if(P.CurrentVer() && + state.Upgradable() && + policy->GetCandidateVer(P) != P.CurrentVer()) { pkgPolicy *policy = CacheFile.GetPolicy(); output_set.insert(policy->GetCandidateVer(P)); diff --git a/apt-private/private-output.cc b/apt-private/private-output.cc index 8f1fb886e..2120b7a83 100644 --- a/apt-private/private-output.cc +++ b/apt-private/private-output.cc @@ -229,7 +229,10 @@ void ListSingleVersion(pkgCacheFile &CacheFile, pkgRecords &records, /*{{{*/ std::string CandidateVerStr = GetCandidateVersion(CacheFile, P); std::string InstalledVerStr = GetInstalledVersion(CacheFile, P); std::string StatusStr; - if(P.CurrentVer() == V && state.Upgradable() && state.CandidateVer != NULL) + if(P.CurrentVer() == V && + state.Upgradable() && + state.CandidateVer != NULL && + policy->GetCandidateVer(P) != P.CurrentVer()) { strprintf(StatusStr, _("[installed,upgradable to: %s]"), CandidateVerStr.c_str()); -- cgit v1.2.3 From 592d06b6f3c2ef2ae47c38005ae3c4e96a0841f2 Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Fri, 5 Sep 2014 12:50:15 +0200 Subject: Ensure we have a Policy in CacheFile.BuildDepCache() This partly reverts d059cc2 and fixes bug #753297 in a more general way by ensuring that CacheFile.BuildDepCache() builds a pkgPolicy if there isn't one already. --- apt-private/private-cacheset.cc | 5 +---- apt-private/private-output.cc | 5 +---- 2 files changed, 2 insertions(+), 8 deletions(-) (limited to 'apt-private') diff --git a/apt-private/private-cacheset.cc b/apt-private/private-cacheset.cc index 159e1d8f1..e37e7b227 100644 --- a/apt-private/private-cacheset.cc +++ b/apt-private/private-cacheset.cc @@ -55,10 +55,7 @@ bool GetLocalitySortedVersionSet(pkgCacheFile &CacheFile, } else if (_config->FindB("APT::Cmd::Upgradable") == true) { - pkgPolicy *policy = CacheFile.GetPolicy(); - if(P.CurrentVer() && - state.Upgradable() && - policy->GetCandidateVer(P) != P.CurrentVer()) + if(P.CurrentVer() && state.Upgradable()) { pkgPolicy *policy = CacheFile.GetPolicy(); output_set.insert(policy->GetCandidateVer(P)); diff --git a/apt-private/private-output.cc b/apt-private/private-output.cc index 2120b7a83..522f7682d 100644 --- a/apt-private/private-output.cc +++ b/apt-private/private-output.cc @@ -229,10 +229,7 @@ void ListSingleVersion(pkgCacheFile &CacheFile, pkgRecords &records, /*{{{*/ std::string CandidateVerStr = GetCandidateVersion(CacheFile, P); std::string InstalledVerStr = GetInstalledVersion(CacheFile, P); std::string StatusStr; - if(P.CurrentVer() == V && - state.Upgradable() && - state.CandidateVer != NULL && - policy->GetCandidateVer(P) != P.CurrentVer()) + if(P.CurrentVer() == V && state.Upgradable()) { strprintf(StatusStr, _("[installed,upgradable to: %s]"), CandidateVerStr.c_str()); -- cgit v1.2.3 From 859093dae7dcadaff2e15a3885a1824b0d5f5913 Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Sat, 30 Aug 2014 11:29:45 +0200 Subject: support regular expressions in 'apt search' apt-cache search supported this since ever and in the code for apt was a fixme indicating this should be added here as well, so here we go. --- apt-private/private-cmndline.cc | 9 +++++-- apt-private/private-search.cc | 52 +++++++++++++++++++++++++++-------------- 2 files changed, 42 insertions(+), 19 deletions(-) (limited to 'apt-private') diff --git a/apt-private/private-cmndline.cc b/apt-private/private-cmndline.cc index a21a9dc8c..a4490f5b4 100644 --- a/apt-private/private-cmndline.cc +++ b/apt-private/private-cmndline.cc @@ -70,6 +70,8 @@ static bool addArgumentsAPTCache(std::vector &Args, char cons else return false; + bool const found_something = Args.empty() == false; + // FIXME: move to the correct command(s) addArg('g', "generate", "APT::Cache::Generate", 0); addArg('t', "target-release", "APT::Default-Release", CommandLine::HasArg); @@ -77,7 +79,8 @@ static bool addArgumentsAPTCache(std::vector &Args, char cons addArg('p', "pkg-cache", "Dir::Cache::pkgcache", CommandLine::HasArg); addArg('s', "src-cache", "Dir::Cache::srcpkgcache", CommandLine::HasArg); - return true; + + return found_something; } /*}}}*/ static bool addArgumentsAPTCDROM(std::vector &Args, char const * const Cmd)/*{{{*/ @@ -172,6 +175,8 @@ static bool addArgumentsAPTGet(std::vector &Args, char const addArg('s', "no-act", "APT::Get::Simulate", 0); } + bool const found_something = Args.empty() == false; + // FIXME: move to the correct command(s) addArg('d',"download-only","APT::Get::Download-Only",0); addArg('y',"yes","APT::Get::Assume-Yes",0); @@ -197,7 +202,7 @@ static bool addArgumentsAPTGet(std::vector &Args, char const addArg(0,"install-suggests","APT::Install-Suggests",CommandLine::Boolean); addArg(0,"fix-policy","APT::Get::Fix-Policy-Broken",0); - return true; + return found_something; } /*}}}*/ static bool addArgumentsAPTMark(std::vector &Args, char const * const Cmd)/*{{{*/ diff --git a/apt-private/private-search.cc b/apt-private/private-search.cc index ecd5d7fad..2230c973a 100644 --- a/apt-private/private-search.cc +++ b/apt-private/private-search.cc @@ -36,8 +36,28 @@ bool FullTextSearch(CommandLine &CmdL) /*{{{*/ if (unlikely(Cache == NULL || Plcy == NULL)) return false; - const char **patterns; - patterns = CmdL.FileList + 1; + // Make sure there is at least one argument + unsigned int const NumPatterns = CmdL.FileSize() -1; + if (NumPatterns < 1) + return _error->Error(_("You must give at least one search pattern")); + +#define APT_FREE_PATTERNS() for (std::vector::iterator P = Patterns.begin(); \ + P != Patterns.end(); ++P) { regfree(&(*P)); } + + // Compile the regex pattern + std::vector Patterns; + for (unsigned int I = 0; I != NumPatterns; ++I) + { + regex_t pattern; + if (regcomp(&pattern, CmdL.FileList[I + 1], REG_EXTENDED | REG_ICASE | REG_NOSUB) != 0) + { + APT_FREE_PATTERNS(); + return _error->Error("Regex compilation error"); + } + Patterns.push_back(pattern); + } + + bool const NamesOnly = _config->FindB("APT::Cache::NamesOnly", false); std::map output_map; std::map::const_iterator K; @@ -56,26 +76,23 @@ bool FullTextSearch(CommandLine &CmdL) /*{{{*/ if (Done%500 == 0) progress.Progress(Done); ++Done; - - int i; + pkgCache::DescIterator Desc = V.TranslatedDescription(); pkgRecords::Parser &parser = records.Lookup(Desc.FileList()); - + bool all_found = true; - for(i=0; patterns[i] != NULL; ++i) + for (std::vector::const_iterator pattern = Patterns.begin(); + pattern != Patterns.end(); ++pattern) { - // FIXME: use regexp instead of simple find() - const char *pattern = patterns[i]; - all_found &= ( - strstr(V.ParentPkg().Name(), pattern) != NULL || - strcasestr(parser.ShortDesc().c_str(), pattern) != NULL || - strcasestr(parser.LongDesc().c_str(), pattern) != NULL); - // search patterns are AND by default so we can skip looking further - // on the first mismatch - if(all_found == false) - break; + if (regexec(&(*pattern), V.ParentPkg().Name(), 0, 0, 0) == 0) + continue; + else if (NamesOnly == false && regexec(&(*pattern), parser.LongDesc().c_str(), 0, 0, 0) == 0) + continue; + // search patterns are AND, so one failing fails all + all_found = false; + break; } - if (all_found) + if (all_found == true) { std::stringstream outs; ListSingleVersion(CacheFile, records, V, outs); @@ -83,6 +100,7 @@ bool FullTextSearch(CommandLine &CmdL) /*{{{*/ V.ParentPkg().Name(), outs.str())); } } + APT_FREE_PATTERNS(); progress.Done(); // FIXME: SORT! and make sorting flexible (alphabetic, by pkg status) -- cgit v1.2.3 From 206b6bb3ec7d4cf45f3ae67e6d317f1da63f5b98 Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Mon, 1 Sep 2014 19:09:40 +0200 Subject: skip version if we already have this package as search-result Git-Dch: Ignore --- apt-private/private-search.cc | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) (limited to 'apt-private') diff --git a/apt-private/private-search.cc b/apt-private/private-search.cc index 2230c973a..2d427fa25 100644 --- a/apt-private/private-search.cc +++ b/apt-private/private-search.cc @@ -32,7 +32,6 @@ bool FullTextSearch(CommandLine &CmdL) /*{{{*/ pkgCacheFile CacheFile; pkgCache *Cache = CacheFile.GetPkgCache(); pkgDepCache::Policy *Plcy = CacheFile.GetPolicy(); - pkgRecords records(CacheFile); if (unlikely(Cache == NULL || Plcy == NULL)) return false; @@ -60,7 +59,6 @@ bool FullTextSearch(CommandLine &CmdL) /*{{{*/ bool const NamesOnly = _config->FindB("APT::Cache::NamesOnly", false); std::map output_map; - std::map::const_iterator K; LocalitySortedVersionSet bag; OpTextProgress progress(*_config); @@ -70,6 +68,7 @@ bool FullTextSearch(CommandLine &CmdL) /*{{{*/ progress.OverallProgress(50, 100, 50, _("Full Text Search")); progress.SubProgress(bag.size()); + pkgRecords records(CacheFile); int Done = 0; for ( ;V != bag.end(); ++V) { @@ -77,16 +76,22 @@ bool FullTextSearch(CommandLine &CmdL) /*{{{*/ progress.Progress(Done); ++Done; + // we want to list each package only once + char const * const PkgName = V.ParentPkg().Name(); + if (output_map.find(PkgName) != output_map.end()) + continue; + pkgCache::DescIterator Desc = V.TranslatedDescription(); pkgRecords::Parser &parser = records.Lookup(Desc.FileList()); + std::string const LongDesc = parser.LongDesc(); bool all_found = true; for (std::vector::const_iterator pattern = Patterns.begin(); pattern != Patterns.end(); ++pattern) { - if (regexec(&(*pattern), V.ParentPkg().Name(), 0, 0, 0) == 0) + if (regexec(&(*pattern), PkgName, 0, 0, 0) == 0) continue; - else if (NamesOnly == false && regexec(&(*pattern), parser.LongDesc().c_str(), 0, 0, 0) == 0) + else if (NamesOnly == false && regexec(&(*pattern), LongDesc.c_str(), 0, 0, 0) == 0) continue; // search patterns are AND, so one failing fails all all_found = false; @@ -97,7 +102,7 @@ bool FullTextSearch(CommandLine &CmdL) /*{{{*/ std::stringstream outs; ListSingleVersion(CacheFile, records, V, outs); output_map.insert(std::make_pair( - V.ParentPkg().Name(), outs.str())); + PkgName, outs.str())); } } APT_FREE_PATTERNS(); @@ -105,6 +110,7 @@ bool FullTextSearch(CommandLine &CmdL) /*{{{*/ // FIXME: SORT! and make sorting flexible (alphabetic, by pkg status) // output the sorted map + std::map::const_iterator K; for (K = output_map.begin(); K != output_map.end(); ++K) std::cout << (*K).second << std::endl; -- cgit v1.2.3 From 2409df55f65c4937ceda21ba069eec769af9e460 Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Mon, 1 Sep 2014 21:43:15 +0200 Subject: use a format string in ListSingleVersion The method already deals with a format string, but had an else path doing a hardcoded format as well. This is changed now to use the same code for both - the format in the second case is still fixed though. Git-Dch: Ignore --- apt-private/private-output.cc | 147 +++++++++++++++++++++--------------------- 1 file changed, 75 insertions(+), 72 deletions(-) (limited to 'apt-private') diff --git a/apt-private/private-output.cc b/apt-private/private-output.cc index 522f7682d..7be56de2e 100644 --- a/apt-private/private-output.cc +++ b/apt-private/private-output.cc @@ -164,15 +164,26 @@ static std::string GetVersion(pkgCacheFile &/*CacheFile*/, pkgCache::VerIterator /*}}}*/ static std::string GetArchitecture(pkgCacheFile &CacheFile, pkgCache::PkgIterator P)/*{{{*/ { - pkgPolicy *policy = CacheFile.GetPolicy(); - pkgCache::VerIterator inst = P.CurrentVer(); - pkgCache::VerIterator cand = policy->GetCandidateVer(P); - - // this may happen for packages in dpkg "deinstall ok config-file" state - if (inst.IsGood() == false && cand.IsGood() == false) - return P.VersionList().Arch(); - - return inst ? inst.Arch() : cand.Arch(); + if (P->CurrentVer == 0) + { + pkgDepCache * const DepCache = CacheFile.GetDepCache(); + pkgDepCache::StateCache const &state = (*DepCache)[P]; + if (state.CandidateVer != NULL) + { + pkgCache::VerIterator const CandV(CacheFile, state.CandidateVer); + return CandV.Arch(); + } + else + { + pkgCache::VerIterator const V = P.VersionList(); + if (V.end() == false) + return V.Arch(); + else + return P.Arch(); + } + } + else + return P.CurrentVer().Arch(); } /*}}}*/ static std::string GetShortDescription(pkgCacheFile &CacheFile, pkgRecords &records, pkgCache::PkgIterator P)/*{{{*/ @@ -200,77 +211,69 @@ void ListSingleVersion(pkgCacheFile &CacheFile, pkgRecords &records, /*{{{*/ pkgCache::VerIterator V, std::ostream &out, bool include_summary) { - pkgCache::PkgIterator P = V.ParentPkg(); - - pkgDepCache *DepCache = CacheFile.GetDepCache(); - pkgDepCache::StateCache &state = (*DepCache)[P]; - - std::string suite = GetArchiveSuite(CacheFile, V); - std::string name_str = P.Name(); + pkgCache::PkgIterator const P = V.ParentPkg(); + pkgDepCache * const DepCache = CacheFile.GetDepCache(); + pkgDepCache::StateCache const &state = (*DepCache)[P]; + std::string output; if (_config->FindB("APT::Cmd::use-format", false)) + output = _config->Find("APT::Cmd::format", "${db::Status-Abbrev} ${Package} ${Version} ${Origin} ${Description}"); + else { - std::string format = _config->Find("APT::Cmd::format", "${db::Status-Abbrev} ${Package} ${Version} ${Origin} ${Description}"); - std::string output = format; - - output = SubstVar(output, "${db::Status-Abbrev}", GetFlagsStr(CacheFile, P)); - output = SubstVar(output, "${Package}", name_str); - output = SubstVar(output, "${installed:Version}", GetInstalledVersion(CacheFile, P)); - output = SubstVar(output, "${candidate:Version}", GetCandidateVersion(CacheFile, P)); - output = SubstVar(output, "${Version}", GetVersion(CacheFile, V)); - output = SubstVar(output, "${Description}", GetShortDescription(CacheFile, records, P)); - output = SubstVar(output, "${Origin}", GetArchiveSuite(CacheFile, V)); - out << output; - } else { - // raring/linux-kernel version [upradable: new-version] + // linux-kernel/unstable version [installed,upradable to: new-version] // description - pkgPolicy *policy = CacheFile.GetPolicy(); - std::string VersionStr = GetVersion(CacheFile, V); - std::string CandidateVerStr = GetCandidateVersion(CacheFile, P); - std::string InstalledVerStr = GetInstalledVersion(CacheFile, P); - std::string StatusStr; - if(P.CurrentVer() == V && state.Upgradable()) + output = "${color:highlight}${Package}${color:neutral}/${Origin} ${Version} ${Architecture} ${apt:Status}"; + } + + // FIXME: some of these names are really icky – and all is nowhere documented + output = SubstVar(output, "${db::Status-Abbrev}", GetFlagsStr(CacheFile, P)); + output = SubstVar(output, "${Package}", P.Name()); + std::string const ArchStr = GetArchitecture(CacheFile, P); + output = SubstVar(output, "${Architecture}", ArchStr); + std::string const InstalledVerStr = GetInstalledVersion(CacheFile, P); + output = SubstVar(output, "${installed:Version}", InstalledVerStr); + std::string const CandidateVerStr = GetCandidateVersion(CacheFile, P); + output = SubstVar(output, "${candidate:Version}", CandidateVerStr); + std::string const VersionStr = GetVersion(CacheFile, V); + output = SubstVar(output, "${Version}", VersionStr); + output = SubstVar(output, "${Origin}", GetArchiveSuite(CacheFile, V)); + + std::string StatusStr = ""; + if (P->CurrentVer != 0) + { + if (P.CurrentVer() == V) { - strprintf(StatusStr, _("[installed,upgradable to: %s]"), - CandidateVerStr.c_str()); - } else if (P.CurrentVer() == V) { - if(!V.Downloadable()) - StatusStr = _("[installed,local]"); - else - if(V.Automatic() && state.Garbage) - StatusStr = _("[installed,auto-removable]"); - else if (state.Flags & pkgCache::Flag::Auto) - StatusStr = _("[installed,automatic]"); - else - StatusStr = _("[installed]"); - } else if (P.CurrentVer() && - policy->GetCandidateVer(P) == V && - state.Upgradable()) { - strprintf(StatusStr, _("[upgradable from: %s]"), - InstalledVerStr.c_str()); - } else { - if (V.ParentPkg()->CurrentState == pkgCache::State::ConfigFiles) - StatusStr = _("[residual-config]"); - else - StatusStr = ""; + if (state.Upgradable() && state.CandidateVer != NULL) + strprintf(StatusStr, _("[installed,upgradable to: %s]"), + CandidateVerStr.c_str()); + else if (V.Downloadable() == false) + StatusStr = _("[installed,local]"); + else if(V.Automatic() == true && state.Garbage == true) + StatusStr = _("[installed,auto-removable]"); + else if ((state.Flags & pkgCache::Flag::Auto) == pkgCache::Flag::Auto) + StatusStr = _("[installed,automatic]"); + else + StatusStr = _("[installed]"); } - out << std::setiosflags(std::ios::left) - << _config->Find("APT::Color::Highlight", "") - << name_str - << _config->Find("APT::Color::Neutral", "") - << "/" << suite - << " " - << VersionStr << " " - << GetArchitecture(CacheFile, P); - if (StatusStr != "") - out << " " << StatusStr; + else if (state.CandidateVer == V && state.Upgradable()) + strprintf(StatusStr, _("[upgradable from: %s]"), + InstalledVerStr.c_str()); + } + else if (V.ParentPkg()->CurrentState == pkgCache::State::ConfigFiles) + StatusStr = _("[residual-config]"); + output = SubstVar(output, "${apt:Status}", StatusStr); + output = SubstVar(output, "${color:highlight}", _config->Find("APT::Color::Highlight", "")); + output = SubstVar(output, "${color:neutral}", _config->Find("APT::Color::Neutral", "")); + + output = APT::String::Strip(output); + if (_config->FindB("APT::Cmd::use-format", false) == false) + { if (include_summary) - { - out << std::endl - << " " << GetShortDescription(CacheFile, records, P) - << std::endl; - } + output += "\n ${Description}\n"; } + output = SubstVar(output, "${Description}", GetShortDescription(CacheFile, records, P)); + + out << output; } /*}}}*/ // ShowList - Show a list /*{{{*/ -- cgit v1.2.3 From 1a68655de92fd036ebc7c920bc2e5e88c54eb34e Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Tue, 2 Sep 2014 14:32:48 +0200 Subject: implement --full in apt search --- apt-private/private-list.cc | 39 ++++++++++++++++--------------------- apt-private/private-output.cc | 45 +++++++++++++++++++++++++++++-------------- apt-private/private-output.h | 4 ++-- apt-private/private-search.cc | 9 ++++++++- 4 files changed, 58 insertions(+), 39 deletions(-) (limited to 'apt-private') diff --git a/apt-private/private-list.cc b/apt-private/private-list.cc index b69002103..d746acf3f 100644 --- a/apt-private/private-list.cc +++ b/apt-private/private-list.cc @@ -85,15 +85,14 @@ private: }; /*}}}*/ static void ListAllVersions(pkgCacheFile &CacheFile, pkgRecords &records,/*{{{*/ - pkgCache::PkgIterator P, - std::ostream &outs, - bool include_summary=true) + pkgCache::PkgIterator const &P, std::ostream &outs, + std::string const &format) { for (pkgCache::VerIterator Ver = P.VersionList(); Ver.end() == false; ++Ver) { - ListSingleVersion(CacheFile, records, Ver, outs, include_summary); - outs << "\n"; + ListSingleVersion(CacheFile, records, Ver, outs, format); + outs << std::endl; } } /*}}}*/ @@ -117,10 +116,9 @@ bool DoList(CommandLine &Cmd) patterns = Cmd.FileList + 1; } - std::map output_map; - std::map::const_iterator K; - - bool includeSummary = _config->FindB("APT::Cmd::List-Include-Summary"); + std::string format = "${color:highlight}${Package}${color:neutral}/${Origin} ${Version} ${Architecture}${ }${apt:Status}"; + if (_config->FindB("APT::Cmd::List-Include-Summary", false) == true) + format += "\n ${Description}\n"; PackageNameMatcher matcher(patterns); LocalitySortedVersionSet bag; @@ -130,36 +128,33 @@ bool DoList(CommandLine &Cmd) Cache->Head().PackageCount, _("Listing")); GetLocalitySortedVersionSet(CacheFile, bag, matcher, progress); - bool ShowAllVersions = _config->FindB("APT::Cmd::All-Versions", false); + bool const ShowAllVersions = _config->FindB("APT::Cmd::All-Versions", false); + std::map output_map; for (LocalitySortedVersionSet::iterator V = bag.begin(); V != bag.end(); ++V) { std::stringstream outs; if(ShowAllVersions == true) - { - ListAllVersions(CacheFile, records, V.ParentPkg(), outs, includeSummary); - output_map.insert(std::make_pair( - V.ParentPkg().Name(), outs.str())); - } else { - ListSingleVersion(CacheFile, records, V, outs, includeSummary); - output_map.insert(std::make_pair( - V.ParentPkg().Name(), outs.str())); - } + ListAllVersions(CacheFile, records, V.ParentPkg(), outs, format); + else + ListSingleVersion(CacheFile, records, V, outs, format); + output_map.insert(std::make_pair( + V.ParentPkg().Name(), outs.str())); } // FIXME: SORT! and make sorting flexible (alphabetic, by pkg status) // output the sorted map + std::map::const_iterator K; for (K = output_map.begin(); K != output_map.end(); ++K) std::cout << (*K).second << std::endl; - // be nice and tell the user if there is more to see if (bag.size() == 1 && ShowAllVersions == false) { // start with -1 as we already displayed one version int versions = -1; pkgCache::VerIterator Ver = *bag.begin(); - for ( ; Ver.end() == false; Ver++) - versions++; + for ( ; Ver.end() == false; ++Ver) + ++versions; if (versions > 0) _error->Notice(P_("There is %i additional version. Please use the '-a' switch to see it", "There are %i additional versions. Please use the '-a' switch to see them.", versions), versions); } diff --git a/apt-private/private-output.cc b/apt-private/private-output.cc index 7be56de2e..fc76a05bc 100644 --- a/apt-private/private-output.cc +++ b/apt-private/private-output.cc @@ -207,9 +207,31 @@ static std::string GetShortDescription(pkgCacheFile &CacheFile, pkgRecords &reco return ShortDescription; } /*}}}*/ +static std::string GetLongDescription(pkgCacheFile &CacheFile, pkgRecords &records, pkgCache::PkgIterator P)/*{{{*/ +{ + pkgPolicy *policy = CacheFile.GetPolicy(); + + pkgCache::VerIterator ver; + if (P->CurrentVer != 0) + ver = P.CurrentVer(); + else + ver = policy->GetCandidateVer(P); + + std::string const EmptyDescription = "(none)"; + if(ver.end() == true) + return EmptyDescription; + + pkgCache::DescIterator const Desc = ver.TranslatedDescription(); + pkgRecords::Parser & parser = records.Lookup(Desc.FileList()); + std::string const longdesc = parser.LongDesc(); + if (longdesc.empty() == true) + return EmptyDescription; + return SubstVar(longdesc, "\n ", "\n "); +} + /*}}}*/ void ListSingleVersion(pkgCacheFile &CacheFile, pkgRecords &records, /*{{{*/ - pkgCache::VerIterator V, std::ostream &out, - bool include_summary) + pkgCache::VerIterator const &V, std::ostream &out, + std::string const &format) { pkgCache::PkgIterator const P = V.ParentPkg(); pkgDepCache * const DepCache = CacheFile.GetDepCache(); @@ -219,11 +241,7 @@ void ListSingleVersion(pkgCacheFile &CacheFile, pkgRecords &records, /*{{{*/ if (_config->FindB("APT::Cmd::use-format", false)) output = _config->Find("APT::Cmd::format", "${db::Status-Abbrev} ${Package} ${Version} ${Origin} ${Description}"); else - { - // linux-kernel/unstable version [installed,upradable to: new-version] - // description - output = "${color:highlight}${Package}${color:neutral}/${Origin} ${Version} ${Architecture} ${apt:Status}"; - } + output = format; // FIXME: some of these names are really icky – and all is nowhere documented output = SubstVar(output, "${db::Status-Abbrev}", GetFlagsStr(CacheFile, P)); @@ -264,14 +282,13 @@ void ListSingleVersion(pkgCacheFile &CacheFile, pkgRecords &records, /*{{{*/ output = SubstVar(output, "${apt:Status}", StatusStr); output = SubstVar(output, "${color:highlight}", _config->Find("APT::Color::Highlight", "")); output = SubstVar(output, "${color:neutral}", _config->Find("APT::Color::Neutral", "")); - - output = APT::String::Strip(output); - if (_config->FindB("APT::Cmd::use-format", false) == false) - { - if (include_summary) - output += "\n ${Description}\n"; - } output = SubstVar(output, "${Description}", GetShortDescription(CacheFile, records, P)); + output = SubstVar(output, "${LongDescription}", GetLongDescription(CacheFile, records, P)); + output = SubstVar(output, "${ }${ }", "${ }"); + output = SubstVar(output, "${ }\n", "\n"); + output = SubstVar(output, "${ }", " "); + if (APT::String::Endswith(output, " ") == true) + output.erase(output.length() - 1); out << output; } diff --git a/apt-private/private-output.h b/apt-private/private-output.h index 6f3a964d7..e0dc9bf62 100644 --- a/apt-private/private-output.h +++ b/apt-private/private-output.h @@ -23,8 +23,8 @@ APT_PUBLIC extern unsigned int ScreenWidth; APT_PUBLIC bool InitOutput(); void ListSingleVersion(pkgCacheFile &CacheFile, pkgRecords &records, - pkgCache::VerIterator V, std::ostream &out, - bool include_summary=true); + pkgCache::VerIterator const &V, std::ostream &out, + std::string const &format); // helper to describe global state diff --git a/apt-private/private-search.cc b/apt-private/private-search.cc index 2d427fa25..5e12902e8 100644 --- a/apt-private/private-search.cc +++ b/apt-private/private-search.cc @@ -69,6 +69,13 @@ bool FullTextSearch(CommandLine &CmdL) /*{{{*/ progress.OverallProgress(50, 100, 50, _("Full Text Search")); progress.SubProgress(bag.size()); pkgRecords records(CacheFile); + + std::string format = "${color:highlight}${Package}${color:neutral}/${Origin} ${Version} ${Architecture}${ }${apt:Status}\n"; + if (_config->FindB("APT::Cache::ShowFull",false) == false) + format += " ${Description}\n"; + else + format += " ${LongDescription}\n"; + int Done = 0; for ( ;V != bag.end(); ++V) { @@ -100,7 +107,7 @@ bool FullTextSearch(CommandLine &CmdL) /*{{{*/ if (all_found == true) { std::stringstream outs; - ListSingleVersion(CacheFile, records, V, outs); + ListSingleVersion(CacheFile, records, V, outs, format); output_map.insert(std::make_pair( PkgName, outs.str())); } -- cgit v1.2.3 From 25594bb5bddc031afc4d62f3164cd9116d778517 Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Tue, 2 Sep 2014 18:20:49 +0200 Subject: make GetLocalitySortedVersionSet more generic MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit No reason in and of by itself at the moment, but prepares for the goal of having 'apt search' and 'apt-cache search' using the same code now that they at least support the same stuff. The 'apt' code is just a multitude slower at the moment… Git-Dch: Ignore --- apt-private/private-cacheset.cc | 89 +++++++++++++++++++++-------------------- apt-private/private-cacheset.h | 12 +++--- apt-private/private-list.cc | 2 +- apt-private/private-search.cc | 17 ++++---- 4 files changed, 63 insertions(+), 57 deletions(-) (limited to 'apt-private') diff --git a/apt-private/private-cacheset.cc b/apt-private/private-cacheset.cc index e37e7b227..eb77be274 100644 --- a/apt-private/private-cacheset.cc +++ b/apt-private/private-cacheset.cc @@ -14,74 +14,77 @@ #include -bool GetLocalitySortedVersionSet(pkgCacheFile &CacheFile, - LocalitySortedVersionSet &output_set, - OpProgress &progress) +bool GetLocalitySortedVersionSet(pkgCacheFile &CacheFile, + APT::VersionContainerInterface * const vci, + OpProgress * const progress) { Matcher null_matcher = Matcher(); - return GetLocalitySortedVersionSet(CacheFile, output_set, + return GetLocalitySortedVersionSet(CacheFile, vci, null_matcher, progress); } -bool GetLocalitySortedVersionSet(pkgCacheFile &CacheFile, - LocalitySortedVersionSet &output_set, +bool GetLocalitySortedVersionSet(pkgCacheFile &CacheFile, + APT::VersionContainerInterface * const vci, Matcher &matcher, - OpProgress &progress) + OpProgress * const progress) { pkgCache *Cache = CacheFile.GetPkgCache(); pkgDepCache *DepCache = CacheFile.GetDepCache(); + APT::CacheSetHelper helper(false); int Done=0; - progress.SubProgress(Cache->Head().PackageCount, _("Sorting")); + if (progress != NULL) + progress->SubProgress(Cache->Head().PackageCount, _("Sorting")); + + bool const insertCurrentVer = _config->FindB("APT::Cmd::Installed", false); + bool const insertUpgradable = _config->FindB("APT::Cmd::Upgradable", false); + bool const insertManualInstalled = _config->FindB("APT::Cmd::Manual-Installed", false); + for (pkgCache::PkgIterator P = Cache->PkgBegin(); P.end() == false; ++P) { - if (Done%500 == 0) - progress.Progress(Done); - Done++; + if (progress != NULL) + { + if (Done % 500 == 0) + progress->Progress(Done); + ++Done; + } + + // exclude virtual pkgs + if (P->VersionList == 0) + continue; if ((matcher)(P) == false) - continue; + continue; - // exclude virtual pkgs - if (P.VersionList() == 0) - continue; pkgDepCache::StateCache &state = (*DepCache)[P]; - if (_config->FindB("APT::Cmd::Installed") == true) + if (insertCurrentVer == true) { - if (P.CurrentVer() != NULL) - { - output_set.insert(P.CurrentVer()); - } + if (P->CurrentVer != 0) + vci->FromPackage(vci, CacheFile, P, APT::VersionContainerInterface::INSTALLED, helper); } - else if (_config->FindB("APT::Cmd::Upgradable") == true) + else if (insertUpgradable == true) { - if(P.CurrentVer() && state.Upgradable()) - { - pkgPolicy *policy = CacheFile.GetPolicy(); - output_set.insert(policy->GetCandidateVer(P)); - } + if(P.CurrentVer() && state.Upgradable()) + vci->FromPackage(vci, CacheFile, P, APT::VersionContainerInterface::CANDIDATE, helper); } - else if (_config->FindB("APT::Cmd::Manual-Installed") == true) + else if (insertManualInstalled == true) { - if (P.CurrentVer() && - ((*DepCache)[P].Flags & pkgCache::Flag::Auto) == false) - { - pkgPolicy *policy = CacheFile.GetPolicy(); - output_set.insert(policy->GetCandidateVer(P)); - } + if (P.CurrentVer() && + ((*DepCache)[P].Flags & pkgCache::Flag::Auto) == false) + vci->FromPackage(vci, CacheFile, P, APT::VersionContainerInterface::CANDIDATE, helper); } - else + else { - pkgPolicy *policy = CacheFile.GetPolicy(); - if (policy->GetCandidateVer(P).IsGood()) - output_set.insert(policy->GetCandidateVer(P)); - else - // no candidate, this may happen for packages in - // dpkg "deinstall ok config-file" state - we pick the first ver - // (which should be the only one) - output_set.insert(P.VersionList()); + if (vci->FromPackage(vci, CacheFile, P, APT::VersionContainerInterface::CANDIDATE, helper) == false) + { + // no candidate, this may happen for packages in + // dpkg "deinstall ok config-file" state - we pick the first ver + // (which should be the only one) + vci->insert(P.VersionList()); + } } } - progress.Done(); + if (progress != NULL) + progress->Done(); return true; } diff --git a/apt-private/private-cacheset.h b/apt-private/private-cacheset.h index 854d16922..ca8f4be5d 100644 --- a/apt-private/private-cacheset.h +++ b/apt-private/private-cacheset.h @@ -62,13 +62,13 @@ public: }; // FIXME: add default argument for OpProgress (or overloaded function) -bool GetLocalitySortedVersionSet(pkgCacheFile &CacheFile, - LocalitySortedVersionSet &output_set, +bool GetLocalitySortedVersionSet(pkgCacheFile &CacheFile, + APT::VersionContainerInterface * const vci, Matcher &matcher, - OpProgress &progress); -bool GetLocalitySortedVersionSet(pkgCacheFile &CacheFile, - LocalitySortedVersionSet &output_set, - OpProgress &progress); + OpProgress * const progress); +bool GetLocalitySortedVersionSet(pkgCacheFile &CacheFile, + APT::VersionContainerInterface * const vci, + OpProgress * const progress); // CacheSetHelper saving virtual packages /*{{{*/ diff --git a/apt-private/private-list.cc b/apt-private/private-list.cc index d746acf3f..536348640 100644 --- a/apt-private/private-list.cc +++ b/apt-private/private-list.cc @@ -127,7 +127,7 @@ bool DoList(CommandLine &Cmd) Cache->Head().PackageCount, Cache->Head().PackageCount, _("Listing")); - GetLocalitySortedVersionSet(CacheFile, bag, matcher, progress); + GetLocalitySortedVersionSet(CacheFile, &bag, matcher, &progress); bool const ShowAllVersions = _config->FindB("APT::Cmd::All-Versions", false); std::map output_map; for (LocalitySortedVersionSet::iterator V = bag.begin(); V != bag.end(); ++V) diff --git a/apt-private/private-search.cc b/apt-private/private-search.cc index 5e12902e8..6bce9ffa4 100644 --- a/apt-private/private-search.cc +++ b/apt-private/private-search.cc @@ -63,7 +63,7 @@ bool FullTextSearch(CommandLine &CmdL) /*{{{*/ LocalitySortedVersionSet bag; OpTextProgress progress(*_config); progress.OverallProgress(0, 100, 50, _("Sorting")); - GetLocalitySortedVersionSet(CacheFile, bag, progress); + GetLocalitySortedVersionSet(CacheFile, &bag, &progress); LocalitySortedVersionSet::iterator V = bag.begin(); progress.OverallProgress(50, 100, 50, _("Full Text Search")); @@ -77,6 +77,7 @@ bool FullTextSearch(CommandLine &CmdL) /*{{{*/ format += " ${LongDescription}\n"; int Done = 0; + std::vector PkgsDone(Cache->Head().PackageCount, false); for ( ;V != bag.end(); ++V) { if (Done%500 == 0) @@ -84,10 +85,11 @@ bool FullTextSearch(CommandLine &CmdL) /*{{{*/ ++Done; // we want to list each package only once - char const * const PkgName = V.ParentPkg().Name(); - if (output_map.find(PkgName) != output_map.end()) + pkgCache::PkgIterator const P = V.ParentPkg(); + if (PkgsDone[P->ID] == true) continue; + char const * const PkgName = P.Name(); pkgCache::DescIterator Desc = V.TranslatedDescription(); pkgRecords::Parser &parser = records.Lookup(Desc.FileList()); std::string const LongDesc = parser.LongDesc(); @@ -106,10 +108,11 @@ bool FullTextSearch(CommandLine &CmdL) /*{{{*/ } if (all_found == true) { - std::stringstream outs; - ListSingleVersion(CacheFile, records, V, outs, format); - output_map.insert(std::make_pair( - PkgName, outs.str())); + PkgsDone[P->ID] = true; + std::stringstream outs; + ListSingleVersion(CacheFile, records, V, outs, format); + output_map.insert(std::make_pair( + PkgName, outs.str())); } } APT_FREE_PATTERNS(); -- cgit v1.2.3 From 22da5c135a74eee8ed998806136e25b8ed038bd0 Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Tue, 9 Sep 2014 13:52:32 +0200 Subject: don't call pager in non-terminals for changelog Most pagers are nice and default to running non-interactively if they aren't connected to a terminal and we relied on that. On ci.debian.net the configured pager is printing a header out of nowhere though, so if we are printing to a non-terminal we call "cat" instead. In the rework we also "remove" the dependency on sensible-utils in sofar as we call some alternatives if calling the utils fail. This seems to be the last problem preventing a "PASS" status on ci.debian.net, so we close the associated bugreport. Closes: 755040 --- apt-private/private-utils.cc | 58 +++++++++++++++++++++++++++++++------------- apt-private/private-utils.h | 4 +-- 2 files changed, 43 insertions(+), 19 deletions(-) (limited to 'apt-private') diff --git a/apt-private/private-utils.cc b/apt-private/private-utils.cc index 9547a1b75..34af83c08 100644 --- a/apt-private/private-utils.cc +++ b/apt-private/private-utils.cc @@ -8,45 +8,69 @@ #include #include -// DisplayFileInPager - Display File with pager /*{{{*/ -void DisplayFileInPager(std::string filename) +// DisplayFileInPager - Display File with pager /*{{{*/ +void DisplayFileInPager(std::string const &filename) { - std::string pager = _config->Find("Dir::Bin::Pager", - "/usr/bin/sensible-pager"); - pid_t Process = ExecFork(); if (Process == 0) { const char *Args[3]; - Args[0] = pager.c_str(); Args[1] = filename.c_str(); - Args[2] = 0; + Args[2] = NULL; + if (isatty(STDOUT_FILENO) == 1) + { + // likely installed, provided by sensible-utils + std::string const pager = _config->Find("Dir::Bin::Pager", + "sensible-pager"); + Args[0] = pager.c_str(); + execvp(Args[0],(char **)Args); + // lets try some obvious alternatives + Args[0] = getenv("PAGER"); + if (Args[0] != NULL) + execvp(Args[0],(char **)Args); + + Args[0] = "pager"; + execvp(Args[0],(char **)Args); + } + // we could read the file ourselves, but… meh + Args[0] = "cat"; execvp(Args[0],(char **)Args); exit(100); } - + // Wait for the subprocess - ExecWait(Process, "sensible-pager", false); + ExecWait(Process, "pager", false); } /*}}}*/ -// EditFileInSensibleEditor - Edit File with editor /*{{{*/ -void EditFileInSensibleEditor(std::string filename) +// EditFileInSensibleEditor - Edit File with editor /*{{{*/ +void EditFileInSensibleEditor(std::string const &filename) { - std::string editor = _config->Find("Dir::Bin::Editor", - "/usr/bin/sensible-editor"); - pid_t Process = ExecFork(); if (Process == 0) { + // likely installed, provided by sensible-utils + std::string const editor = _config->Find("Dir::Bin::Editor", + "sensible-editor"); const char *Args[3]; Args[0] = editor.c_str(); Args[1] = filename.c_str(); - Args[2] = 0; + Args[2] = NULL; + execvp(Args[0],(char **)Args); + // the usual suspects we can try as an alternative + Args[0] = getenv("VISUAL"); + if (Args[0] != NULL) + execvp(Args[0],(char **)Args); + + Args[0] = getenv("EDITOR"); + if (Args[0] != NULL) + execvp(Args[0],(char **)Args); + + Args[0] = "editor"; execvp(Args[0],(char **)Args); exit(100); } - + // Wait for the subprocess - ExecWait(Process, "sensible-editor", false); + ExecWait(Process, "editor", false); } /*}}}*/ diff --git a/apt-private/private-utils.h b/apt-private/private-utils.h index 432699787..8ba480bd4 100644 --- a/apt-private/private-utils.h +++ b/apt-private/private-utils.h @@ -5,7 +5,7 @@ #include -APT_PUBLIC void DisplayFileInPager(std::string filename); -APT_PUBLIC void EditFileInSensibleEditor(std::string filename); +APT_PUBLIC void DisplayFileInPager(std::string const &filename); +APT_PUBLIC void EditFileInSensibleEditor(std::string const &filename); #endif -- cgit v1.2.3 From b0f4b486e6850c5f98520ccf19da71d0ed748ae4 Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Sun, 21 Sep 2014 10:18:03 +0200 Subject: generalize Acquire::GzipIndex --- apt-private/private-update.cc | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'apt-private') diff --git a/apt-private/private-update.cc b/apt-private/private-update.cc index 860d84b86..1cf3012ed 100644 --- a/apt-private/private-update.cc +++ b/apt-private/private-update.cc @@ -56,10 +56,17 @@ bool DoUpdate(CommandLine &CmdL) if (List->GetIndexes(&Fetcher,true) == false) return false; + std::string compExt = APT::Configuration::getCompressionTypes()[0]; pkgAcquire::UriIterator I = Fetcher.UriBegin(); for (; I != Fetcher.UriEnd(); ++I) - c1out << '\'' << I->URI << "' " << flNotDir(I->Owner->DestFile) << ' ' << + { + std::string FileName = flNotDir(I->Owner->DestFile); + if(compExt.empty() == false && + APT::String::Endswith(FileName, compExt)) + FileName = FileName.substr(0, FileName.size() - compExt.size() - 1); + c1out << '\'' << I->URI << "' " << FileName << ' ' << I->Owner->FileSize << ' ' << I->Owner->HashSum() << std::endl; + } return true; } -- cgit v1.2.3 From fe86debbae914b51d2799e7b24abfd1f944f8caf Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Thu, 19 Jun 2014 11:00:02 +0200 Subject: deprecate Pkg->Name in favor of Grp->Name They both store the same information, so this field just takes up space in the Package struct for no good reason. We mark it "just" as deprecated instead of instantly removing it though as it isn't misleading like Section was and is potentially used in the wild more often. --- apt-private/private-cachefile.cc | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'apt-private') diff --git a/apt-private/private-cachefile.cc b/apt-private/private-cachefile.cc index 5e955ac39..29e665245 100644 --- a/apt-private/private-cachefile.cc +++ b/apt-private/private-cachefile.cc @@ -32,8 +32,10 @@ int CacheFile::NameComp(const void *a,const void *b) const pkgCache::Package &A = **(pkgCache::Package **)a; const pkgCache::Package &B = **(pkgCache::Package **)b; + const pkgCache::Group * const GA = SortCache->GrpP + A.Group; + const pkgCache::Group * const GB = SortCache->GrpP + B.Group; - return strcmp(SortCache->StrP + A.Name,SortCache->StrP + B.Name); + return strcmp(SortCache->StrP + GA->Name,SortCache->StrP + GB->Name); } /*}}}*/ // CacheFile::Sort - Sort by name /*{{{*/ -- cgit v1.2.3 From 2a884c612b10b27f4be2cc6dd689bfe448d9361a Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Sun, 17 Aug 2014 12:30:21 +0200 Subject: fix progress output for (dist-)upgrade calculation MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Previously, we had a start and a done of the calculation printed by higher-level code, but this got intermixed by progress reporting from an external solver or the output of autoremove code… The higherlevel code is now only responsible for instantiating a progress object of its choosing (if it wants progress after all) and the rest will be handled by the upgrade code. Either it is used to show the progress of the external solver or the internal solver will give some hints about its overall progress. The later isn't really a proper progress as it will jump forward after each substep, but that is at least a bit better than before without any progress indication. Fixes also the 'strange' non-display of this progress line in -q=1, while all others are shown, which is reflected by all testcase changes. --- apt-private/private-install.cc | 11 +++++++---- apt-private/private-upgrade.cc | 2 -- 2 files changed, 7 insertions(+), 6 deletions(-) (limited to 'apt-private') diff --git a/apt-private/private-install.cc b/apt-private/private-install.cc index 55893bda0..656b97233 100644 --- a/apt-private/private-install.cc +++ b/apt-private/private-install.cc @@ -620,14 +620,17 @@ bool DoCacheManipulationFromCommandLine(CommandLine &CmdL, CacheFile &Cache, { // Call the scored problem resolver bool resolver_fail = false; + OpTextProgress Progress(*_config); + bool const distUpgradeMode = strcmp(CmdL.FileList[0], "dist-upgrade") == 0 || strcmp(CmdL.FileList[0], "full-upgrade") == 0; + if (UpgradeMode == 0) { - if (strcmp(CmdL.FileList[0], "dist-upgrade") == 0 || strcmp(CmdL.FileList[0], "full-upgrade") == 0) - resolver_fail = APT::Upgrade::Upgrade(Cache, 0); + if (distUpgradeMode == true) + resolver_fail = APT::Upgrade::Upgrade(Cache, 0, &Progress); else - resolver_fail = Fix->Resolve(true); + resolver_fail = Fix->Resolve(true, &Progress); } else - resolver_fail = APT::Upgrade::Upgrade(Cache, UpgradeMode); + resolver_fail = APT::Upgrade::Upgrade(Cache, UpgradeMode, &Progress); if (resolver_fail == false && Cache->BrokenCount() == 0) return false; diff --git a/apt-private/private-upgrade.cc b/apt-private/private-upgrade.cc index 31f067576..2a6dcc153 100644 --- a/apt-private/private-upgrade.cc +++ b/apt-private/private-upgrade.cc @@ -22,10 +22,8 @@ static bool UpgradeHelper(CommandLine &CmdL, int UpgradeFlags) if (Cache.OpenForInstall() == false || Cache.CheckDeps() == false) return false; - c0out << _("Calculating upgrade... ") << std::flush; if(!DoCacheManipulationFromCommandLine(CmdL, Cache, UpgradeFlags)) return false; - c0out << _("Done") << std::endl; return InstallPackages(Cache,true); } -- cgit v1.2.3 From 67caa2e6538f13ff7a0d77e98ad6c58af998376d Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Sun, 17 Aug 2014 13:27:59 +0200 Subject: mark pkg(All|Dist)Upgrade as deprecated The comment above their definition marks them already as such, so this is only a formalisation of the deprecation and fixes the occurances we have in our own code together with removing a magic number. Git-Dch: Ignore --- apt-private/private-install.cc | 12 ++++-------- apt-private/private-upgrade.cc | 2 +- 2 files changed, 5 insertions(+), 9 deletions(-) (limited to 'apt-private') diff --git a/apt-private/private-install.cc b/apt-private/private-install.cc index 656b97233..c172f5ee7 100644 --- a/apt-private/private-install.cc +++ b/apt-private/private-install.cc @@ -619,18 +619,14 @@ bool DoCacheManipulationFromCommandLine(CommandLine &CmdL, CacheFile &Cache, if (Fix != NULL) { // Call the scored problem resolver - bool resolver_fail = false; OpTextProgress Progress(*_config); bool const distUpgradeMode = strcmp(CmdL.FileList[0], "dist-upgrade") == 0 || strcmp(CmdL.FileList[0], "full-upgrade") == 0; - if (UpgradeMode == 0) - { - if (distUpgradeMode == true) - resolver_fail = APT::Upgrade::Upgrade(Cache, 0, &Progress); - else - resolver_fail = Fix->Resolve(true, &Progress); - } else + bool resolver_fail = false; + if (distUpgradeMode == true || UpgradeMode != APT::Upgrade::ALLOW_EVERYTHING) resolver_fail = APT::Upgrade::Upgrade(Cache, UpgradeMode, &Progress); + else + resolver_fail = Fix->Resolve(true, &Progress); if (resolver_fail == false && Cache->BrokenCount() == 0) return false; diff --git a/apt-private/private-upgrade.cc b/apt-private/private-upgrade.cc index 2a6dcc153..d13a6af49 100644 --- a/apt-private/private-upgrade.cc +++ b/apt-private/private-upgrade.cc @@ -33,7 +33,7 @@ static bool UpgradeHelper(CommandLine &CmdL, int UpgradeFlags) /* Intelligent upgrader that will install and remove packages at will */ bool DoDistUpgrade(CommandLine &CmdL) { - return UpgradeHelper(CmdL, 0); + return UpgradeHelper(CmdL, APT::Upgrade::ALLOW_EVERYTHING); } /*}}}*/ bool DoUpgrade(CommandLine &CmdL) /*{{{*/ -- cgit v1.2.3 From fdba4d53d6b9b594531c34792798f4044a25157e Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Wed, 3 Sep 2014 18:16:16 +0200 Subject: rework cachesets API to allow future extension MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The introduction of Fnmatch showed that each new selector would require multiple new virtual methods in the CacheSetHelper to work correctly, which isn't that great. We now flip to a single virtual method which handles all cases separated by an enum – as new enum values can be added without an ABI break. Great care was taken to make old code work with the new way of organisation, which means in return that you might be bombarded with deprecation warnings now if you don't adapt, but code should still compile and work as before as can be seen in apt itself with this commit. Git-Dch: Ignore --- apt-private/private-cacheset.cc | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'apt-private') diff --git a/apt-private/private-cacheset.cc b/apt-private/private-cacheset.cc index eb77be274..cb68024db 100644 --- a/apt-private/private-cacheset.cc +++ b/apt-private/private-cacheset.cc @@ -60,22 +60,22 @@ bool GetLocalitySortedVersionSet(pkgCacheFile &CacheFile, if (insertCurrentVer == true) { if (P->CurrentVer != 0) - vci->FromPackage(vci, CacheFile, P, APT::VersionContainerInterface::INSTALLED, helper); + vci->FromPackage(vci, CacheFile, P, APT::CacheSetHelper::INSTALLED, helper); } else if (insertUpgradable == true) { if(P.CurrentVer() && state.Upgradable()) - vci->FromPackage(vci, CacheFile, P, APT::VersionContainerInterface::CANDIDATE, helper); + vci->FromPackage(vci, CacheFile, P, APT::CacheSetHelper::CANDIDATE, helper); } else if (insertManualInstalled == true) { if (P.CurrentVer() && ((*DepCache)[P].Flags & pkgCache::Flag::Auto) == false) - vci->FromPackage(vci, CacheFile, P, APT::VersionContainerInterface::CANDIDATE, helper); + vci->FromPackage(vci, CacheFile, P, APT::CacheSetHelper::CANDIDATE, helper); } else { - if (vci->FromPackage(vci, CacheFile, P, APT::VersionContainerInterface::CANDIDATE, helper) == false) + if (vci->FromPackage(vci, CacheFile, P, APT::CacheSetHelper::CANDIDATE, helper) == false) { // no candidate, this may happen for packages in // dpkg "deinstall ok config-file" state - we pick the first ver -- cgit v1.2.3 From e6f0c9bca4b052d20a2e48ce9715b89e187b671a Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Wed, 3 Sep 2014 19:02:05 +0200 Subject: adapt to the new CacheSetHelper API Git-Dch: Ignore --- apt-private/private-cacheset.h | 25 +++++++++++-------------- apt-private/private-install.cc | 4 ++-- apt-private/private-show.cc | 8 ++++---- 3 files changed, 17 insertions(+), 20 deletions(-) (limited to 'apt-private') diff --git a/apt-private/private-cacheset.h b/apt-private/private-cacheset.h index ca8f4be5d..059c7637e 100644 --- a/apt-private/private-cacheset.h +++ b/apt-private/private-cacheset.h @@ -76,19 +76,16 @@ class CacheSetHelperVirtuals: public APT::CacheSetHelper { public: APT::PackageSet virtualPkgs; - virtual pkgCache::VerIterator canNotFindCandidateVer(pkgCacheFile &Cache, pkgCache::PkgIterator const &Pkg) { - virtualPkgs.insert(Pkg); - return CacheSetHelper::canNotFindCandidateVer(Cache, Pkg); + virtual pkgCache::VerIterator canNotGetVersion(enum CacheSetHelper::VerSelector const select, pkgCacheFile &Cache, pkgCache::PkgIterator const &Pkg) { + if (select == NEWEST || select == CANDIDATE || select == ALL) + virtualPkgs.insert(Pkg); + return CacheSetHelper::canNotGetVersion(select, Cache, Pkg); } - virtual pkgCache::VerIterator canNotFindNewestVer(pkgCacheFile &Cache, pkgCache::PkgIterator const &Pkg) { - virtualPkgs.insert(Pkg); - return CacheSetHelper::canNotFindNewestVer(Cache, Pkg); - } - - virtual void canNotFindAllVer(APT::VersionContainerInterface * vci, pkgCacheFile &Cache, pkgCache::PkgIterator const &Pkg) { - virtualPkgs.insert(Pkg); - CacheSetHelper::canNotFindAllVer(vci, Cache, Pkg); + virtual void canNotFindVersion(enum CacheSetHelper::VerSelector const select, APT::VersionContainerInterface * vci, pkgCacheFile &Cache, pkgCache::PkgIterator const &Pkg) { + if (select == NEWEST || select == CANDIDATE || select == ALL) + virtualPkgs.insert(Pkg); + return CacheSetHelper::canNotFindVersion(select, vci, Cache, Pkg); } CacheSetHelperVirtuals(bool const ShowErrors = true, GlobalError::MsgType const &ErrorType = GlobalError::NOTICE) : CacheSetHelper(ShowErrors, ErrorType) {} @@ -190,7 +187,7 @@ public: } virtual pkgCache::VerIterator canNotFindCandidateVer(pkgCacheFile &Cache, pkgCache::PkgIterator const &Pkg) { - APT::VersionSet const verset = tryVirtualPackage(Cache, Pkg, APT::VersionSet::CANDIDATE); + APT::VersionSet const verset = tryVirtualPackage(Cache, Pkg, CacheSetHelper::CANDIDATE); if (verset.empty() == false) return *(verset.begin()); else if (ShowError == true) { @@ -203,7 +200,7 @@ public: virtual pkgCache::VerIterator canNotFindNewestVer(pkgCacheFile &Cache, pkgCache::PkgIterator const &Pkg) { if (Pkg->ProvidesList != 0) { - APT::VersionSet const verset = tryVirtualPackage(Cache, Pkg, APT::VersionSet::NEWEST); + APT::VersionSet const verset = tryVirtualPackage(Cache, Pkg, CacheSetHelper::NEWEST); if (verset.empty() == false) return *(verset.begin()); if (ShowError == true) @@ -231,7 +228,7 @@ public: } APT::VersionSet tryVirtualPackage(pkgCacheFile &Cache, pkgCache::PkgIterator const &Pkg, - APT::VersionSet::Version const &select) { + CacheSetHelper::VerSelector const select) { /* This is a pure virtual package and there is a single available candidate providing it. */ if (unlikely(Cache[Pkg].CandidateVer != 0) || Pkg->ProvidesList == 0) diff --git a/apt-private/private-install.cc b/apt-private/private-install.cc index c172f5ee7..86ba52857 100644 --- a/apt-private/private-install.cc +++ b/apt-private/private-install.cc @@ -560,9 +560,9 @@ bool DoCacheManipulationFromCommandLine(CommandLine &CmdL, CacheFile &Cache, std::list mods; mods.push_back(APT::VersionSet::Modifier(MOD_INSTALL, "+", - APT::VersionSet::Modifier::POSTFIX, APT::VersionSet::CANDIDATE)); + APT::VersionSet::Modifier::POSTFIX, APT::CacheSetHelper::CANDIDATE)); mods.push_back(APT::VersionSet::Modifier(MOD_REMOVE, "-", - APT::VersionSet::Modifier::POSTFIX, APT::VersionSet::NEWEST)); + APT::VersionSet::Modifier::POSTFIX, APT::CacheSetHelper::NEWEST)); CacheSetHelperAPTGet helper(c0out); verset = APT::VersionSet::GroupedFromCommandLine(Cache, CmdL.FileList + 1, mods, fallback, helper); diff --git a/apt-private/private-show.cc b/apt-private/private-show.cc index 8ae6a6dac..289f035a6 100644 --- a/apt-private/private-show.cc +++ b/apt-private/private-show.cc @@ -141,16 +141,16 @@ bool ShowPackage(CommandLine &CmdL) /*{{{*/ { pkgCacheFile CacheFile; CacheSetHelperVirtuals helper(true, GlobalError::NOTICE); - APT::VersionList::Version const select = _config->FindB("APT::Cache::AllVersions", false) ? - APT::VersionList::ALL : APT::VersionList::CANDIDATE; + APT::CacheSetHelper::VerSelector const select = _config->FindB("APT::Cache::AllVersions", false) ? + APT::CacheSetHelper::ALL : APT::CacheSetHelper::CANDIDATE; APT::VersionList const verset = APT::VersionList::FromCommandLine(CacheFile, CmdL.FileList + 1, select, helper); for (APT::VersionList::const_iterator Ver = verset.begin(); Ver != verset.end(); ++Ver) if (DisplayRecord(CacheFile, Ver, c1out) == false) return false; - if (select == APT::VersionList::CANDIDATE) + if (select == APT::CacheSetHelper::CANDIDATE) { - APT::VersionList const verset_all = APT::VersionList::FromCommandLine(CacheFile, CmdL.FileList + 1, APT::VersionList::ALL, helper); + APT::VersionList const verset_all = APT::VersionList::FromCommandLine(CacheFile, CmdL.FileList + 1, APT::CacheSetHelper::ALL, helper); int const records = verset_all.size() - verset.size(); if (records > 0) _error->Notice(P_("There is %i additional record. Please use the '-a' switch to see it", "There are %i additional records. Please use the '-a' switch to see them.", records), records); -- cgit v1.2.3 From ffbe056dc554b3f1fdf79b4726415a70f6d59dc1 Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Sun, 28 Sep 2014 01:57:49 +0200 Subject: replace c-string Mode with c++-string ActiveSubprocess A long-lasting FIXME in the acquire code points out the problem that we e.g. for decompressors assign c-string representations of c++-strings to the Mode variable, which e.g. cppcheck points out as very bad. In practice, nothing major happens as the c++-strings do not run out of scope until Mode would do, but that is bad style and fragile, so the obvious proper fix is to use a c++ string for storage to begin with. The slight complications stems from the fact that progress reporting code in frontends potentially uses Mode and compares it with NULL, which can't be done with std::string, so instead of just changing the type we introduce a new variable and deprecate the old one. Git-Dch: Ignore --- apt-private/acqprogress.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'apt-private') diff --git a/apt-private/acqprogress.cc b/apt-private/acqprogress.cc index 17a12799c..d6ce192ad 100644 --- a/apt-private/acqprogress.cc +++ b/apt-private/acqprogress.cc @@ -202,9 +202,9 @@ bool AcqTextStatus::Pulse(pkgAcquire *Owner) S += strlen(S); // Show the short mode string - if (I->CurrentItem->Owner->Mode != 0) + if (I->CurrentItem->Owner->ActiveSubprocess.empty() == false) { - snprintf(S,End-S," %s",I->CurrentItem->Owner->Mode); + snprintf(S,End-S, " %s", I->CurrentItem->Owner->ActiveSubprocess.c_str()); S += strlen(S); } -- cgit v1.2.3 From c99fe2e169243fc6e1a3278ce3768f0f521e260b Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Wed, 1 Oct 2014 12:21:55 +0200 Subject: Use Acquire::Allow{InsecureRepositories,DowngradeToInsecureRepositories} The configuration key Acquire::AllowInsecureRepositories controls if apt allows loading of unsigned repositories at all. The configuration Acquire::AllowDowngradeToInsecureRepositories controls if a signed repository can ever become unsigned. This should really never be needed but we provide it to avoid having to mess around in /var/lib/apt/lists if there is a use-case for this (which I can't think of right now). --- apt-private/private-cmndline.cc | 1 + 1 file changed, 1 insertion(+) (limited to 'apt-private') diff --git a/apt-private/private-cmndline.cc b/apt-private/private-cmndline.cc index a4490f5b4..079f81ee3 100644 --- a/apt-private/private-cmndline.cc +++ b/apt-private/private-cmndline.cc @@ -198,6 +198,7 @@ static bool addArgumentsAPTGet(std::vector &Args, char const addArg(0,"only-source","APT::Get::Only-Source",0); addArg(0,"arch-only","APT::Get::Arch-Only",0); addArg(0,"allow-unauthenticated","APT::Get::AllowUnauthenticated",0); + addArg(0,"allow-insecure-repositories","Acquire::AllowInsecureRepositories",0); addArg(0,"install-recommends","APT::Install-Recommends",CommandLine::Boolean); addArg(0,"install-suggests","APT::Install-Suggests",CommandLine::Boolean); addArg(0,"fix-policy","APT::Get::Fix-Policy-Broken",0); -- cgit v1.2.3 From 04a54261afd1c99686109f102afc83346c01c930 Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Mon, 6 Oct 2014 11:15:03 +0200 Subject: ensure partial dirs are 0700 and owned by _apt:root Reworks the API involved in creating and setting up the fetcher to be a bit more pleasent to look at and work with as e.g. an empty string for no lock isn't very nice. With the lock we can also stop creating all our partial directories "just in case". This way we can also be a bit more aggressive with the partial directory itself as with a lock, we know we will gone need it. --- apt-private/private-install.cc | 6 +++--- apt-private/private-update.cc | 4 +--- 2 files changed, 4 insertions(+), 6 deletions(-) (limited to 'apt-private') diff --git a/apt-private/private-install.cc b/apt-private/private-install.cc index 86ba52857..c06caeedd 100644 --- a/apt-private/private-install.cc +++ b/apt-private/private-install.cc @@ -119,14 +119,14 @@ bool InstallPackages(CacheFile &Cache,bool ShwKept,bool Ask, bool Safety) return false; // Create the download object - pkgAcquire Fetcher; - AcqTextStatus Stat(ScreenWidth,_config->FindI("quiet",0)); + AcqTextStatus Stat(ScreenWidth,_config->FindI("quiet",0)); + pkgAcquire Fetcher(&Stat); if (_config->FindB("APT::Get::Print-URIs", false) == true) { // force a hashsum for compatibility reasons _config->CndSet("Acquire::ForceHash", "md5sum"); } - else if (Fetcher.Setup(&Stat, _config->FindDir("Dir::Cache::Archives")) == false) + else if (Fetcher.GetLock(_config->FindDir("Dir::Cache::Archives")) == false) return false; // Read the source list diff --git a/apt-private/private-update.cc b/apt-private/private-update.cc index 1cf3012ed..df77ac33a 100644 --- a/apt-private/private-update.cc +++ b/apt-private/private-update.cc @@ -47,9 +47,7 @@ bool DoUpdate(CommandLine &CmdL) _config->CndSet("Acquire::ForceHash", "md5sum"); // get a fetcher - pkgAcquire Fetcher; - if (Fetcher.Setup(&Stat) == false) - return false; + pkgAcquire Fetcher(&Stat); // Populate it with the source selection and get all Indexes // (GetAll=true) -- cgit v1.2.3 From 4dbfe436c60880f2625e4d3a9d0127a83dd6276e Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Tue, 7 Oct 2014 01:46:30 +0200 Subject: display errortext for all Err as well as Ign logs consistently using Item::Failed in all specializec classes helps setting up some information bits otherwise unset, so some errors had an empty reason as an error. Ign is upgraded to display the error message we ignored to further help in understanding what happens. --- apt-private/acqprogress.cc | 2 ++ 1 file changed, 2 insertions(+) (limited to 'apt-private') diff --git a/apt-private/acqprogress.cc b/apt-private/acqprogress.cc index d6ce192ad..aa88d5334 100644 --- a/apt-private/acqprogress.cc +++ b/apt-private/acqprogress.cc @@ -117,6 +117,8 @@ void AcqTextStatus::Fail(pkgAcquire::ItemDesc &Itm) if (Itm.Owner->Status == pkgAcquire::Item::StatDone) { cout << _("Ign ") << Itm.Description << endl; + if (Itm.Owner->ErrorText.empty() == false) + cout << " " << Itm.Owner->ErrorText << endl; } else { -- cgit v1.2.3 From d6cf2345a35896448e19bfb294ffe66faab00f86 Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Tue, 7 Oct 2014 20:51:07 +0200 Subject: don't show ErrorText for Ign by default Some distributions (or repositories) do not have as much "Ign-discipline" as I would like to, so that could be pretty distracting for our users if enabled by default. It is handy for testcases though. Git-Dch: Ignore --- apt-private/acqprogress.cc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'apt-private') diff --git a/apt-private/acqprogress.cc b/apt-private/acqprogress.cc index aa88d5334..14a53eacb 100644 --- a/apt-private/acqprogress.cc +++ b/apt-private/acqprogress.cc @@ -117,7 +117,8 @@ void AcqTextStatus::Fail(pkgAcquire::ItemDesc &Itm) if (Itm.Owner->Status == pkgAcquire::Item::StatDone) { cout << _("Ign ") << Itm.Description << endl; - if (Itm.Owner->ErrorText.empty() == false) + if (Itm.Owner->ErrorText.empty() == false && + _config->FindB("Acquire::Progress::Ignore::ShowErrorText", false) == true) cout << " " << Itm.Owner->ErrorText << endl; } else -- cgit v1.2.3 From 460601d53039b1d1b5688a8cd58bae10fb746f57 Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Wed, 15 Oct 2014 02:43:44 +0200 Subject: don't drop privileges if _apt has not enough rights MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Privilege dropping breaks download/source/changelog commands as they require the _apt user to have write permissions in the current directory, which is e.g. the case in /tmp, but not in /root, so we disable the privilege dropping if we deal with such a directory based on idea and code by Michael Vogt. The alternative would be to download always to a temp directory and move it then done, but this breaks partial file support. To resolve this, we could move to one of our partial/ directories, but this would require a lock which would block root from using two of these commands in parallel. As both seems unacceptable we instead let the user choose what to do: Either a directory is setupped for _apt, downloading as root is accepted or – which is potentially even better – an unprivileged user is used for the commands. --- apt-private/private-download.cc | 50 ++++++++++++++++++++++++++++++++++++++++- apt-private/private-download.h | 6 ++++- 2 files changed, 54 insertions(+), 2 deletions(-) (limited to 'apt-private') diff --git a/apt-private/private-download.cc b/apt-private/private-download.cc index be7d23c31..3ded9e0b9 100644 --- a/apt-private/private-download.cc +++ b/apt-private/private-download.cc @@ -5,6 +5,7 @@ #include #include #include +#include #include #include @@ -14,9 +15,56 @@ #include #include +#include +#include +#include +#include + #include /*}}}*/ +bool CheckDropPrivsMustBeDisabled(pkgAcquire &Fetcher) /*{{{*/ +{ + // no need/possibility to drop privs + if(getuid() != 0) + return true; + + // the user does not want to drop privs + std::string SandboxUser = _config->Find("APT::Sandbox::User"); + if (SandboxUser.empty()) + return true; + + struct passwd const * const pw = getpwnam(SandboxUser.c_str()); + if (pw == NULL) + return true; + + if (seteuid(pw->pw_uid) != 0) + return _error->Errno("seteuid", "seteuid %u failed", pw->pw_uid); + + bool res = true; + // check if we can write to destfile + for (pkgAcquire::ItemIterator I = Fetcher.ItemsBegin(); + I != Fetcher.ItemsEnd() && res == true; ++I) + { + int fd = open((*I)->DestFile.c_str(), O_CREAT | O_RDWR, 0600); + if (fd < 0) + { + res = false; + std::string msg; + strprintf(msg, _("Can't drop privileges for downloading as file '%s' couldn't be accessed by user '%s'."), + (*I)->DestFile.c_str(), SandboxUser.c_str()); + c0out << msg << std::endl; + _config->Set("APT::Sandbox::User", ""); + } + close(fd); + } + + if (seteuid(0) != 0) + return _error->Errno("seteuid", "seteuid %u failed", 0); + + return res; +} + /*}}}*/ // CheckAuth - check if each download comes form a trusted source /*{{{*/ bool CheckAuth(pkgAcquire& Fetcher, bool const PromptUser) { @@ -31,7 +79,7 @@ bool CheckAuth(pkgAcquire& Fetcher, bool const PromptUser) return AuthPrompt(UntrustedList, PromptUser); } -bool AuthPrompt(std::string UntrustedList, bool const PromptUser) +bool AuthPrompt(std::string const &UntrustedList, bool const PromptUser) { ShowList(c2out,_("WARNING: The following packages cannot be authenticated!"),UntrustedList,""); diff --git a/apt-private/private-download.h b/apt-private/private-download.h index a90ac7eaa..809650a97 100644 --- a/apt-private/private-download.h +++ b/apt-private/private-download.h @@ -3,14 +3,18 @@ #include +#include + class pkgAcquire; +APT_PUBLIC bool CheckDropPrivsMustBeDisabled(pkgAcquire &Fetcher); + // Check if all files in the fetcher are authenticated APT_PUBLIC bool CheckAuth(pkgAcquire& Fetcher, bool const PromptUser); // show a authentication warning prompt and return true if the system // should continue -APT_PUBLIC bool AuthPrompt(std::string UntrustedList, bool const PromptUser); +APT_PUBLIC bool AuthPrompt(std::string const &UntrustedList, bool const PromptUser); APT_PUBLIC bool AcquireRun(pkgAcquire &Fetcher, int const PulseInterval, bool * const Failure, bool * const TransientNetworkFailure); -- cgit v1.2.3 From 9c81f8de38df940559d13a3ea9591d63cbe970bb Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Wed, 15 Oct 2014 04:18:07 +0200 Subject: check for available space, excluding root reserved blocks MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit We are checking the space requirements for ages, but the check uses the free blocks count, which includes the blocks reserved for usage by root. Now that we use an unprivileged user it has no access to these blocks anymore – and more importantly these blocks are a reserve, they shouldn't be used by apt without special encouragement by the user as it would be bad to have dpkg run out of diskspace and maintainerscripts like man-db skip certain actions if not enough space is available freely. --- apt-private/private-download.cc | 39 +++++++++++++++++++++++++++++++++++++++ apt-private/private-download.h | 2 ++ apt-private/private-install.cc | 33 +++------------------------------ apt-private/private-install.h | 2 -- 4 files changed, 44 insertions(+), 32 deletions(-) (limited to 'apt-private') diff --git a/apt-private/private-download.cc b/apt-private/private-download.cc index 3ded9e0b9..8cabf14b5 100644 --- a/apt-private/private-download.cc +++ b/apt-private/private-download.cc @@ -19,6 +19,9 @@ #include #include #include +#include +#include +#include #include /*}}}*/ @@ -146,3 +149,39 @@ bool AcquireRun(pkgAcquire &Fetcher, int const PulseInterval, bool * const Failu return true; } /*}}}*/ +bool CheckFreeSpaceBeforeDownload(std::string const &Dir, unsigned long long FetchBytes)/*{{{*/ +{ + uint32_t const RAMFS_MAGIC = 0x858458f6; + /* Check for enough free space, but only if we are actually going to + download */ + if (_config->FindB("APT::Get::Print-URIs", false) == true || + _config->FindB("APT::Get::Download", true) == false) + return true; + + struct statvfs Buf; + if (statvfs(Dir.c_str(),&Buf) != 0) { + if (errno == EOVERFLOW) + return _error->WarningE("statvfs",_("Couldn't determine free space in %s"), + Dir.c_str()); + else + return _error->Errno("statvfs",_("Couldn't determine free space in %s"), + Dir.c_str()); + } + else + { + unsigned long long const FreeBlocks = _config->Find("APT::Sandbox::User").empty() ? Buf.f_bfree : Buf.f_bavail; + if (FreeBlocks < (FetchBytes / Buf.f_bsize)) + { + struct statfs Stat; + if (statfs(Dir.c_str(),&Stat) != 0 +#if HAVE_STRUCT_STATFS_F_TYPE + || Stat.f_type != RAMFS_MAGIC +#endif + ) + return _error->Error(_("You don't have enough free space in %s."), + Dir.c_str()); + } + } + return true; +} + /*}}}*/ diff --git a/apt-private/private-download.h b/apt-private/private-download.h index 809650a97..0a0ac6b95 100644 --- a/apt-private/private-download.h +++ b/apt-private/private-download.h @@ -18,4 +18,6 @@ APT_PUBLIC bool AuthPrompt(std::string const &UntrustedList, bool const PromptUs APT_PUBLIC bool AcquireRun(pkgAcquire &Fetcher, int const PulseInterval, bool * const Failure, bool * const TransientNetworkFailure); +APT_PUBLIC bool CheckFreeSpaceBeforeDownload(std::string const &Dir, unsigned long long FetchBytes); + #endif diff --git a/apt-private/private-install.cc b/apt-private/private-install.cc index c06caeedd..2a4c3eea5 100644 --- a/apt-private/private-install.cc +++ b/apt-private/private-install.cc @@ -22,11 +22,8 @@ #include #include -#include #include #include -#include -#include #include #include #include @@ -177,33 +174,9 @@ bool InstallPackages(CacheFile &Cache,bool ShwKept,bool Ask, bool Safety) if (_error->PendingError() == true) return false; - /* Check for enough free space, but only if we are actually going to - download */ - if (_config->FindB("APT::Get::Print-URIs") == false && - _config->FindB("APT::Get::Download",true) == true) - { - struct statvfs Buf; - std::string OutputDir = _config->FindDir("Dir::Cache::Archives"); - if (statvfs(OutputDir.c_str(),&Buf) != 0) { - if (errno == EOVERFLOW) - return _error->WarningE("statvfs",_("Couldn't determine free space in %s"), - OutputDir.c_str()); - else - return _error->Errno("statvfs",_("Couldn't determine free space in %s"), - OutputDir.c_str()); - } else if (unsigned(Buf.f_bfree) < (FetchBytes - FetchPBytes)/Buf.f_bsize) - { - struct statfs Stat; - if (statfs(OutputDir.c_str(),&Stat) != 0 -#if HAVE_STRUCT_STATFS_F_TYPE - || unsigned(Stat.f_type) != RAMFS_MAGIC -#endif - ) - return _error->Error(_("You don't have enough free space in %s."), - OutputDir.c_str()); - } - } - + if (CheckFreeSpaceBeforeDownload(_config->FindDir("Dir::Cache::Archives"), (FetchBytes - FetchPBytes)) == false) + return false; + // Fail safe check if (_config->FindI("quiet",0) >= 2 || _config->FindB("APT::Get::Assume-Yes",false) == true) diff --git a/apt-private/private-install.h b/apt-private/private-install.h index 8daa4a776..62276fbff 100644 --- a/apt-private/private-install.h +++ b/apt-private/private-install.h @@ -16,8 +16,6 @@ class CacheFile; class CommandLine; class pkgProblemResolver; -#define RAMFS_MAGIC 0x858458f6 - APT_PUBLIC bool DoInstall(CommandLine &Cmd); bool DoCacheManipulationFromCommandLine(CommandLine &CmdL, CacheFile &Cache, -- cgit v1.2.3 From f83b5627b5a2481e40922c1149255d395c32c7c8 Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Sat, 18 Oct 2014 14:44:41 +0200 Subject: reenable support for -s (and co) in apt-get source The conversion to accept only relevant options for commands has forgotten another one, so adding it again even through the usecase might very well be equally good served by --print-uris. Closes: 742578 --- apt-private/private-cmndline.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'apt-private') diff --git a/apt-private/private-cmndline.cc b/apt-private/private-cmndline.cc index 079f81ee3..aa01be757 100644 --- a/apt-private/private-cmndline.cc +++ b/apt-private/private-cmndline.cc @@ -166,7 +166,7 @@ static bool addArgumentsAPTGet(std::vector &Args, char const if (CmdMatches("install", "remove", "purge", "upgrade", "dist-upgrade", "deselect-upgrade", "autoremove", "clean", "autoclean", "check", - "build-dep", "full-upgrade")) + "build-dep", "full-upgrade", "source")) { addArg('s', "simulate", "APT::Get::Simulate", 0); addArg('s', "just-print", "APT::Get::Simulate", 0); -- cgit v1.2.3 From 03aa08472dcd689572a46ce6efdb1dccf6136334 Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Thu, 23 Oct 2014 01:28:05 +0200 Subject: chown finished partial files earlier partial files are chowned by the Item baseclass to let the methods work with them. Now, this baseclass is also responsible for chowning the files back to root instead of having various deeper levels do this. The consequence is that all overloaded Failed() methods now call the Item::Failed base as their first step. The same is done for Done(). The effect is that even in partial files usually don't belong to _apt anymore, helping sneakernets and reducing possibilities of a bad method modifying files not belonging to them. The change is supported by the framework not only supporting being run as root, but with proper permission management, too, so that privilege dropping can be tested with them. --- apt-private/private-download.cc | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'apt-private') diff --git a/apt-private/private-download.cc b/apt-private/private-download.cc index 8cabf14b5..37fae18e9 100644 --- a/apt-private/private-download.cc +++ b/apt-private/private-download.cc @@ -49,16 +49,23 @@ bool CheckDropPrivsMustBeDisabled(pkgAcquire &Fetcher) /*{{{*/ for (pkgAcquire::ItemIterator I = Fetcher.ItemsBegin(); I != Fetcher.ItemsEnd() && res == true; ++I) { - int fd = open((*I)->DestFile.c_str(), O_CREAT | O_RDWR, 0600); + if ((*I)->DestFile.empty()) + continue; + // we assume that an existing (partial) file means that we have sufficient rights + if (RealFileExists((*I)->DestFile)) + continue; + int fd = open((*I)->DestFile.c_str(), O_CREAT | O_EXCL | O_RDWR, 0600); if (fd < 0) { res = false; std::string msg; strprintf(msg, _("Can't drop privileges for downloading as file '%s' couldn't be accessed by user '%s'."), (*I)->DestFile.c_str(), SandboxUser.c_str()); - c0out << msg << std::endl; + std::cerr << "W: " << msg << std::endl; _config->Set("APT::Sandbox::User", ""); + break; } + unlink((*I)->DestFile.c_str()); close(fd); } -- cgit v1.2.3 From ccf6bdb3efc54165c76b42aae94c498a36acbe1b Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Fri, 7 Nov 2014 14:20:36 +0100 Subject: use a abi version check similar to the gcc check Git-Dch: Ignore --- apt-private/private-install.cc | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'apt-private') diff --git a/apt-private/private-install.cc b/apt-private/private-install.cc index 2a4c3eea5..79a22edf4 100644 --- a/apt-private/private-install.cc +++ b/apt-private/private-install.cc @@ -94,7 +94,7 @@ bool InstallPackages(CacheFile &Cache,bool ShwKept,bool Ask, bool Safety) { pkgSimulate PM(Cache); -#if (APT_PKG_MAJOR >= 4 && APT_PKG_MINOR >= 13) +#if APT_PKG_ABI >= 413 APT::Progress::PackageManager *progress = APT::Progress::PackageManagerProgressFactory(); pkgPackageManager::OrderResult Res = PM.DoInstall(progress); delete progress; @@ -306,8 +306,8 @@ bool InstallPackages(CacheFile &Cache,bool ShwKept,bool Ask, bool Safety) } _system->UnLock(); - -#if (APT_PKG_MAJOR >= 4 && APT_PKG_MINOR >= 13) + +#if APT_PKG_ABI >= 413 APT::Progress::PackageManager *progress = APT::Progress::PackageManagerProgressFactory(); pkgPackageManager::OrderResult Res = PM->DoInstall(progress); delete progress; -- cgit v1.2.3 From ad7e0941b376d792911f240377094a2e78ca8756 Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Sat, 8 Nov 2014 18:14:46 +0100 Subject: streamline display of --help in all tools By convention, if I run a tool with --help or --version I expect it to exit successfully with the usage, while if I do call it wrong (like without any parameters) I expect the usage message shown with a non-zero exit. --- apt-private/private-cmndline.cc | 33 +++++++++++++++++++++++++++++++++ apt-private/private-cmndline.h | 6 ++++++ 2 files changed, 39 insertions(+) (limited to 'apt-private') diff --git a/apt-private/private-cmndline.cc b/apt-private/private-cmndline.cc index aa01be757..bb9a00803 100644 --- a/apt-private/private-cmndline.cc +++ b/apt-private/private-cmndline.cc @@ -2,12 +2,17 @@ #include #include +#include +#include +#include +#include #include #include #include #include +#include #include /*}}}*/ @@ -287,3 +292,31 @@ std::vector getCommandArgs(char const * const Program, char c /*}}}*/ #undef CmdMatches #undef addArg +void ParseCommandLine(CommandLine &CmdL, CommandLine::Dispatch * const Cmds, CommandLine::Args * const Args,/*{{{*/ + Configuration * const * const Cnf, pkgSystem ** const Sys, int const argc, const char *argv[], bool(*ShowHelp)(CommandLine &CmdL)) +{ + CmdL = CommandLine(Args,_config); + if ((Cnf != NULL && pkgInitConfig(**Cnf) == false) || + CmdL.Parse(argc,argv) == false || + (Sys != NULL && pkgInitSystem(*_config, *Sys) == false)) + { + if (_config->FindB("version") == true) + ShowHelp(CmdL); + + _error->DumpErrors(); + exit(100); + } + + // See if the help should be shown + if (_config->FindB("help") == true || _config->FindB("version") == true) + { + ShowHelp(CmdL); + exit(0); + } + if (Cmds != NULL && CmdL.FileSize() == 0) + { + ShowHelp(CmdL); + exit(1); + } +} + /*}}}*/ diff --git a/apt-private/private-cmndline.h b/apt-private/private-cmndline.h index d0af16782..7b468456b 100644 --- a/apt-private/private-cmndline.h +++ b/apt-private/private-cmndline.h @@ -6,6 +6,12 @@ #include +class Configuration; +class pkgSystem; + APT_PUBLIC std::vector getCommandArgs(char const * const Program, char const * const Cmd); +APT_PUBLIC void ParseCommandLine(CommandLine &CmdL, CommandLine::Dispatch * const Cmds, CommandLine::Args * const Args, + Configuration * const * const Cnf, pkgSystem ** const Sys, int const argc, const char * argv[], + bool(*ShowHelp)(CommandLine &CmdL)); #endif -- cgit v1.2.3 From d9e518c6f7dc0ad464495b586d1b8e115d54d41a Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Sat, 8 Nov 2014 20:44:44 +0100 Subject: use the same code to detect quiet setting in all tools Git-Dch: Ignore --- apt-private/private-output.cc | 8 ++++---- apt-private/private-output.h | 3 ++- 2 files changed, 6 insertions(+), 5 deletions(-) (limited to 'apt-private') diff --git a/apt-private/private-output.cc b/apt-private/private-output.cc index fc76a05bc..4e18030ab 100644 --- a/apt-private/private-output.cc +++ b/apt-private/private-output.cc @@ -52,14 +52,14 @@ static void SigWinch(int) #endif } /*}}}*/ -bool InitOutput() /*{{{*/ +bool InitOutput(std::basic_streambuf * const out) /*{{{*/ { if (!isatty(STDOUT_FILENO) && _config->FindI("quiet", -1) == -1) _config->Set("quiet","1"); - c0out.rdbuf(cout.rdbuf()); - c1out.rdbuf(cout.rdbuf()); - c2out.rdbuf(cout.rdbuf()); + c0out.rdbuf(out); + c1out.rdbuf(out); + c2out.rdbuf(out); if (_config->FindI("quiet",0) > 0) c0out.rdbuf(devnull.rdbuf()); if (_config->FindI("quiet",0) > 1) diff --git a/apt-private/private-output.h b/apt-private/private-output.h index e0dc9bf62..d5b57adec 100644 --- a/apt-private/private-output.h +++ b/apt-private/private-output.h @@ -6,6 +6,7 @@ #include #include +#include // forward declaration class pkgCacheFile; @@ -20,7 +21,7 @@ APT_PUBLIC extern std::ostream c2out; APT_PUBLIC extern std::ofstream devnull; APT_PUBLIC extern unsigned int ScreenWidth; -APT_PUBLIC bool InitOutput(); +APT_PUBLIC bool InitOutput(std::basic_streambuf * const out = std::cout.rdbuf()); void ListSingleVersion(pkgCacheFile &CacheFile, pkgRecords &records, pkgCache::VerIterator const &V, std::ostream &out, -- cgit v1.2.3 From 3de7789a75c58204bcc979c72899cfdacba4e2ac Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Sat, 7 Mar 2015 13:11:49 +0100 Subject: fix another d(e)select-upgrade typo MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit You would think one instance of this is enough, but 80e8d923ebc8d5f3f84eb3f922b28ca309c25026 wasn't as globally applied as the commit message suggested… LP: #1399037 --- apt-private/private-cmndline.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'apt-private') diff --git a/apt-private/private-cmndline.cc b/apt-private/private-cmndline.cc index bb9a00803..41aab81f6 100644 --- a/apt-private/private-cmndline.cc +++ b/apt-private/private-cmndline.cc @@ -170,7 +170,7 @@ static bool addArgumentsAPTGet(std::vector &Args, char const addArg(0, "color", "APT::Moo::Color", 0); if (CmdMatches("install", "remove", "purge", "upgrade", "dist-upgrade", - "deselect-upgrade", "autoremove", "clean", "autoclean", "check", + "dselect-upgrade", "autoremove", "clean", "autoclean", "check", "build-dep", "full-upgrade", "source")) { addArg('s', "simulate", "APT::Get::Simulate", 0); -- cgit v1.2.3 From b8eba208daebe3e3f235983e44da9c398d6f7a57 Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Tue, 10 Mar 2015 14:11:54 +0100 Subject: reimplement the last uses of sprintf Working with strings c-style is complicated and error-prune, so by converting to c++ style we gain some simplicity and avoid buffer overflows by later extensions. Git-Dch: Ignore --- apt-private/acqprogress.cc | 173 ++++++++++++++++++++++----------------------- apt-private/acqprogress.h | 4 +- 2 files changed, 88 insertions(+), 89 deletions(-) (limited to 'apt-private') diff --git a/apt-private/acqprogress.cc b/apt-private/acqprogress.cc index 14a53eacb..e834d7d6a 100644 --- a/apt-private/acqprogress.cc +++ b/apt-private/acqprogress.cc @@ -23,6 +23,7 @@ #include #include #include +#include #include #include @@ -34,9 +35,8 @@ using namespace std; // --------------------------------------------------------------------- /* */ AcqTextStatus::AcqTextStatus(unsigned int &ScreenWidth,unsigned int const Quiet) : - pkgAcquireStatus(), ScreenWidth(ScreenWidth), ID(0), Quiet(Quiet) + pkgAcquireStatus(), ScreenWidth(ScreenWidth), LastLineLength(0), ID(0), Quiet(Quiet) { - BlankLine[0] = 0; // testcases use it to disable pulses without disabling other user messages if (Quiet == 0 && _config->FindB("quiet::NoUpdate", false) == true) this->Quiet = 1; @@ -48,7 +48,7 @@ AcqTextStatus::AcqTextStatus(unsigned int &ScreenWidth,unsigned int const Quiet) void AcqTextStatus::Start() { pkgAcquireStatus::Start(); - BlankLine[0] = 0; + LastLineLength = 0; ID = 1; } /*}}}*/ @@ -60,8 +60,7 @@ void AcqTextStatus::IMSHit(pkgAcquire::ItemDesc &Itm) if (Quiet > 1) return; - if (Quiet <= 0) - cout << '\r' << BlankLine << '\r'; + clearLastLine(); cout << _("Hit ") << Itm.Description; cout << endl; @@ -82,8 +81,7 @@ void AcqTextStatus::Fetch(pkgAcquire::ItemDesc &Itm) if (Quiet > 1) return; - if (Quiet <= 0) - cout << '\r' << BlankLine << '\r'; + clearLastLine(); cout << _("Get:") << Itm.Owner->ID << ' ' << Itm.Description; if (Itm.Owner->FileSize != 0) @@ -111,8 +109,7 @@ void AcqTextStatus::Fail(pkgAcquire::ItemDesc &Itm) if (Itm.Owner->Status == pkgAcquire::Item::StatIdle) return; - if (Quiet <= 0) - cout << '\r' << BlankLine << '\r'; + clearLastLine(); if (Itm.Owner->Status == pkgAcquire::Item::StatDone) { @@ -140,8 +137,7 @@ void AcqTextStatus::Stop() if (Quiet > 1) return; - if (Quiet <= 0) - cout << '\r' << BlankLine << '\r' << flush; + clearLastLine(); if (_config->FindB("quiet::NoStatistic", false) == true) return; @@ -167,77 +163,66 @@ bool AcqTextStatus::Pulse(pkgAcquire *Owner) enum {Long = 0,Medium,Short} Mode = Medium; - char Buffer[sizeof(BlankLine)]; - char *End = Buffer + sizeof(Buffer); - char *S = Buffer; - if (ScreenWidth >= sizeof(Buffer)) - ScreenWidth = sizeof(Buffer)-1; - - // Put in the percent done - sprintf(S,"%.0f%%", Percent); - - bool Shown = false; - for (pkgAcquire::Worker *I = Owner->WorkersBegin(); I != 0; - I = Owner->WorkerStep(I)) + std::string Line; { - S += strlen(S); - - // There is no item running - if (I->CurrentItem == 0) + std::stringstream S; + for (pkgAcquire::Worker *I = Owner->WorkersBegin(); I != 0; + I = Owner->WorkerStep(I)) { - if (I->Status.empty() == false) + // There is no item running + if (I->CurrentItem == 0) { - snprintf(S,End-S," [%s]",I->Status.c_str()); - Shown = true; - } - - continue; - } - - Shown = true; + if (I->Status.empty() == false) + S << " [" << I->Status << "]"; - // Add in the short description - if (I->CurrentItem->Owner->ID != 0) - snprintf(S,End-S," [%lu %s",I->CurrentItem->Owner->ID, - I->CurrentItem->ShortDesc.c_str()); - else - snprintf(S,End-S," [%s",I->CurrentItem->ShortDesc.c_str()); - S += strlen(S); + continue; + } - // Show the short mode string - if (I->CurrentItem->Owner->ActiveSubprocess.empty() == false) - { - snprintf(S,End-S, " %s", I->CurrentItem->Owner->ActiveSubprocess.c_str()); - S += strlen(S); - } + // Add in the short description + S << " ["; + if (I->CurrentItem->Owner->ID != 0) + S << I->CurrentItem->Owner->ID << " "; + S << I->CurrentItem->ShortDesc; - // Add the current progress - if (Mode == Long) - snprintf(S,End-S," %llu",I->CurrentSize); - else - { - if (Mode == Medium || I->TotalSize == 0) - snprintf(S,End-S," %sB",SizeToStr(I->CurrentSize).c_str()); - } - S += strlen(S); + // Show the short mode string + if (I->CurrentItem->Owner->ActiveSubprocess.empty() == false) + S << " " << I->CurrentItem->Owner->ActiveSubprocess; - // Add the total size and percent - if (I->TotalSize > 0 && I->CurrentItem->Owner->Complete == false) - { - if (Mode == Short) - snprintf(S,End-S," %.0f%%", - (I->CurrentSize*100.0)/I->TotalSize); + // Add the current progress + if (Mode == Long) + S << " " << I->CurrentSize; else - snprintf(S,End-S,"/%sB %.0f%%",SizeToStr(I->TotalSize).c_str(), + { + if (Mode == Medium || I->TotalSize == 0) + S << " " << SizeToStr(I->CurrentSize) << "B"; + } + + // Add the total size and percent + if (I->TotalSize > 0 && I->CurrentItem->Owner->Complete == false) + { + if (Mode == Short) + ioprintf(S, " %.0f%%", (I->CurrentSize*100.0)/I->TotalSize); + else + ioprintf(S, "/%sB %.0f%%", SizeToStr(I->TotalSize).c_str(), (I->CurrentSize*100.0)/I->TotalSize); + } + S << "]"; } - S += strlen(S); - snprintf(S,End-S,"]"); - } - // Show something.. - if (Shown == false) - snprintf(S,End-S,_(" [Working]")); + // Show at least something + Line = S.str(); + S.clear(); + if (Line.empty() == true) + Line = _(" [Working]"); + } + // Put in the percent done + { + std::stringstream S; + ioprintf(S, "%.0f%%", Percent); + S << Line; + Line = S.str(); + S.clear(); + } /* Put in the ETA and cps meter, block off signals to prevent strangeness during resizing */ @@ -248,34 +233,33 @@ bool AcqTextStatus::Pulse(pkgAcquire *Owner) if (CurrentCPS != 0) { - char Tmp[300]; unsigned long long ETA = (TotalBytes - CurrentBytes)/CurrentCPS; - sprintf(Tmp," %sB/s %s",SizeToStr(CurrentCPS).c_str(),TimeToStr(ETA).c_str()); - unsigned int Len = strlen(Buffer); - unsigned int LenT = strlen(Tmp); - if (Len + LenT < ScreenWidth) + std::string Tmp = " " + SizeToStr(CurrentCPS) + "B/s " + TimeToStr(ETA); + size_t alignment = Line.length() + Tmp.length(); + if (alignment < ScreenWidth) { - memset(Buffer + Len,' ',ScreenWidth - Len); - strcpy(Buffer + ScreenWidth - LenT,Tmp); + alignment = ScreenWidth - alignment; + for (size_t i = 0; i < alignment; ++i) + Line.append(" "); + Line.append(Tmp); } } - Buffer[ScreenWidth] = 0; - BlankLine[ScreenWidth] = 0; + if (Line.length() > ScreenWidth) + Line.erase(ScreenWidth); sigprocmask(SIG_SETMASK,&OldSigs,0); // Draw the current status if (_config->FindB("Apt::Color", false) == true) cout << _config->Find("APT::Color::Yellow"); - if (strlen(Buffer) == strlen(BlankLine)) - cout << '\r' << Buffer << flush; + if (LastLineLength > Line.length()) + clearLastLine(); else - cout << '\r' << BlankLine << '\r' << Buffer << flush; + cout << '\r'; + cout << Line << flush; if (_config->FindB("Apt::Color", false) == true) cout << _config->Find("APT::Color::Neutral") << flush; - memset(BlankLine,' ',strlen(Buffer)); - BlankLine[strlen(Buffer)] = 0; - + LastLineLength = Line.length(); Update = false; return true; @@ -296,8 +280,7 @@ bool AcqTextStatus::MediaChange(string Media,string Drive) return false; - if (Quiet <= 0) - cout << '\r' << BlankLine << '\r'; + clearLastLine(); ioprintf(cout,_("Media change: please insert the disc labeled\n" " '%s'\n" "in the drive '%s' and press enter\n"), @@ -317,3 +300,17 @@ bool AcqTextStatus::MediaChange(string Media,string Drive) return bStatus; } /*}}}*/ +void AcqTextStatus::clearLastLine() { /*{{{*/ + if (Quiet > 0) + return; + + // do not try to clear more than the (now smaller) screen + if (LastLineLength > ScreenWidth) + LastLineLength = ScreenWidth; + + std::cout << '\r'; + for (size_t i = 0; i < LastLineLength; ++i) + std::cout << ' '; + std::cout << '\r' << std::flush; +} + /*}}}*/ diff --git a/apt-private/acqprogress.h b/apt-private/acqprogress.h index 71a10d78a..ab8170126 100644 --- a/apt-private/acqprogress.h +++ b/apt-private/acqprogress.h @@ -17,10 +17,12 @@ class APT_PUBLIC AcqTextStatus : public pkgAcquireStatus { unsigned int &ScreenWidth; - char BlankLine[1024]; + size_t LastLineLength; unsigned long ID; unsigned long Quiet; + void clearLastLine(); + public: virtual bool MediaChange(std::string Media,std::string Drive); -- cgit v1.2.3 From dfad5beea77d75983f6ff8a1b8296b74dd48203e Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Sun, 15 Mar 2015 22:34:54 +0100 Subject: add a simple unit test for acquire progress This isn't testing much of the 'complex' parts, but its better than nothing for now. Git-Dch: Ignore --- apt-private/acqprogress.cc | 53 ++++++++++++++++++++---------------------- apt-private/acqprogress.h | 4 +++- apt-private/private-install.cc | 2 +- apt-private/private-update.cc | 4 ++-- 4 files changed, 31 insertions(+), 32 deletions(-) (limited to 'apt-private') diff --git a/apt-private/acqprogress.cc b/apt-private/acqprogress.cc index e834d7d6a..0c606e48e 100644 --- a/apt-private/acqprogress.cc +++ b/apt-private/acqprogress.cc @@ -1,10 +1,9 @@ // -*- mode: cpp; mode: fold -*- // Description /*{{{*/ -// $Id: acqprogress.cc,v 1.24 2003/04/27 01:56:48 doogie Exp $ /* ###################################################################### - Acquire Progress - Command line progress meter - + Acquire Progress - Command line progress meter + ##################################################################### */ /*}}}*/ // Include files /*{{{*/ @@ -29,13 +28,11 @@ #include /*}}}*/ -using namespace std; - // AcqTextStatus::AcqTextStatus - Constructor /*{{{*/ // --------------------------------------------------------------------- /* */ -AcqTextStatus::AcqTextStatus(unsigned int &ScreenWidth,unsigned int const Quiet) : - pkgAcquireStatus(), ScreenWidth(ScreenWidth), LastLineLength(0), ID(0), Quiet(Quiet) +AcqTextStatus::AcqTextStatus(std::ostream &out, unsigned int &ScreenWidth,unsigned int const Quiet) : + pkgAcquireStatus(), out(out), ScreenWidth(ScreenWidth), LastLineLength(0), ID(0), Quiet(Quiet) { // testcases use it to disable pulses without disabling other user messages if (Quiet == 0 && _config->FindB("quiet::NoUpdate", false) == true) @@ -62,8 +59,8 @@ void AcqTextStatus::IMSHit(pkgAcquire::ItemDesc &Itm) clearLastLine(); - cout << _("Hit ") << Itm.Description; - cout << endl; + out << _("Hit ") << Itm.Description; + out << std::endl; Update = true; } /*}}}*/ @@ -83,10 +80,10 @@ void AcqTextStatus::Fetch(pkgAcquire::ItemDesc &Itm) clearLastLine(); - cout << _("Get:") << Itm.Owner->ID << ' ' << Itm.Description; + out << _("Get:") << Itm.Owner->ID << ' ' << Itm.Description; if (Itm.Owner->FileSize != 0) - cout << " [" << SizeToStr(Itm.Owner->FileSize) << "B]"; - cout << endl; + out << " [" << SizeToStr(Itm.Owner->FileSize) << "B]"; + out << std::endl; } /*}}}*/ // AcqTextStatus::Done - Completed a download /*{{{*/ @@ -113,15 +110,15 @@ void AcqTextStatus::Fail(pkgAcquire::ItemDesc &Itm) if (Itm.Owner->Status == pkgAcquire::Item::StatDone) { - cout << _("Ign ") << Itm.Description << endl; + out << _("Ign ") << Itm.Description << std::endl; if (Itm.Owner->ErrorText.empty() == false && _config->FindB("Acquire::Progress::Ignore::ShowErrorText", false) == true) - cout << " " << Itm.Owner->ErrorText << endl; + out << " " << Itm.Owner->ErrorText << std::endl; } else { - cout << _("Err ") << Itm.Description << endl; - cout << " " << Itm.Owner->ErrorText << endl; + out << _("Err ") << Itm.Description << std::endl; + out << " " << Itm.Owner->ErrorText << std::endl; } Update = true; @@ -143,7 +140,7 @@ void AcqTextStatus::Stop() return; if (FetchedBytes != 0 && _error->PendingError() == false) - ioprintf(cout,_("Fetched %sB in %s (%sB/s)\n"), + ioprintf(out,_("Fetched %sB in %s (%sB/s)\n"), SizeToStr(FetchedBytes).c_str(), TimeToStr(ElapsedTime).c_str(), SizeToStr(CurrentCPS).c_str()); @@ -152,7 +149,7 @@ void AcqTextStatus::Stop() // AcqTextStatus::Pulse - Regular event pulse /*{{{*/ // --------------------------------------------------------------------- /* This draws the current progress. Each line has an overall percent - meter and a per active item status meter along with an overall + meter and a per active item status meter along with an overall bandwidth and ETA indicator. */ bool AcqTextStatus::Pulse(pkgAcquire *Owner) { @@ -250,14 +247,14 @@ bool AcqTextStatus::Pulse(pkgAcquire *Owner) // Draw the current status if (_config->FindB("Apt::Color", false) == true) - cout << _config->Find("APT::Color::Yellow"); + out << _config->Find("APT::Color::Yellow"); if (LastLineLength > Line.length()) clearLastLine(); else - cout << '\r'; - cout << Line << flush; + out << '\r'; + out << Line << std::flush; if (_config->FindB("Apt::Color", false) == true) - cout << _config->Find("APT::Color::Neutral") << flush; + out << _config->Find("APT::Color::Neutral") << std::flush; LastLineLength = Line.length(); Update = false; @@ -268,7 +265,7 @@ bool AcqTextStatus::Pulse(pkgAcquire *Owner) // AcqTextStatus::MediaChange - Media need to be swapped /*{{{*/ // --------------------------------------------------------------------- /* Prompt for a media swap */ -bool AcqTextStatus::MediaChange(string Media,string Drive) +bool AcqTextStatus::MediaChange(std::string Media, std::string Drive) { // If we do not output on a terminal and one of the options to avoid user // interaction is given, we assume that no user is present who could react @@ -281,7 +278,7 @@ bool AcqTextStatus::MediaChange(string Media,string Drive) return false; clearLastLine(); - ioprintf(cout,_("Media change: please insert the disc labeled\n" + ioprintf(out,_("Media change: please insert the disc labeled\n" " '%s'\n" "in the drive '%s' and press enter\n"), Media.c_str(),Drive.c_str()); @@ -301,16 +298,16 @@ bool AcqTextStatus::MediaChange(string Media,string Drive) } /*}}}*/ void AcqTextStatus::clearLastLine() { /*{{{*/ - if (Quiet > 0) + if (Quiet > 0 || LastLineLength == 0) return; // do not try to clear more than the (now smaller) screen if (LastLineLength > ScreenWidth) LastLineLength = ScreenWidth; - std::cout << '\r'; + out << '\r'; for (size_t i = 0; i < LastLineLength; ++i) - std::cout << ' '; - std::cout << '\r' << std::flush; + out << ' '; + out << '\r' << std::flush; } /*}}}*/ diff --git a/apt-private/acqprogress.h b/apt-private/acqprogress.h index ab8170126..7cf990c65 100644 --- a/apt-private/acqprogress.h +++ b/apt-private/acqprogress.h @@ -13,9 +13,11 @@ #include #include +#include class APT_PUBLIC AcqTextStatus : public pkgAcquireStatus { + std::ostream &out; unsigned int &ScreenWidth; size_t LastLineLength; unsigned long ID; @@ -35,7 +37,7 @@ class APT_PUBLIC AcqTextStatus : public pkgAcquireStatus bool Pulse(pkgAcquire *Owner); - AcqTextStatus(unsigned int &ScreenWidth,unsigned int const Quiet); + AcqTextStatus(std::ostream &out, unsigned int &ScreenWidth,unsigned int const Quiet); }; #endif diff --git a/apt-private/private-install.cc b/apt-private/private-install.cc index 79a22edf4..acc6d42c2 100644 --- a/apt-private/private-install.cc +++ b/apt-private/private-install.cc @@ -116,7 +116,7 @@ bool InstallPackages(CacheFile &Cache,bool ShwKept,bool Ask, bool Safety) return false; // Create the download object - AcqTextStatus Stat(ScreenWidth,_config->FindI("quiet",0)); + AcqTextStatus Stat(std::cout, ScreenWidth,_config->FindI("quiet",0)); pkgAcquire Fetcher(&Stat); if (_config->FindB("APT::Get::Print-URIs", false) == true) { diff --git a/apt-private/private-update.cc b/apt-private/private-update.cc index df77ac33a..73a82e988 100644 --- a/apt-private/private-update.cc +++ b/apt-private/private-update.cc @@ -38,8 +38,8 @@ bool DoUpdate(CommandLine &CmdL) pkgSourceList *List = Cache.GetSourceList(); // Create the progress - AcqTextStatus Stat(ScreenWidth,_config->FindI("quiet",0)); - + AcqTextStatus Stat(std::cout, ScreenWidth,_config->FindI("quiet",0)); + // Just print out the uris an exit if the --print-uris flag was used if (_config->FindB("APT::Get::Print-URIs") == true) { -- cgit v1.2.3 From 88593886a42025d51d76051da5929b044e42efee Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Mon, 11 May 2015 15:08:08 +0200 Subject: rewrite all TFRewrite instances to use the new pkgTagSection::Write MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit While it is mostly busywork to rewrite all instances it actually fixes bugs as the data storage used by the new method is std::string rather than a char*, the later mostly created by c_str() from a std::string which the caller has to ensure keeps in scope – something apt-ftparchive actually didn't ensure and relied on copy-on-write behavior instead which c++11 forbids and hence the new default gcc abi doesn't use it. --- apt-private/private-show.cc | 46 +++++++++++++++++++++++---------------------- 1 file changed, 24 insertions(+), 22 deletions(-) (limited to 'apt-private') diff --git a/apt-private/private-show.cc b/apt-private/private-show.cc index 289f035a6..790bc0092 100644 --- a/apt-private/private-show.cc +++ b/apt-private/private-show.cc @@ -97,28 +97,30 @@ static bool DisplayRecord(pkgCacheFile &CacheFile, pkgCache::VerIterator V, manual_installed = 0; // FIXME: add verbose that does not do the removal of the tags? - TFRewriteData RW[] = { - // delete, apt-cache show has this info and most users do not care - {"MD5sum", NULL, NULL}, - {"SHA1", NULL, NULL}, - {"SHA256", NULL, NULL}, - {"Filename", NULL, NULL}, - {"Multi-Arch", NULL, NULL}, - {"Architecture", NULL, NULL}, - {"Conffiles", NULL, NULL}, - // we use the translated description - {"Description", NULL, NULL}, - {"Description-md5", NULL, NULL}, - // improve - {"Installed-Size", installed_size.c_str(), NULL}, - {"Size", package_size.c_str(), "Download-Size"}, - // add - {"APT-Manual-Installed", manual_installed, NULL}, - {"APT-Sources", source_index_file.c_str(), NULL}, - {NULL, NULL, NULL} - }; - - if(TFRewrite(stdout, Tags, NULL, RW) == false) + std::vector RW; + // delete, apt-cache show has this info and most users do not care + RW.push_back(pkgTagSection::Tag::Remove("MD5sum")); + RW.push_back(pkgTagSection::Tag::Remove("SHA1")); + RW.push_back(pkgTagSection::Tag::Remove("SHA256")); + RW.push_back(pkgTagSection::Tag::Remove("SHA512")); + RW.push_back(pkgTagSection::Tag::Remove("Filename")); + RW.push_back(pkgTagSection::Tag::Remove("Multi-Arch")); + RW.push_back(pkgTagSection::Tag::Remove("Architecture")); + RW.push_back(pkgTagSection::Tag::Remove("Conffiles")); + // we use the translated description + RW.push_back(pkgTagSection::Tag::Remove("Description")); + RW.push_back(pkgTagSection::Tag::Remove("Description-md5")); + // improve + RW.push_back(pkgTagSection::Tag::Rewrite("Installed-Size", installed_size)); + RW.push_back(pkgTagSection::Tag::Remove("Size")); + RW.push_back(pkgTagSection::Tag::Rewrite("Download-Size", package_size)); + // add + RW.push_back(pkgTagSection::Tag::Rewrite("APT-Manual-Installed", manual_installed)); + RW.push_back(pkgTagSection::Tag::Rewrite("APT-Sources", source_index_file)); + + FileFd stdoutfd; + if (stdoutfd.OpenDescriptor(STDOUT_FILENO, FileFd::WriteOnly, false) == false || + Tags.Write(stdoutfd, TFRewritePackageOrder, RW) == false || stdoutfd.Close() == false) return _error->Error("Internal Error, Unable to parse a package record"); // write the description -- cgit v1.2.3