Browse Source

put fetch errors in 'source' on our errorstack

refactor the fetching process so that it looks more like the
others we have in the hope that we can reuse code in the future.

This is a soft interface change as 'source' previously printed
errors directly on stderr, while it will now push it onto our usual
error stack.
debian/1.8.y
David Kalnischkies 10 years ago
parent
commit
866893a619
  1. 2
      apt-private/makefile
  2. 96
      apt-private/private-download.cc
  3. 9
      apt-private/private-download.h
  4. 72
      apt-private/private-install.cc
  5. 28
      cmdline/apt-get.cc

2
apt-private/makefile

@ -17,7 +17,7 @@ MAJOR=0.0
MINOR=0
SLIBS=$(PTHREADLIB) -lapt-pkg
PRIVATES=list install output cachefile cacheset update upgrade cmndline moo search show main
PRIVATES=list install download output cachefile cacheset update upgrade cmndline moo search show main
SOURCE += $(foreach private, $(PRIVATES), private-$(private).cc)
HEADERS += $(foreach private, $(PRIVATES), private-$(private).h)

96
apt-private/private-download.cc

@ -0,0 +1,96 @@
// Include Files /*{{{*/
#include <config.h>
#include <apt-pkg/acquire.h>
#include <apt-pkg/acquire-item.h>
#include <apt-pkg/configuration.h>
#include <apt-pkg/error.h>
#include <apt-pkg/strutl.h>
#include "private-output.h"
#include <locale.h>
#include <fstream>
#include <string>
#include <vector>
#include <apti18n.h>
/*}}}*/
// CheckAuth - check if each download comes form a trusted source /*{{{*/
bool CheckAuth(pkgAcquire& Fetcher, bool const PromptUser)
{
std::string UntrustedList;
for (pkgAcquire::ItemIterator I = Fetcher.ItemsBegin(); I < Fetcher.ItemsEnd(); ++I)
if (!(*I)->IsTrusted())
UntrustedList += std::string((*I)->ShortDesc()) + " ";
if (UntrustedList == "")
return true;
ShowList(c2out,_("WARNING: The following packages cannot be authenticated!"),UntrustedList,"");
if (_config->FindB("APT::Get::AllowUnauthenticated",false) == true)
{
c2out << _("Authentication warning overridden.\n");
return true;
}
if (PromptUser == false)
return _error->Error(_("Some packages could not be authenticated"));
if (_config->FindI("quiet",0) < 2
&& _config->FindB("APT::Get::Assume-Yes",false) == false)
{
c2out << _("Install these packages without verification?") << std::flush;
if (!YnPrompt(false))
return _error->Error(_("Some packages could not be authenticated"));
return true;
}
else if (_config->FindB("APT::Get::Force-Yes",false) == true)
return true;
return _error->Error(_("There are problems and -y was used without --force-yes"));
}
/*}}}*/
bool AcquireRun(pkgAcquire &Fetcher, int const PulseInterval, bool * const Failure, bool * const TransientNetworkFailure)/*{{{*/
{
pkgAcquire::RunResult res;
if(PulseInterval > 0)
res = Fetcher.Run(PulseInterval);
else
res = Fetcher.Run();
if (res == pkgAcquire::Failed)
return false;
for (pkgAcquire::ItemIterator I = Fetcher.ItemsBegin();
I != Fetcher.ItemsEnd(); ++I)
{
if ((*I)->Status == pkgAcquire::Item::StatDone &&
(*I)->Complete == true)
continue;
if (TransientNetworkFailure != NULL && (*I)->Status == pkgAcquire::Item::StatIdle)
{
*TransientNetworkFailure = true;
continue;
}
::URI uri((*I)->DescURI());
uri.User.clear();
uri.Password.clear();
std::string descUri = std::string(uri);
_error->Error(_("Failed to fetch %s %s\n"), descUri.c_str(),
(*I)->ErrorText.c_str());
if (Failure != NULL)
*Failure = true;
}
return true;
}
/*}}}*/

9
apt-private/private-download.h

@ -0,0 +1,9 @@
#ifndef APT_PRIVATE_DOWNLOAD_H
#define APT_PRIVATE_DOWNLOAD_H
#include <apt-pkg/acquire.h>
bool CheckAuth(pkgAcquire& Fetcher, bool const PromptUser);
bool AcquireRun(pkgAcquire &Fetcher, int const PulseInterval, bool * const Failure, bool * const TransientNetworkFailure);
#endif

72
apt-private/private-install.cc

