diff options
Diffstat (limited to 'cmdline')
-rw-r--r-- | cmdline/acqprogress.cc | 22 | ||||
-rw-r--r-- | cmdline/apt-cache.cc | 114 | ||||
-rw-r--r-- | cmdline/apt-cdrom.cc | 8 | ||||
-rw-r--r-- | cmdline/apt-config.cc | 7 | ||||
-rw-r--r-- | cmdline/apt-dump-solver.cc | 50 | ||||
-rw-r--r-- | cmdline/apt-extracttemplates.cc | 5 | ||||
-rw-r--r-- | cmdline/apt-get.cc | 419 | ||||
-rw-r--r-- | cmdline/apt-internal-solver.cc | 190 | ||||
-rwxr-xr-x | cmdline/apt-key | 7 | ||||
-rw-r--r-- | cmdline/apt-mark.cc | 7 | ||||
-rw-r--r-- | cmdline/apt-sortpkgs.cc | 9 | ||||
-rw-r--r-- | cmdline/makefile | 14 |
12 files changed, 613 insertions, 239 deletions
diff --git a/cmdline/acqprogress.cc b/cmdline/acqprogress.cc index ba334ce05..1ccb08804 100644 --- a/cmdline/acqprogress.cc +++ b/cmdline/acqprogress.cc @@ -8,19 +8,21 @@ ##################################################################### */ /*}}}*/ // Include files /*{{{*/ -#include "acqprogress.h" +#include<config.h> + #include <apt-pkg/acquire-item.h> #include <apt-pkg/acquire-worker.h> #include <apt-pkg/configuration.h> #include <apt-pkg/strutl.h> #include <apt-pkg/error.h> -#include <apti18n.h> - #include <stdio.h> #include <signal.h> #include <iostream> #include <unistd.h> + +#include "acqprogress.h" +#include <apti18n.h> /*}}}*/ using namespace std; @@ -161,7 +163,7 @@ bool AcqTextStatus::Pulse(pkgAcquire *Owner) ScreenWidth = sizeof(Buffer)-1; // Put in the percent done - sprintf(S,"%ld%%",long(double((CurrentBytes + CurrentItems)*100.0)/double(TotalBytes+TotalItems))); + sprintf(S,"%.0f%%",((CurrentBytes + CurrentItems)*100.0)/(TotalBytes+TotalItems)); bool Shown = false; for (pkgAcquire::Worker *I = Owner->WorkersBegin(); I != 0; @@ -200,7 +202,7 @@ bool AcqTextStatus::Pulse(pkgAcquire *Owner) // Add the current progress if (Mode == Long) - snprintf(S,End-S," %lu",I->CurrentSize); + snprintf(S,End-S," %llu",I->CurrentSize); else { if (Mode == Medium || I->TotalSize == 0) @@ -212,11 +214,11 @@ bool AcqTextStatus::Pulse(pkgAcquire *Owner) if (I->TotalSize > 0 && I->CurrentItem->Owner->Complete == false) { if (Mode == Short) - snprintf(S,End-S," %lu%%", - long(double(I->CurrentSize*100.0)/double(I->TotalSize))); + snprintf(S,End-S," %.0f%%", + (I->CurrentSize*100.0)/I->TotalSize); else - snprintf(S,End-S,"/%sB %lu%%",SizeToStr(I->TotalSize).c_str(), - long(double(I->CurrentSize*100.0)/double(I->TotalSize))); + snprintf(S,End-S,"/%sB %.0f%%",SizeToStr(I->TotalSize).c_str(), + (I->CurrentSize*100.0)/I->TotalSize); } S += strlen(S); snprintf(S,End-S,"]"); @@ -236,7 +238,7 @@ bool AcqTextStatus::Pulse(pkgAcquire *Owner) if (CurrentCPS != 0) { char Tmp[300]; - unsigned long ETA = (unsigned long)((TotalBytes - CurrentBytes)/CurrentCPS); + 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); diff --git a/cmdline/apt-cache.cc b/cmdline/apt-cache.cc index 232bb93ec..a4cdf784e 100644 --- a/cmdline/apt-cache.cc +++ b/cmdline/apt-cache.cc @@ -13,8 +13,9 @@ ##################################################################### */ /*}}}*/ // Include Files /*{{{*/ +#include<config.h> + #include <apt-pkg/error.h> -#include <cassert> #include <apt-pkg/pkgcachegen.h> #include <apt-pkg/cachefile.h> #include <apt-pkg/cacheset.h> @@ -31,17 +32,16 @@ #include <apt-pkg/algorithms.h> #include <apt-pkg/sptr.h> -#include <config.h> -#include <apti18n.h> - +#include <cassert> #include <locale.h> #include <iostream> #include <unistd.h> #include <errno.h> #include <regex.h> #include <stdio.h> - #include <iomanip> + +#include <apti18n.h> /*}}}*/ using namespace std; @@ -141,7 +141,7 @@ bool ShowUnMet(pkgCache::VerIterator const &V, bool const &Important) if (Start == End) break; - Start++; + ++Start; } while (1); @@ -169,7 +169,7 @@ bool ShowUnMet(pkgCache::VerIterator const &V, bool const &Important) if (Start == End) break; cout << " | "; - Start++; + ++Start; } while (1); @@ -187,7 +187,7 @@ bool UnMet(CommandLine &CmdL) if (CmdL.FileSize() <= 1) { - for (pkgCache::PkgIterator P = CacheFile.GetPkgCache()->PkgBegin(); P.end() == false; P++) + for (pkgCache::PkgIterator P = CacheFile.GetPkgCache()->PkgBegin(); P.end() == false; ++P) for (pkgCache::VerIterator V = P.VersionList(); V.end() == false; ++V) if (ShowUnMet(V, Important) == false) return false; @@ -217,13 +217,13 @@ bool DumpPackage(CommandLine &CmdL) { cout << "Package: " << Pkg.FullName(true) << endl; cout << "Versions: " << endl; - for (pkgCache::VerIterator Cur = Pkg.VersionList(); Cur.end() != true; Cur++) + for (pkgCache::VerIterator Cur = Pkg.VersionList(); Cur.end() != true; ++Cur) { cout << Cur.VerStr(); - for (pkgCache::VerFileIterator Vf = Cur.FileList(); Vf.end() == false; Vf++) + for (pkgCache::VerFileIterator Vf = Cur.FileList(); Vf.end() == false; ++Vf) cout << " (" << Vf.File().FileName() << ")"; cout << endl; - for (pkgCache::DescIterator D = Cur.DescriptionList(); D.end() == false; D++) + for (pkgCache::DescIterator D = Cur.DescriptionList(); D.end() == false; ++D) { cout << " Description Language: " << D.LanguageCode() << endl << " File: " << D.FileList().File().FileName() << endl @@ -235,7 +235,7 @@ bool DumpPackage(CommandLine &CmdL) cout << endl; cout << "Reverse Depends: " << endl; - for (pkgCache::DepIterator D = Pkg.RevDependsList(); D.end() != true; D++) + for (pkgCache::DepIterator D = Pkg.RevDependsList(); D.end() != true; ++D) { cout << " " << D.ParentPkg().FullName(true) << ',' << D.TargetPkg().FullName(true); if (D->Version != 0) @@ -245,24 +245,24 @@ bool DumpPackage(CommandLine &CmdL) } cout << "Dependencies: " << endl; - for (pkgCache::VerIterator Cur = Pkg.VersionList(); Cur.end() != true; Cur++) + for (pkgCache::VerIterator Cur = Pkg.VersionList(); Cur.end() != true; ++Cur) { cout << Cur.VerStr() << " - "; - for (pkgCache::DepIterator Dep = Cur.DependsList(); Dep.end() != true; Dep++) + for (pkgCache::DepIterator Dep = Cur.DependsList(); Dep.end() != true; ++Dep) cout << Dep.TargetPkg().FullName(true) << " (" << (int)Dep->CompareOp << " " << DeNull(Dep.TargetVer()) << ") "; cout << endl; } cout << "Provides: " << endl; - for (pkgCache::VerIterator Cur = Pkg.VersionList(); Cur.end() != true; Cur++) + for (pkgCache::VerIterator Cur = Pkg.VersionList(); Cur.end() != true; ++Cur) { cout << Cur.VerStr() << " - "; - for (pkgCache::PrvIterator Prv = Cur.ProvidesList(); Prv.end() != true; Prv++) + for (pkgCache::PrvIterator Prv = Cur.ProvidesList(); Prv.end() != true; ++Prv) cout << Prv.ParentPkg().FullName(true) << " "; cout << endl; } cout << "Reverse Provides: " << endl; - for (pkgCache::PrvIterator Prv = Pkg.ProvidesList(); Prv.end() != true; Prv++) + for (pkgCache::PrvIterator Prv = Pkg.ProvidesList(); Prv.end() != true; ++Prv) cout << Prv.OwnerPkg().FullName(true) << " " << Prv.OwnerVer().VerStr() << endl; } @@ -290,7 +290,7 @@ bool Stats(CommandLine &Cmd) int DVirt = 0; int Missing = 0; pkgCache::PkgIterator I = Cache->PkgBegin(); - for (;I.end() != true; I++) + for (;I.end() != true; ++I) { if (I->VersionList != 0 && I->ProvidesList == 0) { @@ -353,11 +353,11 @@ bool Stats(CommandLine &Cmd) cout << _("Total globbed strings: ") << Count << " (" << SizeToStr(Size) << ')' << endl; unsigned long DepVerSize = 0; - for (pkgCache::PkgIterator P = Cache->PkgBegin(); P.end() == false; P++) + for (pkgCache::PkgIterator P = Cache->PkgBegin(); P.end() == false; ++P) { - for (pkgCache::VerIterator V = P.VersionList(); V.end() == false; V++) + for (pkgCache::VerIterator V = P.VersionList(); V.end() == false; ++V) { - for (pkgCache::DepIterator D = V.DependsList(); D.end() == false; D++) + for (pkgCache::DepIterator D = V.DependsList(); D.end() == false; ++D) { if (D->Version != 0) DepVerSize += strlen(D.TargetVer()) + 1; @@ -394,17 +394,17 @@ bool Dump(CommandLine &Cmd) cout << "Using Versioning System: " << Cache->VS->Label << endl; - for (pkgCache::PkgIterator P = Cache->PkgBegin(); P.end() == false; P++) + for (pkgCache::PkgIterator P = Cache->PkgBegin(); P.end() == false; ++P) { cout << "Package: " << P.FullName(true) << endl; - for (pkgCache::VerIterator V = P.VersionList(); V.end() == false; V++) + for (pkgCache::VerIterator V = P.VersionList(); V.end() == false; ++V) { cout << " Version: " << V.VerStr() << endl; cout << " File: " << V.FileList().File().FileName() << endl; - for (pkgCache::DepIterator D = V.DependsList(); D.end() == false; D++) + for (pkgCache::DepIterator D = V.DependsList(); D.end() == false; ++D) cout << " Depends: " << D.TargetPkg().FullName(true) << ' ' << DeNull(D.TargetVer()) << endl; - for (pkgCache::DescIterator D = V.DescriptionList(); D.end() == false; D++) + for (pkgCache::DescIterator D = V.DescriptionList(); D.end() == false; ++D) { cout << " Description Language: " << D.LanguageCode() << endl << " File: " << D.FileList().File().FileName() << endl @@ -413,7 +413,7 @@ bool Dump(CommandLine &Cmd) } } - for (pkgCache::PkgFileIterator F = Cache->FileBegin(); F.end() == false; F++) + for (pkgCache::PkgFileIterator F = Cache->FileBegin(); F.end() == false; ++F) { cout << "File: " << F.FileName() << endl; cout << " Type: " << F.IndexType() << endl; @@ -449,7 +449,7 @@ bool DumpAvail(CommandLine &Cmd) memset(VFList,0,sizeof(*VFList)*Count); // Map versions that we want to write out onto the VerList array. - for (pkgCache::PkgIterator P = Cache->PkgBegin(); P.end() == false; P++) + for (pkgCache::PkgIterator P = Cache->PkgBegin(); P.end() == false; ++P) { if (P->VersionList == 0) continue; @@ -466,7 +466,7 @@ bool DumpAvail(CommandLine &Cmd) } pkgCache::VerFileIterator VF = V.FileList(); - for (; VF.end() == false ; VF++) + for (; VF.end() == false ; ++VF) if ((VF.File()->Flags & pkgCache::Flag::NotSource) == 0) break; @@ -480,9 +480,9 @@ bool DumpAvail(CommandLine &Cmd) handling works OK. */ if (VF.end() == true) { - for (pkgCache::VerIterator Cur = P.VersionList(); Cur.end() != true; Cur++) + for (pkgCache::VerIterator Cur = P.VersionList(); Cur.end() != true; ++Cur) { - for (VF = Cur.FileList(); VF.end() == false; VF++) + for (VF = Cur.FileList(); VF.end() == false; ++VF) { if ((VF.File()->Flags & pkgCache::Flag::NotSource) == 0) { @@ -615,7 +615,7 @@ bool ShowDepends(CommandLine &CmdL, bool const RevDepends) if (RevDepends == true) cout << "Reverse Depends:" << endl; for (pkgCache::DepIterator D = RevDepends ? Pkg.RevDependsList() : Ver.DependsList(); - D.end() == false; D++) + D.end() == false; ++D) { switch (D->Type) { case pkgCache::Dep::PreDepends: if (!ShowPreDepends) continue; break; @@ -741,7 +741,7 @@ bool XVcg(CommandLine &CmdL) memset(Flags,0,sizeof(*Flags)*Cache->Head().PackageCount); // Map the shapes - for (pkgCache::PkgIterator Pkg = Cache->PkgBegin(); Pkg.end() == false; Pkg++) + for (pkgCache::PkgIterator Pkg = Cache->PkgBegin(); Pkg.end() == false; ++Pkg) { if (Pkg->VersionList == 0) { @@ -788,7 +788,7 @@ bool XVcg(CommandLine &CmdL) while (Act == true) { Act = false; - for (pkgCache::PkgIterator Pkg = Cache->PkgBegin(); Pkg.end() == false; Pkg++) + for (pkgCache::PkgIterator Pkg = Cache->PkgBegin(); Pkg.end() == false; ++Pkg) { // See we need to show this package if (Show[Pkg->ID] == None || Show[Pkg->ID] >= DoneNR) @@ -814,14 +814,14 @@ bool XVcg(CommandLine &CmdL) continue; pkgCache::VerIterator Ver = Pkg.VersionList(); - for (pkgCache::DepIterator D = Ver.DependsList(); D.end() == false; D++) + for (pkgCache::DepIterator D = Ver.DependsList(); D.end() == false; ++D) { // See if anything can meet this dep // Walk along the actual package providing versions bool Hit = false; pkgCache::PkgIterator DPkg = D.TargetPkg(); for (pkgCache::VerIterator I = DPkg.VersionList(); - I.end() == false && Hit == false; I++) + I.end() == false && Hit == false; ++I) { if (Cache->VS->CheckDep(I.VerStr(),D->CompareOp,D.TargetVer()) == true) Hit = true; @@ -829,7 +829,7 @@ bool XVcg(CommandLine &CmdL) // Follow all provides for (pkgCache::PrvIterator I = DPkg.ProvidesList(); - I.end() == false && Hit == false; I++) + I.end() == false && Hit == false; ++I) { if (Cache->VS->CheckDep(I.ProvideVersion(),D->CompareOp,D.TargetVer()) == false) Hit = true; @@ -889,7 +889,7 @@ bool XVcg(CommandLine &CmdL) /* Draw the box colours after the fact since we can not tell what colour they should be until everything is finished drawing */ - for (pkgCache::PkgIterator Pkg = Cache->PkgBegin(); Pkg.end() == false; Pkg++) + for (pkgCache::PkgIterator Pkg = Cache->PkgBegin(); Pkg.end() == false; ++Pkg) { if (Show[Pkg->ID] < DoneNR) continue; @@ -953,7 +953,7 @@ bool Dotty(CommandLine &CmdL) memset(Flags,0,sizeof(*Flags)*Cache->Head().PackageCount); // Map the shapes - for (pkgCache::PkgIterator Pkg = Cache->PkgBegin(); Pkg.end() == false; Pkg++) + for (pkgCache::PkgIterator Pkg = Cache->PkgBegin(); Pkg.end() == false; ++Pkg) { if (Pkg->VersionList == 0) { @@ -1000,7 +1000,7 @@ bool Dotty(CommandLine &CmdL) while (Act == true) { Act = false; - for (pkgCache::PkgIterator Pkg = Cache->PkgBegin(); Pkg.end() == false; Pkg++) + for (pkgCache::PkgIterator Pkg = Cache->PkgBegin(); Pkg.end() == false; ++Pkg) { // See we need to show this package if (Show[Pkg->ID] == None || Show[Pkg->ID] >= DoneNR) @@ -1024,14 +1024,14 @@ bool Dotty(CommandLine &CmdL) continue; pkgCache::VerIterator Ver = Pkg.VersionList(); - for (pkgCache::DepIterator D = Ver.DependsList(); D.end() == false; D++) + for (pkgCache::DepIterator D = Ver.DependsList(); D.end() == false; ++D) { // See if anything can meet this dep // Walk along the actual package providing versions bool Hit = false; pkgCache::PkgIterator DPkg = D.TargetPkg(); for (pkgCache::VerIterator I = DPkg.VersionList(); - I.end() == false && Hit == false; I++) + I.end() == false && Hit == false; ++I) { if (Cache->VS->CheckDep(I.VerStr(),D->CompareOp,D.TargetVer()) == true) Hit = true; @@ -1039,7 +1039,7 @@ bool Dotty(CommandLine &CmdL) // Follow all provides for (pkgCache::PrvIterator I = DPkg.ProvidesList(); - I.end() == false && Hit == false; I++) + I.end() == false && Hit == false; ++I) { if (Cache->VS->CheckDep(I.ProvideVersion(),D->CompareOp,D.TargetVer()) == false) Hit = true; @@ -1094,7 +1094,7 @@ bool Dotty(CommandLine &CmdL) /* Draw the box colours after the fact since we can not tell what colour they should be until everything is finished drawing */ - for (pkgCache::PkgIterator Pkg = Cache->PkgBegin(); Pkg.end() == false; Pkg++) + for (pkgCache::PkgIterator Pkg = Cache->PkgBegin(); Pkg.end() == false; ++Pkg) { if (Show[Pkg->ID] < DoneNR) continue; @@ -1127,7 +1127,7 @@ bool DisplayRecord(pkgCacheFile &CacheFile, pkgCache::VerIterator V) // Find an appropriate file pkgCache::VerFileIterator Vf = V.FileList(); - for (; Vf.end() == false; Vf++) + for (; Vf.end() == false; ++Vf) if ((Vf.File()->Flags & pkgCache::Flag::NotSource) == 0) break; if (Vf.end() == true) @@ -1272,7 +1272,7 @@ bool Search(CommandLine &CmdL) continue; // Include all the packages that provide matching names too - for (pkgCache::PrvIterator Prv = P.ProvidesList() ; Prv.end() == false; Prv++) + for (pkgCache::PrvIterator Prv = P.ProvidesList() ; Prv.end() == false; ++Prv) { pkgCache::VerIterator V = Plcy->GetCandidateVer(Prv.OwnerPkg()); if (V.end() == true) @@ -1341,13 +1341,13 @@ bool ShowAuto(CommandLine &CmdL) std::vector<string> packages; packages.reserve(Cache->HeaderP->PackageCount / 3); - for (pkgCache::PkgIterator P = Cache->PkgBegin(); P.end() == false; P++) + for (pkgCache::PkgIterator P = Cache->PkgBegin(); P.end() == false; ++P) if ((*DepCache)[P].Flags & pkgCache::Flag::Auto) packages.push_back(P.Name()); std::sort(packages.begin(), packages.end()); - for (vector<string>::iterator I = packages.begin(); I != packages.end(); I++) + for (vector<string>::iterator I = packages.begin(); I != packages.end(); ++I) cout << *I << "\n"; _error->Notice(_("This command is deprecated. Please use 'apt-mark showauto' instead.")); @@ -1391,7 +1391,7 @@ bool ShowPkgNames(CommandLine &CmdL) if (CmdL.FileList[1] != 0) { - for (;I.end() != true; I++) + for (;I.end() != true; ++I) { if (All == false && I->FirstPackage == 0) continue; @@ -1405,7 +1405,7 @@ bool ShowPkgNames(CommandLine &CmdL) } // Show all pkgs - for (;I.end() != true; I++) + for (;I.end() != true; ++I) { if (All == false && I->FirstPackage == 0) continue; @@ -1476,7 +1476,7 @@ bool Policy(CommandLine &CmdL) if (CmdL.FileList[1] == 0) { cout << _("Package files:") << endl; - for (pkgCache::PkgFileIterator F = Cache->FileBegin(); F.end() == false; F++) + for (pkgCache::PkgFileIterator F = Cache->FileBegin(); F.end() == false; ++F) { // Locate the associated index files so we can derive a description pkgIndexFile *Indx; @@ -1498,7 +1498,7 @@ bool Policy(CommandLine &CmdL) // Show any packages have explicit pins cout << _("Pinned packages:") << endl; pkgCache::PkgIterator I = Cache->PkgBegin(); - for (;I.end() != true; I++) + for (;I.end() != true; ++I) { if (Plcy->GetPriority(I) == 0) continue; @@ -1560,14 +1560,14 @@ bool Policy(CommandLine &CmdL) // Show the priority tables cout << _(" Version table:") << endl; - for (V = Pkg.VersionList(); V.end() == false; V++) + for (V = Pkg.VersionList(); V.end() == false; ++V) { if (Pkg.CurrentVer() == V) cout << " *** " << V.VerStr(); else cout << " " << V.VerStr(); cout << " " << Plcy->GetPriority(Pkg) << endl; - for (pkgCache::VerFileIterator VF = V.FileList(); VF.end() == false; VF++) + for (pkgCache::VerFileIterator VF = V.FileList(); VF.end() == false; ++VF) { // Locate the associated index files so we can derive a description pkgIndexFile *Indx; @@ -1607,9 +1607,9 @@ bool Madison(CommandLine &CmdL) APT::PackageSet pkgset = APT::PackageSet::FromString(CacheFile, *I, helper); for (APT::PackageSet::const_iterator Pkg = pkgset.begin(); Pkg != pkgset.end(); ++Pkg) { - for (pkgCache::VerIterator V = Pkg.VersionList(); V.end() == false; V++) + for (pkgCache::VerIterator V = Pkg.VersionList(); V.end() == false; ++V) { - for (pkgCache::VerFileIterator VF = V.FileList(); VF.end() == false; VF++) + for (pkgCache::VerFileIterator VF = V.FileList(); VF.end() == false; ++VF) { // This might be nice, but wouldn't uniquely identify the source -mdz // if (VF.File().Archive() != 0) @@ -1619,11 +1619,11 @@ bool Madison(CommandLine &CmdL) // } // Locate the associated index files so we can derive a description - for (pkgSourceList::const_iterator S = SrcList->begin(); S != SrcList->end(); S++) + for (pkgSourceList::const_iterator S = SrcList->begin(); S != SrcList->end(); ++S) { vector<pkgIndexFile *> *Indexes = (*S)->GetIndexFiles(); for (vector<pkgIndexFile *>::const_iterator IF = Indexes->begin(); - IF != Indexes->end(); IF++) + IF != Indexes->end(); ++IF) { if ((*IF)->FindInCache(*(VF.File().Cache())) == VF.File()) { diff --git a/cmdline/apt-cdrom.cc b/cmdline/apt-cdrom.cc index d1268edf9..8608b1215 100644 --- a/cmdline/apt-cdrom.cc +++ b/cmdline/apt-cdrom.cc @@ -11,6 +11,8 @@ ##################################################################### */ /*}}}*/ // Include Files /*{{{*/ +#include<config.h> + #include <apt-pkg/cmndline.h> #include <apt-pkg/error.h> #include <apt-pkg/init.h> @@ -21,10 +23,6 @@ #include <apt-pkg/acquire.h> #include <apt-pkg/acquire-item.h> #include <apt-pkg/cdrom.h> -#include <config.h> -#include <apti18n.h> - -//#include "indexcopy.h" #include <locale.h> #include <iostream> @@ -36,6 +34,8 @@ #include <dirent.h> #include <unistd.h> #include <stdio.h> + +#include <apti18n.h> /*}}}*/ using namespace std; diff --git a/cmdline/apt-config.cc b/cmdline/apt-config.cc index 589ee7ada..df2958975 100644 --- a/cmdline/apt-config.cc +++ b/cmdline/apt-config.cc @@ -16,6 +16,8 @@ ##################################################################### */ /*}}}*/ // Include Files /*{{{*/ +#include<config.h> + #include <apt-pkg/cmndline.h> #include <apt-pkg/error.h> #include <apt-pkg/init.h> @@ -23,13 +25,12 @@ #include <apt-pkg/configuration.h> #include <apt-pkg/aptconfiguration.h> -#include <config.h> -#include <apti18n.h> - #include <locale.h> #include <iostream> #include <string> #include <vector> + +#include <apti18n.h> /*}}}*/ using namespace std; diff --git a/cmdline/apt-dump-solver.cc b/cmdline/apt-dump-solver.cc new file mode 100644 index 000000000..dab0cc6fd --- /dev/null +++ b/cmdline/apt-dump-solver.cc @@ -0,0 +1,50 @@ +// -*- mode: cpp; mode: fold -*- +// Description /*{{{*/ +/* ##################################################################### + + dummy solver to get quickly a scenario file out of APT + + ##################################################################### */ + /*}}}*/ +// Include Files /*{{{*/ +#include <apt-pkg/edsp.h> + +#include <config.h> + +#include <cstdio> + /*}}}*/ + +// ShowHelp - Show a help screen /*{{{*/ +// --------------------------------------------------------------------- +/* */ +bool ShowHelp() { + + std::cout << + PACKAGE " " VERSION " for " COMMON_ARCH " compiled on " __DATE__ " " __TIME__ << std::endl << + "Usage: apt-dump-resolver\n" + "\n" + "apt-dump-resolver is a dummy solver who just dumps its input to the\n" + "file /tmp/dump.edsp and exists with a proper EDSP error.\n" + "\n" + " This dump has lost Super Cow Powers.\n"; + return true; +} + /*}}}*/ +int main(int argc,const char *argv[]) /*{{{*/ +{ + if (argc > 1 && (strcmp(argv[1], "--help") == 0 || strcmp(argv[1],"-h") == 0 || + strcmp(argv[1],"-v") == 0 || strcmp(argv[1],"--version") == 0)) { + ShowHelp(); + return 0; + } + + FILE* input = fdopen(STDIN_FILENO, "r"); + FILE* output = fopen("/tmp/dump.edsp", "w"); + char buffer[400]; + while (fgets(buffer, sizeof(buffer), input) != NULL) + fputs(buffer, output); + fclose(output); + fclose(input); + + EDSP::WriteError("ERR_JUST_DUMPING", "I am too dumb, i can just dump!\nPlease use one of my friends instead!", stdout); +} diff --git a/cmdline/apt-extracttemplates.cc b/cmdline/apt-extracttemplates.cc index 07bc0c25d..5d7b76c23 100644 --- a/cmdline/apt-extracttemplates.cc +++ b/cmdline/apt-extracttemplates.cc @@ -13,6 +13,8 @@ ##################################################################### */ /*}}}*/ // Include Files /*{{{*/ +#include<config.h> + #include <apt-pkg/init.h> #include <apt-pkg/cmndline.h> #include <apt-pkg/pkgcache.h> @@ -28,7 +30,7 @@ #include <apt-pkg/error.h> #include <apt-pkg/strutl.h> #include <apt-pkg/fileutl.h> - + #include <stdio.h> #include <string.h> #include <stdlib.h> @@ -36,7 +38,6 @@ #include <fstream> #include <locale.h> -#include <config.h> #include <apti18n.h> #include "apt-extracttemplates.h" /*}}}*/ diff --git a/cmdline/apt-get.cc b/cmdline/apt-get.cc index 845c92026..d8f207f0a 100644 --- a/cmdline/apt-get.cc +++ b/cmdline/apt-get.cc @@ -25,8 +25,7 @@ ##################################################################### */ /*}}}*/ // Include Files /*{{{*/ -#define _LARGEFILE_SOURCE -#define _LARGEFILE64_SOURCE +#include <config.h> #include <apt-pkg/aptconfiguration.h> #include <apt-pkg/error.h> @@ -46,9 +45,6 @@ #include <apt-pkg/md5.h> #include <apt-pkg/versionmatch.h> -#include <config.h> -#include <apti18n.h> - #include "acqprogress.h" #include <set> @@ -68,8 +64,7 @@ #include <sys/wait.h> #include <sstream> -#define statfs statfs64 -#define statvfs statvfs64 +#include <apti18n.h> /*}}}*/ #define RAMFS_MAGIC 0x858458f6 @@ -135,6 +130,11 @@ bool YnPrompt(bool Default=true) c1out << _("Y") << endl; return true; } + else if (_config->FindB("APT::Get::Assume-No",false) == true) + { + c1out << _("N") << endl; + return false; + } char response[1024] = ""; cin.getline(response, sizeof(response)); @@ -363,7 +363,7 @@ void ShowBroken(ostream &out,CacheFile &Cache,bool Now) if (Start == End) break; - Start++; + ++Start; } } } @@ -537,7 +537,7 @@ bool ShowEssential(ostream &out,CacheFile &Cache) continue; // Print out any essential package depenendents that are to be removed - for (pkgCache::DepIterator D = I.CurrentVer().DependsList(); D.end() == false; D++) + for (pkgCache::DepIterator D = I.CurrentVer().DependsList(); D.end() == false; ++D) { // Skip everything but depends if (D->Type != pkgCache::Dep::PreDepends && @@ -574,7 +574,7 @@ void Stats(ostream &out,pkgDepCache &Dep) unsigned long Downgrade = 0; unsigned long Install = 0; unsigned long ReInstall = 0; - for (pkgCache::PkgIterator I = Dep.PkgBegin(); I.end() == false; I++) + for (pkgCache::PkgIterator I = Dep.PkgBegin(); I.end() == false; ++I) { if (Dep[I].NewInstall() == true) Install++; @@ -666,7 +666,7 @@ public: } // if we found no candidate which provide this package, show non-candidates if (provider == 0) - for (I = Pkg.ProvidesList(); I.end() == false; I++) + for (I = Pkg.ProvidesList(); I.end() == false; ++I) out << " " << I.OwnerPkg().FullName(true) << " " << I.OwnerVer().VerStr() << _(" [Not candidate version]") << endl; else @@ -682,7 +682,7 @@ public: SPtrArray<bool> Seen = new bool[Cache.GetPkgCache()->Head().PackageCount]; memset(Seen,0,Cache.GetPkgCache()->Head().PackageCount*sizeof(*Seen)); for (pkgCache::DepIterator Dep = Pkg.RevDependsList(); - Dep.end() == false; Dep++) { + Dep.end() == false; ++Dep) { if (Dep->Type != pkgCache::Dep::Replaces) continue; if (Seen[Dep.ParentPkg()->ID] == true) @@ -869,9 +869,7 @@ struct TryToInstall { struct TryToRemove { pkgCacheFile* Cache; pkgProblemResolver* Fix; - bool FixBroken; bool PurgePkgs; - unsigned long AutoMarkChanged; TryToRemove(pkgCacheFile &Cache, pkgProblemResolver *PM) : Cache(&Cache), Fix(PM), PurgePkgs(_config->FindB("APT::Get::Purge", false)) {}; @@ -923,7 +921,7 @@ void CacheFile::Sort() List = new pkgCache::Package *[Cache->Head().PackageCount]; memset(List,0,sizeof(*List)*Cache->Head().PackageCount); pkgCache::PkgIterator I = Cache->PkgBegin(); - for (;I.end() != true; I++) + for (;I.end() != true; ++I) List[I->ID] = I; SortCache = *this; @@ -955,7 +953,7 @@ bool CacheFile::CheckDeps(bool AllowBroken) if ((DCache->PolicyBrokenCount() > 0)) { // upgrade all policy-broken packages with ForceImportantDeps=True - for (pkgCache::PkgIterator I = Cache->PkgBegin(); !I.end(); I++) + for (pkgCache::PkgIterator I = Cache->PkgBegin(); !I.end(); ++I) if ((*DCache)[I].NowPolicyBroken() == true) DCache->MarkInstall(I,true,0, false, true); } @@ -1046,7 +1044,7 @@ bool InstallPackages(CacheFile &Cache,bool ShwKept,bool Ask = true, if (_config->FindB("APT::Get::Purge",false) == true) { pkgCache::PkgIterator I = Cache->PkgBegin(); - for (; I.end() == false; I++) + for (; I.end() == false; ++I) { if (I.Purge() == false && Cache[I].Mode == pkgDepCache::ModeDelete) Cache->MarkDelete(I,true); @@ -1240,7 +1238,7 @@ bool InstallPackages(CacheFile &Cache,bool ShwKept,bool Ask = true, if (_config->FindB("APT::Get::Print-URIs") == true) { pkgAcquire::UriIterator I = Fetcher.UriBegin(); - for (; I != Fetcher.UriEnd(); I++) + for (; I != Fetcher.UriEnd(); ++I) cout << '\'' << I->URI << "' " << flNotDir(I->Owner->DestFile) << ' ' << I->Owner->FileSize << ' ' << I->Owner->HashSum() << endl; return true; @@ -1264,7 +1262,7 @@ bool InstallPackages(CacheFile &Cache,bool ShwKept,bool Ask = true, { if ((*I)->Local == true) { - I++; + ++I; continue; } @@ -1284,7 +1282,7 @@ bool InstallPackages(CacheFile &Cache,bool ShwKept,bool Ask = true, // Print out errors bool Failed = false; - for (pkgAcquire::ItemIterator I = Fetcher.ItemsBegin(); I != Fetcher.ItemsEnd(); I++) + for (pkgAcquire::ItemIterator I = Fetcher.ItemsBegin(); I != Fetcher.ItemsEnd(); ++I) { if ((*I)->Status == pkgAcquire::Item::StatDone && (*I)->Complete == true) @@ -1388,6 +1386,14 @@ bool TryToInstallBuildDep(pkgCache::PkgIterator Pkg,pkgCacheFile &Cache, return AllowFail; } + if (_config->FindB("Debug::BuildDeps",false) == true) + { + if (Remove == true) + cout << " Trying to remove " << Pkg << endl; + else + cout << " Trying to install " << Pkg << endl; + } + if (Remove == true) { TryToRemove RemoveAction(Cache, &Fix); @@ -1436,7 +1442,7 @@ pkgSrcRecords::Parser *FindSrc(const char *Name,pkgRecords &Recs, // we have a default release, try to locate the pkg. we do it like // this because GetCandidateVer() will not "downgrade", that means // "apt-get source -t stable apt" won't work on a unstable system - for (pkgCache::VerIterator Ver = Pkg.VersionList();; Ver++) + for (pkgCache::VerIterator Ver = Pkg.VersionList();; ++Ver) { // try first only exact matches, later fuzzy matches if (Ver.end() == true) @@ -1457,7 +1463,7 @@ pkgSrcRecords::Parser *FindSrc(const char *Name,pkgRecords &Recs, continue; for (pkgCache::VerFileIterator VF = Ver.FileList(); - VF.end() == false; VF++) + VF.end() == false; ++VF) { /* If this is the status file, and the current version is not the version in the status file (ie it is not installed, or somesuch) @@ -1609,7 +1615,7 @@ bool DoUpdate(CommandLine &CmdL) return false; pkgAcquire::UriIterator I = Fetcher.UriBegin(); - for (; I != Fetcher.UriEnd(); I++) + for (; I != Fetcher.UriEnd(); ++I) cout << '\'' << I->URI << "' " << flNotDir(I->Owner->DestFile) << ' ' << I->Owner->FileSize << ' ' << I->Owner->HashSum() << endl; return true; @@ -1619,7 +1625,8 @@ bool DoUpdate(CommandLine &CmdL) if (_config->FindB("APT::Get::Download",true) == true) ListUpdate(Stat, *List); - // Rebuild the cache. + // Rebuild the cache. + pkgCacheFile::RemoveCaches(); if (Cache.BuildCaches() == false) return false; @@ -1697,7 +1704,7 @@ bool DoAutomaticRemove(CacheFile &Cache) // we could have removed a new dependency of a garbage package, // so check if a reverse depends is broken and if so install it again. - if (tooMuch.empty() == false && Cache->BrokenCount() != 0) + if (tooMuch.empty() == false && (Cache->BrokenCount() != 0 || Cache->PolicyBrokenCount() != 0)) { bool Changed; do { @@ -1708,8 +1715,8 @@ bool DoAutomaticRemove(CacheFile &Cache) for (pkgCache::DepIterator R = P.RevDependsList(); R.end() == false; ++R) { - if (R->Type != pkgCache::Dep::Depends && - R->Type != pkgCache::Dep::PreDepends) + if (R.IsNegative() == true || + Cache->IsImportantDep(R) == false) continue; pkgCache::PkgIterator N = R.ParentPkg(); if (N.end() == true || (N->CurrentVer == 0 && (*Cache)[N].Install() == false)) @@ -1886,8 +1893,7 @@ bool DoInstall(CommandLine &CmdL) { // Call the scored problem resolver Fix->InstallProtect(); - if (Fix->Resolve(true) == false) - _error->Discard(); + Fix->Resolve(true); delete Fix; } @@ -1913,8 +1919,11 @@ bool DoInstall(CommandLine &CmdL) c1out << _("The following information may help to resolve the situation:") << endl; c1out << endl; ShowBroken(c1out,Cache,false); - return _error->Error(_("Broken packages")); - } + if (_error->PendingError() == true) + return false; + else + return _error->Error(_("Broken packages")); + } } if (!DoAutomaticRemove(Cache)) return false; @@ -1992,7 +2001,7 @@ bool DoInstall(CommandLine &CmdL) if(Start.TargetPkg().ProvidesList() != 0) { pkgCache::PrvIterator I = Start.TargetPkg().ProvidesList(); - for (; I.end() == false; I++) + for (; I.end() == false; ++I) { pkgCache::PkgIterator Pkg = I.OwnerPkg(); if (Cache[Pkg].CandidateVerIter(Cache) == I.OwnerVer() && @@ -2015,7 +2024,7 @@ bool DoInstall(CommandLine &CmdL) if (Start >= End) break; - Start++; + ++Start; } if(foundInstalledInOrGroup == false) @@ -2129,7 +2138,7 @@ bool DoDSelectUpgrade(CommandLine &CmdL) // Install everything with the install flag set pkgCache::PkgIterator I = Cache->PkgBegin(); - for (;I.end() != true; I++) + for (;I.end() != true; ++I) { /* Install the package only if it is a new install, the autoupgrader will deal with the rest */ @@ -2139,7 +2148,7 @@ bool DoDSelectUpgrade(CommandLine &CmdL) /* Now install their deps too, if we do this above then order of the status file is significant for | groups */ - for (I = Cache->PkgBegin();I.end() != true; I++) + for (I = Cache->PkgBegin();I.end() != true; ++I) { /* Install the package only if it is a new install, the autoupgrader will deal with the rest */ @@ -2148,7 +2157,7 @@ bool DoDSelectUpgrade(CommandLine &CmdL) } // Apply erasures now, they override everything else. - for (I = Cache->PkgBegin();I.end() != true; I++) + for (I = Cache->PkgBegin();I.end() != true; ++I) { // Remove packages if (I->SelectedState == pkgCache::State::DeInstall || @@ -2165,7 +2174,7 @@ bool DoDSelectUpgrade(CommandLine &CmdL) // Hold back held packages. if (_config->FindB("APT::Ignore-Hold",false) == false) { - for (pkgCache::PkgIterator I = Cache->PkgBegin(); I.end() == false; I++) + for (pkgCache::PkgIterator I = Cache->PkgBegin(); I.end() == false; ++I) { if (I->SelectedState == pkgCache::State::Hold) { @@ -2197,10 +2206,14 @@ bool DoDSelectUpgrade(CommandLine &CmdL) /* */ bool DoClean(CommandLine &CmdL) { + std::string const archivedir = _config->FindDir("Dir::Cache::archives"); + std::string const pkgcache = _config->FindFile("Dir::cache::pkgcache"); + std::string const srcpkgcache = _config->FindFile("Dir::cache::srcpkgcache"); + if (_config->FindB("APT::Get::Simulate") == true) { - cout << "Del " << _config->FindDir("Dir::Cache::archives") << "* " << - _config->FindDir("Dir::Cache::archives") << "partial/*" << endl; + cout << "Del " << archivedir << "* " << archivedir << "partial/*"<< endl + << "Del " << pkgcache << " " << srcpkgcache << endl; return true; } @@ -2208,14 +2221,17 @@ bool DoClean(CommandLine &CmdL) FileFd Lock; if (_config->FindB("Debug::NoLocking",false) == false) { - Lock.Fd(GetLock(_config->FindDir("Dir::Cache::Archives") + "lock")); + Lock.Fd(GetLock(archivedir + "lock")); if (_error->PendingError() == true) return _error->Error(_("Unable to lock the download directory")); } pkgAcquire Fetcher; - Fetcher.Clean(_config->FindDir("Dir::Cache::archives")); - Fetcher.Clean(_config->FindDir("Dir::Cache::archives") + "partial/"); + Fetcher.Clean(archivedir); + Fetcher.Clean(archivedir + "partial/"); + + pkgCacheFile::RemoveCaches(); + return true; } /*}}}*/ @@ -2273,7 +2289,7 @@ bool DoDownload(CommandLine &CmdL) pkgAcquire Fetcher; AcqTextStatus Stat(ScreenWidth, _config->FindI("quiet",0)); - if (_config->FindB("APT::Get::Print-URIs") == true) + if (_config->FindB("APT::Get::Print-URIs") == false) Fetcher.Setup(&Stat); pkgRecords Recs(Cache); @@ -2297,6 +2313,8 @@ bool DoDownload(CommandLine &CmdL) strprintf(descr, _("Downloading %s %s"), Pkg.Name(), Ver.VerStr()); // get the most appropriate hash HashString hash; + if (rec.SHA512Hash() != "") + hash = HashString("sha512", rec.SHA512Hash()); if (rec.SHA256Hash() != "") hash = HashString("sha256", rec.SHA256Hash()); else if (rec.SHA1Hash() != "") @@ -2311,7 +2329,7 @@ bool DoDownload(CommandLine &CmdL) if (_config->FindB("APT::Get::Print-URIs") == true) { pkgAcquire::UriIterator I = Fetcher.UriBegin(); - for (; I != Fetcher.UriEnd(); I++) + for (; I != Fetcher.UriEnd(); ++I) cout << '\'' << I->URI << "' " << flNotDir(I->Owner->DestFile) << ' ' << I->Owner->FileSize << ' ' << I->Owner->HashSum() << endl; return true; @@ -2366,8 +2384,7 @@ bool DoSource(CommandLine &CmdL) // Create the download object AcqTextStatus Stat(ScreenWidth,_config->FindI("quiet",0)); pkgAcquire Fetcher; - if (Fetcher.Setup(&Stat) == false) - return false; + Fetcher.SetLog(&Stat); DscFile *Dsc = new DscFile[CmdL.FileSize()]; @@ -2430,7 +2447,7 @@ bool DoSource(CommandLine &CmdL) // Load them into the fetcher for (vector<pkgSrcRecords::File>::const_iterator I = Lst.begin(); - I != Lst.end(); I++) + I != Lst.end(); ++I) { // Try to guess what sort of file it is we are getting. if (I->Type == "dsc") @@ -2532,7 +2549,7 @@ bool DoSource(CommandLine &CmdL) if (_config->FindB("APT::Get::Print-URIs") == true) { pkgAcquire::UriIterator I = Fetcher.UriBegin(); - for (; I != Fetcher.UriEnd(); I++) + for (; I != Fetcher.UriEnd(); ++I) cout << '\'' << I->URI << "' " << flNotDir(I->Owner->DestFile) << ' ' << I->Owner->FileSize << ' ' << I->Owner->HashSum() << endl; delete[] Dsc; @@ -2548,7 +2565,7 @@ bool DoSource(CommandLine &CmdL) // Print error messages bool Failed = false; - for (pkgAcquire::ItemIterator I = Fetcher.ItemsBegin(); I != Fetcher.ItemsEnd(); I++) + for (pkgAcquire::ItemIterator I = Fetcher.ItemsBegin(); I != Fetcher.ItemsEnd(); ++I) { if ((*I)->Status == pkgAcquire::Item::StatDone && (*I)->Complete == true) @@ -2577,7 +2594,7 @@ bool DoSource(CommandLine &CmdL) if (Process == 0) { bool const fixBroken = _config->FindB("APT::Get::Fix-Broken", false); - for (unsigned I = 0; I != J; I++) + for (unsigned I = 0; I != J; ++I) { string Dir = Dsc[I].Package + '-' + Cache->VS().UpstreamVersion(Dsc[I].Version.c_str()); @@ -2613,12 +2630,17 @@ bool DoSource(CommandLine &CmdL) // Try to compile it with dpkg-buildpackage if (_config->FindB("APT::Get::Compile",false) == true) { + string buildopts = _config->Find("APT::Get::Host-Architecture"); + if (buildopts.empty() == false) + buildopts = "-a " + buildopts + " "; + buildopts.append(_config->Find("DPkg::Build-Options","-b -uc")); + // Call dpkg-buildpackage char S[500]; snprintf(S,sizeof(S),"cd %s && %s %s", Dir.c_str(), _config->Find("Dir::Bin::dpkg-buildpackage","dpkg-buildpackage").c_str(), - _config->Find("DPkg::Build-Options","-b -uc").c_str()); + buildopts.c_str()); if (system(S) != 0) { @@ -2680,8 +2702,19 @@ bool DoBuildDep(CommandLine &CmdL) if (Fetcher.Setup(&Stat) == false) return false; + bool StripMultiArch; + string hostArch = _config->Find("APT::Get::Host-Architecture"); + if (hostArch.empty() == false) + { + std::vector<std::string> archs = APT::Configuration::getArchitectures(); + if (std::find(archs.begin(), archs.end(), hostArch) == archs.end()) + return _error->Error(_("No architecture information available for %s. See apt.conf(5) APT::Architectures for setup"), hostArch.c_str()); + StripMultiArch = false; + } + else + StripMultiArch = true; + unsigned J = 0; - bool const StripMultiArch = APT::Configuration::getArchitectures().size() <= 1; for (const char **I = CmdL.FileList + 1; *I != 0; I++, J++) { string Src; @@ -2710,22 +2743,32 @@ bool DoBuildDep(CommandLine &CmdL) BuildDeps.push_back(rec); } - if (BuildDeps.size() == 0) + if (BuildDeps.empty() == true) { ioprintf(c1out,_("%s has no build depends.\n"),Src.c_str()); continue; } - + // Install the requested packages vector <pkgSrcRecords::Parser::BuildDepRec>::iterator D; pkgProblemResolver Fix(Cache); bool skipAlternatives = false; // skip remaining alternatives in an or group - for (D = BuildDeps.begin(); D != BuildDeps.end(); D++) + for (D = BuildDeps.begin(); D != BuildDeps.end(); ++D) { bool hasAlternatives = (((*D).Op & pkgCache::Dep::Or) == pkgCache::Dep::Or); if (skipAlternatives == true) { + /* + * if there are alternatives, we've already picked one, so skip + * the rest + * + * TODO: this means that if there's a build-dep on A|B and B is + * installed, we'll still try to install A; more importantly, + * if A is currently broken, we cannot go back and try B. To fix + * this would require we do a Resolve cycle for each package we + * add to the install list. Ugh + */ if (!hasAlternatives) skipAlternatives = false; // end of or group continue; @@ -2734,27 +2777,117 @@ bool DoBuildDep(CommandLine &CmdL) if ((*D).Type == pkgSrcRecords::Parser::BuildConflict || (*D).Type == pkgSrcRecords::Parser::BuildConflictIndep) { - pkgCache::PkgIterator Pkg = Cache->FindPkg((*D).Package); + pkgCache::GrpIterator Grp = Cache->FindGrp((*D).Package); // Build-conflicts on unknown packages are silently ignored - if (Pkg.end() == true) + if (Grp.end() == true) continue; - pkgCache::VerIterator IV = (*Cache)[Pkg].InstVerIter(*Cache); - - /* - * Remove if we have an installed version that satisfies the - * version criteria - */ - if (IV.end() == false && - Cache->VS().CheckDep(IV.VerStr(),(*D).Op,(*D).Version.c_str()) == true) - TryToInstallBuildDep(Pkg,Cache,Fix,true,false); + for (pkgCache::PkgIterator Pkg = Grp.PackageList(); Pkg.end() == false; Pkg = Grp.NextPkg(Pkg)) + { + pkgCache::VerIterator IV = (*Cache)[Pkg].InstVerIter(*Cache); + /* + * Remove if we have an installed version that satisfies the + * version criteria + */ + if (IV.end() == false && + Cache->VS().CheckDep(IV.VerStr(),(*D).Op,(*D).Version.c_str()) == true) + TryToInstallBuildDep(Pkg,Cache,Fix,true,false); + } } else // BuildDep || BuildDepIndep { - pkgCache::PkgIterator Pkg = Cache->FindPkg((*D).Package); if (_config->FindB("Debug::BuildDeps",false) == true) cout << "Looking for " << (*D).Package << "...\n"; + pkgCache::PkgIterator Pkg; + + // Cross-Building? + if (StripMultiArch == false) + { + size_t const colon = D->Package.find(":"); + if (colon != string::npos && + (strcmp(D->Package.c_str() + colon, ":any") == 0 || strcmp(D->Package.c_str() + colon, ":native") == 0)) + Pkg = Cache->FindPkg(D->Package.substr(0,colon)); + else + Pkg = Cache->FindPkg(D->Package); + + // We need to decide if host or build arch, so find a version we can look at + pkgCache::VerIterator Ver; + + // a bad version either is invalid or doesn't satify dependency + #define BADVER(Ver) Ver.end() == true || \ + (Ver.end() == false && D->Version.empty() == false && \ + Cache->VS().CheckDep(Ver.VerStr(),D->Op,D->Version.c_str()) == false) + + if (Pkg.end() == false) + { + Ver = (*Cache)[Pkg].InstVerIter(*Cache); + if (BADVER(Ver)) + Ver = (*Cache)[Pkg].CandidateVerIter(*Cache); + } + if (BADVER(Ver)) + { + pkgCache::PkgIterator HostPkg = Cache->FindPkg(D->Package, hostArch); + if (HostPkg.end() == false) + { + Ver = (*Cache)[HostPkg].InstVerIter(*Cache); + if (BADVER(Ver)) + Ver = (*Cache)[HostPkg].CandidateVerIter(*Cache); + } + } + if ((BADVER(Ver)) == false) + { + string forbidden; + if (Ver->MultiArch == pkgCache::Version::None || Ver->MultiArch == pkgCache::Version::All); + else if (Ver->MultiArch == pkgCache::Version::Same) + { + if (colon != string::npos) + Pkg = Ver.ParentPkg().Group().FindPkg(hostArch); + else if (strcmp(D->Package.c_str() + colon, ":any") == 0) + forbidden = "Multi-Arch: same"; + // :native gets the buildArch + } + else if (Ver->MultiArch == pkgCache::Version::Foreign || Ver->MultiArch == pkgCache::Version::AllForeign) + { + if (colon != string::npos) + forbidden = "Multi-Arch: foreign"; + } + else if (Ver->MultiArch == pkgCache::Version::Allowed || Ver->MultiArch == pkgCache::Version::AllAllowed) + { + if (colon == string::npos) + Pkg = Ver.ParentPkg().Group().FindPkg(hostArch); + else if (strcmp(D->Package.c_str() + colon, ":any") == 0) + { + // prefer any installed over preferred non-installed architectures + pkgCache::GrpIterator Grp = Ver.ParentPkg().Group(); + // we don't check for version here as we are better of with upgrading than remove and install + for (Pkg = Grp.PackageList(); Pkg.end() == false; Pkg = Grp.NextPkg(Pkg)) + if (Pkg.CurrentVer().end() == false) + break; + if (Pkg.end() == true) + Pkg = Grp.FindPreferredPkg(true); + } + // native gets buildArch + } + if (forbidden.empty() == false) + { + if (_config->FindB("Debug::BuildDeps",false) == true) + cout << " :any is not allowed from M-A: same package " << (*D).Package << endl; + if (hasAlternatives) + continue; + return _error->Error(_("%s dependency for %s can't be satisfied " + "because %s is not allowed on '%s' packages"), + Last->BuildDepType(D->Type), Src.c_str(), + D->Package.c_str(), "Multi-Arch: same"); + } + } + else if (_config->FindB("Debug::BuildDeps",false) == true) + cout << " No multiarch info as we have no satisfying installed nor candidate for " << D->Package << " on build or host arch" << endl; + #undef BADVER + } + else + Pkg = Cache->FindPkg(D->Package); + if (Pkg.end() == true) { if (_config->FindB("Debug::BuildDeps",false) == true) @@ -2769,99 +2902,74 @@ bool DoBuildDep(CommandLine &CmdL) (*D).Package.c_str()); } - /* - * if there are alternatives, we've already picked one, so skip - * the rest - * - * TODO: this means that if there's a build-dep on A|B and B is - * installed, we'll still try to install A; more importantly, - * if A is currently broken, we cannot go back and try B. To fix - * this would require we do a Resolve cycle for each package we - * add to the install list. Ugh - */ - - /* - * If this is a virtual package, we need to check the list of - * packages that provide it and see if any of those are - * installed - */ - pkgCache::PrvIterator Prv = Pkg.ProvidesList(); - for (; Prv.end() != true; Prv++) - { - if (_config->FindB("Debug::BuildDeps",false) == true) - cout << " Checking provider " << Prv.OwnerPkg().FullName() << endl; - - if ((*Cache)[Prv.OwnerPkg()].InstVerIter(*Cache).end() == false) - break; - } - - // Get installed version and version we are going to install pkgCache::VerIterator IV = (*Cache)[Pkg].InstVerIter(*Cache); + if (IV.end() == false) + { + if (_config->FindB("Debug::BuildDeps",false) == true) + cout << " Is installed\n"; - if ((*D).Version[0] != '\0') { - // Versioned dependency - - pkgCache::VerIterator CV = (*Cache)[Pkg].CandidateVerIter(*Cache); - - for (; CV.end() != true; CV++) - { - if (Cache->VS().CheckDep(CV.VerStr(),(*D).Op,(*D).Version.c_str()) == true) - break; - } - if (CV.end() == true) - { - if (hasAlternatives) - { - continue; - } - else - { - return _error->Error(_("%s dependency for %s cannot be satisfied " - "because no available versions of package %s " - "can satisfy version requirements"), - Last->BuildDepType((*D).Type),Src.c_str(), - (*D).Package.c_str()); - } - } - } - else - { - // Only consider virtual packages if there is no versioned dependency - if (Prv.end() == false) - { - if (_config->FindB("Debug::BuildDeps",false) == true) - cout << " Is provided by installed package " << Prv.OwnerPkg().FullName() << endl; - skipAlternatives = hasAlternatives; - continue; - } - } + if (D->Version.empty() == true || + Cache->VS().CheckDep(IV.VerStr(),(*D).Op,(*D).Version.c_str()) == true) + { + skipAlternatives = hasAlternatives; + continue; + } - if (IV.end() == false) - { - if (_config->FindB("Debug::BuildDeps",false) == true) - cout << " Is installed\n"; + if (_config->FindB("Debug::BuildDeps",false) == true) + cout << " ...but the installed version doesn't meet the version requirement\n"; - if (Cache->VS().CheckDep(IV.VerStr(),(*D).Op,(*D).Version.c_str()) == true) - { - skipAlternatives = hasAlternatives; - continue; - } + if (((*D).Op & pkgCache::Dep::LessEq) == pkgCache::Dep::LessEq) + return _error->Error(_("Failed to satisfy %s dependency for %s: Installed package %s is too new"), + Last->BuildDepType((*D).Type), Src.c_str(), Pkg.FullName(true).c_str()); + } - if (_config->FindB("Debug::BuildDeps",false) == true) - cout << " ...but the installed version doesn't meet the version requirement\n"; - - if (((*D).Op & pkgCache::Dep::LessEq) == pkgCache::Dep::LessEq) - { - return _error->Error(_("Failed to satisfy %s dependency for %s: Installed package %s is too new"), - Last->BuildDepType((*D).Type), - Src.c_str(), - Pkg.FullName(true).c_str()); - } - } + // Only consider virtual packages if there is no versioned dependency + if ((*D).Version.empty() == true) + { + /* + * If this is a virtual package, we need to check the list of + * packages that provide it and see if any of those are + * installed + */ + pkgCache::PrvIterator Prv = Pkg.ProvidesList(); + for (; Prv.end() != true; ++Prv) + { + if (_config->FindB("Debug::BuildDeps",false) == true) + cout << " Checking provider " << Prv.OwnerPkg().FullName() << endl; + if ((*Cache)[Prv.OwnerPkg()].InstVerIter(*Cache).end() == false) + break; + } - if (_config->FindB("Debug::BuildDeps",false) == true) - cout << " Trying to install " << (*D).Package << endl; + if (Prv.end() == false) + { + if (_config->FindB("Debug::BuildDeps",false) == true) + cout << " Is provided by installed package " << Prv.OwnerPkg().FullName() << endl; + skipAlternatives = hasAlternatives; + continue; + } + } + else // versioned dependency + { + pkgCache::VerIterator CV = (*Cache)[Pkg].CandidateVerIter(*Cache); + if (CV.end() == true || + Cache->VS().CheckDep(CV.VerStr(),(*D).Op,(*D).Version.c_str()) == false) + { + if (hasAlternatives) + continue; + else if (CV.end() == false) + return _error->Error(_("%s dependency for %s cannot be satisfied " + "because candidate version of package %s " + "can't satisfy version requirements"), + Last->BuildDepType(D->Type), Src.c_str(), + D->Package.c_str()); + else + return _error->Error(_("%s dependency for %s cannot be satisfied " + "because package %s has no candidate version"), + Last->BuildDepType(D->Type), Src.c_str(), + D->Package.c_str()); + } + } if (TryToInstallBuildDep(Pkg,Cache,Fix,false,false) == true) { @@ -3241,12 +3349,14 @@ int main(int argc,const char *argv[]) /*{{{*/ {'s',"dry-run","APT::Get::Simulate",0}, {'s',"no-act","APT::Get::Simulate",0}, {'y',"yes","APT::Get::Assume-Yes",0}, - {'y',"assume-yes","APT::Get::Assume-Yes",0}, + {'y',"assume-yes","APT::Get::Assume-Yes",0}, + {0,"assume-no","APT::Get::Assume-No",0}, {'f',"fix-broken","APT::Get::Fix-Broken",0}, {'u',"show-upgraded","APT::Get::Show-Upgraded",0}, {'m',"ignore-missing","APT::Get::Fix-Missing",0}, {'t',"target-release","APT::Default-Release",CommandLine::HasArg}, {'t',"default-release","APT::Default-Release",CommandLine::HasArg}, + {'a',"host-architecture","APT::Get::Host-Architecture",CommandLine::HasArg}, {0,"download","APT::Get::Download",0}, {0,"fix-missing","APT::Get::Fix-Missing",0}, {0,"ignore-hold","APT::Ignore-Hold",0}, @@ -3270,6 +3380,7 @@ int main(int argc,const char *argv[]) /*{{{*/ {0,"install-recommends","APT::Install-Recommends",CommandLine::Boolean}, {0,"install-suggests","APT::Install-Suggests",CommandLine::Boolean}, {0,"fix-policy","APT::Get::Fix-Policy-Broken",0}, + {0,"solver","APT::Solver",CommandLine::HasArg}, {'c',"config-file",0,CommandLine::ConfigFile}, {'o',"option",0,CommandLine::ArbItem}, {0,0,0,0}}; diff --git a/cmdline/apt-internal-solver.cc b/cmdline/apt-internal-solver.cc new file mode 100644 index 000000000..ef6c688fe --- /dev/null +++ b/cmdline/apt-internal-solver.cc @@ -0,0 +1,190 @@ +// -*- mode: cpp; mode: fold -*- +// Description /*{{{*/ +/* ##################################################################### + + cover around the internal solver to be able to run it like an external + + ##################################################################### */ + /*}}}*/ +// Include Files /*{{{*/ +#include <apt-pkg/error.h> +#include <apt-pkg/cmndline.h> +#include <apt-pkg/init.h> +#include <apt-pkg/cachefile.h> +#include <apt-pkg/strutl.h> +#include <apt-pkg/edsp.h> +#include <apt-pkg/algorithms.h> +#include <apt-pkg/fileutl.h> + +#include <config.h> +#include <apti18n.h> + +#include <unistd.h> +#include <cstdio> + /*}}}*/ + +// ShowHelp - Show a help screen /*{{{*/ +// --------------------------------------------------------------------- +/* */ +bool ShowHelp(CommandLine &CmdL) { + ioprintf(std::cout,_("%s %s for %s compiled on %s %s\n"),PACKAGE,VERSION, + COMMON_ARCH,__DATE__,__TIME__); + + std::cout << + _("Usage: apt-internal-resolver\n" + "\n" + "apt-internal-resolver is an interface to use the current internal\n" + "like an external resolver for the APT family for debugging or alike\n" + "\n" + "Options:\n" + " -h This help text.\n" + " -q Loggable output - no progress indicator\n" + " -c=? Read this configuration file\n" + " -o=? Set an arbitrary configuration option, eg -o dir::cache=/tmp\n" + "apt.conf(5) manual pages for more information and options.\n" + " This APT has Super Cow Powers.\n"); + return true; +} + /*}}}*/ +int main(int argc,const char *argv[]) /*{{{*/ +{ + CommandLine::Args Args[] = { + {'h',"help","help",0}, + {'v',"version","version",0}, + {'q',"quiet","quiet",CommandLine::IntLevel}, + {'q',"silent","quiet",CommandLine::IntLevel}, + {'c',"config-file",0,CommandLine::ConfigFile}, + {'o',"option",0,CommandLine::ArbItem}, + {0,0,0,0}}; + + CommandLine CmdL(Args,_config); + if (pkgInitConfig(*_config) == false || + CmdL.Parse(argc,argv) == false) { + _error->DumpErrors(); + return 2; + } + + // See if the help should be shown + if (_config->FindB("help") == true || + _config->FindB("version") == true) { + ShowHelp(CmdL); + return 1; + } + + if (CmdL.FileList[0] != 0 && strcmp(CmdL.FileList[0], "scenario") == 0) + { + if (pkgInitSystem(*_config,_system) == false) { + std::cerr << "System could not be initialized!" << std::endl; + return 1; + } + pkgCacheFile CacheFile; + CacheFile.Open(NULL, false); + APT::PackageSet pkgset = APT::PackageSet::FromCommandLine(CacheFile, CmdL.FileList + 1); + FILE* output = stdout; + if (pkgset.empty() == true) + EDSP::WriteScenario(CacheFile, output); + else + EDSP::WriteLimitedScenario(CacheFile, output, pkgset); + fclose(output); + _error->DumpErrors(std::cerr); + return 0; + } + + // Deal with stdout not being a tty + if (!isatty(STDOUT_FILENO) && _config->FindI("quiet", -1) == -1) + _config->Set("quiet","1"); + + if (_config->FindI("quiet", 0) < 1) + _config->Set("Debug::EDSP::WriteSolution", true); + + _config->Set("APT::Solver", "internal"); + _config->Set("edsp::scenario", "stdin"); + int input = STDIN_FILENO; + FILE* output = stdout; + SetNonBlock(input, false); + + EDSP::WriteProgress(0, "Start up solver…", output); + + if (pkgInitSystem(*_config,_system) == false) { + std::cerr << "System could not be initialized!" << std::endl; + return 1; + } + + EDSP::WriteProgress(1, "Read request…", output); + + if (WaitFd(input, false, 5) == false) + std::cerr << "WAIT timed out in the resolver" << std::endl; + + std::list<std::string> install, remove; + bool upgrade, distUpgrade, autoRemove; + if (EDSP::ReadRequest(input, install, remove, upgrade, distUpgrade, autoRemove) == false) { + std::cerr << "Parsing the request failed!" << std::endl; + return 2; + } + + EDSP::WriteProgress(5, "Read scenario…", output); + + pkgCacheFile CacheFile; + CacheFile.Open(NULL, false); + + EDSP::WriteProgress(50, "Apply request on scenario…", output); + + if (EDSP::ApplyRequest(install, remove, CacheFile) == false) { + std::cerr << "Failed to apply request to depcache!" << std::endl; + return 3; + } + + pkgProblemResolver Fix(CacheFile); + for (std::list<std::string>::const_iterator i = remove.begin(); + i != remove.end(); ++i) { + pkgCache::PkgIterator P = CacheFile->FindPkg(*i); + Fix.Clear(P); + Fix.Protect(P); + Fix.Remove(P); + } + + for (std::list<std::string>::const_iterator i = install.begin(); + i != install.end(); ++i) { + pkgCache::PkgIterator P = CacheFile->FindPkg(*i); + Fix.Clear(P); + Fix.Protect(P); + } + + for (std::list<std::string>::const_iterator i = install.begin(); + i != install.end(); ++i) + CacheFile->MarkInstall(CacheFile->FindPkg(*i), true); + + EDSP::WriteProgress(60, "Call problemresolver on current scenario…", output); + + if (upgrade == true) { + if (pkgAllUpgrade(CacheFile) == false) { + EDSP::WriteError("ERR_UNSOLVABLE_UPGRADE", "An upgrade error occured", output); + return 0; + } + } else if (distUpgrade == true) { + if (pkgDistUpgrade(CacheFile) == false) { + EDSP::WriteError("ERR_UNSOLVABLE_DIST_UPGRADE", "An dist-upgrade error occured", output); + return 0; + } + } else if (Fix.Resolve() == false) { + EDSP::WriteError("ERR_UNSOLVABLE", "An error occured", output); + return 0; + } + + EDSP::WriteProgress(95, "Write solution…", output); + + if (EDSP::WriteSolution(CacheFile, output) == false) { + std::cerr << "Failed to output the solution!" << std::endl; + return 4; + } + + EDSP::WriteProgress(100, "Done", output); + + bool const Errors = _error->PendingError(); + if (_config->FindI("quiet",0) > 0) + _error->DumpErrors(std::cerr); + else + _error->DumpErrors(std::cerr, GlobalError::DEBUG); + return Errors == true ? 100 : 0; +} + /*}}}*/ diff --git a/cmdline/apt-key b/cmdline/apt-key index 843163f82..97d6e0323 100755 --- a/cmdline/apt-key +++ b/cmdline/apt-key @@ -5,9 +5,12 @@ unset GREP_OPTIONS # We don't use a secret keyring, of course, but gpg panics and # implodes if there isn't one available -GPG_CMD='gpg --ignore-time-conflict --no-options --no-default-keyring --secret-keyring /etc/apt/secring.gpg' +SECRETKEYRING="$(mktemp)" +trap "rm -f '${SECRETKEYRING}'" 0 HUP INT QUIT ILL ABRT FPE SEGV PIPE TERM +GPG_CMD="gpg --ignore-time-conflict --no-options --no-default-keyring --secret-keyring ${SECRETKEYRING}" if [ "$(id -u)" -eq 0 ]; then + # we could use a tmpfile here too, but creation of this tends to be time-consuming GPG_CMD="$GPG_CMD --trustdb-name /etc/apt/trustdb.gpg" fi @@ -149,7 +152,7 @@ if [ "$1" = "--keyring" ]; then #echo "keyfile given" shift TRUSTEDFILE="$1" - if [ -r "$TRUSTEDFILE" ]; then + if [ -r "$TRUSTEDFILE" ] || [ "$2" = 'add' ]; then GPG="$GPG --keyring $TRUSTEDFILE --primary-keyring $TRUSTEDFILE" else echo >&2 "Error: The specified keyring »$TRUSTEDFILE« is missing or not readable" diff --git a/cmdline/apt-mark.cc b/cmdline/apt-mark.cc index b2c664979..8c9a47913 100644 --- a/cmdline/apt-mark.cc +++ b/cmdline/apt-mark.cc @@ -5,6 +5,8 @@ ##################################################################### */ /*}}}*/ // Include Files /*{{{*/ +#include <config.h> + #include <apt-pkg/cachefile.h> #include <apt-pkg/cacheset.h> #include <apt-pkg/cmndline.h> @@ -12,10 +14,9 @@ #include <apt-pkg/init.h> #include <apt-pkg/strutl.h> -#include <config.h> -#include <apti18n.h> - #include <algorithm> + +#include <apti18n.h> /*}}}*/ using namespace std; diff --git a/cmdline/apt-sortpkgs.cc b/cmdline/apt-sortpkgs.cc index 171b0ba13..44b74cf6c 100644 --- a/cmdline/apt-sortpkgs.cc +++ b/cmdline/apt-sortpkgs.cc @@ -12,6 +12,8 @@ ##################################################################### */ /*}}}*/ // Include Files /*{{{*/ +#include <config.h> + #include <apt-pkg/tagfile.h> #include <apt-pkg/error.h> #include <apt-pkg/configuration.h> @@ -19,14 +21,13 @@ #include <apt-pkg/init.h> #include <apt-pkg/strutl.h> -#include <config.h> -#include <apti18n.h> - #include <vector> #include <algorithm> #include <locale.h> #include <unistd.h> + +#include <apti18n.h> /*}}}*/ using namespace std; @@ -106,7 +107,7 @@ bool DoIt(string InFile) // Emit unsigned char *Buffer = new unsigned char[Largest+1]; - for (vector<PkgName>::iterator I = List.begin(); I != List.end(); I++) + for (vector<PkgName>::iterator I = List.begin(); I != List.end(); ++I) { // Read in the Record. if (Fd.Seek(I->Offset) == false || Fd.Read(Buffer,I->Length) == false) diff --git a/cmdline/makefile b/cmdline/makefile index e867dae73..07e9eb8ca 100644 --- a/cmdline/makefile +++ b/cmdline/makefile @@ -65,3 +65,17 @@ include $(PROGRAM_H) #TO=$(BIN) #TARGET=program #include $(COPY_H) + +# The internal solver acting as an external +PROGRAM=apt-internal-solver +SLIBS = -lapt-pkg $(INTLLIBS) +LIB_MAKES = apt-pkg/makefile +SOURCE = apt-internal-solver.cc +include $(PROGRAM_H) + +# This just dumps out the state +PROGRAM=apt-dump-solver +SLIBS = -lapt-pkg $(INTLLIBS) +LIB_MAKES = apt-pkg/makefile +SOURCE = apt-dump-solver.cc +include $(PROGRAM_H) |