diff options
Diffstat (limited to 'apt-private')
-rw-r--r-- | apt-private/acqprogress.cc | 218 | ||||
-rw-r--r-- | apt-private/acqprogress.h | 8 | ||||
-rw-r--r-- | apt-private/private-cachefile.cc | 4 | ||||
-rw-r--r-- | apt-private/private-cachefile.h | 23 | ||||
-rw-r--r-- | apt-private/private-cacheset.cc | 8 | ||||
-rw-r--r-- | apt-private/private-cacheset.h | 25 | ||||
-rw-r--r-- | apt-private/private-cmndline.cc | 34 | ||||
-rw-r--r-- | apt-private/private-cmndline.h | 6 | ||||
-rw-r--r-- | apt-private/private-download.cc | 96 | ||||
-rw-r--r-- | apt-private/private-download.h | 8 | ||||
-rw-r--r-- | apt-private/private-install.cc | 92 | ||||
-rw-r--r-- | apt-private/private-install.h | 2 | ||||
-rw-r--r-- | apt-private/private-list.cc | 12 | ||||
-rw-r--r-- | apt-private/private-output.cc | 8 | ||||
-rw-r--r-- | apt-private/private-output.h | 3 | ||||
-rw-r--r-- | apt-private/private-show.cc | 54 | ||||
-rw-r--r-- | apt-private/private-update.cc | 8 | ||||
-rw-r--r-- | apt-private/private-upgrade.cc | 4 |
18 files changed, 382 insertions, 231 deletions
diff --git a/apt-private/acqprogress.cc b/apt-private/acqprogress.cc index 0f5b53e50..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 /*{{{*/ @@ -23,20 +22,18 @@ #include <stdio.h> #include <signal.h> #include <iostream> +#include <sstream> #include <unistd.h> #include <apti18n.h> /*}}}*/ -using namespace std; - // AcqTextStatus::AcqTextStatus - Constructor /*{{{*/ // --------------------------------------------------------------------- /* */ -AcqTextStatus::AcqTextStatus(unsigned int &ScreenWidth,unsigned int const Quiet) : - pkgAcquireStatus(), ScreenWidth(ScreenWidth), 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) { - 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 +45,7 @@ AcqTextStatus::AcqTextStatus(unsigned int &ScreenWidth,unsigned int const Quiet) void AcqTextStatus::Start() { pkgAcquireStatus::Start(); - BlankLine[0] = 0; + LastLineLength = 0; ID = 1; } /*}}}*/ @@ -60,13 +57,10 @@ void AcqTextStatus::IMSHit(pkgAcquire::ItemDesc &Itm) if (Quiet > 1) return; - if (Quiet <= 0) - cout << '\r' << BlankLine << '\r'; + clearLastLine(); - cout << _("Hit ") << Itm.Description; - if (Itm.Owner->FileSize != 0) - cout << " [" << SizeToStr(Itm.Owner->FileSize) << "B]"; - cout << endl; + out << _("Hit ") << Itm.Description; + out << std::endl; Update = true; } /*}}}*/ @@ -84,13 +78,12 @@ 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; + 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,17 +106,19 @@ 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) { - 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) + 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; @@ -139,11 +134,13 @@ void AcqTextStatus::Stop() if (Quiet > 1) return; - if (Quiet <= 0) - cout << '\r' << BlankLine << '\r' << flush; + clearLastLine(); + + if (_config->FindB("quiet::NoStatistic", false) == true) + 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) { @@ -163,77 +160,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%%",((CurrentBytes + CurrentItems)*100.0)/(TotalBytes+TotalItems)); - - 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; - } + if (I->Status.empty() == false) + S << " [" << I->Status << "]"; - Shown = true; + continue; + } - // 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); + // Add in the short description + S << " ["; + if (I->CurrentItem->Owner->ID != 0) + S << I->CurrentItem->Owner->ID << " "; + S << I->CurrentItem->ShortDesc; - // Show the short mode string - if (I->CurrentItem->Owner->Mode != 0) - { - snprintf(S,End-S," %s",I->CurrentItem->Owner->Mode); - S += strlen(S); - } - - // 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 */ @@ -244,34 +230,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; + out << _config->Find("APT::Color::Yellow"); + if (LastLineLength > Line.length()) + clearLastLine(); else - cout << '\r' << BlankLine << '\r' << Buffer << flush; + out << '\r'; + out << Line << std::flush; if (_config->FindB("Apt::Color", false) == true) - cout << _config->Find("APT::Color::Neutral") << flush; - - memset(BlankLine,' ',strlen(Buffer)); - BlankLine[strlen(Buffer)] = 0; + out << _config->Find("APT::Color::Neutral") << std::flush; + LastLineLength = Line.length(); Update = false; return true; @@ -280,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 @@ -292,9 +277,8 @@ bool AcqTextStatus::MediaChange(string Media,string Drive) return false; - if (Quiet <= 0) - cout << '\r' << BlankLine << '\r'; - ioprintf(cout,_("Media change: please insert the disc labeled\n" + clearLastLine(); + 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()); @@ -313,3 +297,17 @@ bool AcqTextStatus::MediaChange(string Media,string Drive) return bStatus; } /*}}}*/ +void AcqTextStatus::clearLastLine() { /*{{{*/ + if (Quiet > 0 || LastLineLength == 0) + return; + + // do not try to clear more than the (now smaller) screen + if (LastLineLength > ScreenWidth) + LastLineLength = ScreenWidth; + + out << '\r'; + for (size_t i = 0; i < LastLineLength; ++i) + out << ' '; + out << '\r' << std::flush; +} + /*}}}*/ diff --git a/apt-private/acqprogress.h b/apt-private/acqprogress.h index 71a10d78a..7cf990c65 100644 --- a/apt-private/acqprogress.h +++ b/apt-private/acqprogress.h @@ -13,14 +13,18 @@ #include <apt-pkg/macros.h> #include <string> +#include <iostream> class APT_PUBLIC AcqTextStatus : public pkgAcquireStatus { + std::ostream &out; 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); @@ -33,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-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 /*{{{*/ 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 <apt-pkg/configuration.h> #include <apt-pkg/pkgcache.h> #include <apt-pkg/macros.h> +#include <apt-pkg/sourcelist.h> +#include <apti18n.h> +// 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-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 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-cmndline.cc b/apt-private/private-cmndline.cc index c0f631a08..41aab81f6 100644 --- a/apt-private/private-cmndline.cc +++ b/apt-private/private-cmndline.cc @@ -2,12 +2,17 @@ #include <config.h> #include <apt-pkg/cmndline.h> +#include <apt-pkg/configuration.h> +#include <apt-pkg/pkgsystem.h> +#include <apt-pkg/init.h> +#include <apt-pkg/error.h> #include <apt-private/private-cmndline.h> #include <vector> #include <stdarg.h> #include <string.h> +#include <stdlib.h> #include <apti18n.h> /*}}}*/ @@ -198,6 +203,7 @@ static bool addArgumentsAPTGet(std::vector<CommandLine::Args> &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); @@ -286,3 +292,31 @@ std::vector<CommandLine::Args> 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 <vector> +class Configuration; +class pkgSystem; + APT_PUBLIC std::vector<CommandLine::Args> 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 diff --git a/apt-private/private-download.cc b/apt-private/private-download.cc index be7d23c31..37fae18e9 100644 --- a/apt-private/private-download.cc +++ b/apt-private/private-download.cc @@ -5,6 +5,7 @@ #include <apt-pkg/acquire-item.h> #include <apt-pkg/configuration.h> #include <apt-pkg/error.h> +#include <apt-pkg/fileutl.h> #include <apt-pkg/strutl.h> #include <apt-private/private-output.h> @@ -14,9 +15,66 @@ #include <string> #include <vector> +#include <unistd.h> +#include <sys/types.h> +#include <pwd.h> +#include <fcntl.h> +#include <sys/vfs.h> +#include <sys/statvfs.h> +#include <errno.h> + #include <apti18n.h> /*}}}*/ +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) + { + 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()); + std::cerr << "W: " << msg << std::endl; + _config->Set("APT::Sandbox::User", ""); + break; + } + unlink((*I)->DestFile.c_str()); + 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 +89,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,""); @@ -98,3 +156,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 a90ac7eaa..0a0ac6b95 100644 --- a/apt-private/private-download.h +++ b/apt-private/private-download.h @@ -3,15 +3,21 @@ #include <apt-pkg/macros.h> +#include <string> + 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); +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 e08cd8057..acc6d42c2 100644 --- a/apt-private/private-install.cc +++ b/apt-private/private-install.cc @@ -20,16 +20,15 @@ #include <apt-pkg/packagemanager.h> #include <apt-pkg/pkgcache.h> #include <apt-pkg/upgrade.h> +#include <apt-pkg/install-progress.h> -#include <errno.h> #include <stdlib.h> #include <string.h> -#include <sys/statfs.h> -#include <sys/statvfs.h> #include <algorithm> #include <iostream> #include <set> #include <vector> +#include <map> #include <apt-private/acqprogress.h> #include <apt-private/private-install.h> @@ -95,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; @@ -117,14 +116,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(std::cout, 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 @@ -175,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) @@ -331,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; @@ -558,9 +533,9 @@ bool DoCacheManipulationFromCommandLine(CommandLine &CmdL, CacheFile &Cache, std::list<APT::VersionSet::Modifier> 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); @@ -617,15 +592,14 @@ bool DoCacheManipulationFromCommandLine(CommandLine &CmdL, CacheFile &Cache, if (Fix != NULL) { // Call the scored problem resolver + OpTextProgress Progress(*_config); + bool const distUpgradeMode = strcmp(CmdL.FileList[0], "dist-upgrade") == 0 || strcmp(CmdL.FileList[0], "full-upgrade") == 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 (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; @@ -680,10 +654,34 @@ 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)) + { + // 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<metaIndex *> List; + std::map<std::string, std::string> Options; + if(Type->CreateItem(List, *I, "", "", Options)) + { + // we have our own CacheFile that gives us a SourceList + // with superpowerz + SourceList *sources = (SourceList*)Cache.GetSourceList(); + sources->AddMetaIndex(List[0]); + } + } + } + } + + // then open the cache if (Cache.OpenForInstall() == false || Cache.CheckDeps(CmdL.FileSize() != 1) == false) return false; - + std::map<unsigned short, APT::VersionSet> verset; if(!DoCacheManipulationFromCommandLine(CmdL, Cache, verset, 0)) 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, diff --git a/apt-private/private-list.cc b/apt-private/private-list.cc index 536348640..aa3a2c24b 100644 --- a/apt-private/private-list.cc +++ b/apt-private/private-list.cc @@ -37,28 +37,20 @@ struct PackageSortAlphabetic /*{{{*/ return (l_name < r_name); } }; - /*}}}*/ -class PackageNameMatcher : public Matcher /*{{{*/ + +class PackageNameMatcher : public Matcher { -#ifdef PACKAGE_MATCHER_ABI_COMPAT -#define PackageMatcher PackageNameMatchesFnmatch -#endif public: PackageNameMatcher(const char **patterns) { 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::Use-Regexp", false) == true) cachefilter = new APT::CacheFilter::PackageNameMatchesRegEx(pattern); else cachefilter = new APT::CacheFilter::PackageNameMatchesFnmatch(pattern); -#endif filters.push_back(cachefilter); } } 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<char> * 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 <fstream> #include <string> +#include <iostream> // 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<char> * const out = std::cout.rdbuf()); void ListSingleVersion(pkgCacheFile &CacheFile, pkgRecords &records, pkgCache::VerIterator const &V, std::ostream &out, diff --git a/apt-private/private-show.cc b/apt-private/private-show.cc index 8ae6a6dac..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<pkgTagSection::Tag> 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 @@ -141,16 +143,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); diff --git a/apt-private/private-update.cc b/apt-private/private-update.cc index 1cf3012ed..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) { @@ -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) diff --git a/apt-private/private-upgrade.cc b/apt-private/private-upgrade.cc index 31f067576..d13a6af49 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); } @@ -35,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) /*{{{*/ |