@ -42,6 +42,7 @@
#include <sstream>
#include "private-install.h"
#include "private-download.h"
#include "private-cachefile.h"
#include "private-output.h"
#include "private-cacheset.h"
@ -50,50 +51,6 @@
#include <apti18n.h>
/*}}}*/
// CheckAuth - check if each download comes form a trusted source /*{{{*/
// ---------------------------------------------------------------------
/* */
static bool CheckAuth(pkgAcquire& Fetcher)
{
std::string UntrustedList;
for (pkgAcquire::ItemIterator I = Fetcher.ItemsBegin(); I < Fetcher.ItemsEnd(); ++I)
{
if (!(*I)->IsTrusted())
{
UntrustedList += std::string((*I)->ShortDesc()) + " ";
}
}
if (UntrustedList == "")
{
return true;
}
ShowList(c2out,_("WARNING: The following packages cannot be authenticated!"),UntrustedList,"");
if (_config->FindB("APT::Get::AllowUnauthenticated",false) == true)
{
c2out << _("Authentication warning overridden.\n");
return true;
}
if (_config->FindI("quiet",0) < 2
&& _config->FindB("APT::Get::Assume-Yes",false) == false)
{
c2out << _("Install these packages without verification?") << std::flush;
if (!YnPrompt(false))
return _error->Error(_("Some packages could not be authenticated"));
return true;
}
else if (_config->FindB("APT::Get::Force-Yes",false) == true)
{
return true;
}
return _error->Error(_("There are problems and -y was used without --force-yes"));
}
/*}}}*/
// InstallPackages - Actually download and install the packages /*{{{*/
// ---------------------------------------------------------------------
/* This displays the informative messages describing what is going to
@ -304,7 +261,7 @@ bool InstallPackages(CacheFile &Cache,bool ShwKept,bool Ask, bool Safety)
return true;
}
if (!CheckAuth(Fetcher))
if (!CheckAuth(Fetcher, true))
return false;
/* Unlock the dpkg lock if we are not going to be doing an install
@ -336,29 +293,10 @@ bool InstallPackages(CacheFile &Cache,bool ShwKept,bool Ask, bool Safety)
I = Fetcher.ItemsBegin();
}
}
if (Fetcher.Run() == pkgAcquire::Failed)
return false;
// Print out errors
bool Failed = false;
for (pkgAcquire::ItemIterator I = Fetcher.ItemsBegin(); I != Fetcher.ItemsEnd(); ++I)
{
if ((*I)->Status == pkgAcquire::Item::StatDone &&
(*I)->Complete == true)
continue;
if ((*I)->Status == pkgAcquire::Item::StatIdle)
{
Transient = true;
// Failed = true;
continue;
}
fprintf(stderr,_("Failed to fetch %s %s\n"),(*I)->DescURI().c_str(),
(*I)->ErrorText.c_str());
Failed = true;
}
bool Failed = false;
if (AcquireRun(Fetcher, 0, &Failed, &Transient) == false)
return false;
/* If we are in no download mode and missing files and there were
'failures' then the user must specify -m. Furthermore, there

28
cmdline/apt-get.cc

@ -50,7 +50,7 @@
#include <apt-pkg/pkgrecords.h>
#include <apt-pkg/indexfile.h>
#include <apt-private/private-download.h>
#include <apt-private/private-install.h>
#include <apt-private/private-upgrade.h>
#include <apt-private/private-output.h>
@ -62,9 +62,11 @@
#include <apt-private/acqprogress.h>
#include <set>
#include <fstream>
#include <sstream>
#include <locale.h>
#include <langinfo.h>
#include <fstream>
#include <termios.h>
#include <sys/ioctl.h>
#include <sys/stat.h>
@ -76,7 +78,6 @@
#include <errno.h>
#include <regex.h>
#include <sys/wait.h>
#include <sstream>
#include <apt-private/private-output.h>
#include <apt-private/private-main.h>
@ -812,27 +813,10 @@ bool DoSource(CommandLine &CmdL)
delete[] Dsc;
return true;
}
// Run it
if (Fetcher.Run() == pkgAcquire::Failed)
{
delete[] Dsc;
return false;
}
// Print error messages
// Run it
bool Failed = false;
for (pkgAcquire::ItemIterator I = Fetcher.ItemsBegin(); I != Fetcher.ItemsEnd(); ++I)
{
if ((*I)->Status == pkgAcquire::Item::StatDone &&
(*I)->Complete == true)
continue;
fprintf(stderr,_("Failed to fetch %s %s\n"),(*I)->DescURI().c_str(),
(*I)->ErrorText.c_str());
Failed = true;
}
if (Failed == true)
if (AcquireRun(Fetcher, 0, &Failed, NULL) == false || Failed == true)
{
delete[] Dsc;
return _error->Error(_("Failed to fetch some archives."));

Loading…
Cancel
Save