]> git.saurik.com Git - apt.git/blame - apt-private/private-update.cc
Merge branch 'debian/sid' into debian/experimental
[apt.git] / apt-private / private-update.cc
CommitLineData
b9179170
MV
1// Include files /*{{{*/
2#include<config.h>
3
b9179170 4#include <apt-pkg/acquire-item.h>
b9179170 5#include <apt-pkg/cachefile.h>
453b82a3
DK
6#include <apt-pkg/cmndline.h>
7#include <apt-pkg/error.h>
8#include <apt-pkg/fileutl.h>
9#include <apt-pkg/sourcelist.h>
d428d131 10#include <apt-pkg/update.h>
453b82a3
DK
11#include <apt-pkg/acquire.h>
12#include <apt-pkg/configuration.h>
b9179170 13
453b82a3
DK
14#include <apt-private/acqprogress.h>
15#include <apt-private/private-cachefile.h>
16#include <apt-private/private-output.h>
17#include <apt-private/private-update.h>
b9179170 18
453b82a3
DK
19#include <ostream>
20#include <string>
b9179170
MV
21
22#include <apti18n.h>
23 /*}}}*/
24
25// DoUpdate - Update the package lists /*{{{*/
26// ---------------------------------------------------------------------
27/* */
28bool DoUpdate(CommandLine &CmdL)
29{
30 if (CmdL.FileSize() != 1)
31 return _error->Error(_("The update command takes no arguments"));
32
33 CacheFile Cache;
34
35 // Get the source list
36 if (Cache.BuildSourceList() == false)
37 return false;
38 pkgSourceList *List = Cache.GetSourceList();
39
40 // Create the progress
41 AcqTextStatus Stat(ScreenWidth,_config->FindI("quiet",0));
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 // get a fetcher
50 pkgAcquire Fetcher;
51 if (Fetcher.Setup(&Stat) == false)
52 return false;
53
54 // Populate it with the source selection and get all Indexes
55 // (GetAll=true)
56 if (List->GetIndexes(&Fetcher,true) == false)
57 return false;
58
b0f4b486 59 std::string compExt = APT::Configuration::getCompressionTypes()[0];
b9179170
MV
60 pkgAcquire::UriIterator I = Fetcher.UriBegin();
61 for (; I != Fetcher.UriEnd(); ++I)
b0f4b486
MV
62 {
63 std::string FileName = flNotDir(I->Owner->DestFile);
64 if(compExt.empty() == false &&
65 APT::String::Endswith(FileName, compExt))
66 FileName = FileName.substr(0, FileName.size() - compExt.size() - 1);
67 c1out << '\'' << I->URI << "' " << FileName << ' ' <<
b9179170 68 I->Owner->FileSize << ' ' << I->Owner->HashSum() << std::endl;
b0f4b486 69 }
b9179170
MV
70 return true;
71 }
72
73 // do the work
74 if (_config->FindB("APT::Get::Download",true) == true)
75 ListUpdate(Stat, *List);
76
77 // Rebuild the cache.
78 if (_config->FindB("pkgCacheFile::Generate", true) == true)
79 {
80 pkgCacheFile::RemoveCaches();
81 if (Cache.BuildCaches() == false)
82 return false;
83 }
84
8f418981
MV
85 // show basic stats (if the user whishes)
86 if (_config->FindB("APT::Cmd::Show-Update-Stats", false) == true)
87 {
88 int upgradable = 0;
89 Cache.Open();
90 for (pkgCache::PkgIterator I = Cache->PkgBegin(); I.end() != true; ++I)
91 {
92 pkgDepCache::StateCache &state = Cache[I];
7d1b93d9 93 if (I->CurrentVer != 0 && state.Upgradable() && state.CandidateVer != NULL)
8f418981
MV
94 upgradable++;
95 }
dab5f874 96 const char *msg = P_(
8f418981
MV
97 "%i package can be upgraded. Run 'apt list --upgradable' to see it.\n",
98 "%i packages can be upgraded. Run 'apt list --upgradable' to see them.\n",
99 upgradable);
24d05892
MV
100 if (upgradable == 0)
101 c1out << _("All packages are up to date.") << std::endl;
102 else
103 ioprintf(c1out, msg, upgradable);
8f418981
MV
104 }
105
b9179170
MV
106 return true;
107}
108 /*}}}*/