]> git.saurik.com Git - apt.git/blame - apt-private/private-update.cc
don't try to get acquire lock in simulation mode
[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>
2b0660b5 16#include <apt-private/private-download.h>
453b82a3
DK
17#include <apt-private/private-output.h>
18#include <apt-private/private-update.h>
b9179170 19
453b82a3
DK
20#include <ostream>
21#include <string>
b9179170
MV
22
23#include <apti18n.h>
24 /*}}}*/
25
26// DoUpdate - Update the package lists /*{{{*/
27// ---------------------------------------------------------------------
28/* */
29bool DoUpdate(CommandLine &CmdL)
30{
31 if (CmdL.FileSize() != 1)
32 return _error->Error(_("The update command takes no arguments"));
33
34 CacheFile Cache;
35
36 // Get the source list
37 if (Cache.BuildSourceList() == false)
38 return false;
39 pkgSourceList *List = Cache.GetSourceList();
40
b9179170
MV
41 // Just print out the uris an exit if the --print-uris flag was used
42 if (_config->FindB("APT::Get::Print-URIs") == true)
43 {
44 // force a hashsum for compatibility reasons
45 _config->CndSet("Acquire::ForceHash", "md5sum");
46
2b0660b5 47 // Populate it with the source selection and get all Indexes
b9179170 48 // (GetAll=true)
2b0660b5 49 aptAcquireWithTextStatus Fetcher;
b9179170
MV
50 if (List->GetIndexes(&Fetcher,true) == false)
51 return false;
52
b0f4b486 53 std::string compExt = APT::Configuration::getCompressionTypes()[0];
b9179170
MV
54 pkgAcquire::UriIterator I = Fetcher.UriBegin();
55 for (; I != Fetcher.UriEnd(); ++I)
b0f4b486
MV
56 {
57 std::string FileName = flNotDir(I->Owner->DestFile);
58 if(compExt.empty() == false &&
59 APT::String::Endswith(FileName, compExt))
60 FileName = FileName.substr(0, FileName.size() - compExt.size() - 1);
61 c1out << '\'' << I->URI << "' " << FileName << ' ' <<
b9179170 62 I->Owner->FileSize << ' ' << I->Owner->HashSum() << std::endl;
b0f4b486 63 }
b9179170
MV
64 return true;
65 }
66
67 // do the work
68 if (_config->FindB("APT::Get::Download",true) == true)
2b0660b5
DK
69 {
70 AcqTextStatus Stat(std::cout, ScreenWidth,_config->FindI("quiet",0));
71 ListUpdate(Stat, *List);
72 }
b9179170
MV
73
74 // Rebuild the cache.
75 if (_config->FindB("pkgCacheFile::Generate", true) == true)
76 {
77 pkgCacheFile::RemoveCaches();
78 if (Cache.BuildCaches() == false)
79 return false;
80 }
81
8f418981
MV
82 // show basic stats (if the user whishes)
83 if (_config->FindB("APT::Cmd::Show-Update-Stats", false) == true)
84 {
85 int upgradable = 0;
7a139fa8
JAK
86 if (Cache.Open() == false)
87 return false;
8f418981
MV
88 for (pkgCache::PkgIterator I = Cache->PkgBegin(); I.end() != true; ++I)
89 {
90 pkgDepCache::StateCache &state = Cache[I];
7d1b93d9 91 if (I->CurrentVer != 0 && state.Upgradable() && state.CandidateVer != NULL)
8f418981
MV
92 upgradable++;
93 }
dab5f874 94 const char *msg = P_(
8f418981
MV
95 "%i package can be upgraded. Run 'apt list --upgradable' to see it.\n",
96 "%i packages can be upgraded. Run 'apt list --upgradable' to see them.\n",
97 upgradable);
24d05892
MV
98 if (upgradable == 0)
99 c1out << _("All packages are up to date.") << std::endl;
100 else
101 ioprintf(c1out, msg, upgradable);
8f418981
MV
102 }
103
b9179170
MV
104 return true;
105}
106 /*}}}*/