diff options
Diffstat (limited to 'cmdline')
-rw-r--r-- | cmdline/acqprogress.cc | 22 | ||||
-rw-r--r-- | cmdline/acqprogress.h | 4 | ||||
-rw-r--r-- | cmdline/apt-cache.cc | 16 | ||||
-rw-r--r-- | cmdline/apt-cdrom.cc | 10 | ||||
-rw-r--r-- | cmdline/apt-config.cc | 8 | ||||
-rw-r--r-- | cmdline/apt-dump-solver.cc | 51 | ||||
-rw-r--r-- | cmdline/apt-extracttemplates.cc | 6 | ||||
-rw-r--r-- | cmdline/apt-get.cc | 35 | ||||
-rw-r--r-- | cmdline/apt-internal-solver.cc | 192 | ||||
-rw-r--r-- | cmdline/apt-mark.cc | 8 | ||||
-rw-r--r-- | cmdline/apt-sortpkgs.cc | 9 | ||||
-rw-r--r-- | cmdline/makefile | 14 |
12 files changed, 331 insertions, 44 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/acqprogress.h b/cmdline/acqprogress.h index 48f90ae59..8f0903923 100644 --- a/cmdline/acqprogress.h +++ b/cmdline/acqprogress.h @@ -12,6 +12,8 @@ #include <apt-pkg/acquire.h> +#include <string> + class AcqTextStatus : public pkgAcquireStatus { unsigned int &ScreenWidth; @@ -21,7 +23,7 @@ class AcqTextStatus : public pkgAcquireStatus public: - virtual bool MediaChange(string Media,string Drive); + virtual bool MediaChange(std::string Media,std::string Drive); virtual void IMSHit(pkgAcquire::ItemDesc &Itm); virtual void Fetch(pkgAcquire::ItemDesc &Itm); virtual void Done(pkgAcquire::ItemDesc &Itm); diff --git a/cmdline/apt-cache.cc b/cmdline/apt-cache.cc index db5475227..82a31c9b1 100644 --- a/cmdline/apt-cache.cc +++ b/cmdline/apt-cache.cc @@ -13,9 +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> #include <apt-pkg/init.h> @@ -23,6 +23,7 @@ #include <apt-pkg/sourcelist.h> #include <apt-pkg/cmndline.h> #include <apt-pkg/strutl.h> +#include <apt-pkg/fileutl.h> #include <apt-pkg/pkgrecords.h> #include <apt-pkg/srcrecords.h> #include <apt-pkg/version.h> @@ -30,18 +31,21 @@ #include <apt-pkg/tagfile.h> #include <apt-pkg/algorithms.h> #include <apt-pkg/sptr.h> +#include <apt-pkg/pkgsystem.h> +#include <apt-pkg/indexfile.h> +#include <apt-pkg/metaindex.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 <algorithm> + +#include <apti18n.h> /*}}}*/ using namespace std; diff --git a/cmdline/apt-cdrom.cc b/cmdline/apt-cdrom.cc index d1268edf9..fa48debcd 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,8 @@ #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 <apt-pkg/configuration.h> +#include <apt-pkg/pkgsystem.h> #include <locale.h> #include <iostream> @@ -36,6 +36,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..94f6ee9b0 100644 --- a/cmdline/apt-config.cc +++ b/cmdline/apt-config.cc @@ -16,20 +16,22 @@ ##################################################################### */ /*}}}*/ // Include Files /*{{{*/ +#include<config.h> + #include <apt-pkg/cmndline.h> #include <apt-pkg/error.h> #include <apt-pkg/init.h> #include <apt-pkg/strutl.h> #include <apt-pkg/configuration.h> #include <apt-pkg/aptconfiguration.h> - -#include <config.h> -#include <apti18n.h> +#include <apt-pkg/pkgsystem.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..e82e15c6e --- /dev/null +++ b/cmdline/apt-dump-solver.cc @@ -0,0 +1,51 @@ +// -*- 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> +#include <iostream> + /*}}}*/ + +// 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..d5c1a3208 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,8 @@ #include <apt-pkg/error.h> #include <apt-pkg/strutl.h> #include <apt-pkg/fileutl.h> - +#include <apt-pkg/pkgsystem.h> + #include <stdio.h> #include <string.h> #include <stdlib.h> @@ -36,7 +39,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 49ac8f2cf..1925dea87 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> @@ -37,6 +36,7 @@ #include <apt-pkg/algorithms.h> #include <apt-pkg/acquire-item.h> #include <apt-pkg/strutl.h> +#include <apt-pkg/fileutl.h> #include <apt-pkg/clean.h> #include <apt-pkg/srcrecords.h> #include <apt-pkg/version.h> @@ -45,9 +45,10 @@ #include <apt-pkg/sptr.h> #include <apt-pkg/md5.h> #include <apt-pkg/versionmatch.h> - -#include <config.h> -#include <apti18n.h> +#include <apt-pkg/progress.h> +#include <apt-pkg/pkgsystem.h> +#include <apt-pkg/pkgrecords.h> +#include <apt-pkg/indexfile.h> #include "acqprogress.h" @@ -68,8 +69,7 @@ #include <sys/wait.h> #include <sstream> -#define statfs statfs64 -#define statvfs statvfs64 +#include <apti18n.h> /*}}}*/ #define RAMFS_MAGIC 0x858458f6 @@ -135,6 +135,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)); @@ -1902,8 +1907,7 @@ bool DoInstall(CommandLine &CmdL) { // Call the scored problem resolver Fix->InstallProtect(); - if (Fix->Resolve(true) == false) - _error->Discard(); + Fix->Resolve(true); delete Fix; } @@ -1929,8 +1933,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; @@ -2320,6 +2327,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() != "") @@ -3354,7 +3363,8 @@ 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}, @@ -3384,6 +3394,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..1b636e4d5 --- /dev/null +++ b/cmdline/apt-internal-solver.cc @@ -0,0 +1,192 @@ +// -*- 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/cacheset.h> +#include <apt-pkg/strutl.h> +#include <apt-pkg/edsp.h> +#include <apt-pkg/algorithms.h> +#include <apt-pkg/fileutl.h> +#include <apt-pkg/pkgsystem.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-mark.cc b/cmdline/apt-mark.cc index b2c664979..339cbdf44 100644 --- a/cmdline/apt-mark.cc +++ b/cmdline/apt-mark.cc @@ -5,17 +5,19 @@ ##################################################################### */ /*}}}*/ // Include Files /*{{{*/ +#include <config.h> + #include <apt-pkg/cachefile.h> #include <apt-pkg/cacheset.h> #include <apt-pkg/cmndline.h> #include <apt-pkg/error.h> #include <apt-pkg/init.h> #include <apt-pkg/strutl.h> - -#include <config.h> -#include <apti18n.h> +#include <apt-pkg/pkgsystem.h> #include <algorithm> + +#include <apti18n.h> /*}}}*/ using namespace std; diff --git a/cmdline/apt-sortpkgs.cc b/cmdline/apt-sortpkgs.cc index f95a434cc..20ae14f2a 100644 --- a/cmdline/apt-sortpkgs.cc +++ b/cmdline/apt-sortpkgs.cc @@ -12,21 +12,24 @@ ##################################################################### */ /*}}}*/ // Include Files /*{{{*/ +#include <config.h> + #include <apt-pkg/tagfile.h> #include <apt-pkg/error.h> #include <apt-pkg/configuration.h> #include <apt-pkg/cmndline.h> #include <apt-pkg/init.h> #include <apt-pkg/strutl.h> +#include <apt-pkg/fileutl.h> +#include <apt-pkg/pkgsystem.h> -#include <config.h> -#include <apti18n.h> - #include <vector> #include <algorithm> #include <locale.h> #include <unistd.h> + +#include <apti18n.h> /*}}}*/ using namespace std; 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) |