]> git.saurik.com Git - apt.git/blame - cmdline/apt-get.cc
add cacheset push_back wrapping for std::back_inserter
[apt.git] / cmdline / apt-get.cc
CommitLineData
5ec427c2
AL
1// -*- mode: cpp; mode: fold -*-
2// Description /*{{{*/
640c5d94 3// $Id: apt-get.cc,v 1.156 2004/08/28 01:05:16 mdz Exp $
5ec427c2
AL
4/* ######################################################################
5
6 apt-get - Cover for dpkg
7
8 This is an allout cover for dpkg implementing a safer front end. It is
9 based largely on libapt-pkg.
10
11 The syntax is different,
12 apt-get [opt] command [things]
13 Where command is:
14 update - Resyncronize the package files from their sources
15 upgrade - Smart-Download the newest versions of all packages
16 dselect-upgrade - Follows dselect's changes to the Status: field
17 and installes new and removes old packages
1e3f4083 18 dist-upgrade - Powerful upgrader designed to handle the issues with
5ec427c2
AL
19 a new distribution.
20 install - Download and install a given package (by name, not by .deb)
21 check - Update the package cache and check for broken packages
22 clean - Erase the .debs downloaded to /var/cache/apt/archives and
23 the partial dir too
24
25 ##################################################################### */
26 /*}}}*/
27// Include Files /*{{{*/
ea542140
DK
28#include <config.h>
29
453b82a3
DK
30#include <apt-pkg/acquire-item.h>
31#include <apt-pkg/algorithms.h>
086bb6d7 32#include <apt-pkg/aptconfiguration.h>
453b82a3
DK
33#include <apt-pkg/cachefile.h>
34#include <apt-pkg/cacheset.h>
35#include <apt-pkg/clean.h>
0a8e3465 36#include <apt-pkg/cmndline.h>
453b82a3 37#include <apt-pkg/debmetaindex.h>
0a8e3465 38#include <apt-pkg/depcache.h>
453b82a3 39#include <apt-pkg/error.h>
472ff00e 40#include <apt-pkg/fileutl.h>
453b82a3 41#include <apt-pkg/indexfile.h>
453b82a3 42#include <apt-pkg/init.h>
092ae175 43#include <apt-pkg/md5.h>
453b82a3 44#include <apt-pkg/metaindex.h>
472ff00e 45#include <apt-pkg/pkgrecords.h>
453b82a3
DK
46#include <apt-pkg/pkgsystem.h>
47#include <apt-pkg/progress.h>
48#include <apt-pkg/sourcelist.h>
49#include <apt-pkg/srcrecords.h>
50#include <apt-pkg/strutl.h>
51#include <apt-pkg/version.h>
52#include <apt-pkg/acquire.h>
53#include <apt-pkg/configuration.h>
54#include <apt-pkg/macros.h>
55#include <apt-pkg/pkgcache.h>
56#include <apt-pkg/cacheiterators.h>
82e369c4 57#include <apt-pkg/upgrade.h>
6cfadda1 58#include <apt-pkg/sptr.h>
ffee1c2b 59
453b82a3
DK
60#include <apt-private/acqprogress.h>
61#include <apt-private/private-cacheset.h>
62#include <apt-private/private-cachefile.h>
63#include <apt-private/private-cmndline.h>
866893a6 64#include <apt-private/private-download.h>
b9179170 65#include <apt-private/private-install.h>
453b82a3
DK
66#include <apt-private/private-main.h>
67#include <apt-private/private-moo.h>
b9179170 68#include <apt-private/private-output.h>
b9179170 69#include <apt-private/private-update.h>
453b82a3 70#include <apt-private/private-upgrade.h>
cfacba52 71#include <apt-private/private-utils.h>
b9179170 72
453b82a3
DK
73#include <errno.h>
74#include <signal.h>
75#include <stddef.h>
76#include <stdio.h>
77#include <stdlib.h>
78#include <string.h>
a3f1d60c 79#include <sys/ioctl.h>
1bc849af 80#include <sys/stat.h>
453b82a3 81#include <unistd.h>
03aa0847
DK
82#include <pwd.h>
83#include <grp.h>
84
453b82a3
DK
85#include <algorithm>
86#include <fstream>
87#include <iostream>
8881b11e 88#include <sstream>
453b82a3
DK
89#include <set>
90#include <string>
91#include <vector>
5ec427c2 92
b9179170
MV
93#include <apti18n.h>
94 /*}}}*/
afb1e2e3 95
b9179170 96using namespace std;
642ebc1a 97
b8ad5512 98// TryToInstallBuildDep - Try to install a single package /*{{{*/
c373c37a
AL
99// ---------------------------------------------------------------------
100/* This used to be inlined in DoInstall, but with the advent of regex package
101 name matching it was split out.. */
c3ccac92 102static bool TryToInstallBuildDep(pkgCache::PkgIterator Pkg,pkgCacheFile &Cache,
c373c37a 103 pkgProblemResolver &Fix,bool Remove,bool BrokenFix,
70e706ad 104 bool AllowFail = true)
c373c37a 105{
21d4c9f1 106 if (Cache[Pkg].CandidateVer == 0 && Pkg->ProvidesList != 0)
c373c37a 107 {
21d4c9f1 108 CacheSetHelperAPTGet helper(c1out);
4caf8231 109 helper.showErrors(false);
21d4c9f1
DK
110 pkgCache::VerIterator Ver = helper.canNotFindNewestVer(Cache, Pkg);
111 if (Ver.end() == false)
112 Pkg = Ver.ParentPkg();
113 else if (helper.showVirtualPackageErrors(Cache) == false)
114 return AllowFail;
c373c37a 115 }
61d6a8de 116
ac321486
DK
117 if (_config->FindB("Debug::BuildDeps",false) == true)
118 {
119 if (Remove == true)
120 cout << " Trying to remove " << Pkg << endl;
121 else
122 cout << " Trying to install " << Pkg << endl;
123 }
124
c373c37a
AL
125 if (Remove == true)
126 {
71d73928 127 TryToRemove RemoveAction(Cache, &Fix);
21d4c9f1
DK
128 RemoveAction(Pkg.VersionList());
129 } else if (Cache[Pkg].CandidateVer != 0) {
71d73928 130 TryToInstall InstallAction(Cache, &Fix, BrokenFix);
21d4c9f1 131 InstallAction(Cache[Pkg].CandidateVerIter(Cache));
6806db8a 132 InstallAction.doAutoInstall();
21d4c9f1
DK
133 } else
134 return AllowFail;
60681f93 135
b2e465d6
AL
136 return true;
137}
138 /*}}}*/
5ad0096a
DK
139// GetReleaseFileForSourceRecord - Return Suite for the given srcrecord /*{{{*/
140static pkgCache::RlsFileIterator GetReleaseFileForSourceRecord(CacheFile &CacheFile,
141 pkgSourceList *SrcList, pkgSrcRecords::Parser *Parse)
7014e148
MV
142{
143 // try to find release
144 const pkgIndexFile& CurrentIndexFile = Parse->Index();
145
146 for (pkgSourceList::const_iterator S = SrcList->begin();
147 S != SrcList->end(); ++S)
148 {
149 vector<pkgIndexFile *> *Indexes = (*S)->GetIndexFiles();
150 for (vector<pkgIndexFile *>::const_iterator IF = Indexes->begin();
151 IF != Indexes->end(); ++IF)
152 {
153 if (&CurrentIndexFile == (*IF))
5ad0096a 154 return (*S)->FindInCache(CacheFile, false);
7014e148
MV
155 }
156 }
5ad0096a 157 return pkgCache::RlsFileIterator(CacheFile);
7014e148
MV
158}
159 /*}}}*/
b2e465d6
AL
160// FindSrc - Find a source record /*{{{*/
161// ---------------------------------------------------------------------
162/* */
a221efc3 163static pkgSrcRecords::Parser *FindSrc(const char *Name,
b2e465d6 164 pkgSrcRecords &SrcRecs,string &Src,
7014e148 165 CacheFile &CacheFile)
b2e465d6 166{
adf379e7
MV
167 string VerTag, UserRequestedVerTag;
168 string ArchTag = "";
7014e148 169 string RelTag = _config->Find("APT::Default-Release");
b2e465d6 170 string TmpSrc = Name;
7014e148 171 pkgDepCache *Cache = CacheFile.GetDepCache();
aca056a9 172
adf379e7
MV
173 // extract release
174 size_t found = TmpSrc.find_last_of("/");
175 if (found != string::npos)
176 {
177 RelTag = TmpSrc.substr(found+1);
178 TmpSrc = TmpSrc.substr(0,found);
179 }
180 // extract the version
181 found = TmpSrc.find_last_of("=");
182 if (found != string::npos)
183 {
184 VerTag = UserRequestedVerTag = TmpSrc.substr(found+1);
185 TmpSrc = TmpSrc.substr(0,found);
186 }
187 // extract arch
188 found = TmpSrc.find_last_of(":");
189 if (found != string::npos)
190 {
191 ArchTag = TmpSrc.substr(found+1);
ebf6c42d
DK
192 TmpSrc = TmpSrc.substr(0,found);
193 }
aca056a9 194
fb3dc579
MV
195 /* Lookup the version of the package we would install if we were to
196 install a version and determine the source package name, then look
197 in the archive for a source package of the same name. */
198 bool MatchSrcOnly = _config->FindB("APT::Get::Only-Source");
adf379e7
MV
199 pkgCache::PkgIterator Pkg;
200 if (ArchTag != "")
201 Pkg = Cache->FindPkg(TmpSrc, ArchTag);
202 else
203 Pkg = Cache->FindPkg(TmpSrc);
204
205 // if we can't find a package but the user qualified with a arch,
206 // error out here
207 if (Pkg.end() && ArchTag != "")
208 {
209 Src = Name;
210 _error->Error(_("Can not find a package for architecture '%s'"),
211 ArchTag.c_str());
212 return 0;
213 }
214
fb3dc579 215 if (MatchSrcOnly == false && Pkg.end() == false)
aca056a9 216 {
adf379e7 217 if(VerTag != "" || RelTag != "" || ArchTag != "")
aca056a9 218 {
e84adb76 219 bool fuzzy = false;
fb3dc579
MV
220 // we have a default release, try to locate the pkg. we do it like
221 // this because GetCandidateVer() will not "downgrade", that means
222 // "apt-get source -t stable apt" won't work on a unstable system
f7f0d6c7 223 for (pkgCache::VerIterator Ver = Pkg.VersionList();; ++Ver)
aca056a9 224 {
e84adb76
DK
225 // try first only exact matches, later fuzzy matches
226 if (Ver.end() == true)
227 {
228 if (fuzzy == true)
229 break;
230 fuzzy = true;
231 Ver = Pkg.VersionList();
259f688a
MV
232 // exit right away from the Pkg.VersionList() loop if we
233 // don't have any versions
234 if (Ver.end() == true)
235 break;
e84adb76 236 }
adf379e7 237
37f45a57
MV
238 // ignore arches that are not for us
239 if (ArchTag != "" && Ver.Arch() != ArchTag)
240 continue;
241
adf379e7
MV
242 // pick highest version for the arch unless the user wants
243 // something else
244 if (ArchTag != "" && VerTag == "" && RelTag == "")
adf379e7
MV
245 if(Cache->VS().CmpVersion(VerTag, Ver.VerStr()) < 0)
246 VerTag = Ver.VerStr();
adf379e7 247
e84adb76
DK
248 // We match against a concrete version (or a part of this version)
249 if (VerTag.empty() == false &&
7014e148 250 (fuzzy == true || Cache->VS().CmpVersion(VerTag, Ver.VerStr()) != 0) && // exact match
e84adb76
DK
251 (fuzzy == false || strncmp(VerTag.c_str(), Ver.VerStr(), VerTag.size()) != 0)) // fuzzy match
252 continue;
253
fb3dc579 254 for (pkgCache::VerFileIterator VF = Ver.FileList();
f7f0d6c7 255 VF.end() == false; ++VF)
aca056a9 256 {
fb3dc579
MV
257 /* If this is the status file, and the current version is not the
258 version in the status file (ie it is not installed, or somesuch)
259 then it is not a candidate for installation, ever. This weeds
260 out bogus entries that may be due to config-file states, or
261 other. */
262 if ((VF.File()->Flags & pkgCache::Flag::NotSource) ==
263 pkgCache::Flag::NotSource && Pkg.CurrentVer() != Ver)
264 continue;
265
fb3dc579
MV
266 // or we match against a release
267 if(VerTag.empty() == false ||
7014e148
MV
268 (VF.File().Archive() != 0 && VF.File().Archive() == RelTag) ||
269 (VF.File().Codename() != 0 && VF.File().Codename() == RelTag))
fb3dc579 270 {
e84adb76 271 // the Version we have is possibly fuzzy or includes binUploads,
765190e4 272 // so we use the Version of the SourcePkg (empty if same as package)
765190e4 273 Src = Ver.SourcePkgName();
a221efc3 274 VerTag = Ver.SourceVerStr();
fb3dc579
MV
275 break;
276 }
aca056a9 277 }
61690a7e
MV
278 if (Src.empty() == false)
279 break;
aca056a9 280 }
026f60e2 281 }
adf379e7 282
37f45a57
MV
283 if (Src == "" && ArchTag != "")
284 {
c9829e07
MV
285 if (VerTag != "")
286 _error->Error(_("Can not find a package '%s' with version '%s'"),
287 Pkg.FullName().c_str(), VerTag.c_str());
288 if (RelTag != "")
289 _error->Error(_("Can not find a package '%s' with release '%s'"),
290 Pkg.FullName().c_str(), RelTag.c_str());
37f45a57
MV
291 Src = Name;
292 return 0;
293 }
294
295
61690a7e 296 if (Src.empty() == true)
b2e465d6 297 {
61690a7e
MV
298 // if we don't have found a fitting package yet so we will
299 // choose a good candidate and proceed with that.
300 // Maybe we will find a source later on with the right VerTag
7014e148
MV
301 // or RelTag
302 pkgCache::VerIterator Ver = Cache->GetCandidateVer(Pkg);
fb3dc579 303 if (Ver.end() == false)
b2e465d6 304 {
a221efc3
DK
305 if (strcmp(Ver.SourcePkgName(),Ver.ParentPkg().Name()) != 0)
306 Src = Ver.SourcePkgName();
307 if (VerTag.empty() == true && strcmp(Ver.SourceVerStr(),Ver.VerStr()) != 0)
308 VerTag = Ver.SourceVerStr();
b2e465d6 309 }
fb3dc579
MV
310 }
311 }
312
313 if (Src.empty() == true)
7014e148 314 {
fb3dc579 315 Src = TmpSrc;
7014e148 316 }
fb3dc579
MV
317 else
318 {
319 /* if we have a source pkg name, make sure to only search
320 for srcpkg names, otherwise apt gets confused if there
321 is a binary package "pkg1" and a source package "pkg1"
322 with the same name but that comes from different packages */
323 MatchSrcOnly = true;
324 if (Src != TmpSrc)
325 {
326 ioprintf(c1out, _("Picking '%s' as source package instead of '%s'\n"), Src.c_str(), TmpSrc.c_str());
327 }
b2e465d6 328 }
89ad8e7c 329
b2e465d6
AL
330 // The best hit
331 pkgSrcRecords::Parser *Last = 0;
332 unsigned long Offset = 0;
333 string Version;
7014e148 334 pkgSourceList *SrcList = CacheFile.GetSourceList();
89ad8e7c 335
b2e465d6
AL
336 /* Iterate over all of the hits, which includes the resulting
337 binary packages in the search */
338 pkgSrcRecords::Parser *Parse;
fb3dc579 339 while (true)
b2e465d6 340 {
fb3dc579
MV
341 SrcRecs.Restart();
342 while ((Parse = SrcRecs.Find(Src.c_str(), MatchSrcOnly)) != 0)
b2e465d6 343 {
fb3dc579
MV
344 const string Ver = Parse->Version();
345
7014e148 346 // See if we need to look for a specific release tag
65dcff55 347 if (RelTag != "" && UserRequestedVerTag == "")
7014e148 348 {
5ad0096a
DK
349 pkgCache::RlsFileIterator const Rls = GetReleaseFileForSourceRecord(CacheFile, SrcList, Parse);
350 if (Rls.end() == false)
7014e148 351 {
5ad0096a
DK
352 if ((Rls->Archive != 0 && RelTag == Rls.Archive()) ||
353 (Rls->Codename != 0 && RelTag == Rls.Codename()))
354 {
355 Last = Parse;
356 Offset = Parse->Offset();
357 Version = Ver;
358 }
7014e148
MV
359 }
360 }
361
fb3dc579 362 // Ignore all versions which doesn't fit
e84adb76 363 if (VerTag.empty() == false &&
7014e148 364 Cache->VS().CmpVersion(VerTag, Ver) != 0) // exact match
b2e465d6 365 continue;
fb3dc579
MV
366
367 // Newer version or an exact match? Save the hit
7014e148 368 if (Last == 0 || Cache->VS().CmpVersion(Version,Ver) < 0) {
fb3dc579
MV
369 Last = Parse;
370 Offset = Parse->Offset();
371 Version = Ver;
372 }
373
7014e148
MV
374 // was the version check above an exact match?
375 // If so, we don't need to look further
376 if (VerTag.empty() == false && (VerTag == Ver))
fb3dc579 377 break;
b2e465d6 378 }
65dcff55 379 if (UserRequestedVerTag == "" && Version != "" && RelTag != "")
bfa7bfc8 380 ioprintf(c1out, "Selected version '%s' (%s) for %s\n",
651ae5ce
MV
381 Version.c_str(), RelTag.c_str(), Src.c_str());
382
fb3dc579
MV
383 if (Last != 0 || VerTag.empty() == true)
384 break;
017d3f3b 385 _error->Error(_("Can not find version '%s' of package '%s'"), VerTag.c_str(), TmpSrc.c_str());
ddff663f 386 return 0;
b2e465d6 387 }
fb3dc579 388
ce6162be 389 if (Last == 0 || Last->Jump(Offset) == false)
b2e465d6 390 return 0;
fb3dc579 391
b2e465d6
AL
392 return Last;
393}
394 /*}}}*/
182a6a55 395/* mark packages as automatically/manually installed. {{{*/
c3ccac92 396static bool DoMarkAuto(CommandLine &CmdL)
d63a1458
JAK
397{
398 bool Action = true;
399 int AutoMarkChanged = 0;
400 OpTextProgress progress;
401 CacheFile Cache;
402 if (Cache.Open() == false)
403 return false;
404
405 if (strcasecmp(CmdL.FileList[0],"markauto") == 0)
406 Action = true;
407 else if (strcasecmp(CmdL.FileList[0],"unmarkauto") == 0)
408 Action = false;
409
410 for (const char **I = CmdL.FileList + 1; *I != 0; I++)
411 {
412 const char *S = *I;
413 // Locate the package
414 pkgCache::PkgIterator Pkg = Cache->FindPkg(S);
415 if (Pkg.end() == true) {
416 return _error->Error(_("Couldn't find package %s"),S);
417 }
418 else
419 {
420 if (!Action)
421 ioprintf(c1out,_("%s set to manually installed.\n"), Pkg.Name());
422 else
423 ioprintf(c1out,_("%s set to automatically installed.\n"),
424 Pkg.Name());
425
426 Cache->MarkAuto(Pkg,Action);
427 AutoMarkChanged++;
428 }
429 }
182a6a55
DK
430
431 _error->Notice(_("This command is deprecated. Please use 'apt-mark auto' and 'apt-mark manual' instead."));
432
d63a1458
JAK
433 if (AutoMarkChanged && ! _config->FindB("APT::Get::Simulate",false))
434 return Cache->writeStateFile(NULL);
435 return false;
436}
0a8e3465 437 /*}}}*/
0a8e3465
AL
438// DoDSelectUpgrade - Do an upgrade by following dselects selections /*{{{*/
439// ---------------------------------------------------------------------
440/* Follows dselect's selections */
65512241 441static bool DoDSelectUpgrade(CommandLine &)
0a8e3465
AL
442{
443 CacheFile Cache;
c37b9502 444 if (Cache.OpenForInstall() == false || Cache.CheckDeps() == false)
0a8e3465
AL
445 return false;
446
a4decc40
MV
447 pkgDepCache::ActionGroup group(Cache);
448
0a8e3465
AL
449 // Install everything with the install flag set
450 pkgCache::PkgIterator I = Cache->PkgBegin();
f7f0d6c7 451 for (;I.end() != true; ++I)
0a8e3465
AL
452 {
453 /* Install the package only if it is a new install, the autoupgrader
454 will deal with the rest */
455 if (I->SelectedState == pkgCache::State::Install)
456 Cache->MarkInstall(I,false);
457 }
458
459 /* Now install their deps too, if we do this above then order of
460 the status file is significant for | groups */
f7f0d6c7 461 for (I = Cache->PkgBegin();I.end() != true; ++I)
0a8e3465
AL
462 {
463 /* Install the package only if it is a new install, the autoupgrader
464 will deal with the rest */
465 if (I->SelectedState == pkgCache::State::Install)
2f45c76a 466 Cache->MarkInstall(I,true);
0a8e3465
AL
467 }
468
469 // Apply erasures now, they override everything else.
f7f0d6c7 470 for (I = Cache->PkgBegin();I.end() != true; ++I)
0a8e3465
AL
471 {
472 // Remove packages
473 if (I->SelectedState == pkgCache::State::DeInstall ||
474 I->SelectedState == pkgCache::State::Purge)
d556d1a1 475 Cache->MarkDelete(I,I->SelectedState == pkgCache::State::Purge);
0a8e3465
AL
476 }
477
2f45c76a 478 /* Resolve any problems that dselect created, allupgrade cannot handle
1e3f4083 479 such things. We do so quite aggressively too.. */
2f45c76a
AL
480 if (Cache->BrokenCount() != 0)
481 {
482 pkgProblemResolver Fix(Cache);
483
484 // Hold back held packages.
b2e465d6 485 if (_config->FindB("APT::Ignore-Hold",false) == false)
2f45c76a 486 {
f7f0d6c7 487 for (pkgCache::PkgIterator I = Cache->PkgBegin(); I.end() == false; ++I)
2f45c76a
AL
488 {
489 if (I->SelectedState == pkgCache::State::Hold)
490 {
491 Fix.Protect(I);
492 Cache->MarkKeep(I);
493 }
494 }
495 }
496
497 if (Fix.Resolve() == false)
498 {
421c8d10 499 ShowBroken(c1out,Cache,false);
2a7e07c7 500 return _error->Error(_("Internal error, problem resolver broke stuff"));
2f45c76a
AL
501 }
502 }
503
504 // Now upgrade everything
67caa2e6 505 if (APT::Upgrade::Upgrade(Cache, APT::Upgrade::FORBID_REMOVE_PACKAGES | APT::Upgrade::FORBID_INSTALL_NEW_PACKAGES) == false)
0a8e3465 506 {
421c8d10 507 ShowBroken(c1out,Cache,false);
2a7e07c7 508 return _error->Error(_("Internal error, problem resolver broke stuff"));
0a8e3465
AL
509 }
510
511 return InstallPackages(Cache,false);
512}
513 /*}}}*/
514// DoClean - Remove download archives /*{{{*/
515// ---------------------------------------------------------------------
516/* */
65512241 517static bool DoClean(CommandLine &)
0a8e3465 518{
657ecd4a 519 std::string const archivedir = _config->FindDir("Dir::Cache::archives");
20e6965a 520 std::string const listsdir = _config->FindDir("Dir::state::lists");
657ecd4a 521
8b067c22
AL
522 if (_config->FindB("APT::Get::Simulate") == true)
523 {
20e6965a
DK
524 std::string const pkgcache = _config->FindFile("Dir::cache::pkgcache");
525 std::string const srcpkgcache = _config->FindFile("Dir::cache::srcpkgcache");
657ecd4a 526 cout << "Del " << archivedir << "* " << archivedir << "partial/*"<< endl
20e6965a 527 << "Del " << listsdir << "partial/*" << endl
657ecd4a 528 << "Del " << pkgcache << " " << srcpkgcache << endl;
8b067c22
AL
529 return true;
530 }
20e6965a 531
7a1b1f8b 532 pkgAcquire Fetcher;
7e04a6bf 533 Fetcher.GetLock(archivedir);
657ecd4a
DK
534 Fetcher.Clean(archivedir);
535 Fetcher.Clean(archivedir + "partial/");
536
7e04a6bf 537 Fetcher.GetLock(listsdir);
20e6965a
DK
538 Fetcher.Clean(listsdir + "partial/");
539
8de79b68 540 pkgCacheFile::RemoveCaches();
657ecd4a 541
0a8e3465
AL
542 return true;
543}
544 /*}}}*/
1bc849af
AL
545// DoAutoClean - Smartly remove downloaded archives /*{{{*/
546// ---------------------------------------------------------------------
547/* This is similar to clean but it only purges things that cannot be
548 downloaded, that is old versions of cached packages. */
65a1e968
AL
549class LogCleaner : public pkgArchiveCleaner
550{
551 protected:
3b302846 552 virtual void Erase(const char *File,string Pkg,string Ver,struct stat &St) APT_OVERRIDE
65a1e968 553 {
4cc8bab0 554 c1out << "Del " << Pkg << " " << Ver << " [" << SizeToStr(St.st_size) << "B]" << endl;
c1e78ee5
AL
555
556 if (_config->FindB("APT::Get::Simulate") == false)
557 unlink(File);
65a1e968
AL
558 };
559};
560
65512241 561static bool DoAutoClean(CommandLine &)
1bc849af 562{
1b6d659c
AL
563 // Lock the archive directory
564 FileFd Lock;
565 if (_config->FindB("Debug::NoLocking",false) == false)
566 {
de24f8ce
MV
567 int lock_fd = GetLock(_config->FindDir("Dir::Cache::Archives") + "lock");
568 if (lock_fd < 0)
b2e465d6 569 return _error->Error(_("Unable to lock the download directory"));
de24f8ce 570 Lock.Fd(lock_fd);
1b6d659c
AL
571 }
572
1bc849af 573 CacheFile Cache;
2d11135a 574 if (Cache.Open() == false)
1bc849af
AL
575 return false;
576
65a1e968 577 LogCleaner Cleaner;
1bc849af
AL
578
579 return Cleaner.Go(_config->FindDir("Dir::Cache::archives"),*Cache) &&
580 Cleaner.Go(_config->FindDir("Dir::Cache::archives") + "partial/",*Cache);
581}
582 /*}}}*/
0e3e112e
MV
583// DoDownload - download a binary /*{{{*/
584// ---------------------------------------------------------------------
c3ccac92 585static bool DoDownload(CommandLine &CmdL)
0e3e112e
MV
586{
587 CacheFile Cache;
588 if (Cache.ReadOnlyOpen() == false)
589 return false;
d57f6084 590
353c135e 591 APT::CacheSetHelper helper;
8f3594c3 592 APT::VersionSet verset = APT::VersionSet::FromCommandLine(Cache,
43acd019 593 CmdL.FileList + 1, APT::CacheSetHelper::CANDIDATE, helper);
0e3e112e
MV
594
595 if (verset.empty() == true)
596 return false;
597
dfad5bee 598 AcqTextStatus Stat(std::cout, ScreenWidth,_config->FindI("quiet",0));
04a54261 599 pkgAcquire Fetcher(&Stat);
42d41ddb 600
0e3e112e
MV
601 pkgRecords Recs(Cache);
602 pkgSourceList *SrcList = Cache.GetSourceList();
567785b9 603
d57f6084
DK
604 // reuse the usual acquire methods for deb files, but don't drop them into
605 // the usual directories - keep everything in the current directory
606 std::vector<std::string> storefile(verset.size());
607 std::string const cwd = SafeGetCWD();
608 _config->Set("Dir::Cache::Archives", cwd);
609 int i = 0;
8f3594c3 610 for (APT::VersionSet::const_iterator Ver = verset.begin();
d57f6084 611 Ver != verset.end(); ++Ver, ++i)
0e3e112e 612 {
d57f6084 613 pkgAcquire::Item *I = new pkgAcqArchive(&Fetcher, SrcList, &Recs, *Ver, storefile[i]);
03aa0847
DK
614 if (storefile[i].empty())
615 continue;
d57f6084
DK
616 std::string const filename = cwd + flNotDir(storefile[i]);
617 storefile[i].assign(filename);
618 I->DestFile.assign(filename);
0e3e112e
MV
619 }
620
42d41ddb
DK
621 // Just print out the uris and exit if the --print-uris flag was used
622 if (_config->FindB("APT::Get::Print-URIs") == true)
623 {
624 pkgAcquire::UriIterator I = Fetcher.UriBegin();
f7f0d6c7 625 for (; I != Fetcher.UriEnd(); ++I)
b0f4b486 626 cout << '\'' << I->URI << "' " << flNotDir(I->Owner->DestFile) << ' ' <<
42d41ddb
DK
627 I->Owner->FileSize << ' ' << I->Owner->HashSum() << endl;
628 return true;
629 }
630
d57f6084
DK
631 if (_error->PendingError() == true || CheckAuth(Fetcher, false) == false)
632 return false;
633
634 bool Failed = false;
635 if (AcquireRun(Fetcher, 0, &Failed, NULL) == false)
636 return false;
637
638 // copy files in local sources to the current directory
639 for (pkgAcquire::ItemIterator I = Fetcher.ItemsBegin(); I != Fetcher.ItemsEnd(); ++I)
6ae22905
MV
640 {
641 std::string const filename = cwd + flNotDir((*I)->DestFile);
642 if ((*I)->Local == true &&
643 filename != (*I)->DestFile &&
644 (*I)->Status == pkgAcquire::Item::StatDone)
d57f6084 645 {
d57f6084
DK
646 std::ifstream src((*I)->DestFile.c_str(), std::ios::binary);
647 std::ofstream dst(filename.c_str(), std::ios::binary);
648 dst << src.rdbuf();
649 }
6ae22905 650 }
d57f6084 651 return Failed == false;
0e3e112e
MV
652}
653 /*}}}*/
0a8e3465
AL
654// DoCheck - Perform the check operation /*{{{*/
655// ---------------------------------------------------------------------
656/* Opening automatically checks the system, this command is mostly used
657 for debugging */
65512241 658static bool DoCheck(CommandLine &)
0a8e3465
AL
659{
660 CacheFile Cache;
661 Cache.Open();
2d11135a 662 Cache.CheckDeps();
0a8e3465
AL
663
664 return true;
665}
666 /*}}}*/
36375005
AL
667// DoSource - Fetch a source archive /*{{{*/
668// ---------------------------------------------------------------------
2d11135a 669/* Fetch souce packages */
fb0ee66e
AL
670struct DscFile
671{
672 string Package;
673 string Version;
674 string Dsc;
675};
676
c3ccac92 677static bool DoSource(CommandLine &CmdL)
36375005
AL
678{
679 CacheFile Cache;
2d11135a 680 if (Cache.Open(false) == false)
36375005
AL
681 return false;
682
2d11135a 683 if (CmdL.FileSize() <= 1)
b2e465d6 684 return _error->Error(_("Must specify at least one package to fetch source for"));
2d11135a 685
36375005 686 // Read the source list
1bb8cd67
DK
687 if (Cache.BuildSourceList() == false)
688 return false;
689 pkgSourceList *List = Cache.GetSourceList();
36375005
AL
690
691 // Create the text record parsers
1bb8cd67 692 pkgSrcRecords SrcRecs(*List);
36375005
AL
693 if (_error->PendingError() == true)
694 return false;
695
696 // Create the download object
dfad5bee 697 AcqTextStatus Stat(std::cout, ScreenWidth,_config->FindI("quiet",0));
04a54261 698 pkgAcquire Fetcher(&Stat);
fb0ee66e 699
98cc7fd2 700 std::unique_ptr<DscFile[]> Dsc(new DscFile[CmdL.FileSize()]);
36375005 701
092ae175
MV
702 // insert all downloaded uris into this set to avoid downloading them
703 // twice
704 set<string> queued;
8545b536
DK
705
706 // Diff only mode only fetches .diff files
707 bool const diffOnly = _config->FindB("APT::Get::Diff-Only", false);
708 // Tar only mode only fetches .tar files
709 bool const tarOnly = _config->FindB("APT::Get::Tar-Only", false);
710 // Dsc only mode only fetches .dsc files
711 bool const dscOnly = _config->FindB("APT::Get::Dsc-Only", false);
712
36375005 713 // Load the requestd sources into the fetcher
fb0ee66e 714 unsigned J = 0;
9112f777 715 std::vector<std::string> UntrustedList;
fb0ee66e 716 for (const char **I = CmdL.FileList + 1; *I != 0; I++, J++)
36375005
AL
717 {
718 string Src;
a221efc3 719 pkgSrcRecords::Parser *Last = FindSrc(*I,SrcRecs,Src,Cache);
6070a346 720 if (Last == 0) {
b2e465d6 721 return _error->Error(_("Unable to find a source package for %s"),Src.c_str());
6070a346 722 }
a3f1d60c
MV
723
724 if (Last->Index().IsTrusted() == false)
9112f777
DK
725 UntrustedList.push_back(Src);
726
3238423f
MV
727 string srec = Last->AsStr();
728 string::size_type pos = srec.find("\nVcs-");
774a6687 729 while (pos != string::npos)
3238423f
MV
730 {
731 pos += strlen("\nVcs-");
732 string vcs = srec.substr(pos,srec.find(":",pos)-pos);
774a6687
MV
733 if(vcs == "Browser")
734 {
735 pos = srec.find("\nVcs-", pos);
736 continue;
737 }
3238423f
MV
738 pos += vcs.length()+2;
739 string::size_type epos = srec.find("\n", pos);
7c4f1ca5 740 string const uri = srec.substr(pos,epos-pos);
b799e134 741 ioprintf(c1out, _("NOTICE: '%s' packaging is maintained in "
3238423f 742 "the '%s' version control system at:\n"
8756297c 743 "%s\n"),
3238423f 744 Src.c_str(), vcs.c_str(), uri.c_str());
7c4f1ca5
DK
745 std::string vcscmd;
746 if (vcs == "Bzr")
747 vcscmd = "bzr branch " + uri;
748 else if (vcs == "Git")
749 vcscmd = "git clone " + uri;
750
751 if (vcscmd.empty() == false)
752 ioprintf(c1out,_("Please use:\n%s\n"
753 "to retrieve the latest (possibly unreleased) "
754 "updates to the package.\n"),
755 vcscmd.c_str());
b799e134 756 break;
3238423f
MV
757 }
758
36375005 759 // Back track
3a2b39ee
DK
760 vector<pkgSrcRecords::File2> Lst;
761 if (Last->Files2(Lst) == false) {
36375005 762 return false;
6070a346 763 }
36375005
AL
764
765 // Load them into the fetcher
3a2b39ee 766 for (vector<pkgSrcRecords::File2>::const_iterator I = Lst.begin();
f7f0d6c7 767 I != Lst.end(); ++I)
36375005
AL
768 {
769 // Try to guess what sort of file it is we are getting.
b2e465d6 770 if (I->Type == "dsc")
fb0ee66e 771 {
fb0ee66e
AL
772 Dsc[J].Package = Last->Package();
773 Dsc[J].Version = Last->Version();
774 Dsc[J].Dsc = flNotDir(I->Path);
775 }
092ae175 776
8545b536
DK
777 // Handle the only options so that multiple can be used at once
778 if (diffOnly == true || tarOnly == true || dscOnly == true)
779 {
780 if ((diffOnly == true && I->Type == "diff") ||
781 (tarOnly == true && I->Type == "tar") ||
782 (dscOnly == true && I->Type == "dsc"))
783 ; // Fine, we want this file downloaded
784 else
785 continue;
786 }
1979e742 787
092ae175
MV
788 // don't download the same uri twice (should this be moved to
789 // the fetcher interface itself?)
790 if(queued.find(Last->Index().ArchiveURI(I->Path)) != queued.end())
791 continue;
792 queued.insert(Last->Index().ArchiveURI(I->Path));
cb6a2b3e 793
092ae175 794 // check if we have a file with that md5 sum already localy
1262d358
DK
795 std::string localFile = flNotDir(I->Path);
796 if (FileExists(localFile) == true)
797 if(I->Hashes.VerifyFile(localFile) == true)
092ae175 798 {
443cb67c 799 ioprintf(c1out,_("Skipping already downloaded file '%s'\n"),
1262d358 800 localFile.c_str());
092ae175
MV
801 continue;
802 }
1262d358
DK
803
804 // see if we have a hash (Acquire::ForceHash is the only way to have none)
b3501edb 805 if (I->Hashes.usable() == false && _config->FindB("APT::Get::AllowUnauthenticated",false) == false)
1262d358
DK
806 {
807 ioprintf(c1out, "Skipping download of file '%s' as requested hashsum is not available for authentication\n",
808 localFile.c_str());
809 continue;
092ae175
MV
810 }
811
b2e465d6 812 new pkgAcqFile(&Fetcher,Last->Index().ArchiveURI(I->Path),
d61960d9 813 I->Hashes, I->FileSize, Last->Index().SourceInfo(*Last,*I), Src);
36375005
AL
814 }
815 }
a3f1d60c 816
36375005 817 // Display statistics
3a882565
DK
818 unsigned long long FetchBytes = Fetcher.FetchNeeded();
819 unsigned long long FetchPBytes = Fetcher.PartialPresent();
820 unsigned long long DebBytes = Fetcher.TotalNeeded();
36375005 821
9c81f8de
DK
822 if (CheckFreeSpaceBeforeDownload(".", (FetchBytes - FetchPBytes)) == false)
823 return false;
824
36375005 825 // Number of bytes
36375005 826 if (DebBytes != FetchBytes)
4d8d8112
DK
827 //TRANSLATOR: The required space between number and unit is already included
828 // in the replacement strings, so %sB will be correctly translate in e.g. 1,5 MB
b2e465d6
AL
829 ioprintf(c1out,_("Need to get %sB/%sB of source archives.\n"),
830 SizeToStr(FetchBytes).c_str(),SizeToStr(DebBytes).c_str());
36375005 831 else
4d8d8112
DK
832 //TRANSLATOR: The required space between number and unit is already included
833 // in the replacement string, so %sB will be correctly translate in e.g. 1,5 MB
b2e465d6
AL
834 ioprintf(c1out,_("Need to get %sB of source archives.\n"),
835 SizeToStr(DebBytes).c_str());
836
2c0c53b3
AL
837 if (_config->FindB("APT::Get::Simulate",false) == true)
838 {
839 for (unsigned I = 0; I != J; I++)
db0db9fe 840 ioprintf(cout,_("Fetch source %s\n"),Dsc[I].Package.c_str());
2c0c53b3
AL
841 return true;
842 }
460601d5 843
36375005
AL
844 // Just print out the uris an exit if the --print-uris flag was used
845 if (_config->FindB("APT::Get::Print-URIs") == true)
846 {
847 pkgAcquire::UriIterator I = Fetcher.UriBegin();
f7f0d6c7 848 for (; I != Fetcher.UriEnd(); ++I)
36375005 849 cout << '\'' << I->URI << "' " << flNotDir(I->Owner->DestFile) << ' ' <<
495e5cb2 850 I->Owner->FileSize << ' ' << I->Owner->HashSum() << endl;
36375005
AL
851 return true;
852 }
36375005 853
460601d5 854 // check authentication status of the source as well
9112f777 855 if (UntrustedList.empty() == false && AuthPrompt(UntrustedList, false) == false)
460601d5
DK
856 return false;
857
866893a6 858 // Run it
fb0ee66e 859 bool Failed = false;
866893a6 860 if (AcquireRun(Fetcher, 0, &Failed, NULL) == false || Failed == true)
6070a346 861 {
b2e465d6 862 return _error->Error(_("Failed to fetch some archives."));
6070a346
DK
863 }
864
fb0ee66e 865 if (_config->FindB("APT::Get::Download-only",false) == true)
b2e465d6
AL
866 {
867 c1out << _("Download complete and in download only mode") << endl;
fb0ee66e 868 return true;
b2e465d6
AL
869 }
870
fb0ee66e 871 // Unpack the sources
54676e1a
AL
872 pid_t Process = ExecFork();
873
874 if (Process == 0)
fb0ee66e 875 {
827d04d3 876 bool const fixBroken = _config->FindB("APT::Get::Fix-Broken", false);
f7f0d6c7 877 for (unsigned I = 0; I != J; ++I)
fb0ee66e 878 {
b2e465d6 879 string Dir = Dsc[I].Package + '-' + Cache->VS().UpstreamVersion(Dsc[I].Version.c_str());
fb0ee66e 880
17c0e8e1
AL
881 // Diff only mode only fetches .diff files
882 if (_config->FindB("APT::Get::Diff-Only",false) == true ||
a3eaf954
AL
883 _config->FindB("APT::Get::Tar-Only",false) == true ||
884 Dsc[I].Dsc.empty() == true)
17c0e8e1 885 continue;
a3eaf954 886
54676e1a
AL
887 // See if the package is already unpacked
888 struct stat Stat;
827d04d3 889 if (fixBroken == false && stat(Dir.c_str(),&Stat) == 0 &&
54676e1a
AL
890 S_ISDIR(Stat.st_mode) != 0)
891 {
b2e465d6
AL
892 ioprintf(c0out ,_("Skipping unpack of already unpacked source in %s\n"),
893 Dir.c_str());
54676e1a
AL
894 }
895 else
896 {
897 // Call dpkg-source
c53cf70d
DK
898 std::string const sourceopts = _config->Find("DPkg::Source-Options", "-x");
899 std::string S;
900 strprintf(S, "%s %s %s",
54676e1a 901 _config->Find("Dir::Bin::dpkg-source","dpkg-source").c_str(),
c53cf70d
DK
902 sourceopts.c_str(), Dsc[I].Dsc.c_str());
903 if (system(S.c_str()) != 0)
54676e1a 904 {
c53cf70d
DK
905 fprintf(stderr, _("Unpack command '%s' failed.\n"), S.c_str());
906 fprintf(stderr, _("Check if the 'dpkg-dev' package is installed.\n"));
54676e1a 907 _exit(1);
c53cf70d 908 }
54676e1a 909 }
c53cf70d 910
54676e1a
AL
911 // Try to compile it with dpkg-buildpackage
912 if (_config->FindB("APT::Get::Compile",false) == true)
913 {
234675b7
DK
914 string buildopts = _config->Find("APT::Get::Host-Architecture");
915 if (buildopts.empty() == false)
c5102538 916 buildopts = "-a" + buildopts + " ";
ce7f128c
DK
917
918 // get all active build profiles
919 std::string const profiles = APT::Configuration::getBuildProfilesString();
920 if (profiles.empty() == false)
921 buildopts.append(" -P").append(profiles).append(" ");
922
234675b7
DK
923 buildopts.append(_config->Find("DPkg::Build-Options","-b -uc"));
924
54676e1a 925 // Call dpkg-buildpackage
c53cf70d
DK
926 std::string S;
927 strprintf(S, "cd %s && %s %s",
54676e1a
AL
928 Dir.c_str(),
929 _config->Find("Dir::Bin::dpkg-buildpackage","dpkg-buildpackage").c_str(),
234675b7 930 buildopts.c_str());
c53cf70d
DK
931
932 if (system(S.c_str()) != 0)
54676e1a 933 {
c53cf70d 934 fprintf(stderr, _("Build command '%s' failed.\n"), S.c_str());
54676e1a 935 _exit(1);
c53cf70d
DK
936 }
937 }
54676e1a 938 }
c53cf70d 939
54676e1a
AL
940 _exit(0);
941 }
3a4477a4 942
7c4f1ca5 943 return ExecWait(Process, "dpkg-source");
b2e465d6
AL
944}
945 /*}}}*/
946// DoBuildDep - Install/removes packages to satisfy build dependencies /*{{{*/
947// ---------------------------------------------------------------------
948/* This function will look at the build depends list of the given source
949 package and install the necessary packages to make it true, or fail. */
c3ccac92 950static bool DoBuildDep(CommandLine &CmdL)
b2e465d6
AL
951{
952 CacheFile Cache;
35180212
JAK
953
954 _config->Set("APT::Install-Recommends", false);
df53919b
JAK
955
956 bool WantLock = _config->FindB("APT::Get::Print-URIs", false) == false;
35180212 957
df53919b 958 if (Cache.Open(WantLock) == false)
b2e465d6
AL
959 return false;
960
961 if (CmdL.FileSize() <= 1)
962 return _error->Error(_("Must specify at least one package to check builddeps for"));
963
964 // Read the source list
1bb8cd67
DK
965 if (Cache.BuildSourceList() == false)
966 return false;
967 pkgSourceList *List = Cache.GetSourceList();
54676e1a 968
b2e465d6 969 // Create the text record parsers
1bb8cd67 970 pkgSrcRecords SrcRecs(*List);
b2e465d6
AL
971 if (_error->PendingError() == true)
972 return false;
973
234675b7
DK
974 bool StripMultiArch;
975 string hostArch = _config->Find("APT::Get::Host-Architecture");
976 if (hostArch.empty() == false)
977 {
978 std::vector<std::string> archs = APT::Configuration::getArchitectures();
979 if (std::find(archs.begin(), archs.end(), hostArch) == archs.end())
980 return _error->Error(_("No architecture information available for %s. See apt.conf(5) APT::Architectures for setup"), hostArch.c_str());
981 StripMultiArch = false;
982 }
983 else
984 StripMultiArch = true;
985
b2e465d6
AL
986 unsigned J = 0;
987 for (const char **I = CmdL.FileList + 1; *I != 0; I++, J++)
988 {
989 string Src;
feab34c5 990 pkgSrcRecords::Parser *Last = 0;
6c413b18 991 std::unique_ptr<pkgSrcRecords::Parser> LastOwner;
feab34c5 992
a5bb5e1e
MV
993 // an unpacked debian source tree
994 using APT::String::Startswith;
995 if ((Startswith(*I, "./") || Startswith(*I, "/")) &&
996 DirectoryExists(*I))
77da39b9 997 {
a5bb5e1e 998 ioprintf(c1out, _("Note, using directory '%s' to get the build dependencies\n"), *I);
77da39b9 999 // FIXME: how can we make this more elegant?
463c8d80 1000 std::string TypeName = "Debian control file";
77da39b9
MV
1001 pkgIndexFile::Type *Type = pkgIndexFile::Type::GetType(TypeName.c_str());
1002 if(Type != NULL)
6c413b18 1003 LastOwner.reset(Last = Type->CreateSrcPkgParser(*I));
77da39b9 1004 }
a49e7948 1005 // if its a local file (e.g. .dsc) use this
77da39b9 1006 else if (FileExists(*I))
feab34c5 1007 {
a5bb5e1e
MV
1008 ioprintf(c1out, _("Note, using file '%s' to get the build dependencies\n"), *I);
1009
a49e7948 1010 // see if we can get a parser for this pkgIndexFile type
463c8d80 1011 string TypeName = "Debian " + flExtension(*I) + " file";
a49e7948
MV
1012 pkgIndexFile::Type *Type = pkgIndexFile::Type::GetType(TypeName.c_str());
1013 if(Type != NULL)
6c413b18 1014 LastOwner.reset(Last = Type->CreateSrcPkgParser(*I));
feab34c5 1015 } else {
a49e7948 1016 // normal case, search the cache for the source file
765190e4 1017 Last = FindSrc(*I,SrcRecs,Src,Cache);
feab34c5 1018 }
a49e7948 1019
b2e465d6
AL
1020 if (Last == 0)
1021 return _error->Error(_("Unable to find a source package for %s"),Src.c_str());
1022
1023 // Process the build-dependencies
1024 vector<pkgSrcRecords::Parser::BuildDepRec> BuildDeps;
65f99834
DK
1025 // FIXME: Can't specify architecture to use for [wildcard] matching, so switch default arch temporary
1026 if (hostArch.empty() == false)
1027 {
1028 std::string nativeArch = _config->Find("APT::Architecture");
1029 _config->Set("APT::Architecture", hostArch);
1030 bool Success = Last->BuildDepends(BuildDeps, _config->FindB("APT::Get::Arch-Only", false), StripMultiArch);
1031 _config->Set("APT::Architecture", nativeArch);
1032 if (Success == false)
1033 return _error->Error(_("Unable to get build-dependency information for %s"),Src.c_str());
1034 }
1035 else if (Last->BuildDepends(BuildDeps, _config->FindB("APT::Get::Arch-Only", false), StripMultiArch) == false)
1036 return _error->Error(_("Unable to get build-dependency information for %s"),Src.c_str());
feab34c5 1037
7d6f9f8f
AL
1038 // Also ensure that build-essential packages are present
1039 Configuration::Item const *Opts = _config->Tree("APT::Build-Essential");
1040 if (Opts)
1041 Opts = Opts->Child;
1042 for (; Opts; Opts = Opts->Next)
1043 {
1044 if (Opts->Value.empty() == true)
1045 continue;
1046
1047 pkgSrcRecords::Parser::BuildDepRec rec;
1048 rec.Package = Opts->Value;
1049 rec.Type = pkgSrcRecords::Parser::BuildDependIndep;
1050 rec.Op = 0;
58d76831 1051 BuildDeps.push_back(rec);
7d6f9f8f
AL
1052 }
1053
f7f0d6c7 1054 if (BuildDeps.empty() == true)
b2e465d6
AL
1055 {
1056 ioprintf(c1out,_("%s has no build depends.\n"),Src.c_str());
1057 continue;
1058 }
234675b7 1059
b2e465d6 1060 // Install the requested packages
b2e465d6
AL
1061 vector <pkgSrcRecords::Parser::BuildDepRec>::iterator D;
1062 pkgProblemResolver Fix(Cache);
58d76831 1063 bool skipAlternatives = false; // skip remaining alternatives in an or group
f7f0d6c7 1064 for (D = BuildDeps.begin(); D != BuildDeps.end(); ++D)
b2e465d6 1065 {
58d76831
AL
1066 bool hasAlternatives = (((*D).Op & pkgCache::Dep::Or) == pkgCache::Dep::Or);
1067
1068 if (skipAlternatives == true)
1069 {
3fdb6f83
DK
1070 /*
1071 * if there are alternatives, we've already picked one, so skip
1072 * the rest
1073 *
1074 * TODO: this means that if there's a build-dep on A|B and B is
1075 * installed, we'll still try to install A; more importantly,
1076 * if A is currently broken, we cannot go back and try B. To fix
1077 * this would require we do a Resolve cycle for each package we
1078 * add to the install list. Ugh
1079 */
58d76831
AL
1080 if (!hasAlternatives)
1081 skipAlternatives = false; // end of or group
1082 continue;
1083 }
1084
aa2d22be
AL
1085 if ((*D).Type == pkgSrcRecords::Parser::BuildConflict ||
1086 (*D).Type == pkgSrcRecords::Parser::BuildConflictIndep)
d3fc0061 1087 {
e3a86238 1088 pkgCache::GrpIterator Grp = Cache->FindGrp((*D).Package);
aa2d22be 1089 // Build-conflicts on unknown packages are silently ignored
e3a86238 1090 if (Grp.end() == true)
aa2d22be
AL
1091 continue;
1092
e3a86238
DK
1093 for (pkgCache::PkgIterator Pkg = Grp.PackageList(); Pkg.end() == false; Pkg = Grp.NextPkg(Pkg))
1094 {
1095 pkgCache::VerIterator IV = (*Cache)[Pkg].InstVerIter(*Cache);
1096 /*
1097 * Remove if we have an installed version that satisfies the
1098 * version criteria
1099 */
1100 if (IV.end() == false &&
1101 Cache->VS().CheckDep(IV.VerStr(),(*D).Op,(*D).Version.c_str()) == true)
1102 TryToInstallBuildDep(Pkg,Cache,Fix,true,false);
1103 }
d3fc0061 1104 }
aa2d22be
AL
1105 else // BuildDep || BuildDepIndep
1106 {
58d76831
AL
1107 if (_config->FindB("Debug::BuildDeps",false) == true)
1108 cout << "Looking for " << (*D).Package << "...\n";
1109
234675b7
DK
1110 pkgCache::PkgIterator Pkg;
1111
1112 // Cross-Building?
c307a4f0 1113 if (StripMultiArch == false && D->Type != pkgSrcRecords::Parser::BuildDependIndep)
234675b7
DK
1114 {
1115 size_t const colon = D->Package.find(":");
666faa35
DK
1116 if (colon != string::npos)
1117 {
1118 if (strcmp(D->Package.c_str() + colon, ":any") == 0 || strcmp(D->Package.c_str() + colon, ":native") == 0)
1119 Pkg = Cache->FindPkg(D->Package.substr(0,colon));
1120 else
1121 Pkg = Cache->FindPkg(D->Package);
1122 }
234675b7 1123 else
666faa35 1124 Pkg = Cache->FindPkg(D->Package, hostArch);
234675b7 1125
234675b7 1126 // a bad version either is invalid or doesn't satify dependency
d5dea0be
DK
1127 #define BADVER(Ver) (Ver.end() == true || \
1128 (D->Version.empty() == false && \
1129 Cache->VS().CheckDep(Ver.VerStr(),D->Op,D->Version.c_str()) == false))
234675b7 1130
d5dea0be 1131 APT::VersionList verlist;
234675b7
DK
1132 if (Pkg.end() == false)
1133 {
d5dea0be
DK
1134 pkgCache::VerIterator Ver = (*Cache)[Pkg].InstVerIter(*Cache);
1135 if (BADVER(Ver) == false)
1136 verlist.insert(Ver);
1137 Ver = (*Cache)[Pkg].CandidateVerIter(*Cache);
1138 if (BADVER(Ver) == false)
1139 verlist.insert(Ver);
234675b7 1140 }
d5dea0be 1141 if (verlist.empty() == true)
234675b7 1142 {
666faa35
DK
1143 pkgCache::PkgIterator BuildPkg = Cache->FindPkg(D->Package, "native");
1144 if (BuildPkg.end() == false && Pkg != BuildPkg)
234675b7 1145 {
666faa35 1146 pkgCache::VerIterator Ver = (*Cache)[BuildPkg].InstVerIter(*Cache);
d5dea0be
DK
1147 if (BADVER(Ver) == false)
1148 verlist.insert(Ver);
666faa35 1149 Ver = (*Cache)[BuildPkg].CandidateVerIter(*Cache);
d5dea0be
DK
1150 if (BADVER(Ver) == false)
1151 verlist.insert(Ver);
234675b7
DK
1152 }
1153 }
d5dea0be
DK
1154 #undef BADVER
1155
1156 string forbidden;
1157 // We need to decide if host or build arch, so find a version we can look at
1158 APT::VersionList::const_iterator Ver = verlist.begin();
1159 for (; Ver != verlist.end(); ++Ver)
234675b7 1160 {
d5dea0be 1161 forbidden.clear();
22df31be 1162 if (Ver->MultiArch == pkgCache::Version::No || Ver->MultiArch == pkgCache::Version::All)
737c7a7b
SL
1163 {
1164 if (colon == string::npos)
737c7a7b 1165 Pkg = Ver.ParentPkg().Group().FindPkg(hostArch);
a9a370d9 1166 else if (strcmp(D->Package.c_str() + colon, ":any") == 0)
22df31be 1167 forbidden = "Multi-Arch: no";
666faa35
DK
1168 else if (strcmp(D->Package.c_str() + colon, ":native") == 0)
1169 Pkg = Ver.ParentPkg().Group().FindPkg("native");
737c7a7b 1170 }
234675b7
DK
1171 else if (Ver->MultiArch == pkgCache::Version::Same)
1172 {
737c7a7b 1173 if (colon == string::npos)
234675b7
DK
1174 Pkg = Ver.ParentPkg().Group().FindPkg(hostArch);
1175 else if (strcmp(D->Package.c_str() + colon, ":any") == 0)
1176 forbidden = "Multi-Arch: same";
666faa35
DK
1177 else if (strcmp(D->Package.c_str() + colon, ":native") == 0)
1178 Pkg = Ver.ParentPkg().Group().FindPkg("native");
234675b7 1179 }
2a2a7ef4 1180 else if ((Ver->MultiArch & pkgCache::Version::Foreign) == pkgCache::Version::Foreign)
234675b7 1181 {
666faa35
DK
1182 if (colon == string::npos)
1183 Pkg = Ver.ParentPkg().Group().FindPkg("native");
1184 else if (strcmp(D->Package.c_str() + colon, ":any") == 0 ||
1185 strcmp(D->Package.c_str() + colon, ":native") == 0)
234675b7
DK
1186 forbidden = "Multi-Arch: foreign";
1187 }
2a2a7ef4 1188 else if ((Ver->MultiArch & pkgCache::Version::Allowed) == pkgCache::Version::Allowed)
234675b7
DK
1189 {
1190 if (colon == string::npos)
1191 Pkg = Ver.ParentPkg().Group().FindPkg(hostArch);
1192 else if (strcmp(D->Package.c_str() + colon, ":any") == 0)
1193 {
1194 // prefer any installed over preferred non-installed architectures
1195 pkgCache::GrpIterator Grp = Ver.ParentPkg().Group();
1196 // we don't check for version here as we are better of with upgrading than remove and install
1197 for (Pkg = Grp.PackageList(); Pkg.end() == false; Pkg = Grp.NextPkg(Pkg))
1198 if (Pkg.CurrentVer().end() == false)
1199 break;
1200 if (Pkg.end() == true)
1201 Pkg = Grp.FindPreferredPkg(true);
1202 }
666faa35
DK
1203 else if (strcmp(D->Package.c_str() + colon, ":native") == 0)
1204 Pkg = Ver.ParentPkg().Group().FindPkg("native");
234675b7 1205 }
d5dea0be 1206
234675b7
DK
1207 if (forbidden.empty() == false)
1208 {
1209 if (_config->FindB("Debug::BuildDeps",false) == true)
d5dea0be
DK
1210 cout << D->Package.substr(colon, string::npos) << " is not allowed from " << forbidden << " package " << (*D).Package << " (" << Ver.VerStr() << ")" << endl;
1211 continue;
1212 }
1213
1214 //we found a good version
1215 break;
1216 }
1217 if (Ver == verlist.end())
1218 {
1219 if (_config->FindB("Debug::BuildDeps",false) == true)
1220 cout << " No multiarch info as we have no satisfying installed nor candidate for " << D->Package << " on build or host arch" << endl;
1221
1222 if (forbidden.empty() == false)
1223 {
234675b7
DK
1224 if (hasAlternatives)
1225 continue;
1226 return _error->Error(_("%s dependency for %s can't be satisfied "
1227 "because %s is not allowed on '%s' packages"),
1228 Last->BuildDepType(D->Type), Src.c_str(),
a9a370d9 1229 D->Package.c_str(), forbidden.c_str());
234675b7
DK
1230 }
1231 }
234675b7
DK
1232 }
1233 else
1234 Pkg = Cache->FindPkg(D->Package);
1235
727d8712 1236 if (Pkg.end() == true || (Pkg->VersionList == 0 && Pkg->ProvidesList == 0))
aa2d22be 1237 {
58d76831
AL
1238 if (_config->FindB("Debug::BuildDeps",false) == true)
1239 cout << " (not found)" << (*D).Package << endl;
1240
1241 if (hasAlternatives)
1242 continue;
1243
1244 return _error->Error(_("%s dependency for %s cannot be satisfied "
1245 "because the package %s cannot be found"),
1246 Last->BuildDepType((*D).Type),Src.c_str(),
1247 (*D).Package.c_str());
aa2d22be
AL
1248 }
1249
e5002e30 1250 pkgCache::VerIterator IV = (*Cache)[Pkg].InstVerIter(*Cache);
91bee655
DK
1251 if (IV.end() == false)
1252 {
1253 if (_config->FindB("Debug::BuildDeps",false) == true)
1254 cout << " Is installed\n";
e5002e30 1255
91bee655
DK
1256 if (D->Version.empty() == true ||
1257 Cache->VS().CheckDep(IV.VerStr(),(*D).Op,(*D).Version.c_str()) == true)
1258 {
1259 skipAlternatives = hasAlternatives;
1260 continue;
1261 }
cfa5659c 1262
91bee655
DK
1263 if (_config->FindB("Debug::BuildDeps",false) == true)
1264 cout << " ...but the installed version doesn't meet the version requirement\n";
58d76831 1265
91bee655
DK
1266 if (((*D).Op & pkgCache::Dep::LessEq) == pkgCache::Dep::LessEq)
1267 return _error->Error(_("Failed to satisfy %s dependency for %s: Installed package %s is too new"),
1268 Last->BuildDepType((*D).Type), Src.c_str(), Pkg.FullName(true).c_str());
1269 }
58d76831 1270
fe027879
DK
1271 // Only consider virtual packages if there is no versioned dependency
1272 if ((*D).Version.empty() == true)
1273 {
1274 /*
1275 * If this is a virtual package, we need to check the list of
1276 * packages that provide it and see if any of those are
1277 * installed
1278 */
1279 pkgCache::PrvIterator Prv = Pkg.ProvidesList();
f7f0d6c7 1280 for (; Prv.end() != true; ++Prv)
fe027879
DK
1281 {
1282 if (_config->FindB("Debug::BuildDeps",false) == true)
1283 cout << " Checking provider " << Prv.OwnerPkg().FullName() << endl;
58d76831 1284
fe027879
DK
1285 if ((*Cache)[Prv.OwnerPkg()].InstVerIter(*Cache).end() == false)
1286 break;
1287 }
58d76831 1288
fe027879
DK
1289 if (Prv.end() == false)
1290 {
1291 if (_config->FindB("Debug::BuildDeps",false) == true)
1292 cout << " Is provided by installed package " << Prv.OwnerPkg().FullName() << endl;
1293 skipAlternatives = hasAlternatives;
1294 continue;
1295 }
1296 }
2baf02ca
DK
1297 else // versioned dependency
1298 {
1299 pkgCache::VerIterator CV = (*Cache)[Pkg].CandidateVerIter(*Cache);
1300 if (CV.end() == true ||
1301 Cache->VS().CheckDep(CV.VerStr(),(*D).Op,(*D).Version.c_str()) == false)
1302 {
1303 if (hasAlternatives)
1304 continue;
1305 else if (CV.end() == false)
1306 return _error->Error(_("%s dependency for %s cannot be satisfied "
1307 "because candidate version of package %s "
1308 "can't satisfy version requirements"),
1309 Last->BuildDepType(D->Type), Src.c_str(),
1310 D->Package.c_str());
1311 else
1312 return _error->Error(_("%s dependency for %s cannot be satisfied "
1313 "because package %s has no candidate version"),
1314 Last->BuildDepType(D->Type), Src.c_str(),
1315 D->Package.c_str());
1316 }
1317 }
58d76831 1318
f1f874bd 1319 if (TryToInstallBuildDep(Pkg,Cache,Fix,false,false,false) == true)
58d76831
AL
1320 {
1321 // We successfully installed something; skip remaining alternatives
1322 skipAlternatives = hasAlternatives;
d59228b0 1323 if(_config->FindB("APT::Get::Build-Dep-Automatic", false) == true)
496a05c6 1324 Cache->MarkAuto(Pkg, true);
58d76831
AL
1325 continue;
1326 }
1327 else if (hasAlternatives)
1328 {
1329 if (_config->FindB("Debug::BuildDeps",false) == true)
1330 cout << " Unsatisfiable, trying alternatives\n";
1331 continue;
1332 }
1333 else
1334 {
1335 return _error->Error(_("Failed to satisfy %s dependency for %s: %s"),
1336 Last->BuildDepType((*D).Type),
1337 Src.c_str(),
1338 (*D).Package.c_str());
1339 }
b2e465d6
AL
1340 }
1341 }
f3c736f9 1342
b2e465d6
AL
1343 if (Fix.Resolve(true) == false)
1344 _error->Discard();
1345
1346 // Now we check the state of the packages,
1347 if (Cache->BrokenCount() != 0)
0dae8ac5
DK
1348 {
1349 ShowBroken(cout, Cache, false);
1350 return _error->Error(_("Build-dependencies for %s could not be satisfied."),*I);
1351 }
b2e465d6
AL
1352 }
1353
1354 if (InstallPackages(Cache, false, true) == false)
1355 return _error->Error(_("Failed to process build dependencies"));
36375005
AL
1356 return true;
1357}
1358 /*}}}*/
a4c40430 1359// DoChangelog - Get changelog from the command line /*{{{*/
c3ccac92 1360static bool DoChangelog(CommandLine &CmdL)
a4c40430
MV
1361{
1362 CacheFile Cache;
1363 if (Cache.ReadOnlyOpen() == false)
1364 return false;
d56e2917 1365
353c135e 1366 APT::CacheSetHelper helper;
c4cca791 1367 APT::VersionList verset = APT::VersionList::FromCommandLine(Cache,
43acd019 1368 CmdL.FileList + 1, APT::CacheSetHelper::CANDIDATE, helper);
72dd5bec
DK
1369 if (verset.empty() == true)
1370 return false;
a4c40430 1371 pkgAcquire Fetcher;
d56e2917
DK
1372 AcqTextStatus Stat(std::cout, ScreenWidth,_config->FindI("quiet",0));
1373 Fetcher.SetLog(&Stat);
fcb144b9 1374
d56e2917
DK
1375 bool const downOnly = _config->FindB("APT::Get::Download-Only", false);
1376 bool const printOnly = _config->FindB("APT::Get::Print-URIs", false);
1377
1378 for (APT::VersionList::const_iterator Ver = verset.begin();
1379 Ver != verset.end();
1380 ++Ver)
a98b6615 1381 {
d56e2917
DK
1382 if (printOnly)
1383 new pkgAcqChangelog(&Fetcher, Ver, "/dev/null");
1384 else if (downOnly)
1385 new pkgAcqChangelog(&Fetcher, Ver, ".");
1386 else
1387 new pkgAcqChangelog(&Fetcher, Ver);
a98b6615 1388 }
fcb144b9 1389
d56e2917
DK
1390 if (printOnly == false)
1391 {
d56e2917
DK
1392 bool Failed = false;
1393 if (AcquireRun(Fetcher, 0, &Failed, NULL) == false || Failed == true)
1394 return false;
1395 }
72dd5bec 1396
d56e2917 1397 if (downOnly == false || printOnly == true)
72dd5bec 1398 {
d56e2917
DK
1399 bool Failed = false;
1400 for (pkgAcquire::ItemIterator I = Fetcher.ItemsBegin(); I != Fetcher.ItemsEnd(); ++I)
03aa0847 1401 {
d56e2917 1402 if (printOnly)
03aa0847 1403 {
d56e2917
DK
1404 if ((*I)->ErrorText.empty() == false)
1405 {
1406 Failed = true;
1407 _error->Error("%s", (*I)->ErrorText.c_str());
1408 }
1409 else
1410 cout << '\'' << (*I)->DescURI() << "' " << flNotDir((*I)->DestFile) << std::endl;
03aa0847 1411 }
d56e2917
DK
1412 else
1413 DisplayFileInPager((*I)->DestFile);
03aa0847 1414 }
d56e2917 1415 return Failed == false;
18ae8b29 1416 }
72dd5bec 1417
4a6fe09c 1418 return true;
a4c40430
MV
1419}
1420 /*}}}*/
c2a4a8dd 1421// DoIndexTargets - Lists all IndexTargets /*{{{*/
8881b11e
DK
1422static std::string format_key(std::string key)
1423{
1424 // deb822 is case-insensitive, but the human eye prefers candy
1425 std::transform(key.begin(), key.end(), key.begin(), ::tolower);
1426 key[0] = ::toupper(key[0]);
1427 size_t found = key.find("_uri");
1428 if (found != std::string::npos)
1429 key.replace(found, 4, "-URI");
1430 while ((found = key.find('_')) != std::string::npos)
1431 {
1432 key[found] = '-';
1433 key[found + 1] = ::toupper(key[found + 1]);
1434 }
1435 return key;
1436}
c2a4a8dd 1437static bool DoIndexTargets(CommandLine &CmdL)
8881b11e
DK
1438{
1439 pkgCacheFile CacheFile;
1440 pkgSourceList *SrcList = CacheFile.GetSourceList();
1441
1442 if (SrcList == NULL)
1443 return false;
1444
c2a4a8dd
DK
1445 std::string const Format = _config->Find("APT::Get::IndexTargets::Format");
1446 bool const ReleaseInfo = _config->FindB("APT::Get::IndexTargets::ReleaseInfo", true);
8881b11e
DK
1447 bool Filtered = CmdL.FileSize() > 1;
1448 for (pkgSourceList::const_iterator S = SrcList->begin(); S != SrcList->end(); ++S)
1449 {
1450 std::vector<IndexTarget> const targets = (*S)->GetIndexTargets();
1451 std::map<std::string, string> AddOptions;
3fd89e62
DK
1452 if (ReleaseInfo)
1453 {
1454 AddOptions.insert(std::make_pair("TRUSTED", ((*S)->IsTrusted() ? "yes" : "no")));
1455 pkgCache &Cache = *CacheFile.GetPkgCache();
1456 pkgCache::RlsFileIterator const RlsFile = (*S)->FindInCache(Cache, false);
1457 if (RlsFile.end())
1458 continue;
1459#define APT_RELEASE(X,Y) if (RlsFile.Y() != NULL) AddOptions.insert(std::make_pair(X, RlsFile.Y()))
1460 APT_RELEASE("CODENAME", Codename);
1461 APT_RELEASE("SUITE", Archive);
1462 APT_RELEASE("VERSION", Version);
1463 APT_RELEASE("ORIGIN", Origin);
1464 APT_RELEASE("LABEL", Label);
1465#undef APT_RELEASE
1466 }
8881b11e
DK
1467
1468 for (std::vector<IndexTarget>::const_iterator T = targets.begin(); T != targets.end(); ++T)
1469 {
3fd89e62
DK
1470 std::string filename = T->Option(ReleaseInfo ? IndexTarget::EXISTING_FILENAME : IndexTarget::FILENAME);
1471 if (filename.empty())
1472 continue;
1473
8881b11e
DK
1474 std::ostringstream stanza;
1475 if (Filtered || Format.empty())
1476 {
1477 stanza << "MetaKey: " << T->MetaKey << "\n"
1478 << "ShortDesc: " << T->ShortDesc << "\n"
1479 << "Description: " << T->Description << "\n"
1480 << "URI: " << T->URI << "\n"
3fd89e62 1481 << "Filename: " << filename << "\n"
d7a51997
DK
1482 << "Optional: " << (T->IsOptional ? "yes" : "no") << "\n"
1483 << "KeepCompressed: " << (T->KeepCompressed ? "yes" : "no") << "\n";
8881b11e
DK
1484 for (std::map<std::string,std::string>::const_iterator O = AddOptions.begin(); O != AddOptions.end(); ++O)
1485 stanza << format_key(O->first) << ": " << O->second << "\n";
1486 for (std::map<std::string,std::string>::const_iterator O = T->Options.begin(); O != T->Options.end(); ++O)
1a3a14ac
DK
1487 {
1488 if (O->first == "PDIFFS")
1489 stanza << "PDiffs: " << O->second << "\n";
d7a51997
DK
1490 else if (O->first == "COMPRESSIONTYPES")
1491 stanza << "CompressionTypes: " << O->second << "\n";
9adb9778
DK
1492 else if (O->first == "DEFAULTENABLED")
1493 stanza << "DefaultEnabled: " << O->second << "\n";
1a3a14ac
DK
1494 else
1495 stanza << format_key(O->first) << ": " << O->second << "\n";
1496 }
8881b11e
DK
1497 stanza << "\n";
1498
1499 if (Filtered)
1500 {
1501 // that is a bit crude, but good enough for now
1502 bool found = true;
1503 std::string haystack = std::string("\n") + stanza.str() + "\n";
1504 std::transform(haystack.begin(), haystack.end(), haystack.begin(), ::tolower);
1505 size_t const filesize = CmdL.FileSize() - 1;
1506 for (size_t i = 0; i != filesize; ++i)
1507 {
1508 std::string needle = std::string("\n") + CmdL.FileList[i + 1] + "\n";
1509 std::transform(needle.begin(), needle.end(), needle.begin(), ::tolower);
1510 if (haystack.find(needle) != std::string::npos)
1511 continue;
1512 found = false;
1513 break;
1514 }
1515 if (found == false)
1516 continue;
1517 }
1518 }
1519
1520 if (Format.empty())
1521 cout << stanza.str();
1522 else
1523 {
3fd89e62
DK
1524 std::string out = SubstVar(Format, "$(FILENAME)", filename);
1525 out = T->Format(out);
8881b11e
DK
1526 for (std::map<std::string,std::string>::const_iterator O = AddOptions.begin(); O != AddOptions.end(); ++O)
1527 out = SubstVar(out, std::string("$(") + O->first + ")", O->second);
1528 cout << out << std::endl;
1529 }
1530 }
1531 }
1532
1533 return true;
1534}
1535 /*}}}*/
0a8e3465
AL
1536// ShowHelp - Show a help screen /*{{{*/
1537// ---------------------------------------------------------------------
1538/* */
65512241 1539static bool ShowHelp(CommandLine &)
0a8e3465 1540{
249aec3b
JB
1541 ioprintf(cout, "%s %s (%s)\n", PACKAGE, PACKAGE_VERSION, COMMON_ARCH);
1542
04aa15a8 1543 if (_config->FindB("version") == true)
b2e465d6 1544 {
db0db9fe 1545 cout << _("Supported modules:") << endl;
249aec3b 1546
b2e465d6
AL
1547 for (unsigned I = 0; I != pkgVersioningSystem::GlobalListLen; I++)
1548 {
1549 pkgVersioningSystem *VS = pkgVersioningSystem::GlobalList[I];
1550 if (_system != 0 && _system->VS == VS)
1551 cout << '*';
1552 else
1553 cout << ' ';
1554 cout << "Ver: " << VS->Label << endl;
249aec3b 1555
b2e465d6
AL
1556 /* Print out all the packaging systems that will work with
1557 this VS */
1558 for (unsigned J = 0; J != pkgSystem::GlobalListLen; J++)
1559 {
1560 pkgSystem *Sys = pkgSystem::GlobalList[J];
1561 if (_system == Sys)
1562 cout << '*';
1563 else
1564 cout << ' ';
1565 if (Sys->VS->TestCompatibility(*VS) == true)
1566 cout << "Pkg: " << Sys->Label << " (Priority " << Sys->Score(*_config) << ")" << endl;
1567 }
1568 }
1569
1570 for (unsigned I = 0; I != pkgSourceList::Type::GlobalListLen; I++)
1571 {
1572 pkgSourceList::Type *Type = pkgSourceList::Type::GlobalList[I];
1573 cout << " S.L: '" << Type->Name << "' " << Type->Label << endl;
1574 }
1575
1576 for (unsigned I = 0; I != pkgIndexFile::Type::GlobalListLen; I++)
1577 {
1578 pkgIndexFile::Type *Type = pkgIndexFile::Type::GlobalList[I];
1579 cout << " Idx: " << Type->Label << endl;
1580 }
1581
1582 return true;
1583 }
1584
1585 cout <<
1586 _("Usage: apt-get [options] command\n"
1587 " apt-get [options] install|remove pkg1 [pkg2 ...]\n"
1588 " apt-get [options] source pkg1 [pkg2 ...]\n"
1589 "\n"
1590 "apt-get is a simple command line interface for downloading and\n"
1591 "installing packages. The most frequently used commands are update\n"
1592 "and install.\n"
1593 "\n"
1594 "Commands:\n"
1595 " update - Retrieve new lists of packages\n"
1596 " upgrade - Perform an upgrade\n"
1597 " install - Install new packages (pkg is libc6 not libc6.deb)\n"
1598 " remove - Remove packages\n"
12bffed7 1599 " autoremove - Remove automatically all unused packages\n"
73fc19d0 1600 " purge - Remove packages and config files\n"
b2e465d6
AL
1601 " source - Download source archives\n"
1602 " build-dep - Configure build-dependencies for source packages\n"
1603 " dist-upgrade - Distribution upgrade, see apt-get(8)\n"
1604 " dselect-upgrade - Follow dselect selections\n"
1605 " clean - Erase downloaded archive files\n"
1606 " autoclean - Erase old downloaded archive files\n"
1607 " check - Verify that there are no broken dependencies\n"
5f967f2d
MV
1608 " changelog - Download and display the changelog for the given package\n"
1609 " download - Download the binary package into the current directory\n"
b2e465d6
AL
1610 "\n"
1611 "Options:\n"
1612 " -h This help text.\n"
1613 " -q Loggable output - no progress indicator\n"
1614 " -qq No output except for errors\n"
1615 " -d Download only - do NOT install or unpack archives\n"
1616 " -s No-act. Perform ordering simulation\n"
1617 " -y Assume Yes to all queries and do not prompt\n"
0748d509 1618 " -f Attempt to correct a system with broken dependencies in place\n"
b2e465d6
AL
1619 " -m Attempt to continue if archives are unlocatable\n"
1620 " -u Show a list of upgraded packages as well\n"
1621 " -b Build the source package after fetching it\n"
ac625538 1622 " -V Show verbose version numbers\n"
b2e465d6 1623 " -c=? Read this configuration file\n"
a2884e32 1624 " -o=? Set an arbitrary configuration option, eg -o dir::cache=/tmp\n"
b2e465d6
AL
1625 "See the apt-get(8), sources.list(5) and apt.conf(5) manual\n"
1626 "pages for more information and options.\n"
1627 " This APT has Super Cow Powers.\n");
1628 return true;
d7827aca
AL
1629}
1630 /*}}}*/
92fcbfc1 1631int main(int argc,const char *argv[]) /*{{{*/
0a8e3465 1632{
83d89a9f
AL
1633 CommandLine::Dispatch Cmds[] = {{"update",&DoUpdate},
1634 {"upgrade",&DoUpgrade},
1635 {"install",&DoInstall},
1636 {"remove",&DoInstall},
24401c09 1637 {"purge",&DoInstall},
74a05226 1638 {"autoremove",&DoInstall},
f66738d7 1639 {"auto-remove",&DoInstall},
d63a1458
JAK
1640 {"markauto",&DoMarkAuto},
1641 {"unmarkauto",&DoMarkAuto},
83d89a9f 1642 {"dist-upgrade",&DoDistUpgrade},
5b1997c0 1643 {"full-upgrade",&DoDistUpgrade},
83d89a9f 1644 {"dselect-upgrade",&DoDSelectUpgrade},
b2e465d6 1645 {"build-dep",&DoBuildDep},
83d89a9f 1646 {"clean",&DoClean},
1bc849af 1647 {"autoclean",&DoAutoClean},
f66738d7 1648 {"auto-clean",&DoAutoClean},
83d89a9f 1649 {"check",&DoCheck},
67111687 1650 {"source",&DoSource},
459b5f5d 1651 {"download",&DoDownload},
a4c40430 1652 {"changelog",&DoChangelog},
c2a4a8dd 1653 {"indextargets",&DoIndexTargets},
b2e465d6 1654 {"moo",&DoMoo},
67111687 1655 {"help",&ShowHelp},
83d89a9f 1656 {0,0}};
67111687 1657
b9179170
MV
1658 std::vector<CommandLine::Args> Args = getCommandArgs("apt-get", CommandLine::GetCommand(Cmds, argc, argv));
1659
67111687
AL
1660 // Set up gettext support
1661 setlocale(LC_ALL,"");
1662 textdomain(PACKAGE);
1663
0a8e3465 1664 // Parse the command line and initialize the package library
ad7e0941
DK
1665 CommandLine CmdL;
1666 ParseCommandLine(CmdL, Cmds, Args.data(), &_config, &_system, argc, argv, ShowHelp);
55a5a46c 1667
b9179170
MV
1668 // see if we are in simulate mode
1669 CheckSimulateMode(CmdL);
55a5a46c 1670
3163087b
MV
1671 // Init the signals
1672 InitSignals();
1673
0a8e3465 1674 // Setup the output streams
b9179170 1675 InitOutput();
d7827aca 1676
0a8e3465 1677 // Match the operation
83d89a9f 1678 CmdL.DispatchArg(Cmds);
0a8e3465
AL
1679
1680 // Print any errors or warnings found during parsing
65beb572
DK
1681 bool const Errors = _error->PendingError();
1682 if (_config->FindI("quiet",0) > 0)
0a8e3465 1683 _error->DumpErrors();
65beb572
DK
1684 else
1685 _error->DumpErrors(GlobalError::DEBUG);
1686 return Errors == true ? 100 : 0;
0a8e3465 1687}
92fcbfc1 1688 /*}}}*/