correct some style/performance/warnings from cppcheck
[ntk/apt.git] / apt-private / private-download.cc
CommitLineData
866893a6
DK
1// Include Files /*{{{*/
2#include <config.h>
3
4#include <apt-pkg/acquire.h>
5#include <apt-pkg/acquire-item.h>
6#include <apt-pkg/configuration.h>
7#include <apt-pkg/error.h>
8#include <apt-pkg/strutl.h>
9
10#include "private-output.h"
11
12#include <locale.h>
13
14#include <fstream>
15#include <string>
16#include <vector>
17
18#include <apti18n.h>
19 /*}}}*/
20
21// CheckAuth - check if each download comes form a trusted source /*{{{*/
22bool CheckAuth(pkgAcquire& Fetcher, bool const PromptUser)
23{
24 std::string UntrustedList;
25 for (pkgAcquire::ItemIterator I = Fetcher.ItemsBegin(); I < Fetcher.ItemsEnd(); ++I)
26 if (!(*I)->IsTrusted())
27 UntrustedList += std::string((*I)->ShortDesc()) + " ";
28
29 if (UntrustedList == "")
30 return true;
31
32 ShowList(c2out,_("WARNING: The following packages cannot be authenticated!"),UntrustedList,"");
33
34 if (_config->FindB("APT::Get::AllowUnauthenticated",false) == true)
35 {
36 c2out << _("Authentication warning overridden.\n");
37 return true;
38 }
39
40 if (PromptUser == false)
41 return _error->Error(_("Some packages could not be authenticated"));
42
43 if (_config->FindI("quiet",0) < 2
44 && _config->FindB("APT::Get::Assume-Yes",false) == false)
45 {
46 c2out << _("Install these packages without verification?") << std::flush;
47 if (!YnPrompt(false))
48 return _error->Error(_("Some packages could not be authenticated"));
49
50 return true;
51 }
52 else if (_config->FindB("APT::Get::Force-Yes",false) == true)
53 return true;
54
55 return _error->Error(_("There are problems and -y was used without --force-yes"));
56}
57 /*}}}*/
58bool AcquireRun(pkgAcquire &Fetcher, int const PulseInterval, bool * const Failure, bool * const TransientNetworkFailure)/*{{{*/
59{
60 pkgAcquire::RunResult res;
61 if(PulseInterval > 0)
62 res = Fetcher.Run(PulseInterval);
63 else
64 res = Fetcher.Run();
65
66 if (res == pkgAcquire::Failed)
67 return false;
68
69 for (pkgAcquire::ItemIterator I = Fetcher.ItemsBegin();
70 I != Fetcher.ItemsEnd(); ++I)
71 {
72
73 if ((*I)->Status == pkgAcquire::Item::StatDone &&
74 (*I)->Complete == true)
75 continue;
76
77 if (TransientNetworkFailure != NULL && (*I)->Status == pkgAcquire::Item::StatIdle)
78 {
79 *TransientNetworkFailure = true;
80 continue;
81 }
82
83 ::URI uri((*I)->DescURI());
84 uri.User.clear();
85 uri.Password.clear();
86 std::string descUri = std::string(uri);
87 _error->Error(_("Failed to fetch %s %s\n"), descUri.c_str(),
88 (*I)->ErrorText.c_str());
89
90 if (Failure != NULL)
91 *Failure = true;
92 }
93
94 return true;
95}
96 /*}}}*/