apt  2.2.4
About: Apt (Advanced Package Tool) is a management system for software packages (Debian/Ubuntu). Release series 2.2.
  Fossies Dox: apt-2.2.4.tar.gz  ("unofficial" and yet experimental doxygen-generated source code documentation)  

private-update.cc
Go to the documentation of this file.
1 // Include files /*{{{*/
2 #include <config.h>
3 
4 #include <apt-pkg/acquire-item.h>
5 #include <apt-pkg/acquire.h>
6 #include <apt-pkg/cachefile.h>
7 #include <apt-pkg/cmndline.h>
8 #include <apt-pkg/configuration.h>
9 #include <apt-pkg/error.h>
10 #include <apt-pkg/fileutl.h>
11 #include <apt-pkg/metaindex.h>
12 #include <apt-pkg/sourcelist.h>
13 #include <apt-pkg/strutl.h>
14 #include <apt-pkg/update.h>
15 
21 
22 #include <ostream>
23 #include <string>
24 
25 #include <apti18n.h>
26  /*}}}*/
27 
28 // DoUpdate - Update the package lists /*{{{*/
29 // ---------------------------------------------------------------------
30 /* */
31 bool DoUpdate(CommandLine &CmdL)
32 {
33  if (CmdL.FileSize() != 1)
34  return _error->Error(_("The update command takes no arguments"));
35 
36  CacheFile Cache;
37 
38  // Get the source list
39  if (Cache.BuildSourceList() == false)
40  return false;
41  pkgSourceList *List = Cache.GetSourceList();
42 
43  // Just print out the uris an exit if the --print-uris flag was used
44  if (_config->FindB("APT::Get::Print-URIs") == true)
45  {
46  // force a hashsum for compatibility reasons
47  _config->CndSet("Acquire::ForceHash", "md5sum");
48 
49  // Populate it with the source selection and get all Indexes
50  // (GetAll=true)
52  if (List->GetIndexes(&Fetcher,true) == false)
53  return false;
54 
55  std::string compExt = APT::Configuration::getCompressionTypes()[0];
57  for (; I != Fetcher.UriEnd(); ++I)
58  {
59  std::string FileName = flNotDir(I->Owner->DestFile);
60  if(compExt.empty() == false &&
61  APT::String::Endswith(FileName, compExt))
62  FileName = FileName.substr(0, FileName.size() - compExt.size() - 1);
63  c1out << '\'' << I->URI << "' " << FileName << ' ' <<
64  std::to_string(I->Owner->FileSize) << ' ' << I->Owner->HashSum() << std::endl;
65  }
66  return true;
67  }
68 
69  // do the work
70  if (_config->FindB("APT::Get::Download",true) == true)
71  {
72  AcqTextStatus Stat(std::cout, ScreenWidth,_config->FindI("quiet",0));
73  ListUpdate(Stat, *List);
74  }
75 
76  if (_config->FindB("pkgCacheFile::Generate", true) == false)
77  return true;
78 
79  // Rebuild the cache.
81  if (Cache.BuildCaches(false) == false)
82  return false;
83 
84  if (_config->FindB("APT::Get::Update::SourceListWarnings", true))
85  {
86  List = Cache.GetSourceList();
87  for (pkgSourceList::const_iterator S = List->begin(); S != List->end(); ++S)
88  {
89  if (APT::String::Startswith((*S)->GetURI(), "ftp://") == false)
90  continue;
91  pkgCache::RlsFileIterator const RlsFile = (*S)->FindInCache(Cache, false);
92  if (RlsFile.end() || RlsFile->Origin == 0 || RlsFile->Label == 0)
93  continue;
94  char const *const affected[][2] = {
95  {"Debian", "Debian"},
96  {"Debian", "Debian-Security"},
97  {"Debian Backports", "Debian Backports"},
98  };
99  auto const matchRelease = [&](decltype(affected[0]) a) {
100  return strcmp(RlsFile.Origin(), a[0]) == 0 && strcmp(RlsFile.Label(), a[1]) == 0;
101  };
102  if (std::find_if(std::begin(affected), std::end(affected), matchRelease) != std::end(affected))
103  _error->Warning("Debian shuts down public FTP services currently still used in your sources.list(5) as '%s'.\n"
104  "See press release %s for details.",
105  (*S)->GetURI().c_str(), "https://debian.org/News/2017/20170425");
106  }
107  for (pkgSourceList::const_iterator S = List->begin(); S != List->end(); ++S)
108  {
109  URI uri((*S)->GetURI());
110  if (uri.User.empty() && uri.Password.empty())
111  continue;
112  // we can't really predict if a +http method supports everything http does,
113  // so we play it safe and use an allowlist here.
114  char const *const affected[] = {"http", "https", "tor+http", "tor+https", "ftp"};
115  if (std::find(std::begin(affected), std::end(affected), uri.Access) != std::end(affected))
116  // TRANSLATOR: the first two are manpage references, the last the URI from a sources.list
117  _error->Notice(_("Usage of %s should be preferred over embedding login information directly in the %s entry for '%s'"),
118  "apt_auth.conf(5)", "sources.list(5)", URI::ArchiveOnly(uri).c_str());
119  }
120  }
121 
122  // show basic stats (if the user whishes)
123  if (_config->FindB("APT::Cmd::Show-Update-Stats", false) == true)
124  {
125  int upgradable = 0;
126  if (Cache.Open(false) == false)
127  return false;
128  for (pkgCache::PkgIterator I = Cache->PkgBegin(); I.end() != true; ++I)
129  {
130  pkgDepCache::StateCache &state = Cache[I];
131  if (I->CurrentVer != 0 && state.Upgradable() && state.CandidateVer != NULL)
132  upgradable++;
133  }
134  const char *msg = P_(
135  "%i package can be upgraded. Run 'apt list --upgradable' to see it.\n",
136  "%i packages can be upgraded. Run 'apt list --upgradable' to see them.\n",
137  upgradable);
138  if (upgradable == 0)
139  c1out << _("All packages are up to date.") << std::endl;
140  else
141  ioprintf(c1out, msg, upgradable);
142 
143  RunScripts("APT::Update::Post-Invoke-Stats");
144  }
145 
146  return true;
147 }
148  /*}}}*/
static bool std::string const metaIndex const *const pkgAcqMetaClearSig *const pkgAcquire::Item *const I
static char const *const msg
bool BuildCaches(bool WithLock=true)
bool Open(bool WithLock=true)
unsigned int FileSize() const APT_PURE
Definition: cmndline.cc:353
int FindI(const char *Name, int const &Default=0) const
bool FindB(const char *Name, bool const &Default=false) const
void CndSet(const char *Name, const std::string &Value)
Definition: strutl.h:193
std::string Access
Definition: strutl.h:198
static std::string ArchiveOnly(const std::string &URI)
Definition: strutl.cc:1798
std::string User
Definition: strutl.h:199
std::string Password
Definition: strutl.h:200
std::string URI
Definition: metaindex.h:39
UriIterator UriBegin()
Get the head of the list of enqueued item URIs.
Definition: acquire.cc:872
UriIterator UriEnd()
Get the end iterator of the list of enqueued item URIs.
Definition: acquire.cc:880
UriIterator(pkgAcquire::Queue *Q)
Create a new UriIterator.
bool BuildSourceList(OpProgress *Progress=NULL)
Definition: cachefile.cc:151
pkgSourceList * GetSourceList()
Definition: cachefile.h:76
static void RemoveCaches()
Definition: cachefile.cc:308
bool GetIndexes(pkgAcquire *Owner, bool GetAll=false) const
Definition: sourcelist.cc:484
const_iterator begin() const
Definition: sourcelist.h:97
const_iterator end() const
Definition: sourcelist.h:98
std::vector< metaIndex * >::const_iterator const_iterator
Definition: sourcelist.h:76
Configuration * _config
string flNotDir(string File)
Definition: fileutl.cc:664
bool RunScripts(const char *Cnf)
Definition: fileutl.cc:91
APT_PUBLIC std::vector< std::string > const getCompressionTypes(bool const &Cached=true)
Returns a vector of usable Compression Types.
bool Endswith(const std::string &s, const std::string &end)
Definition: strutl.cc:77
bool Startswith(const std::string &s, const std::string &start)
Definition: strutl.cc:84
unsigned int ScreenWidth
APT_PUBLIC std::ostream c1out
bool DoUpdate(CommandLine &CmdL)
bool Upgradable() const
Definition: depcache.h:253
Version * CandidateVer
Definition: depcache.h:218
void ioprintf(ostream &out, const char *format,...)
Definition: strutl.cc:1433
bool ListUpdate(pkgAcquireStatus &Stat, pkgSourceList &List, int PulseInterval)
Definition: update.cc:25