]> git.saurik.com Git - apt.git/blame - cmdline/apt-get.cc
improve error message
[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
18 dist-upgrade - Powerfull upgrader designed to handle the issues with
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
086bb6d7 30#include <apt-pkg/aptconfiguration.h>
0a8e3465
AL
31#include <apt-pkg/error.h>
32#include <apt-pkg/cmndline.h>
33#include <apt-pkg/init.h>
34#include <apt-pkg/depcache.h>
35#include <apt-pkg/sourcelist.h>
0a8e3465 36#include <apt-pkg/algorithms.h>
0919e3f9 37#include <apt-pkg/acquire-item.h>
cdcc6d34 38#include <apt-pkg/strutl.h>
472ff00e 39#include <apt-pkg/fileutl.h>
1bc849af 40#include <apt-pkg/clean.h>
36375005
AL
41#include <apt-pkg/srcrecords.h>
42#include <apt-pkg/version.h>
2d11135a 43#include <apt-pkg/cachefile.h>
8fde7239 44#include <apt-pkg/cacheset.h>
b2e465d6 45#include <apt-pkg/sptr.h>
092ae175 46#include <apt-pkg/md5.h>
b2e465d6 47#include <apt-pkg/versionmatch.h>
472ff00e
DK
48#include <apt-pkg/progress.h>
49#include <apt-pkg/pkgsystem.h>
50#include <apt-pkg/pkgrecords.h>
51#include <apt-pkg/indexfile.h>
ffee1c2b 52
0919e3f9
AL
53#include "acqprogress.h"
54
092ae175 55#include <set>
233c2b66 56#include <locale.h>
c8ca0ce1 57#include <langinfo.h>
90f057fd 58#include <fstream>
d7827aca
AL
59#include <termios.h>
60#include <sys/ioctl.h>
1bc849af 61#include <sys/stat.h>
885d204b 62#include <sys/statfs.h>
101030ab 63#include <sys/statvfs.h>
d7827aca 64#include <signal.h>
65a1e968 65#include <unistd.h>
3e3221ba 66#include <stdio.h>
d6e79b75 67#include <errno.h>
c373c37a 68#include <regex.h>
54676e1a 69#include <sys/wait.h>
afb1e2e3 70#include <sstream>
4b12ea90 71
ea542140 72#include <apti18n.h>
0a8e3465
AL
73 /*}}}*/
74
885d204b
OS
75#define RAMFS_MAGIC 0x858458f6
76
076d01b0
AL
77using namespace std;
78
79ostream c0out(0);
80ostream c1out(0);
81ostream c2out(0);
0a8e3465 82ofstream devnull("/dev/null");
463870e4 83unsigned int ScreenWidth = 80 - 1; /* - 1 for the cursor */
0a8e3465 84
1089ca89
AL
85// class CacheFile - Cover class for some dependency cache functions /*{{{*/
86// ---------------------------------------------------------------------
87/* */
88class CacheFile : public pkgCacheFile
89{
90 static pkgCache *SortCache;
91 static int NameComp(const void *a,const void *b);
92
93 public:
94 pkgCache::Package **List;
95
96 void Sort();
97 bool CheckDeps(bool AllowBroken = false);
0077d829
AL
98 bool BuildCaches(bool WithLock = true)
99 {
100 OpTextProgress Prog(*_config);
ea4b220b 101 if (pkgCacheFile::BuildCaches(&Prog,WithLock) == false)
0077d829
AL
102 return false;
103 return true;
104 }
1089ca89
AL
105 bool Open(bool WithLock = true)
106 {
107 OpTextProgress Prog(*_config);
ea4b220b 108 if (pkgCacheFile::Open(&Prog,WithLock) == false)
1089ca89
AL
109 return false;
110 Sort();
b2e465d6 111
1089ca89
AL
112 return true;
113 };
c37b9502
AL
114 bool OpenForInstall()
115 {
116 if (_config->FindB("APT::Get::Print-URIs") == true)
079a992d 117 return Open(false);
c37b9502 118 else
079a992d 119 return Open(true);
c37b9502 120 }
1089ca89 121 CacheFile() : List(0) {};
7a9f09bd
MV
122 ~CacheFile() {
123 delete[] List;
124 }
1089ca89
AL
125};
126 /*}}}*/
127
a6568219
AL
128// YnPrompt - Yes No Prompt. /*{{{*/
129// ---------------------------------------------------------------------
130/* Returns true on a Yes.*/
7db98ffc 131bool YnPrompt(bool Default=true)
a6568219 132{
55732492
DK
133 /* nl_langinfo does not support LANGUAGE setting, so we unset it here
134 to have the help-message (hopefully) match the expected characters */
135 char * language = getenv("LANGUAGE");
136 if (language != NULL)
137 language = strdup(language);
138 if (language != NULL)
139 unsetenv("LANGUAGE");
140
141 if (Default == true)
142 // TRANSLATOR: Yes/No question help-text: defaulting to Y[es]
143 // e.g. "Do you want to continue? [Y/n] "
144 // The user has to answer with an input matching the
145 // YESEXPR/NOEXPR defined in your l10n.
146 c2out << " " << _("[Y/n]") << " " << std::flush;
147 else
148 // TRANSLATOR: Yes/No question help-text: defaulting to N[o]
149 // e.g. "Should this file be removed? [y/N] "
150 // The user has to answer with an input matching the
151 // YESEXPR/NOEXPR defined in your l10n.
152 c2out << " " << _("[y/N]") << " " << std::flush;
153
154 if (language != NULL)
155 {
156 setenv("LANGUAGE", language, 0);
157 free(language);
158 }
159
a6568219
AL
160 if (_config->FindB("APT::Get::Assume-Yes",false) == true)
161 {
55732492 162 // TRANSLATOR: "Yes" answer printed for a yes/no question if --assume-yes is set
10cda9fe 163 c1out << _("Y") << endl;
a6568219
AL
164 return true;
165 }
d4cfaed3
DK
166 else if (_config->FindB("APT::Get::Assume-No",false) == true)
167 {
55732492 168 // TRANSLATOR: "No" answer printed for a yes/no question if --assume-no is set
d4cfaed3
DK
169 c1out << _("N") << endl;
170 return false;
171 }
10cda9fe
AL
172
173 char response[1024] = "";
174 cin.getline(response, sizeof(response));
175
176 if (!cin)
b2e465d6 177 return false;
10cda9fe
AL
178
179 if (strlen(response) == 0)
7db98ffc 180 return Default;
10cda9fe
AL
181
182 regex_t Pattern;
183 int Res;
184
185 Res = regcomp(&Pattern, nl_langinfo(YESEXPR),
186 REG_EXTENDED|REG_ICASE|REG_NOSUB);
187
188 if (Res != 0) {
189 char Error[300];
190 regerror(Res,&Pattern,Error,sizeof(Error));
191 return _error->Error(_("Regex compilation error - %s"),Error);
192 }
a6568219 193
10cda9fe
AL
194 Res = regexec(&Pattern, response, 0, NULL, 0);
195 if (Res == 0)
196 return true;
197 return false;
a6568219
AL
198}
199 /*}}}*/
6f86c974
AL
200// AnalPrompt - Annoying Yes No Prompt. /*{{{*/
201// ---------------------------------------------------------------------
202/* Returns true on a Yes.*/
203bool AnalPrompt(const char *Text)
204{
205 char Buf[1024];
206 cin.getline(Buf,sizeof(Buf));
207 if (strcmp(Buf,Text) == 0)
208 return true;
209 return false;
210}
211 /*}}}*/
0a8e3465
AL
212// ShowList - Show a list /*{{{*/
213// ---------------------------------------------------------------------
b2e465d6 214/* This prints out a string of space separated words with a title and
0a8e3465 215 a two space indent line wraped to the current screen width. */
ac625538 216bool ShowList(ostream &out,string Title,string List,string VersionsList)
0a8e3465
AL
217{
218 if (List.empty() == true)
83d89a9f 219 return true;
4968036c
AL
220 // trim trailing space
221 int NonSpace = List.find_last_not_of(' ');
222 if (NonSpace != -1)
223 {
224 List = List.erase(NonSpace + 1);
225 if (List.empty() == true)
226 return true;
227 }
0a8e3465
AL
228
229 // Acount for the leading space
230 int ScreenWidth = ::ScreenWidth - 3;
231
232 out << Title << endl;
233 string::size_type Start = 0;
ac625538 234 string::size_type VersionsStart = 0;
0a8e3465
AL
235 while (Start < List.size())
236 {
ac625538
AL
237 if(_config->FindB("APT::Get::Show-Versions",false) == true &&
238 VersionsList.size() > 0) {
239 string::size_type End;
240 string::size_type VersionsEnd;
241
242 End = List.find(' ',Start);
243 VersionsEnd = VersionsList.find('\n', VersionsStart);
244
245 out << " " << string(List,Start,End - Start) << " (" <<
246 string(VersionsList,VersionsStart,VersionsEnd - VersionsStart) <<
247 ")" << endl;
03b9be80
AL
248
249 if (End == string::npos || End < Start)
250 End = Start + ScreenWidth;
251
ac625538
AL
252 Start = End + 1;
253 VersionsStart = VersionsEnd + 1;
254 } else {
255 string::size_type End;
256
257 if (Start + ScreenWidth >= List.size())
258 End = List.size();
259 else
260 End = List.rfind(' ',Start+ScreenWidth);
261
262 if (End == string::npos || End < Start)
263 End = Start + ScreenWidth;
264 out << " " << string(List,Start,End - Start) << endl;
265 Start = End + 1;
266 }
0a8e3465 267 }
ac625538 268
83d89a9f 269 return false;
0a8e3465
AL
270}
271 /*}}}*/
272// ShowBroken - Debugging aide /*{{{*/
273// ---------------------------------------------------------------------
274/* This prints out the names of all the packages that are broken along
275 with the name of each each broken dependency and a quite version
b2e465d6
AL
276 description.
277
278 The output looks like:
677cbcbc 279 The following packages have unmet dependencies:
b2e465d6
AL
280 exim: Depends: libc6 (>= 2.1.94) but 2.1.3-10 is to be installed
281 Depends: libldap2 (>= 2.0.2-2) but it is not going to be installed
282 Depends: libsasl7 but it is not going to be installed
283 */
421c8d10 284void ShowBroken(ostream &out,CacheFile &Cache,bool Now)
0a8e3465 285{
72cf877c
DK
286 if (Cache->BrokenCount() == 0)
287 return;
288
677cbcbc 289 out << _("The following packages have unmet dependencies:") << endl;
1089ca89 290 for (unsigned J = 0; J < Cache->Head().PackageCount; J++)
0a8e3465 291 {
1089ca89
AL
292 pkgCache::PkgIterator I(Cache,Cache.List[J]);
293
079a992d
AL
294 if (Now == true)
295 {
296 if (Cache[I].NowBroken() == false)
297 continue;
298 }
299 else
300 {
301 if (Cache[I].InstBroken() == false)
302 continue;
303 }
304
303a1703 305 // Print out each package and the failed dependencies
75ce2062
DK
306 out << " " << I.FullName(true) << " :";
307 unsigned const Indent = I.FullName(true).size() + 3;
303a1703 308 bool First = true;
079a992d
AL
309 pkgCache::VerIterator Ver;
310
311 if (Now == true)
312 Ver = I.CurrentVer();
313 else
314 Ver = Cache[I].InstVerIter(Cache);
315
316 if (Ver.end() == true)
0a8e3465 317 {
079a992d 318 out << endl;
303a1703
AL
319 continue;
320 }
321
079a992d 322 for (pkgCache::DepIterator D = Ver.DependsList(); D.end() == false;)
303a1703 323 {
30e1eab5
AL
324 // Compute a single dependency element (glob or)
325 pkgCache::DepIterator Start;
326 pkgCache::DepIterator End;
d20333af 327 D.GlobOr(Start,End); // advances D
76fbce56 328
079a992d 329 if (Cache->IsImportantDep(End) == false)
303a1703 330 continue;
079a992d
AL
331
332 if (Now == true)
333 {
334 if ((Cache[End] & pkgDepCache::DepGNow) == pkgDepCache::DepGNow)
335 continue;
336 }
337 else
338 {
339 if ((Cache[End] & pkgDepCache::DepGInstall) == pkgDepCache::DepGInstall)
340 continue;
341 }
342
648e3cb4
AL
343 bool FirstOr = true;
344 while (1)
0a8e3465 345 {
648e3cb4
AL
346 if (First == false)
347 for (unsigned J = 0; J != Indent; J++)
348 out << ' ';
349 First = false;
350
351 if (FirstOr == false)
352 {
353 for (unsigned J = 0; J != strlen(End.DepType()) + 3; J++)
354 out << ' ';
355 }
0a8e3465 356 else
648e3cb4
AL
357 out << ' ' << End.DepType() << ": ";
358 FirstOr = false;
359
75ce2062 360 out << Start.TargetPkg().FullName(true);
648e3cb4
AL
361
362 // Show a quick summary of the version requirements
363 if (Start.TargetVer() != 0)
b2e465d6 364 out << " (" << Start.CompType() << " " << Start.TargetVer() << ")";
648e3cb4
AL
365
366 /* Show a summary of the target package if possible. In the case
367 of virtual packages we show nothing */
368 pkgCache::PkgIterator Targ = Start.TargetPkg();
369 if (Targ->ProvidesList == 0)
7e798dd7 370 {
b2e465d6 371 out << ' ';
648e3cb4 372 pkgCache::VerIterator Ver = Cache[Targ].InstVerIter(Cache);
f0ec51c2
AL
373 if (Now == true)
374 Ver = Targ.CurrentVer();
079a992d 375
648e3cb4 376 if (Ver.end() == false)
b2e465d6
AL
377 {
378 if (Now == true)
379 ioprintf(out,_("but %s is installed"),Ver.VerStr());
380 else
381 ioprintf(out,_("but %s is to be installed"),Ver.VerStr());
382 }
648e3cb4 383 else
303a1703 384 {
648e3cb4
AL
385 if (Cache[Targ].CandidateVerIter(Cache).end() == true)
386 {
387 if (Targ->ProvidesList == 0)
b2e465d6 388 out << _("but it is not installable");
648e3cb4 389 else
b2e465d6 390 out << _("but it is a virtual package");
648e3cb4 391 }
303a1703 392 else
b2e465d6 393 out << (Now?_("but it is not installed"):_("but it is not going to be installed"));
648e3cb4
AL
394 }
395 }
396
397 if (Start != End)
b2e465d6 398 out << _(" or");
648e3cb4
AL
399 out << endl;
400
401 if (Start == End)
402 break;
f7f0d6c7 403 ++Start;
648e3cb4 404 }
303a1703 405 }
0a8e3465
AL
406 }
407}
408 /*}}}*/
409// ShowNew - Show packages to newly install /*{{{*/
410// ---------------------------------------------------------------------
411/* */
1089ca89 412void ShowNew(ostream &out,CacheFile &Cache)
0a8e3465 413{
89260e53 414 /* Print out a list of packages that are going to be installed extra
0a8e3465 415 to what the user asked */
0a8e3465 416 string List;
ac625538 417 string VersionsList;
1089ca89
AL
418 for (unsigned J = 0; J < Cache->Head().PackageCount; J++)
419 {
420 pkgCache::PkgIterator I(Cache,Cache.List[J]);
ac625538 421 if (Cache[I].NewInstall() == true) {
75ce2062 422 List += I.FullName(true) + " ";
ac625538
AL
423 VersionsList += string(Cache[I].CandVersion) + "\n";
424 }
1089ca89
AL
425 }
426
ac625538 427 ShowList(out,_("The following NEW packages will be installed:"),List,VersionsList);
0a8e3465
AL
428}
429 /*}}}*/
430// ShowDel - Show packages to delete /*{{{*/
431// ---------------------------------------------------------------------
432/* */
1089ca89 433void ShowDel(ostream &out,CacheFile &Cache)
0a8e3465
AL
434{
435 /* Print out a list of packages that are going to be removed extra
436 to what the user asked */
0a8e3465 437 string List;
ac625538 438 string VersionsList;
1089ca89 439 for (unsigned J = 0; J < Cache->Head().PackageCount; J++)
fc4b5c9f 440 {
1089ca89
AL
441 pkgCache::PkgIterator I(Cache,Cache.List[J]);
442 if (Cache[I].Delete() == true)
fc4b5c9f 443 {
1089ca89 444 if ((Cache[I].iFlags & pkgDepCache::Purge) == pkgDepCache::Purge)
75ce2062 445 List += I.FullName(true) + "* ";
fc4b5c9f 446 else
75ce2062 447 List += I.FullName(true) + " ";
ac625538
AL
448
449 VersionsList += string(Cache[I].CandVersion)+ "\n";
fc4b5c9f
AL
450 }
451 }
3d615484 452
ac625538 453 ShowList(out,_("The following packages will be REMOVED:"),List,VersionsList);
0a8e3465
AL
454}
455 /*}}}*/
456// ShowKept - Show kept packages /*{{{*/
457// ---------------------------------------------------------------------
458/* */
f292686b 459void ShowKept(ostream &out,CacheFile &Cache)
0a8e3465 460{
0a8e3465 461 string List;
ac625538 462 string VersionsList;
f292686b 463 for (unsigned J = 0; J < Cache->Head().PackageCount; J++)
0a8e3465 464 {
f292686b
AL
465 pkgCache::PkgIterator I(Cache,Cache.List[J]);
466
0a8e3465 467 // Not interesting
f292686b
AL
468 if (Cache[I].Upgrade() == true || Cache[I].Upgradable() == false ||
469 I->CurrentVer == 0 || Cache[I].Delete() == true)
0a8e3465
AL
470 continue;
471
75ce2062 472 List += I.FullName(true) + " ";
ac625538 473 VersionsList += string(Cache[I].CurVersion) + " => " + Cache[I].CandVersion + "\n";
0a8e3465 474 }
aee7bceb 475 ShowList(out,_("The following packages have been kept back:"),List,VersionsList);
0a8e3465
AL
476}
477 /*}}}*/
478// ShowUpgraded - Show upgraded packages /*{{{*/
479// ---------------------------------------------------------------------
480/* */
1089ca89 481void ShowUpgraded(ostream &out,CacheFile &Cache)
0a8e3465 482{
0a8e3465 483 string List;
ac625538 484 string VersionsList;
1089ca89 485 for (unsigned J = 0; J < Cache->Head().PackageCount; J++)
0a8e3465 486 {
1089ca89
AL
487 pkgCache::PkgIterator I(Cache,Cache.List[J]);
488
0a8e3465 489 // Not interesting
1089ca89 490 if (Cache[I].Upgrade() == false || Cache[I].NewInstall() == true)
0a8e3465 491 continue;
803ea2a8 492
75ce2062 493 List += I.FullName(true) + " ";
ac625538 494 VersionsList += string(Cache[I].CurVersion) + " => " + Cache[I].CandVersion + "\n";
0a8e3465 495 }
aee7bceb 496 ShowList(out,_("The following packages will be upgraded:"),List,VersionsList);
b2e465d6
AL
497}
498 /*}}}*/
499// ShowDowngraded - Show downgraded packages /*{{{*/
500// ---------------------------------------------------------------------
501/* */
502bool ShowDowngraded(ostream &out,CacheFile &Cache)
503{
504 string List;
ac625538 505 string VersionsList;
b2e465d6
AL
506 for (unsigned J = 0; J < Cache->Head().PackageCount; J++)
507 {
508 pkgCache::PkgIterator I(Cache,Cache.List[J]);
509
510 // Not interesting
511 if (Cache[I].Downgrade() == false || Cache[I].NewInstall() == true)
512 continue;
803ea2a8 513
75ce2062 514 List += I.FullName(true) + " ";
ac625538 515 VersionsList += string(Cache[I].CurVersion) + " => " + Cache[I].CandVersion + "\n";
b2e465d6 516 }
aee7bceb 517 return ShowList(out,_("The following packages will be DOWNGRADED:"),List,VersionsList);
0a8e3465
AL
518}
519 /*}}}*/
520// ShowHold - Show held but changed packages /*{{{*/
521// ---------------------------------------------------------------------
522/* */
1089ca89 523bool ShowHold(ostream &out,CacheFile &Cache)
0a8e3465 524{
0a8e3465 525 string List;
ac625538 526 string VersionsList;
1089ca89 527 for (unsigned J = 0; J < Cache->Head().PackageCount; J++)
0a8e3465 528 {
1089ca89
AL
529 pkgCache::PkgIterator I(Cache,Cache.List[J]);
530 if (Cache[I].InstallVer != (pkgCache::Version *)I.CurrentVer() &&
ac625538 531 I->SelectedState == pkgCache::State::Hold) {
75ce2062 532 List += I.FullName(true) + " ";
ac625538
AL
533 VersionsList += string(Cache[I].CurVersion) + " => " + Cache[I].CandVersion + "\n";
534 }
0a8e3465
AL
535 }
536
ac625538 537 return ShowList(out,_("The following held packages will be changed:"),List,VersionsList);
0a8e3465
AL
538}
539 /*}}}*/
540// ShowEssential - Show an essential package warning /*{{{*/
541// ---------------------------------------------------------------------
542/* This prints out a warning message that is not to be ignored. It shows
543 all essential packages and their dependents that are to be removed.
544 It is insanely risky to remove the dependents of an essential package! */
1089ca89 545bool ShowEssential(ostream &out,CacheFile &Cache)
0a8e3465 546{
0a8e3465 547 string List;
ac625538 548 string VersionsList;
b2e465d6
AL
549 bool *Added = new bool[Cache->Head().PackageCount];
550 for (unsigned int I = 0; I != Cache->Head().PackageCount; I++)
0a8e3465
AL
551 Added[I] = false;
552
1089ca89 553 for (unsigned J = 0; J < Cache->Head().PackageCount; J++)
0a8e3465 554 {
1089ca89 555 pkgCache::PkgIterator I(Cache,Cache.List[J]);
b2e465d6
AL
556 if ((I->Flags & pkgCache::Flag::Essential) != pkgCache::Flag::Essential &&
557 (I->Flags & pkgCache::Flag::Important) != pkgCache::Flag::Important)
0a8e3465
AL
558 continue;
559
560 // The essential package is being removed
1089ca89 561 if (Cache[I].Delete() == true)
0a8e3465
AL
562 {
563 if (Added[I->ID] == false)
564 {
565 Added[I->ID] = true;
75ce2062 566 List += I.FullName(true) + " ";
ac625538 567 //VersionsList += string(Cache[I].CurVersion) + "\n"; ???
0a8e3465
AL
568 }
569 }
a02f24e0
DK
570 else
571 continue;
572
0a8e3465
AL
573 if (I->CurrentVer == 0)
574 continue;
575
576 // Print out any essential package depenendents that are to be removed
f7f0d6c7 577 for (pkgCache::DepIterator D = I.CurrentVer().DependsList(); D.end() == false; ++D)
0a8e3465 578 {
3e3221ba
AL
579 // Skip everything but depends
580 if (D->Type != pkgCache::Dep::PreDepends &&
581 D->Type != pkgCache::Dep::Depends)
582 continue;
583
0a8e3465 584 pkgCache::PkgIterator P = D.SmartTargetPkg();
1089ca89 585 if (Cache[P].Delete() == true)
0a8e3465
AL
586 {
587 if (Added[P->ID] == true)
588 continue;
589 Added[P->ID] = true;
3e3221ba
AL
590
591 char S[300];
75ce2062 592 snprintf(S,sizeof(S),_("%s (due to %s) "),P.FullName(true).c_str(),I.FullName(true).c_str());
3e3221ba 593 List += S;
ac625538 594 //VersionsList += "\n"; ???
0a8e3465
AL
595 }
596 }
597 }
598
83d89a9f 599 delete [] Added;
080bf1be 600 return ShowList(out,_("WARNING: The following essential packages will be removed.\n"
ac625538 601 "This should NOT be done unless you know exactly what you are doing!"),List,VersionsList);
0a8e3465 602}
7db98ffc 603
0a8e3465
AL
604 /*}}}*/
605// Stats - Show some statistics /*{{{*/
606// ---------------------------------------------------------------------
607/* */
608void Stats(ostream &out,pkgDepCache &Dep)
609{
610 unsigned long Upgrade = 0;
b2e465d6 611 unsigned long Downgrade = 0;
0a8e3465 612 unsigned long Install = 0;
d0c59649 613 unsigned long ReInstall = 0;
f7f0d6c7 614 for (pkgCache::PkgIterator I = Dep.PkgBegin(); I.end() == false; ++I)
0a8e3465
AL
615 {
616 if (Dep[I].NewInstall() == true)
617 Install++;
618 else
b2e465d6 619 {
0a8e3465
AL
620 if (Dep[I].Upgrade() == true)
621 Upgrade++;
b2e465d6
AL
622 else
623 if (Dep[I].Downgrade() == true)
624 Downgrade++;
625 }
626
d0c59649
AL
627 if (Dep[I].Delete() == false && (Dep[I].iFlags & pkgDepCache::ReInstall) == pkgDepCache::ReInstall)
628 ReInstall++;
0a8e3465
AL
629 }
630
2adb5fda 631 ioprintf(out,_("%lu upgraded, %lu newly installed, "),
b2e465d6
AL
632 Upgrade,Install);
633
d0c59649 634 if (ReInstall != 0)
b2e465d6
AL
635 ioprintf(out,_("%lu reinstalled, "),ReInstall);
636 if (Downgrade != 0)
637 ioprintf(out,_("%lu downgraded, "),Downgrade);
0a8e3465 638
2d425135 639 ioprintf(out,_("%lu to remove and %lu not upgraded.\n"),
b2e465d6
AL
640 Dep.DelCount(),Dep.KeepCount());
641
0a8e3465 642 if (Dep.BadCount() != 0)
2adb5fda 643 ioprintf(out,_("%lu not fully installed or removed.\n"),
b2e465d6 644 Dep.BadCount());
0a8e3465
AL
645}
646 /*}}}*/
21d4c9f1
DK
647// CacheSetHelperAPTGet - responsible for message telling from the CacheSets/*{{{*/
648class CacheSetHelperAPTGet : public APT::CacheSetHelper {
649 /** \brief stream message should be printed to */
650 std::ostream &out;
651 /** \brief were things like Task or RegEx used to select packages? */
652 bool explicitlyNamed;
653
654 APT::PackageSet virtualPkgs;
655
656public:
2c085486
DK
657 std::list<std::pair<pkgCache::VerIterator, std::string> > selectedByRelease;
658
21d4c9f1
DK
659 CacheSetHelperAPTGet(std::ostream &out) : APT::CacheSetHelper(true), out(out) {
660 explicitlyNamed = true;
661 }
662
15fc8636
DK
663 virtual void showTaskSelection(pkgCache::PkgIterator const &Pkg, string const &pattern) {
664 ioprintf(out, _("Note, selecting '%s' for task '%s'\n"),
665 Pkg.FullName(true).c_str(), pattern.c_str());
21d4c9f1
DK
666 explicitlyNamed = false;
667 }
15fc8636
DK
668 virtual void showRegExSelection(pkgCache::PkgIterator const &Pkg, string const &pattern) {
669 ioprintf(out, _("Note, selecting '%s' for regex '%s'\n"),
670 Pkg.FullName(true).c_str(), pattern.c_str());
21d4c9f1
DK
671 explicitlyNamed = false;
672 }
673 virtual void showSelectedVersion(pkgCache::PkgIterator const &Pkg, pkgCache::VerIterator const Ver,
15fc8636 674 string const &ver, bool const verIsRel) {
2c085486
DK
675 if (ver == Ver.VerStr())
676 return;
677 selectedByRelease.push_back(make_pair(Ver, ver));
21d4c9f1
DK
678 }
679
680 bool showVirtualPackageErrors(pkgCacheFile &Cache) {
681 if (virtualPkgs.empty() == true)
682 return true;
683 for (APT::PackageSet::const_iterator Pkg = virtualPkgs.begin();
684 Pkg != virtualPkgs.end(); ++Pkg) {
685 if (Pkg->ProvidesList != 0) {
686 ioprintf(c1out,_("Package %s is a virtual package provided by:\n"),
687 Pkg.FullName(true).c_str());
688
689 pkgCache::PrvIterator I = Pkg.ProvidesList();
690 unsigned short provider = 0;
691 for (; I.end() == false; ++I) {
692 pkgCache::PkgIterator Pkg = I.OwnerPkg();
693
694 if (Cache[Pkg].CandidateVerIter(Cache) == I.OwnerVer()) {
4fe19044 695 c1out << " " << Pkg.FullName(true) << " " << I.OwnerVer().VerStr();
21d4c9f1 696 if (Cache[Pkg].Install() == true && Cache[Pkg].NewInstall() == false)
4fe19044
DK
697 c1out << _(" [Installed]");
698 c1out << endl;
21d4c9f1
DK
699 ++provider;
700 }
701 }
702 // if we found no candidate which provide this package, show non-candidates
703 if (provider == 0)
f7f0d6c7 704 for (I = Pkg.ProvidesList(); I.end() == false; ++I)
4fe19044 705 c1out << " " << I.OwnerPkg().FullName(true) << " " << I.OwnerVer().VerStr()
21d4c9f1
DK
706 << _(" [Not candidate version]") << endl;
707 else
708 out << _("You should explicitly select one to install.") << endl;
709 } else {
4fe19044 710 ioprintf(c1out,
21d4c9f1
DK
711 _("Package %s is not available, but is referred to by another package.\n"
712 "This may mean that the package is missing, has been obsoleted, or\n"
713 "is only available from another source\n"),Pkg.FullName(true).c_str());
714
715 string List;
716 string VersionsList;
717 SPtrArray<bool> Seen = new bool[Cache.GetPkgCache()->Head().PackageCount];
718 memset(Seen,0,Cache.GetPkgCache()->Head().PackageCount*sizeof(*Seen));
719 for (pkgCache::DepIterator Dep = Pkg.RevDependsList();
f7f0d6c7 720 Dep.end() == false; ++Dep) {
21d4c9f1
DK
721 if (Dep->Type != pkgCache::Dep::Replaces)
722 continue;
723 if (Seen[Dep.ParentPkg()->ID] == true)
724 continue;
725 Seen[Dep.ParentPkg()->ID] = true;
726 List += Dep.ParentPkg().FullName(true) + " ";
727 //VersionsList += string(Dep.ParentPkg().CurVersion) + "\n"; ???
728 }
4fe19044 729 ShowList(c1out,_("However the following packages replace it:"),List,VersionsList);
21d4c9f1 730 }
4fe19044 731 c1out << std::endl;
21d4c9f1
DK
732 }
733 return false;
734 }
735
736 virtual pkgCache::VerIterator canNotFindCandidateVer(pkgCacheFile &Cache, pkgCache::PkgIterator const &Pkg) {
737 APT::VersionSet const verset = tryVirtualPackage(Cache, Pkg, APT::VersionSet::CANDIDATE);
738 if (verset.empty() == false)
739 return *(verset.begin());
15fc8636 740 else if (ShowError == true) {
21d4c9f1
DK
741 _error->Error(_("Package '%s' has no installation candidate"),Pkg.FullName(true).c_str());
742 virtualPkgs.insert(Pkg);
743 }
744 return pkgCache::VerIterator(Cache, 0);
745 }
746
747 virtual pkgCache::VerIterator canNotFindNewestVer(pkgCacheFile &Cache, pkgCache::PkgIterator const &Pkg) {
ca5e41fd
DK
748 if (Pkg->ProvidesList != 0)
749 {
750 APT::VersionSet const verset = tryVirtualPackage(Cache, Pkg, APT::VersionSet::NEWEST);
751 if (verset.empty() == false)
752 return *(verset.begin());
753 if (ShowError == true)
754 ioprintf(out, _("Virtual packages like '%s' can't be removed\n"), Pkg.FullName(true).c_str());
755 }
756 else
757 {
758 pkgCache::GrpIterator Grp = Pkg.Group();
759 pkgCache::PkgIterator P = Grp.PackageList();
760 for (; P.end() != true; P = Grp.NextPkg(P))
761 {
762 if (P == Pkg)
763 continue;
764 if (P->CurrentVer != 0) {
765 // TRANSLATORS: Note, this is not an interactive question
766 ioprintf(c1out,_("Package '%s' is not installed, so not removed. Did you mean '%s'?\n"),
767 Pkg.FullName(true).c_str(), P.FullName(true).c_str());
768 break;
769 }
770 }
771 if (P.end() == true)
772 ioprintf(c1out,_("Package '%s' is not installed, so not removed\n"),Pkg.FullName(true).c_str());
773 }
21d4c9f1
DK
774 return pkgCache::VerIterator(Cache, 0);
775 }
776
777 APT::VersionSet tryVirtualPackage(pkgCacheFile &Cache, pkgCache::PkgIterator const &Pkg,
778 APT::VersionSet::Version const &select) {
779 /* This is a pure virtual package and there is a single available
780 candidate providing it. */
781 if (unlikely(Cache[Pkg].CandidateVer != 0) || Pkg->ProvidesList == 0)
782 return APT::VersionSet();
783
784 pkgCache::PkgIterator Prov;
785 bool found_one = false;
786 for (pkgCache::PrvIterator P = Pkg.ProvidesList(); P; ++P) {
787 pkgCache::VerIterator const PVer = P.OwnerVer();
788 pkgCache::PkgIterator const PPkg = PVer.ParentPkg();
789
790 /* Ignore versions that are not a candidate. */
791 if (Cache[PPkg].CandidateVer != PVer)
792 continue;
793
794 if (found_one == false) {
795 Prov = PPkg;
796 found_one = true;
797 } else if (PPkg != Prov) {
286afa36
DK
798 // same group, so it's a foreign package
799 if (PPkg->Group == Prov->Group) {
800 // do we already have the requested arch?
801 if (strcmp(Pkg.Arch(), Prov.Arch()) == 0 ||
802 strcmp(Prov.Arch(), "all") == 0 ||
803 unlikely(strcmp(PPkg.Arch(), Prov.Arch()) == 0)) // packages have only on candidate, but just to be sure
804 continue;
805 // see which architecture we prefer more and switch to it
806 std::vector<std::string> archs = APT::Configuration::getArchitectures();
807 if (std::find(archs.begin(), archs.end(), PPkg.Arch()) < std::find(archs.begin(), archs.end(), Prov.Arch()))
808 Prov = PPkg;
809 continue;
810 }
21d4c9f1
DK
811 found_one = false; // we found at least two
812 break;
813 }
814 }
815
816 if (found_one == true) {
817 ioprintf(out, _("Note, selecting '%s' instead of '%s'\n"),
818 Prov.FullName(true).c_str(), Pkg.FullName(true).c_str());
819 return APT::VersionSet::FromPackage(Cache, Prov, select, *this);
820 }
821 return APT::VersionSet();
822 }
823
824 inline bool allPkgNamedExplicitly() const { return explicitlyNamed; }
825
826};
827 /*}}}*/
828// TryToInstall - Mark a package for installation /*{{{*/
829struct TryToInstall {
830 pkgCacheFile* Cache;
831 pkgProblemResolver* Fix;
832 bool FixBroken;
833 unsigned long AutoMarkChanged;
6806db8a 834 APT::PackageSet doAutoInstallLater;
21d4c9f1 835
15fc8636 836 TryToInstall(pkgCacheFile &Cache, pkgProblemResolver *PM, bool const FixBroken) : Cache(&Cache), Fix(PM),
21d4c9f1
DK
837 FixBroken(FixBroken), AutoMarkChanged(0) {};
838
839 void operator() (pkgCache::VerIterator const &Ver) {
840 pkgCache::PkgIterator Pkg = Ver.ParentPkg();
2fbfb111 841
21d4c9f1
DK
842 Cache->GetDepCache()->SetCandidateVersion(Ver);
843 pkgDepCache::StateCache &State = (*Cache)[Pkg];
844
845 // Handle the no-upgrade case
846 if (_config->FindB("APT::Get::upgrade",true) == false && Pkg->CurrentVer != 0)
847 ioprintf(c1out,_("Skipping %s, it is already installed and upgrade is not set.\n"),
848 Pkg.FullName(true).c_str());
849 // Ignore request for install if package would be new
850 else if (_config->FindB("APT::Get::Only-Upgrade", false) == true && Pkg->CurrentVer == 0)
851 ioprintf(c1out,_("Skipping %s, it is not installed and only upgrades are requested.\n"),
852 Pkg.FullName(true).c_str());
853 else {
71d73928
DK
854 if (Fix != NULL) {
855 Fix->Clear(Pkg);
856 Fix->Protect(Pkg);
857 }
21d4c9f1
DK
858 Cache->GetDepCache()->MarkInstall(Pkg,false);
859
860 if (State.Install() == false) {
861 if (_config->FindB("APT::Get::ReInstall",false) == true) {
862 if (Pkg->CurrentVer == 0 || Pkg.CurrentVer().Downloadable() == false)
863 ioprintf(c1out,_("Reinstallation of %s is not possible, it cannot be downloaded.\n"),
864 Pkg.FullName(true).c_str());
865 else
866 Cache->GetDepCache()->SetReInstall(Pkg, true);
867 } else
868 ioprintf(c1out,_("%s is already the newest version.\n"),
869 Pkg.FullName(true).c_str());
870 }
871
872 // Install it with autoinstalling enabled (if we not respect the minial
873 // required deps or the policy)
6806db8a
DK
874 if (FixBroken == false)
875 doAutoInstallLater.insert(Pkg);
21d4c9f1
DK
876 }
877
878 // see if we need to fix the auto-mark flag
879 // e.g. apt-get install foo
880 // where foo is marked automatic
881 if (State.Install() == false &&
882 (State.Flags & pkgCache::Flag::Auto) &&
883 _config->FindB("APT::Get::ReInstall",false) == false &&
884 _config->FindB("APT::Get::Only-Upgrade",false) == false &&
885 _config->FindB("APT::Get::Download-Only",false) == false)
886 {
887 ioprintf(c1out,_("%s set to manually installed.\n"),
888 Pkg.FullName(true).c_str());
889 Cache->GetDepCache()->MarkAuto(Pkg,false);
890 AutoMarkChanged++;
891 }
892 }
6806db8a 893
2c085486
DK
894 bool propergateReleaseCandiateSwitching(std::list<std::pair<pkgCache::VerIterator, std::string> > start, std::ostream &out)
895 {
067cc369
DK
896 for (std::list<std::pair<pkgCache::VerIterator, std::string> >::const_iterator s = start.begin();
897 s != start.end(); ++s)
898 Cache->GetDepCache()->SetCandidateVersion(s->first);
899
2c085486
DK
900 bool Success = true;
901 std::list<std::pair<pkgCache::VerIterator, pkgCache::VerIterator> > Changed;
902 for (std::list<std::pair<pkgCache::VerIterator, std::string> >::const_iterator s = start.begin();
903 s != start.end(); ++s)
904 {
905 Changed.push_back(std::make_pair(s->first, pkgCache::VerIterator(*Cache)));
906 // We continue here even if it failed to enhance the ShowBroken output
907 Success &= Cache->GetDepCache()->SetCandidateRelease(s->first, s->second, Changed);
908 }
909 for (std::list<std::pair<pkgCache::VerIterator, pkgCache::VerIterator> >::const_iterator c = Changed.begin();
910 c != Changed.end(); ++c)
911 {
912 if (c->second.end() == true)
913 ioprintf(out, _("Selected version '%s' (%s) for '%s'\n"),
914 c->first.VerStr(), c->first.RelStr().c_str(), c->first.ParentPkg().FullName(true).c_str());
915 else if (c->first.ParentPkg()->Group != c->second.ParentPkg()->Group)
916 {
917 pkgCache::VerIterator V = (*Cache)[c->first.ParentPkg()].CandidateVerIter(*Cache);
918 ioprintf(out, _("Selected version '%s' (%s) for '%s' because of '%s'\n"), V.VerStr(),
919 V.RelStr().c_str(), V.ParentPkg().FullName(true).c_str(), c->second.ParentPkg().FullName(true).c_str());
920 }
921 }
922 return Success;
923 }
924
6806db8a
DK
925 void doAutoInstall() {
926 for (APT::PackageSet::const_iterator P = doAutoInstallLater.begin();
927 P != doAutoInstallLater.end(); ++P) {
928 pkgDepCache::StateCache &State = (*Cache)[P];
929 if (State.InstBroken() == false && State.InstPolicyBroken() == false)
930 continue;
931 Cache->GetDepCache()->MarkInstall(P, true);
932 }
933 doAutoInstallLater.clear();
934 }
21d4c9f1
DK
935};
936 /*}}}*/
937// TryToRemove - Mark a package for removal /*{{{*/
938struct TryToRemove {
939 pkgCacheFile* Cache;
940 pkgProblemResolver* Fix;
6cb1583a 941 bool PurgePkgs;
21d4c9f1 942
71d73928 943 TryToRemove(pkgCacheFile &Cache, pkgProblemResolver *PM) : Cache(&Cache), Fix(PM),
6cb1583a 944 PurgePkgs(_config->FindB("APT::Get::Purge", false)) {};
21d4c9f1
DK
945
946 void operator() (pkgCache::VerIterator const &Ver)
947 {
948 pkgCache::PkgIterator Pkg = Ver.ParentPkg();
949
71d73928
DK
950 if (Fix != NULL)
951 {
952 Fix->Clear(Pkg);
953 Fix->Protect(Pkg);
954 Fix->Remove(Pkg);
955 }
21d4c9f1 956
6cb1583a
DK
957 if ((Pkg->CurrentVer == 0 && PurgePkgs == false) ||
958 (PurgePkgs == true && Pkg->CurrentState == pkgCache::State::NotInstalled))
bea41712 959 {
0c73b84b
DK
960 pkgCache::GrpIterator Grp = Pkg.Group();
961 pkgCache::PkgIterator P = Grp.PackageList();
962 for (; P.end() != true; P = Grp.NextPkg(P))
963 {
964 if (P == Pkg)
965 continue;
966 if (P->CurrentVer != 0 || (PurgePkgs == true && P->CurrentState != pkgCache::State::NotInstalled))
967 {
968 // TRANSLATORS: Note, this is not an interactive question
969 ioprintf(c1out,_("Package '%s' is not installed, so not removed. Did you mean '%s'?\n"),
970 Pkg.FullName(true).c_str(), P.FullName(true).c_str());
971 break;
972 }
973 }
974 if (P.end() == true)
975 ioprintf(c1out,_("Package '%s' is not installed, so not removed\n"),Pkg.FullName(true).c_str());
976
bea41712
DK
977 // MarkInstall refuses to install packages on hold
978 Pkg->SelectedState = pkgCache::State::Hold;
979 }
21d4c9f1 980 else
6cb1583a 981 Cache->GetDepCache()->MarkDelete(Pkg, PurgePkgs);
21d4c9f1
DK
982 }
983};
984 /*}}}*/
1089ca89 985// CacheFile::NameComp - QSort compare by name /*{{{*/
0a8e3465
AL
986// ---------------------------------------------------------------------
987/* */
1089ca89
AL
988pkgCache *CacheFile::SortCache = 0;
989int CacheFile::NameComp(const void *a,const void *b)
0a8e3465 990{
8508b1df
AL
991 if (*(pkgCache::Package **)a == 0 || *(pkgCache::Package **)b == 0)
992 return *(pkgCache::Package **)a - *(pkgCache::Package **)b;
0a8e3465 993
1089ca89
AL
994 const pkgCache::Package &A = **(pkgCache::Package **)a;
995 const pkgCache::Package &B = **(pkgCache::Package **)b;
996
997 return strcmp(SortCache->StrP + A.Name,SortCache->StrP + B.Name);
998}
999 /*}}}*/
1000// CacheFile::Sort - Sort by name /*{{{*/
1001// ---------------------------------------------------------------------
1002/* */
1003void CacheFile::Sort()
1004{
1005 delete [] List;
1006 List = new pkgCache::Package *[Cache->Head().PackageCount];
1007 memset(List,0,sizeof(*List)*Cache->Head().PackageCount);
1008 pkgCache::PkgIterator I = Cache->PkgBegin();
f7f0d6c7 1009 for (;I.end() != true; ++I)
1089ca89
AL
1010 List[I->ID] = I;
1011
1012 SortCache = *this;
1013 qsort(List,Cache->Head().PackageCount,sizeof(*List),NameComp);
1014}
0a8e3465 1015 /*}}}*/
b2e465d6 1016// CacheFile::CheckDeps - Open the cache file /*{{{*/
0a8e3465
AL
1017// ---------------------------------------------------------------------
1018/* This routine generates the caches and then opens the dependency cache
1019 and verifies that the system is OK. */
2d11135a 1020bool CacheFile::CheckDeps(bool AllowBroken)
0a8e3465 1021{
4ef9a929
MV
1022 bool FixBroken = _config->FindB("APT::Get::Fix-Broken",false);
1023
d38b7b3d
AL
1024 if (_error->PendingError() == true)
1025 return false;
0a8e3465 1026
0a8e3465 1027 // Check that the system is OK
b2e465d6 1028 if (DCache->DelCount() != 0 || DCache->InstCount() != 0)
db0db9fe 1029 return _error->Error("Internal error, non-zero counts");
0a8e3465
AL
1030
1031 // Apply corrections for half-installed packages
b2e465d6 1032 if (pkgApplyStatus(*DCache) == false)
0a8e3465
AL
1033 return false;
1034
4ef9a929
MV
1035 if (_config->FindB("APT::Get::Fix-Policy-Broken",false) == true)
1036 {
1037 FixBroken = true;
1038 if ((DCache->PolicyBrokenCount() > 0))
1039 {
1040 // upgrade all policy-broken packages with ForceImportantDeps=True
f7f0d6c7 1041 for (pkgCache::PkgIterator I = Cache->PkgBegin(); !I.end(); ++I)
4ef9a929 1042 if ((*DCache)[I].NowPolicyBroken() == true)
7610bb3d 1043 DCache->MarkInstall(I,true,0, false, true);
4ef9a929
MV
1044 }
1045 }
1046
0a8e3465 1047 // Nothing is broken
b2e465d6 1048 if (DCache->BrokenCount() == 0 || AllowBroken == true)
0a8e3465
AL
1049 return true;
1050
1051 // Attempt to fix broken things
4ef9a929 1052 if (FixBroken == true)
0a8e3465 1053 {
b2e465d6
AL
1054 c1out << _("Correcting dependencies...") << flush;
1055 if (pkgFixBroken(*DCache) == false || DCache->BrokenCount() != 0)
0a8e3465 1056 {
b2e465d6 1057 c1out << _(" failed.") << endl;
421c8d10 1058 ShowBroken(c1out,*this,true);
0a8e3465 1059
b2e465d6 1060 return _error->Error(_("Unable to correct dependencies"));
0a8e3465 1061 }
b2e465d6
AL
1062 if (pkgMinimizeUpgrade(*DCache) == false)
1063 return _error->Error(_("Unable to minimize the upgrade set"));
0a8e3465 1064
b2e465d6 1065 c1out << _(" Done") << endl;
0a8e3465
AL
1066 }
1067 else
1068 {
b5647402 1069 c1out << _("You might want to run 'apt-get -f install' to correct these.") << endl;
421c8d10 1070 ShowBroken(c1out,*this,true);
0a8e3465 1071
b2e465d6 1072 return _error->Error(_("Unmet dependencies. Try using -f."));
0a8e3465
AL
1073 }
1074
1075 return true;
1076}
92fcbfc1
DK
1077 /*}}}*/
1078// CheckAuth - check if each download comes form a trusted source /*{{{*/
1079// ---------------------------------------------------------------------
1080/* */
7db98ffc
MZ
1081static bool CheckAuth(pkgAcquire& Fetcher)
1082{
1083 string UntrustedList;
1084 for (pkgAcquire::ItemIterator I = Fetcher.ItemsBegin(); I < Fetcher.ItemsEnd(); ++I)
1085 {
1086 if (!(*I)->IsTrusted())
1087 {
1088 UntrustedList += string((*I)->ShortDesc()) + " ";
1089 }
1090 }
1091
1092 if (UntrustedList == "")
1093 {
1094 return true;
1095 }
1096
1097 ShowList(c2out,_("WARNING: The following packages cannot be authenticated!"),UntrustedList,"");
1098
1099 if (_config->FindB("APT::Get::AllowUnauthenticated",false) == true)
1100 {
2a7e07c7 1101 c2out << _("Authentication warning overridden.\n");
7db98ffc
MZ
1102 return true;
1103 }
1104
1105 if (_config->FindI("quiet",0) < 2
1106 && _config->FindB("APT::Get::Assume-Yes",false) == false)
1107 {
55732492 1108 c2out << _("Install these packages without verification?") << flush;
7db98ffc
MZ
1109 if (!YnPrompt(false))
1110 return _error->Error(_("Some packages could not be authenticated"));
1111
1112 return true;
1113 }
1114 else if (_config->FindB("APT::Get::Force-Yes",false) == true)
1115 {
1116 return true;
1117 }
1118
1119 return _error->Error(_("There are problems and -y was used without --force-yes"));
1120}
0a8e3465 1121 /*}}}*/
0a8e3465
AL
1122// InstallPackages - Actually download and install the packages /*{{{*/
1123// ---------------------------------------------------------------------
1124/* This displays the informative messages describing what is going to
1125 happen and then calls the download routines */
a3eaf954 1126bool InstallPackages(CacheFile &Cache,bool ShwKept,bool Ask = true,
80fbda96 1127 bool Safety = true)
0a8e3465 1128{
fc4b5c9f
AL
1129 if (_config->FindB("APT::Get::Purge",false) == true)
1130 {
1131 pkgCache::PkgIterator I = Cache->PkgBegin();
f7f0d6c7 1132 for (; I.end() == false; ++I)
d556d1a1
AL
1133 {
1134 if (I.Purge() == false && Cache[I].Mode == pkgDepCache::ModeDelete)
1135 Cache->MarkDelete(I,true);
1136 }
fc4b5c9f
AL
1137 }
1138
83d89a9f 1139 bool Fail = false;
6f86c974 1140 bool Essential = false;
83d89a9f 1141
a6568219 1142 // Show all the various warning indicators
0a8e3465
AL
1143 ShowDel(c1out,Cache);
1144 ShowNew(c1out,Cache);
1145 if (ShwKept == true)
1146 ShowKept(c1out,Cache);
7a215bee 1147 Fail |= !ShowHold(c1out,Cache);
906fbf88 1148 if (_config->FindB("APT::Get::Show-Upgraded",true) == true)
0a8e3465 1149 ShowUpgraded(c1out,Cache);
b2e465d6 1150 Fail |= !ShowDowngraded(c1out,Cache);
5d1d0738
AL
1151 if (_config->FindB("APT::Get::Download-Only",false) == false)
1152 Essential = !ShowEssential(c1out,Cache);
6f86c974 1153 Fail |= Essential;
0a8e3465 1154 Stats(c1out,Cache);
7db98ffc 1155
0a8e3465 1156 // Sanity check
d38b7b3d 1157 if (Cache->BrokenCount() != 0)
0a8e3465 1158 {
421c8d10 1159 ShowBroken(c1out,Cache,false);
2a7e07c7 1160 return _error->Error(_("Internal error, InstallPackages was called with broken packages!"));
0a8e3465
AL
1161 }
1162
d0c59649 1163 if (Cache->DelCount() == 0 && Cache->InstCount() == 0 &&
d38b7b3d 1164 Cache->BadCount() == 0)
c60d151b 1165 return true;
03e39e59 1166
d150b09d 1167 // No remove flag
b2e465d6 1168 if (Cache->DelCount() != 0 && _config->FindB("APT::Get::Remove",true) == false)
db0db9fe 1169 return _error->Error(_("Packages need to be removed but remove is disabled."));
d150b09d 1170
03e39e59
AL
1171 // Run the simulator ..
1172 if (_config->FindB("APT::Get::Simulate") == true)
1173 {
1174 pkgSimulate PM(Cache);
2a7e07c7
MV
1175 int status_fd = _config->FindI("APT::Status-Fd",-1);
1176 pkgPackageManager::OrderResult Res = PM.DoInstall(status_fd);
281daf46
AL
1177 if (Res == pkgPackageManager::Failed)
1178 return false;
1179 if (Res != pkgPackageManager::Completed)
2a7e07c7 1180 return _error->Error(_("Internal error, Ordering didn't finish"));
281daf46 1181 return true;
03e39e59
AL
1182 }
1183
1184 // Create the text record parser
1185 pkgRecords Recs(Cache);
83d89a9f
AL
1186 if (_error->PendingError() == true)
1187 return false;
1cd1c398 1188
03e39e59 1189 // Create the download object
1cd1c398 1190 pkgAcquire Fetcher;
03e39e59 1191 AcqTextStatus Stat(ScreenWidth,_config->FindI("quiet",0));
a722b2c5
DK
1192 if (_config->FindB("APT::Get::Print-URIs", false) == true)
1193 {
1194 // force a hashsum for compatibility reasons
1195 _config->CndSet("Acquire::ForceHash", "md5sum");
a722b2c5
DK
1196 }
1197 else if (Fetcher.Setup(&Stat, _config->FindDir("Dir::Cache::Archives")) == false)
1cd1c398 1198 return false;
03e39e59
AL
1199
1200 // Read the source list
1bb8cd67
DK
1201 if (Cache.BuildSourceList() == false)
1202 return false;
1203 pkgSourceList *List = Cache.GetSourceList();
03e39e59
AL
1204
1205 // Create the package manager and prepare to download
b2e465d6 1206 SPtr<pkgPackageManager> PM= _system->CreatePM(Cache);
1bb8cd67 1207 if (PM->GetArchives(&Fetcher,List,&Recs) == false ||
424c3bc0 1208 _error->PendingError() == true)
03e39e59
AL
1209 return false;
1210
7a1b1f8b 1211 // Display statistics
3a882565
DK
1212 unsigned long long FetchBytes = Fetcher.FetchNeeded();
1213 unsigned long long FetchPBytes = Fetcher.PartialPresent();
1214 unsigned long long DebBytes = Fetcher.TotalNeeded();
d38b7b3d
AL
1215 if (DebBytes != Cache->DebSize())
1216 {
1217 c0out << DebBytes << ',' << Cache->DebSize() << endl;
2a7e07c7 1218 c0out << _("How odd.. The sizes didn't match, email apt@packages.debian.org") << endl;
d38b7b3d 1219 }
138d4b3d 1220
7a1b1f8b 1221 // Number of bytes
a6568219 1222 if (DebBytes != FetchBytes)
4d8d8112
DK
1223 //TRANSLATOR: The required space between number and unit is already included
1224 // in the replacement strings, so %sB will be correctly translate in e.g. 1,5 MB
ac7fd99c 1225 ioprintf(c1out,_("Need to get %sB/%sB of archives.\n"),
b2e465d6 1226 SizeToStr(FetchBytes).c_str(),SizeToStr(DebBytes).c_str());
813603a0 1227 else if (DebBytes != 0)
4d8d8112
DK
1228 //TRANSLATOR: The required space between number and unit is already included
1229 // in the replacement string, so %sB will be correctly translate in e.g. 1,5 MB
ac7fd99c 1230 ioprintf(c1out,_("Need to get %sB of archives.\n"),
b2e465d6
AL
1231 SizeToStr(DebBytes).c_str());
1232
10bb1f5f
AL
1233 // Size delta
1234 if (Cache->UsrSize() >= 0)
4d8d8112
DK
1235 //TRANSLATOR: The required space between number and unit is already included
1236 // in the replacement string, so %sB will be correctly translate in e.g. 1,5 MB
813603a0 1237 ioprintf(c1out,_("After this operation, %sB of additional disk space will be used.\n"),
b2e465d6 1238 SizeToStr(Cache->UsrSize()).c_str());
10bb1f5f 1239 else
4d8d8112
DK
1240 //TRANSLATOR: The required space between number and unit is already included
1241 // in the replacement string, so %sB will be correctly translate in e.g. 1,5 MB
813603a0 1242 ioprintf(c1out,_("After this operation, %sB disk space will be freed.\n"),
b2e465d6 1243 SizeToStr(-1*Cache->UsrSize()).c_str());
10bb1f5f
AL
1244
1245 if (_error->PendingError() == true)
1246 return false;
31a0531d 1247
01b64152
AL
1248 /* Check for enough free space, but only if we are actually going to
1249 download */
18e20d63
AL
1250 if (_config->FindB("APT::Get::Print-URIs") == false &&
1251 _config->FindB("APT::Get::Download",true) == true)
01b64152
AL
1252 {
1253 struct statvfs Buf;
1254 string OutputDir = _config->FindDir("Dir::Cache::Archives");
c1ce032a
DK
1255 if (statvfs(OutputDir.c_str(),&Buf) != 0) {
1256 if (errno == EOVERFLOW)
1257 return _error->WarningE("statvfs",_("Couldn't determine free space in %s"),
1258 OutputDir.c_str());
1259 else
1260 return _error->Errno("statvfs",_("Couldn't determine free space in %s"),
1261 OutputDir.c_str());
1262 } else if (unsigned(Buf.f_bfree) < (FetchBytes - FetchPBytes)/Buf.f_bsize)
885d204b
OS
1263 {
1264 struct statfs Stat;
f64196e8
DK
1265 if (statfs(OutputDir.c_str(),&Stat) != 0
1266#if HAVE_STRUCT_STATFS_F_TYPE
1267 || unsigned(Stat.f_type) != RAMFS_MAGIC
1268#endif
1269 )
885d204b
OS
1270 return _error->Error(_("You don't have enough free space in %s."),
1271 OutputDir.c_str());
1272 }
01b64152
AL
1273 }
1274
83d89a9f 1275 // Fail safe check
0c95c765
AL
1276 if (_config->FindI("quiet",0) >= 2 ||
1277 _config->FindB("APT::Get::Assume-Yes",false) == true)
83d89a9f
AL
1278 {
1279 if (Fail == true && _config->FindB("APT::Get::Force-Yes",false) == false)
b2e465d6 1280 return _error->Error(_("There are problems and -y was used without --force-yes"));
83d89a9f 1281 }
83d89a9f 1282
80fbda96 1283 if (Essential == true && Safety == true)
6f86c974 1284 {
d150b09d 1285 if (_config->FindB("APT::Get::Trivial-Only",false) == true)
b2e465d6 1286 return _error->Error(_("Trivial Only specified but this is not a trivial operation."));
18056707
DK
1287
1288 // TRANSLATOR: This string needs to be typed by the user as a confirmation, so be
1289 // careful with hard to type or special characters (like non-breaking spaces)
b2e465d6
AL
1290 const char *Prompt = _("Yes, do as I say!");
1291 ioprintf(c2out,
080bf1be 1292 _("You are about to do something potentially harmful.\n"
b2e465d6
AL
1293 "To continue type in the phrase '%s'\n"
1294 " ?] "),Prompt);
1295 c2out << flush;
1296 if (AnalPrompt(Prompt) == false)
6f86c974 1297 {
b2e465d6 1298 c2out << _("Abort.") << endl;
a6568219 1299 exit(1);
6f86c974
AL
1300 }
1301 }
1302 else
d150b09d 1303 {
6f86c974 1304 // Prompt to continue
38262e68 1305 if (Ask == true || Fail == true)
6f86c974 1306 {
d150b09d 1307 if (_config->FindB("APT::Get::Trivial-Only",false) == true)
b2e465d6 1308 return _error->Error(_("Trivial Only specified but this is not a trivial operation."));
d150b09d 1309
0c95c765 1310 if (_config->FindI("quiet",0) < 2 &&
6f86c974 1311 _config->FindB("APT::Get::Assume-Yes",false) == false)
0c95c765 1312 {
55732492
DK
1313 c2out << _("Do you want to continue?") << flush;
1314
0c95c765
AL
1315 if (YnPrompt() == false)
1316 {
b2e465d6 1317 c2out << _("Abort.") << endl;
0c95c765
AL
1318 exit(1);
1319 }
1320 }
6f86c974
AL
1321 }
1322 }
1323
36375005 1324 // Just print out the uris an exit if the --print-uris flag was used
f7a08e33
AL
1325 if (_config->FindB("APT::Get::Print-URIs") == true)
1326 {
1327 pkgAcquire::UriIterator I = Fetcher.UriBegin();
f7f0d6c7 1328 for (; I != Fetcher.UriEnd(); ++I)
f7a08e33 1329 cout << '\'' << I->URI << "' " << flNotDir(I->Owner->DestFile) << ' ' <<
495e5cb2 1330 I->Owner->FileSize << ' ' << I->Owner->HashSum() << endl;
f7a08e33
AL
1331 return true;
1332 }
b2e465d6 1333
7db98ffc
MZ
1334 if (!CheckAuth(Fetcher))
1335 return false;
1336
b2e465d6
AL
1337 /* Unlock the dpkg lock if we are not going to be doing an install
1338 after. */
1339 if (_config->FindB("APT::Get::Download-Only",false) == true)
1340 _system->UnLock();
83d89a9f 1341
03e39e59 1342 // Run it
281daf46 1343 while (1)
30e1eab5 1344 {
a3eaf954 1345 bool Transient = false;
b2e465d6 1346 if (_config->FindB("APT::Get::Download",true) == false)
a3eaf954 1347 {
076d01b0 1348 for (pkgAcquire::ItemIterator I = Fetcher.ItemsBegin(); I < Fetcher.ItemsEnd();)
a3eaf954
AL
1349 {
1350 if ((*I)->Local == true)
1351 {
f7f0d6c7 1352 ++I;
a3eaf954
AL
1353 continue;
1354 }
1355
1356 // Close the item and check if it was found in cache
1357 (*I)->Finished();
1358 if ((*I)->Complete == false)
1359 Transient = true;
1360
1361 // Clear it out of the fetch list
1362 delete *I;
1363 I = Fetcher.ItemsBegin();
1364 }
1365 }
1366
1367 if (Fetcher.Run() == pkgAcquire::Failed)
1368 return false;
30e1eab5 1369
281daf46
AL
1370 // Print out errors
1371 bool Failed = false;
f7f0d6c7 1372 for (pkgAcquire::ItemIterator I = Fetcher.ItemsBegin(); I != Fetcher.ItemsEnd(); ++I)
f01fe790 1373 {
281daf46
AL
1374 if ((*I)->Status == pkgAcquire::Item::StatDone &&
1375 (*I)->Complete == true)
1376 continue;
1377
281daf46
AL
1378 if ((*I)->Status == pkgAcquire::Item::StatIdle)
1379 {
1380 Transient = true;
1381 // Failed = true;
1382 continue;
1383 }
a3eaf954 1384
b2e465d6
AL
1385 fprintf(stderr,_("Failed to fetch %s %s\n"),(*I)->DescURI().c_str(),
1386 (*I)->ErrorText.c_str());
f01fe790 1387 Failed = true;
f01fe790 1388 }
5ec427c2 1389
a3eaf954 1390 /* If we are in no download mode and missing files and there were
5ec427c2
AL
1391 'failures' then the user must specify -m. Furthermore, there
1392 is no such thing as a transient error in no-download mode! */
a3eaf954 1393 if (Transient == true &&
b2e465d6 1394 _config->FindB("APT::Get::Download",true) == false)
5ec427c2
AL
1395 {
1396 Transient = false;
1397 Failed = true;
1398 }
f01fe790 1399
281daf46
AL
1400 if (_config->FindB("APT::Get::Download-Only",false) == true)
1401 {
1402 if (Failed == true && _config->FindB("APT::Get::Fix-Missing",false) == false)
b2e465d6
AL
1403 return _error->Error(_("Some files failed to download"));
1404 c1out << _("Download complete and in download only mode") << endl;
281daf46
AL
1405 return true;
1406 }
1407
8195ae46 1408 if (Failed == true && _config->FindB("APT::Get::Fix-Missing",false) == false)
f01fe790 1409 {
b2e465d6 1410 return _error->Error(_("Unable to fetch some archives, maybe run apt-get update or try with --fix-missing?"));
f01fe790
AL
1411 }
1412
281daf46 1413 if (Transient == true && Failed == true)
b2e465d6 1414 return _error->Error(_("--fix-missing and media swapping is not currently supported"));
281daf46
AL
1415
1416 // Try to deal with missing package files
b2e465d6 1417 if (Failed == true && PM->FixMissing() == false)
281daf46 1418 {
b2e465d6 1419 cerr << _("Unable to correct missing packages.") << endl;
db0db9fe 1420 return _error->Error(_("Aborting install."));
281daf46 1421 }
afb1e2e3 1422
b2e465d6 1423 _system->UnLock();
2a7e07c7
MV
1424 int status_fd = _config->FindI("APT::Status-Fd",-1);
1425 pkgPackageManager::OrderResult Res = PM->DoInstall(status_fd);
281daf46
AL
1426 if (Res == pkgPackageManager::Failed || _error->PendingError() == true)
1427 return false;
1428 if (Res == pkgPackageManager::Completed)
642ebc1a 1429 break;
281daf46
AL
1430
1431 // Reload the fetcher object and loop again for media swapping
1432 Fetcher.Shutdown();
1bb8cd67 1433 if (PM->GetArchives(&Fetcher,List,&Recs) == false)
281daf46 1434 return false;
b2e465d6
AL
1435
1436 _system->Lock();
642ebc1a
DK
1437 }
1438
1439 std::set<std::string> const disappearedPkgs = PM->GetDisappearedPackages();
1440 if (disappearedPkgs.empty() == true)
1441 return true;
1442
1443 string disappear;
1444 for (std::set<std::string>::const_iterator d = disappearedPkgs.begin();
1445 d != disappearedPkgs.end(); ++d)
1446 disappear.append(*d).append(" ");
1447
1448 ShowList(c1out, P_("The following package disappeared from your system as\n"
1449 "all files have been overwritten by other packages:",
1450 "The following packages disappeared from your system as\n"
1451 "all files have been overwritten by other packages:", disappearedPkgs.size()), disappear, "");
a12d5352 1452 c0out << _("Note: This is done automatically and on purpose by dpkg.") << std::endl;
642ebc1a
DK
1453
1454 return true;
0a8e3465
AL
1455}
1456 /*}}}*/
b8ad5512 1457// TryToInstallBuildDep - Try to install a single package /*{{{*/
c373c37a
AL
1458// ---------------------------------------------------------------------
1459/* This used to be inlined in DoInstall, but with the advent of regex package
1460 name matching it was split out.. */
21d4c9f1 1461bool TryToInstallBuildDep(pkgCache::PkgIterator Pkg,pkgCacheFile &Cache,
c373c37a 1462 pkgProblemResolver &Fix,bool Remove,bool BrokenFix,
70e706ad 1463 bool AllowFail = true)
c373c37a 1464{
21d4c9f1 1465 if (Cache[Pkg].CandidateVer == 0 && Pkg->ProvidesList != 0)
c373c37a 1466 {
21d4c9f1 1467 CacheSetHelperAPTGet helper(c1out);
4caf8231 1468 helper.showErrors(false);
21d4c9f1
DK
1469 pkgCache::VerIterator Ver = helper.canNotFindNewestVer(Cache, Pkg);
1470 if (Ver.end() == false)
1471 Pkg = Ver.ParentPkg();
1472 else if (helper.showVirtualPackageErrors(Cache) == false)
1473 return AllowFail;
c373c37a 1474 }
61d6a8de 1475
ac321486
DK
1476 if (_config->FindB("Debug::BuildDeps",false) == true)
1477 {
1478 if (Remove == true)
1479 cout << " Trying to remove " << Pkg << endl;
1480 else
1481 cout << " Trying to install " << Pkg << endl;
1482 }
1483
c373c37a
AL
1484 if (Remove == true)
1485 {
71d73928 1486 TryToRemove RemoveAction(Cache, &Fix);
21d4c9f1
DK
1487 RemoveAction(Pkg.VersionList());
1488 } else if (Cache[Pkg].CandidateVer != 0) {
71d73928 1489 TryToInstall InstallAction(Cache, &Fix, BrokenFix);
21d4c9f1 1490 InstallAction(Cache[Pkg].CandidateVerIter(Cache));
6806db8a 1491 InstallAction.doAutoInstall();
21d4c9f1
DK
1492 } else
1493 return AllowFail;
60681f93 1494
b2e465d6
AL
1495 return true;
1496}
1497 /*}}}*/
1498// FindSrc - Find a source record /*{{{*/
1499// ---------------------------------------------------------------------
1500/* */
1501pkgSrcRecords::Parser *FindSrc(const char *Name,pkgRecords &Recs,
1502 pkgSrcRecords &SrcRecs,string &Src,
1503 pkgDepCache &Cache)
1504{
b2e465d6 1505 string VerTag;
fb3dc579 1506 string DefRel = _config->Find("APT::Default-Release");
b2e465d6 1507 string TmpSrc = Name;
aca056a9 1508
fb3dc579
MV
1509 // extract the version/release from the pkgname
1510 const size_t found = TmpSrc.find_last_of("/=");
1511 if (found != string::npos) {
1512 if (TmpSrc[found] == '/')
1513 DefRel = TmpSrc.substr(found+1);
1514 else
1515 VerTag = TmpSrc.substr(found+1);
ebf6c42d
DK
1516 TmpSrc = TmpSrc.substr(0,found);
1517 }
aca056a9 1518
fb3dc579
MV
1519 /* Lookup the version of the package we would install if we were to
1520 install a version and determine the source package name, then look
1521 in the archive for a source package of the same name. */
1522 bool MatchSrcOnly = _config->FindB("APT::Get::Only-Source");
1523 const pkgCache::PkgIterator Pkg = Cache.FindPkg(TmpSrc);
1524 if (MatchSrcOnly == false && Pkg.end() == false)
aca056a9 1525 {
fb3dc579 1526 if(VerTag.empty() == false || DefRel.empty() == false)
aca056a9 1527 {
e84adb76 1528 bool fuzzy = false;
fb3dc579
MV
1529 // we have a default release, try to locate the pkg. we do it like
1530 // this because GetCandidateVer() will not "downgrade", that means
1531 // "apt-get source -t stable apt" won't work on a unstable system
f7f0d6c7 1532 for (pkgCache::VerIterator Ver = Pkg.VersionList();; ++Ver)
aca056a9 1533 {
e84adb76
DK
1534 // try first only exact matches, later fuzzy matches
1535 if (Ver.end() == true)
1536 {
1537 if (fuzzy == true)
1538 break;
1539 fuzzy = true;
1540 Ver = Pkg.VersionList();
259f688a
MV
1541 // exit right away from the Pkg.VersionList() loop if we
1542 // don't have any versions
1543 if (Ver.end() == true)
1544 break;
e84adb76
DK
1545 }
1546 // We match against a concrete version (or a part of this version)
1547 if (VerTag.empty() == false &&
1548 (fuzzy == true || Cache.VS().CmpVersion(VerTag, Ver.VerStr()) != 0) && // exact match
1549 (fuzzy == false || strncmp(VerTag.c_str(), Ver.VerStr(), VerTag.size()) != 0)) // fuzzy match
1550 continue;
1551
fb3dc579 1552 for (pkgCache::VerFileIterator VF = Ver.FileList();
f7f0d6c7 1553 VF.end() == false; ++VF)
aca056a9 1554 {
fb3dc579
MV
1555 /* If this is the status file, and the current version is not the
1556 version in the status file (ie it is not installed, or somesuch)
1557 then it is not a candidate for installation, ever. This weeds
1558 out bogus entries that may be due to config-file states, or
1559 other. */
1560 if ((VF.File()->Flags & pkgCache::Flag::NotSource) ==
1561 pkgCache::Flag::NotSource && Pkg.CurrentVer() != Ver)
1562 continue;
1563
fb3dc579
MV
1564 // or we match against a release
1565 if(VerTag.empty() == false ||
1566 (VF.File().Archive() != 0 && VF.File().Archive() == DefRel) ||
1567 (VF.File().Codename() != 0 && VF.File().Codename() == DefRel))
1568 {
1569 pkgRecords::Parser &Parse = Recs.Lookup(VF);
1570 Src = Parse.SourcePkg();
61690a7e
MV
1571 // no SourcePkg name, so it is the "binary" name
1572 if (Src.empty() == true)
1573 Src = TmpSrc;
e84adb76
DK
1574 // the Version we have is possibly fuzzy or includes binUploads,
1575 // so we use the Version of the SourcePkg (empty if same as package)
1576 VerTag = Parse.SourceVer();
61690a7e
MV
1577 if (VerTag.empty() == true)
1578 VerTag = Ver.VerStr();
fb3dc579
MV
1579 break;
1580 }
aca056a9 1581 }
61690a7e
MV
1582 if (Src.empty() == false)
1583 break;
aca056a9 1584 }
fb3dc579
MV
1585 if (Src.empty() == true)
1586 {
61690a7e 1587 // Sources files have no codename information
ddff663f
MV
1588 if (VerTag.empty() == true && DefRel.empty() == false)
1589 {
1590 _error->Error(_("Ignore unavailable target release '%s' of package '%s'"), DefRel.c_str(), TmpSrc.c_str());
1591 return 0;
1592 }
fb3dc579 1593 }
026f60e2 1594 }
61690a7e 1595 if (Src.empty() == true)
b2e465d6 1596 {
61690a7e
MV
1597 // if we don't have found a fitting package yet so we will
1598 // choose a good candidate and proceed with that.
1599 // Maybe we will find a source later on with the right VerTag
ce6162be 1600 pkgCache::VerIterator Ver = Cache.GetCandidateVer(Pkg);
fb3dc579 1601 if (Ver.end() == false)
b2e465d6
AL
1602 {
1603 pkgRecords::Parser &Parse = Recs.Lookup(Ver.FileList());
1604 Src = Parse.SourcePkg();
61690a7e
MV
1605 if (VerTag.empty() == true)
1606 VerTag = Parse.SourceVer();
b2e465d6 1607 }
fb3dc579
MV
1608 }
1609 }
1610
1611 if (Src.empty() == true)
1612 Src = TmpSrc;
1613 else
1614 {
1615 /* if we have a source pkg name, make sure to only search
1616 for srcpkg names, otherwise apt gets confused if there
1617 is a binary package "pkg1" and a source package "pkg1"
1618 with the same name but that comes from different packages */
1619 MatchSrcOnly = true;
1620 if (Src != TmpSrc)
1621 {
1622 ioprintf(c1out, _("Picking '%s' as source package instead of '%s'\n"), Src.c_str(), TmpSrc.c_str());
1623 }
b2e465d6 1624 }
89ad8e7c 1625
b2e465d6
AL
1626 // The best hit
1627 pkgSrcRecords::Parser *Last = 0;
1628 unsigned long Offset = 0;
1629 string Version;
89ad8e7c 1630
b2e465d6
AL
1631 /* Iterate over all of the hits, which includes the resulting
1632 binary packages in the search */
1633 pkgSrcRecords::Parser *Parse;
fb3dc579 1634 while (true)
b2e465d6 1635 {
fb3dc579
MV
1636 SrcRecs.Restart();
1637 while ((Parse = SrcRecs.Find(Src.c_str(), MatchSrcOnly)) != 0)
b2e465d6 1638 {
fb3dc579
MV
1639 const string Ver = Parse->Version();
1640
1641 // Ignore all versions which doesn't fit
e84adb76
DK
1642 if (VerTag.empty() == false &&
1643 Cache.VS().CmpVersion(VerTag, Ver) != 0) // exact match
b2e465d6 1644 continue;
fb3dc579
MV
1645
1646 // Newer version or an exact match? Save the hit
1647 if (Last == 0 || Cache.VS().CmpVersion(Version,Ver) < 0) {
1648 Last = Parse;
1649 Offset = Parse->Offset();
1650 Version = Ver;
1651 }
1652
1653 // was the version check above an exact match? If so, we don't need to look further
1654 if (VerTag.empty() == false && VerTag.size() == Ver.size())
1655 break;
b2e465d6 1656 }
fb3dc579
MV
1657 if (Last != 0 || VerTag.empty() == true)
1658 break;
1659 //if (VerTag.empty() == false && Last == 0)
ddff663f
MV
1660 _error->Error(_("Ignore unavailable version '%s' of package '%s'"), VerTag.c_str(), TmpSrc.c_str());
1661 return 0;
b2e465d6 1662 }
fb3dc579 1663
ce6162be 1664 if (Last == 0 || Last->Jump(Offset) == false)
b2e465d6 1665 return 0;
fb3dc579 1666
b2e465d6
AL
1667 return Last;
1668}
1669 /*}}}*/
0a8e3465
AL
1670// DoUpdate - Update the package lists /*{{{*/
1671// ---------------------------------------------------------------------
1672/* */
b2e465d6 1673bool DoUpdate(CommandLine &CmdL)
0a8e3465 1674{
b2e465d6
AL
1675 if (CmdL.FileSize() != 1)
1676 return _error->Error(_("The update command takes no arguments"));
1bb8cd67
DK
1677
1678 CacheFile Cache;
1679
0919e3f9 1680 // Get the source list
1bb8cd67 1681 if (Cache.BuildSourceList() == false)
0919e3f9 1682 return false;
1bb8cd67 1683 pkgSourceList *List = Cache.GetSourceList();
0919e3f9 1684
89b70b5a 1685 // Create the progress
0919e3f9 1686 AcqTextStatus Stat(ScreenWidth,_config->FindI("quiet",0));
89b70b5a 1687
f0863b21
AL
1688 // Just print out the uris an exit if the --print-uris flag was used
1689 if (_config->FindB("APT::Get::Print-URIs") == true)
1690 {
a722b2c5
DK
1691 // force a hashsum for compatibility reasons
1692 _config->CndSet("Acquire::ForceHash", "md5sum");
1693
89b70b5a 1694 // get a fetcher
1cd1c398
DK
1695 pkgAcquire Fetcher;
1696 if (Fetcher.Setup(&Stat) == false)
1697 return false;
89b70b5a 1698
7db98ffc
MZ
1699 // Populate it with the source selection and get all Indexes
1700 // (GetAll=true)
1bb8cd67 1701 if (List->GetIndexes(&Fetcher,true) == false)
7db98ffc
MZ
1702 return false;
1703
f0863b21 1704 pkgAcquire::UriIterator I = Fetcher.UriBegin();
f7f0d6c7 1705 for (; I != Fetcher.UriEnd(); ++I)
f0863b21 1706 cout << '\'' << I->URI << "' " << flNotDir(I->Owner->DestFile) << ' ' <<
495e5cb2 1707 I->Owner->FileSize << ' ' << I->Owner->HashSum() << endl;
f0863b21
AL
1708 return true;
1709 }
7db98ffc 1710
89b70b5a 1711 // do the work
e88d983a 1712 if (_config->FindB("APT::Get::Download",true) == true)
1bb8cd67 1713 ListUpdate(Stat, *List);
e88d983a 1714
8de79b68 1715 // Rebuild the cache.
872ed75f
DK
1716 if (_config->FindB("pkgCacheFile::Generate", true) == true)
1717 {
1718 pkgCacheFile::RemoveCaches();
1719 if (Cache.BuildCaches() == false)
1720 return false;
1721 }
1722
0919e3f9 1723 return true;
afb1e2e3
MV
1724}
1725 /*}}}*/
1726// DoAutomaticRemove - Remove all automatic unused packages /*{{{*/
1727// ---------------------------------------------------------------------
1728/* Remove unused automatic packages */
1729bool DoAutomaticRemove(CacheFile &Cache)
1730{
9d2938d4 1731 bool Debug = _config->FindI("Debug::pkgAutoRemove",false);
b255ff1a 1732 bool doAutoRemove = _config->FindB("APT::Get::AutomaticRemove", false);
7898bd97 1733 bool hideAutoRemove = _config->FindB("APT::Get::HideAutoRemove");
afb1e2e3 1734
03dbbc98 1735 pkgDepCache::ActionGroup group(*Cache);
9d2938d4 1736 if(Debug)
120365ce 1737 std::cout << "DoAutomaticRemove()" << std::endl;
afb1e2e3 1738
03dbbc98
DK
1739 if (doAutoRemove == true &&
1740 _config->FindB("APT::Get::Remove",true) == false)
afb1e2e3 1741 {
3d0de656
MV
1742 c1out << _("We are not supposed to delete stuff, can't start "
1743 "AutoRemover") << std::endl;
03dbbc98 1744 return false;
3d0de656 1745 }
74a05226 1746
03dbbc98
DK
1747 bool purgePkgs = _config->FindB("APT::Get::Purge", false);
1748 bool smallList = (hideAutoRemove == false &&
df6c9723 1749 strcasecmp(_config->Find("APT::Get::HideAutoRemove","").c_str(),"small") == 0);
03dbbc98 1750
03dbbc98 1751 unsigned long autoRemoveCount = 0;
c8b98973 1752 APT::PackageSet tooMuch;
fdfdba56 1753 APT::PackageList autoRemoveList;
9d2938d4 1754 // look over the cache to see what can be removed
fdfdba56 1755 for (unsigned J = 0; J < Cache->Head().PackageCount; ++J)
afb1e2e3 1756 {
fdfdba56 1757 pkgCache::PkgIterator Pkg(Cache,Cache.List[J]);
9d2938d4
MV
1758 if (Cache[Pkg].Garbage)
1759 {
1760 if(Pkg.CurrentVer() != 0 || Cache[Pkg].Install())
1761 if(Debug)
75ce2062 1762 std::cout << "We could delete %s" << Pkg.FullName(true).c_str() << std::endl;
03dbbc98 1763
3d0de656 1764 if (doAutoRemove)
9d2938d4
MV
1765 {
1766 if(Pkg.CurrentVer() != 0 &&
1767 Pkg->CurrentState != pkgCache::State::ConfigFiles)
b29c4482 1768 Cache->MarkDelete(Pkg, purgePkgs, 0, false);
9d2938d4 1769 else
74a05226 1770 Cache->MarkKeep(Pkg, false, false);
9d2938d4 1771 }
03dbbc98
DK
1772 else
1773 {
fdfdba56
DK
1774 if (hideAutoRemove == false && Cache[Pkg].Delete() == false)
1775 autoRemoveList.insert(Pkg);
a8dfff90
DK
1776 // if the package is a new install and already garbage we don't need to
1777 // install it in the first place, so nuke it instead of show it
1778 if (Cache[Pkg].Install() == true && Pkg.CurrentVer() == 0)
c8b98973 1779 {
81ce5781
DK
1780 if (Pkg.CandVersion() != 0)
1781 tooMuch.insert(Pkg);
b29c4482 1782 Cache->MarkDelete(Pkg, false, 0, false);
c8b98973 1783 }
03dbbc98 1784 // only show stuff in the list that is not yet marked for removal
fdfdba56 1785 else if(hideAutoRemove == false && Cache[Pkg].Delete() == false)
f0f2f956 1786 ++autoRemoveCount;
03dbbc98 1787 }
9d2938d4 1788 }
afb1e2e3 1789 }
a8dfff90 1790
c8b98973
DK
1791 // we could have removed a new dependency of a garbage package,
1792 // so check if a reverse depends is broken and if so install it again.
b41929c0 1793 if (tooMuch.empty() == false && (Cache->BrokenCount() != 0 || Cache->PolicyBrokenCount() != 0))
c8b98973
DK
1794 {
1795 bool Changed;
1796 do {
1797 Changed = false;
81ce5781
DK
1798 for (APT::PackageSet::const_iterator Pkg = tooMuch.begin();
1799 Pkg != tooMuch.end() && Changed == false; ++Pkg)
c8b98973 1800 {
81ce5781 1801 APT::PackageSet too;
aaab1007 1802 too.insert(*Pkg);
81ce5781
DK
1803 for (pkgCache::PrvIterator Prv = Cache[Pkg].CandidateVerIter(Cache).ProvidesList();
1804 Prv.end() == false; ++Prv)
1805 too.insert(Prv.ParentPkg());
1806 for (APT::PackageSet::const_iterator P = too.begin();
1807 P != too.end() && Changed == false; ++P) {
1808 for (pkgCache::DepIterator R = P.RevDependsList();
1809 R.end() == false; ++R)
c8b98973 1810 {
81ce5781
DK
1811 if (R.IsNegative() == true ||
1812 Cache->IsImportantDep(R) == false)
1813 continue;
1814 pkgCache::PkgIterator N = R.ParentPkg();
1815 if (N.end() == true || (N->CurrentVer == 0 && (*Cache)[N].Install() == false))
1816 continue;
1817 if (Debug == true)
1818 std::clog << "Save " << Pkg << " as another installed garbage package depends on it" << std::endl;
b29c4482 1819 Cache->MarkInstall(Pkg, false, 0, false);
81ce5781 1820 if (hideAutoRemove == false)
81ce5781 1821 ++autoRemoveCount;
81ce5781
DK
1822 tooMuch.erase(Pkg);
1823 Changed = true;
1824 break;
c8b98973 1825 }
c8b98973
DK
1826 }
1827 }
1828 } while (Changed == true);
1829 }
1830
fdfdba56
DK
1831 std::string autoremovelist, autoremoveversions;
1832 if (smallList == false && autoRemoveCount != 0)
1833 {
1834 for (APT::PackageList::const_iterator Pkg = autoRemoveList.begin(); Pkg != autoRemoveList.end(); ++Pkg)
1835 {
1836 if (Cache[Pkg].Garbage == false)
1837 continue;
1838 autoremovelist += Pkg.FullName(true) + " ";
1839 autoremoveversions += string(Cache[Pkg].CandVersion) + "\n";
1840 }
1841 }
1842
a8dfff90
DK
1843 // Now see if we had destroyed anything (if we had done anything)
1844 if (Cache->BrokenCount() != 0)
1845 {
1846 c1out << _("Hmm, seems like the AutoRemover destroyed something which really\n"
1847 "shouldn't happen. Please file a bug report against apt.") << endl;
1848 c1out << endl;
1849 c1out << _("The following information may help to resolve the situation:") << endl;
1850 c1out << endl;
1851 ShowBroken(c1out,Cache,false);
1852
1853 return _error->Error(_("Internal Error, AutoRemover broke stuff"));
1854 }
1855
03dbbc98
DK
1856 // if we don't remove them, we should show them!
1857 if (doAutoRemove == false && (autoremovelist.empty() == false || autoRemoveCount != 0))
1858 {
1859 if (smallList == false)
d204fc7a 1860 ShowList(c1out, P_("The following package was automatically installed and is no longer required:",
f0f2f956
DK
1861 "The following packages were automatically installed and are no longer required:",
1862 autoRemoveCount), autoremovelist, autoremoveversions);
03dbbc98 1863 else
f0f2f956
DK
1864 ioprintf(c1out, P_("%lu package was automatically installed and is no longer required.\n",
1865 "%lu packages were automatically installed and are no longer required.\n", autoRemoveCount), autoRemoveCount);
de378651 1866 c1out << P_("Use 'apt-get autoremove' to remove it.", "Use 'apt-get autoremove' to remove them.", autoRemoveCount) << std::endl;
03dbbc98 1867 }
afb1e2e3 1868 return true;
db1e7193 1869}
92fcbfc1 1870 /*}}}*/
db1e7193
MV
1871// DoUpgrade - Upgrade all packages /*{{{*/
1872// ---------------------------------------------------------------------
1873/* Upgrade all packages without installing new packages or erasing old
1874 packages */
1875bool DoUpgrade(CommandLine &CmdL)
1876{
1877 CacheFile Cache;
1878 if (Cache.OpenForInstall() == false || Cache.CheckDeps() == false)
1879 return false;
1880
1881 // Do the upgrade
1882 if (pkgAllUpgrade(Cache) == false)
1883 {
1884 ShowBroken(c1out,Cache,false);
1885 return _error->Error(_("Internal error, AllUpgrade broke stuff"));
1886 }
1887
1888 return InstallPackages(Cache,true);
afb1e2e3
MV
1889}
1890 /*}}}*/
0a8e3465
AL
1891// DoInstall - Install packages from the command line /*{{{*/
1892// ---------------------------------------------------------------------
1893/* Install named packages */
1894bool DoInstall(CommandLine &CmdL)
1895{
1896 CacheFile Cache;
c37b9502
AL
1897 if (Cache.OpenForInstall() == false ||
1898 Cache.CheckDeps(CmdL.FileSize() != 1) == false)
0a8e3465
AL
1899 return false;
1900
7c57fe64
AL
1901 // Enter the special broken fixing mode if the user specified arguments
1902 bool BrokenFix = false;
1903 if (Cache->BrokenCount() != 0)
1904 BrokenFix = true;
71d73928
DK
1905
1906 pkgProblemResolver* Fix = NULL;
92d956ea 1907 if (_config->FindB("APT::Get::CallResolver", true) == true)
71d73928 1908 Fix = new pkgProblemResolver(Cache);
31367812 1909
e67c0834
DK
1910 static const unsigned short MOD_REMOVE = 1;
1911 static const unsigned short MOD_INSTALL = 2;
1912
1913 unsigned short fallback = MOD_INSTALL;
303a1703 1914 if (strcasecmp(CmdL.FileList[0],"remove") == 0)
e67c0834 1915 fallback = MOD_REMOVE;
e47c7d16
MV
1916 else if (strcasecmp(CmdL.FileList[0], "purge") == 0)
1917 {
1918 _config->Set("APT::Get::Purge", true);
e67c0834 1919 fallback = MOD_REMOVE;
e47c7d16 1920 }
74a05226 1921 else if (strcasecmp(CmdL.FileList[0], "autoremove") == 0)
0a8e3465 1922 {
54668e4e 1923 _config->Set("APT::Get::AutomaticRemove", "true");
e67c0834 1924 fallback = MOD_REMOVE;
54668e4e 1925 }
70e706ad
DK
1926
1927 std::list<APT::VersionSet::Modifier> mods;
e67c0834 1928 mods.push_back(APT::VersionSet::Modifier(MOD_INSTALL, "+",
b8ad5512 1929 APT::VersionSet::Modifier::POSTFIX, APT::VersionSet::CANDIDATE));
e67c0834 1930 mods.push_back(APT::VersionSet::Modifier(MOD_REMOVE, "-",
b8ad5512 1931 APT::VersionSet::Modifier::POSTFIX, APT::VersionSet::NEWEST));
70e706ad
DK
1932 CacheSetHelperAPTGet helper(c0out);
1933 std::map<unsigned short, APT::VersionSet> verset = APT::VersionSet::GroupedFromCommandLine(Cache,
1934 CmdL.FileList + 1, mods, fallback, helper);
31367812 1935
70e706ad 1936 if (_error->PendingError() == true)
b8ad5512
DK
1937 {
1938 helper.showVirtualPackageErrors(Cache);
71d73928
DK
1939 if (Fix != NULL)
1940 delete Fix;
70e706ad 1941 return false;
b8ad5512 1942 }
31367812 1943
e67c0834 1944
b8ad5512
DK
1945 TryToInstall InstallAction(Cache, Fix, BrokenFix);
1946 TryToRemove RemoveAction(Cache, Fix);
1947
70e706ad
DK
1948 // new scope for the ActionGroup
1949 {
1950 pkgDepCache::ActionGroup group(Cache);
69c2ecbd 1951 unsigned short const order[] = { MOD_REMOVE, MOD_INSTALL, 0 };
b8ad5512 1952
e67c0834 1953 for (unsigned short i = 0; order[i] != 0; ++i)
31367812 1954 {
71d73928 1955 if (order[i] == MOD_INSTALL)
b8ad5512 1956 InstallAction = std::for_each(verset[MOD_INSTALL].begin(), verset[MOD_INSTALL].end(), InstallAction);
71d73928
DK
1957 else if (order[i] == MOD_REMOVE)
1958 RemoveAction = std::for_each(verset[MOD_REMOVE].begin(), verset[MOD_REMOVE].end(), RemoveAction);
1959 }
1960
92d956ea 1961 if (Fix != NULL && _config->FindB("APT::Get::AutoSolving", true) == true)
71d73928
DK
1962 {
1963 for (unsigned short i = 0; order[i] != 0; ++i)
1964 {
1965 if (order[i] != MOD_INSTALL)
1966 continue;
2c085486 1967 InstallAction.propergateReleaseCandiateSwitching(helper.selectedByRelease, c0out);
6806db8a
DK
1968 InstallAction.doAutoInstall();
1969 }
54668e4e 1970 }
0a8e3465 1971
31367812 1972 if (_error->PendingError() == true)
71d73928
DK
1973 {
1974 if (Fix != NULL)
1975 delete Fix;
31367812 1976 return false;
71d73928 1977 }
31367812 1978
54668e4e
MV
1979 /* If we are in the Broken fixing mode we do not attempt to fix the
1980 problems. This is if the user invoked install without -f and gave
1981 packages */
1982 if (BrokenFix == true && Cache->BrokenCount() != 0)
1983 {
b5647402 1984 c1out << _("You might want to run 'apt-get -f install' to correct these:") << endl;
54668e4e 1985 ShowBroken(c1out,Cache,false);
71d73928
DK
1986 if (Fix != NULL)
1987 delete Fix;
54668e4e
MV
1988 return _error->Error(_("Unmet dependencies. Try 'apt-get -f install' with no packages (or specify a solution)."));
1989 }
71d73928
DK
1990
1991 if (Fix != NULL)
1992 {
1993 // Call the scored problem resolver
d953d210 1994 Fix->Resolve(true);
71d73928
DK
1995 delete Fix;
1996 }
0a8e3465 1997
54668e4e
MV
1998 // Now we check the state of the packages,
1999 if (Cache->BrokenCount() != 0)
303a1703 2000 {
b2e465d6 2001 c1out <<
54668e4e
MV
2002 _("Some packages could not be installed. This may mean that you have\n"
2003 "requested an impossible situation or if you are using the unstable\n"
2004 "distribution that some required packages have not yet been created\n"
2005 "or been moved out of Incoming.") << endl;
ecd414ef 2006 /*
54668e4e
MV
2007 if (Packages == 1)
2008 {
2009 c1out << endl;
2010 c1out <<
2011 _("Since you only requested a single operation it is extremely likely that\n"
2012 "the package is simply not installable and a bug report against\n"
2013 "that package should be filed.") << endl;
2014 }
ecd414ef 2015 */
303a1703 2016
54668e4e
MV
2017 c1out << _("The following information may help to resolve the situation:") << endl;
2018 c1out << endl;
2019 ShowBroken(c1out,Cache,false);
d953d210
DK
2020 if (_error->PendingError() == true)
2021 return false;
2022 else
2023 return _error->Error(_("Broken packages"));
2024 }
120365ce 2025 }
5a68ea79
MV
2026 if (!DoAutomaticRemove(Cache))
2027 return false;
afb1e2e3 2028
0a8e3465
AL
2029 /* Print out a list of packages that are going to be installed extra
2030 to what the user asked */
e67c0834 2031 if (Cache->InstCount() != verset[MOD_INSTALL].size())
0a8e3465
AL
2032 {
2033 string List;
ac625538 2034 string VersionsList;
1089ca89 2035 for (unsigned J = 0; J < Cache->Head().PackageCount; J++)
0a8e3465 2036 {
1089ca89 2037 pkgCache::PkgIterator I(Cache,Cache.List[J]);
0a8e3465
AL
2038 if ((*Cache)[I].Install() == false)
2039 continue;
6a2512be 2040 pkgCache::VerIterator Cand = Cache[I].CandidateVerIter(Cache);
0a8e3465 2041
6a2512be
DK
2042 if (verset[MOD_INSTALL].find(Cand) != verset[MOD_INSTALL].end())
2043 continue;
2044
2045 List += I.FullName(true) + " ";
2046 VersionsList += string(Cache[I].CandVersion) + "\n";
0a8e3465
AL
2047 }
2048
ac625538 2049 ShowList(c1out,_("The following extra packages will be installed:"),List,VersionsList);
0a8e3465
AL
2050 }
2051
a7e41689
AL
2052 /* Print out a list of suggested and recommended packages */
2053 {
69c2ecbd 2054 string SuggestsList, RecommendsList;
72122b62 2055 string SuggestsVersions, RecommendsVersions;
a7e41689
AL
2056 for (unsigned J = 0; J < Cache->Head().PackageCount; J++)
2057 {
29f37db8 2058 pkgCache::PkgIterator Pkg(Cache,Cache.List[J]);
a7e41689
AL
2059
2060 /* Just look at the ones we want to install */
29f37db8 2061 if ((*Cache)[Pkg].Install() == false)
a7e41689
AL
2062 continue;
2063
29f37db8
MV
2064 // get the recommends/suggests for the candidate ver
2065 pkgCache::VerIterator CV = (*Cache)[Pkg].CandidateVerIter(*Cache);
2066 for (pkgCache::DepIterator D = CV.DependsList(); D.end() == false; )
2067 {
2068 pkgCache::DepIterator Start;
2069 pkgCache::DepIterator End;
2070 D.GlobOr(Start,End); // advances D
2071
cd33a786
MV
2072 // FIXME: we really should display a or-group as a or-group to the user
2073 // the problem is that ShowList is incapable of doing this
29f37db8
MV
2074 string RecommendsOrList,RecommendsOrVersions;
2075 string SuggestsOrList,SuggestsOrVersions;
2076 bool foundInstalledInOrGroup = false;
2077 for(;;)
2078 {
2079 /* Skip if package is installed already, or is about to be */
75ce2062 2080 string target = Start.TargetPkg().FullName(true) + " ";
2d847a59
DK
2081 pkgCache::PkgIterator const TarPkg = Start.TargetPkg();
2082 if (TarPkg->SelectedState == pkgCache::State::Install ||
d1aa9162 2083 TarPkg->SelectedState == pkgCache::State::Hold ||
2d847a59 2084 Cache[Start.TargetPkg()].Install())
29f37db8
MV
2085 {
2086 foundInstalledInOrGroup=true;
2087 break;
2088 }
2089
2090 /* Skip if we already saw it */
2091 if (int(SuggestsList.find(target)) != -1 || int(RecommendsList.find(target)) != -1)
2092 {
2093 foundInstalledInOrGroup=true;
2094 break;
2095 }
2096
2097 // this is a dep on a virtual pkg, check if any package that provides it
2098 // should be installed
2099 if(Start.TargetPkg().ProvidesList() != 0)
2100 {
2101 pkgCache::PrvIterator I = Start.TargetPkg().ProvidesList();
f7f0d6c7 2102 for (; I.end() == false; ++I)
29f37db8
MV
2103 {
2104 pkgCache::PkgIterator Pkg = I.OwnerPkg();
2105 if (Cache[Pkg].CandidateVerIter(Cache) == I.OwnerVer() &&
2106 Pkg.CurrentVer() != 0)
2107 foundInstalledInOrGroup=true;
2108 }
2109 }
2110
2111 if (Start->Type == pkgCache::Dep::Suggests)
2112 {
2113 SuggestsOrList += target;
2114 SuggestsOrVersions += string(Cache[Start.TargetPkg()].CandVersion) + "\n";
2115 }
2116
2117 if (Start->Type == pkgCache::Dep::Recommends)
2118 {
2119 RecommendsOrList += target;
2120 RecommendsOrVersions += string(Cache[Start.TargetPkg()].CandVersion) + "\n";
2121 }
2122
2123 if (Start >= End)
2124 break;
f7f0d6c7 2125 ++Start;
29f37db8
MV
2126 }
2127
2128 if(foundInstalledInOrGroup == false)
2129 {
2130 RecommendsList += RecommendsOrList;
2131 RecommendsVersions += RecommendsOrVersions;
2132 SuggestsList += SuggestsOrList;
2133 SuggestsVersions += SuggestsOrVersions;
2134 }
2135
2136 }
a7e41689 2137 }
29f37db8 2138
72122b62
AL
2139 ShowList(c1out,_("Suggested packages:"),SuggestsList,SuggestsVersions);
2140 ShowList(c1out,_("Recommended packages:"),RecommendsList,RecommendsVersions);
a7e41689
AL
2141
2142 }
2143
e4b74e4b
MV
2144 // if nothing changed in the cache, but only the automark information
2145 // we write the StateFile here, otherwise it will be written in
2146 // cache.commit()
b8ad5512 2147 if (InstallAction.AutoMarkChanged > 0 &&
e4b74e4b 2148 Cache->DelCount() == 0 && Cache->InstCount() == 0 &&
9964a721
MV
2149 Cache->BadCount() == 0 &&
2150 _config->FindB("APT::Get::Simulate",false) == false)
e4b74e4b
MV
2151 Cache->writeStateFile(NULL);
2152
03e39e59 2153 // See if we need to prompt
70e706ad 2154 // FIXME: check if really the packages in the set are going to be installed
e67c0834 2155 if (Cache->InstCount() == verset[MOD_INSTALL].size() && Cache->DelCount() == 0)
2c3bc8bb 2156 return InstallPackages(Cache,false,false);
13e8426f 2157
03e39e59 2158 return InstallPackages(Cache,false);
0a8e3465 2159}
182a6a55
DK
2160 /*}}}*/
2161/* mark packages as automatically/manually installed. {{{*/
d63a1458
JAK
2162bool DoMarkAuto(CommandLine &CmdL)
2163{
2164 bool Action = true;
2165 int AutoMarkChanged = 0;
2166 OpTextProgress progress;
2167 CacheFile Cache;
2168 if (Cache.Open() == false)
2169 return false;
2170
2171 if (strcasecmp(CmdL.FileList[0],"markauto") == 0)
2172 Action = true;
2173 else if (strcasecmp(CmdL.FileList[0],"unmarkauto") == 0)
2174 Action = false;
2175
2176 for (const char **I = CmdL.FileList + 1; *I != 0; I++)
2177 {
2178 const char *S = *I;
2179 // Locate the package
2180 pkgCache::PkgIterator Pkg = Cache->FindPkg(S);
2181 if (Pkg.end() == true) {
2182 return _error->Error(_("Couldn't find package %s"),S);
2183 }
2184 else
2185 {
2186 if (!Action)
2187 ioprintf(c1out,_("%s set to manually installed.\n"), Pkg.Name());
2188 else
2189 ioprintf(c1out,_("%s set to automatically installed.\n"),
2190 Pkg.Name());
2191
2192 Cache->MarkAuto(Pkg,Action);
2193 AutoMarkChanged++;
2194 }
2195 }
182a6a55
DK
2196
2197 _error->Notice(_("This command is deprecated. Please use 'apt-mark auto' and 'apt-mark manual' instead."));
2198
d63a1458
JAK
2199 if (AutoMarkChanged && ! _config->FindB("APT::Get::Simulate",false))
2200 return Cache->writeStateFile(NULL);
2201 return false;
2202}
0a8e3465
AL
2203 /*}}}*/
2204// DoDistUpgrade - Automatic smart upgrader /*{{{*/
2205// ---------------------------------------------------------------------
2206/* Intelligent upgrader that will install and remove packages at will */
2207bool DoDistUpgrade(CommandLine &CmdL)
2208{
2209 CacheFile Cache;
c37b9502 2210 if (Cache.OpenForInstall() == false || Cache.CheckDeps() == false)
0a8e3465
AL
2211 return false;
2212
db0db9fe 2213 c0out << _("Calculating upgrade... ") << flush;
0a8e3465
AL
2214 if (pkgDistUpgrade(*Cache) == false)
2215 {
b2e465d6 2216 c0out << _("Failed") << endl;
421c8d10 2217 ShowBroken(c1out,Cache,false);
0a8e3465
AL
2218 return false;
2219 }
2220
b2e465d6 2221 c0out << _("Done") << endl;
0a8e3465
AL
2222
2223 return InstallPackages(Cache,true);
2224}
2225 /*}}}*/
2226// DoDSelectUpgrade - Do an upgrade by following dselects selections /*{{{*/
2227// ---------------------------------------------------------------------
2228/* Follows dselect's selections */
2229bool DoDSelectUpgrade(CommandLine &CmdL)
2230{
2231 CacheFile Cache;
c37b9502 2232 if (Cache.OpenForInstall() == false || Cache.CheckDeps() == false)
0a8e3465
AL
2233 return false;
2234
a4decc40
MV
2235 pkgDepCache::ActionGroup group(Cache);
2236
0a8e3465
AL
2237 // Install everything with the install flag set
2238 pkgCache::PkgIterator I = Cache->PkgBegin();
f7f0d6c7 2239 for (;I.end() != true; ++I)
0a8e3465
AL
2240 {
2241 /* Install the package only if it is a new install, the autoupgrader
2242 will deal with the rest */
2243 if (I->SelectedState == pkgCache::State::Install)
2244 Cache->MarkInstall(I,false);
2245 }
2246
2247 /* Now install their deps too, if we do this above then order of
2248 the status file is significant for | groups */
f7f0d6c7 2249 for (I = Cache->PkgBegin();I.end() != true; ++I)
0a8e3465
AL
2250 {
2251 /* Install the package only if it is a new install, the autoupgrader
2252 will deal with the rest */
2253 if (I->SelectedState == pkgCache::State::Install)
2f45c76a 2254 Cache->MarkInstall(I,true);
0a8e3465
AL
2255 }
2256
2257 // Apply erasures now, they override everything else.
f7f0d6c7 2258 for (I = Cache->PkgBegin();I.end() != true; ++I)
0a8e3465
AL
2259 {
2260 // Remove packages
2261 if (I->SelectedState == pkgCache::State::DeInstall ||
2262 I->SelectedState == pkgCache::State::Purge)
d556d1a1 2263 Cache->MarkDelete(I,I->SelectedState == pkgCache::State::Purge);
0a8e3465
AL
2264 }
2265
2f45c76a
AL
2266 /* Resolve any problems that dselect created, allupgrade cannot handle
2267 such things. We do so quite agressively too.. */
2268 if (Cache->BrokenCount() != 0)
2269 {
2270 pkgProblemResolver Fix(Cache);
2271
2272 // Hold back held packages.
b2e465d6 2273 if (_config->FindB("APT::Ignore-Hold",false) == false)
2f45c76a 2274 {
f7f0d6c7 2275 for (pkgCache::PkgIterator I = Cache->PkgBegin(); I.end() == false; ++I)
2f45c76a
AL
2276 {
2277 if (I->SelectedState == pkgCache::State::Hold)
2278 {
2279 Fix.Protect(I);
2280 Cache->MarkKeep(I);
2281 }
2282 }
2283 }
2284
2285 if (Fix.Resolve() == false)
2286 {
421c8d10 2287 ShowBroken(c1out,Cache,false);
2a7e07c7 2288 return _error->Error(_("Internal error, problem resolver broke stuff"));
2f45c76a
AL
2289 }
2290 }
2291
2292 // Now upgrade everything
0a8e3465
AL
2293 if (pkgAllUpgrade(Cache) == false)
2294 {
421c8d10 2295 ShowBroken(c1out,Cache,false);
2a7e07c7 2296 return _error->Error(_("Internal error, problem resolver broke stuff"));
0a8e3465
AL
2297 }
2298
2299 return InstallPackages(Cache,false);
2300}
2301 /*}}}*/
2302// DoClean - Remove download archives /*{{{*/
2303// ---------------------------------------------------------------------
2304/* */
2305bool DoClean(CommandLine &CmdL)
2306{
657ecd4a
DK
2307 std::string const archivedir = _config->FindDir("Dir::Cache::archives");
2308 std::string const pkgcache = _config->FindFile("Dir::cache::pkgcache");
2309 std::string const srcpkgcache = _config->FindFile("Dir::cache::srcpkgcache");
2310
8b067c22
AL
2311 if (_config->FindB("APT::Get::Simulate") == true)
2312 {
657ecd4a
DK
2313 cout << "Del " << archivedir << "* " << archivedir << "partial/*"<< endl
2314 << "Del " << pkgcache << " " << srcpkgcache << endl;
8b067c22
AL
2315 return true;
2316 }
2317
1b6d659c
AL
2318 // Lock the archive directory
2319 FileFd Lock;
2320 if (_config->FindB("Debug::NoLocking",false) == false)
2321 {
de24f8ce
MV
2322 int lock_fd = GetLock(archivedir + "lock");
2323 if (lock_fd < 0)
b2e465d6 2324 return _error->Error(_("Unable to lock the download directory"));
de24f8ce 2325 Lock.Fd(lock_fd);
1b6d659c
AL
2326 }
2327
7a1b1f8b 2328 pkgAcquire Fetcher;
657ecd4a
DK
2329 Fetcher.Clean(archivedir);
2330 Fetcher.Clean(archivedir + "partial/");
2331
8de79b68 2332 pkgCacheFile::RemoveCaches();
657ecd4a 2333
0a8e3465
AL
2334 return true;
2335}
2336 /*}}}*/
1bc849af
AL
2337// DoAutoClean - Smartly remove downloaded archives /*{{{*/
2338// ---------------------------------------------------------------------
2339/* This is similar to clean but it only purges things that cannot be
2340 downloaded, that is old versions of cached packages. */
65a1e968
AL
2341class LogCleaner : public pkgArchiveCleaner
2342{
2343 protected:
2344 virtual void Erase(const char *File,string Pkg,string Ver,struct stat &St)
2345 {
4cc8bab0 2346 c1out << "Del " << Pkg << " " << Ver << " [" << SizeToStr(St.st_size) << "B]" << endl;
c1e78ee5
AL
2347
2348 if (_config->FindB("APT::Get::Simulate") == false)
2349 unlink(File);
65a1e968
AL
2350 };
2351};
2352
1bc849af
AL
2353bool DoAutoClean(CommandLine &CmdL)
2354{
1b6d659c
AL
2355 // Lock the archive directory
2356 FileFd Lock;
2357 if (_config->FindB("Debug::NoLocking",false) == false)
2358 {
de24f8ce
MV
2359 int lock_fd = GetLock(_config->FindDir("Dir::Cache::Archives") + "lock");
2360 if (lock_fd < 0)
b2e465d6 2361 return _error->Error(_("Unable to lock the download directory"));
de24f8ce 2362 Lock.Fd(lock_fd);
1b6d659c
AL
2363 }
2364
1bc849af 2365 CacheFile Cache;
2d11135a 2366 if (Cache.Open() == false)
1bc849af
AL
2367 return false;
2368
65a1e968 2369 LogCleaner Cleaner;
1bc849af
AL
2370
2371 return Cleaner.Go(_config->FindDir("Dir::Cache::archives"),*Cache) &&
2372 Cleaner.Go(_config->FindDir("Dir::Cache::archives") + "partial/",*Cache);
2373}
2374 /*}}}*/
0e3e112e
MV
2375// DoDownload - download a binary /*{{{*/
2376// ---------------------------------------------------------------------
2377bool DoDownload(CommandLine &CmdL)
2378{
2379 CacheFile Cache;
2380 if (Cache.ReadOnlyOpen() == false)
2381 return false;
2382
2383 APT::CacheSetHelper helper(c0out);
c4cca791
DK
2384 APT::VersionList verset = APT::VersionList::FromCommandLine(Cache,
2385 CmdL.FileList + 1, APT::VersionList::CANDIDATE, helper);
0e3e112e
MV
2386
2387 if (verset.empty() == true)
2388 return false;
2389
42d41ddb
DK
2390 pkgAcquire Fetcher;
2391 AcqTextStatus Stat(ScreenWidth, _config->FindI("quiet",0));
fd8b88d6 2392 if (_config->FindB("APT::Get::Print-URIs") == false)
42d41ddb
DK
2393 Fetcher.Setup(&Stat);
2394
0e3e112e
MV
2395 pkgRecords Recs(Cache);
2396 pkgSourceList *SrcList = Cache.GetSourceList();
567785b9
DK
2397 bool gotAll = true;
2398
c4cca791 2399 for (APT::VersionList::const_iterator Ver = verset.begin();
0e3e112e
MV
2400 Ver != verset.end();
2401 ++Ver)
2402 {
2403 string descr;
2404 // get the right version
2405 pkgCache::PkgIterator Pkg = Ver.ParentPkg();
2406 pkgRecords::Parser &rec=Recs.Lookup(Ver.FileList());
2407 pkgCache::VerFileIterator Vf = Ver.FileList();
2408 if (Vf.end() == true)
567785b9
DK
2409 {
2410 _error->Error("Can not find VerFile for %s in version %s", Pkg.FullName().c_str(), Ver.VerStr());
2411 gotAll = false;
2412 continue;
2413 }
0e3e112e
MV
2414 pkgCache::PkgFileIterator F = Vf.File();
2415 pkgIndexFile *index;
2416 if(SrcList->FindIndex(F, index) == false)
567785b9
DK
2417 {
2418 _error->Error(_("Can't find a source to download version '%s' of '%s'"), Ver.VerStr(), Pkg.FullName().c_str());
2419 gotAll = false;
2420 continue;
2421 }
0e3e112e
MV
2422 string uri = index->ArchiveURI(rec.FileName());
2423 strprintf(descr, _("Downloading %s %s"), Pkg.Name(), Ver.VerStr());
2424 // get the most appropriate hash
2425 HashString hash;
d9b9e9e2
MV
2426 if (rec.SHA512Hash() != "")
2427 hash = HashString("sha512", rec.SHA512Hash());
ee5f5d25 2428 else if (rec.SHA256Hash() != "")
0e3e112e
MV
2429 hash = HashString("sha256", rec.SHA256Hash());
2430 else if (rec.SHA1Hash() != "")
2431 hash = HashString("sha1", rec.SHA1Hash());
2432 else if (rec.MD5Hash() != "")
2433 hash = HashString("md5", rec.MD5Hash());
2434 // get the file
2435 new pkgAcqFile(&Fetcher, uri, hash.toStr(), (*Ver)->Size, descr, Pkg.Name(), ".");
0e3e112e 2436 }
567785b9
DK
2437 if (gotAll == false)
2438 return false;
0e3e112e 2439
42d41ddb
DK
2440 // Just print out the uris and exit if the --print-uris flag was used
2441 if (_config->FindB("APT::Get::Print-URIs") == true)
2442 {
2443 pkgAcquire::UriIterator I = Fetcher.UriBegin();
f7f0d6c7 2444 for (; I != Fetcher.UriEnd(); ++I)
42d41ddb
DK
2445 cout << '\'' << I->URI << "' " << flNotDir(I->Owner->DestFile) << ' ' <<
2446 I->Owner->FileSize << ' ' << I->Owner->HashSum() << endl;
2447 return true;
2448 }
2449
2450 return (Fetcher.Run() == pkgAcquire::Continue);
0e3e112e
MV
2451}
2452 /*}}}*/
0a8e3465
AL
2453// DoCheck - Perform the check operation /*{{{*/
2454// ---------------------------------------------------------------------
2455/* Opening automatically checks the system, this command is mostly used
2456 for debugging */
2457bool DoCheck(CommandLine &CmdL)
2458{
2459 CacheFile Cache;
2460 Cache.Open();
2d11135a 2461 Cache.CheckDeps();
0a8e3465
AL
2462
2463 return true;
2464}
2465 /*}}}*/
36375005
AL
2466// DoSource - Fetch a source archive /*{{{*/
2467// ---------------------------------------------------------------------
2d11135a 2468/* Fetch souce packages */
fb0ee66e
AL
2469struct DscFile
2470{
2471 string Package;
2472 string Version;
2473 string Dsc;
2474};
2475
36375005
AL
2476bool DoSource(CommandLine &CmdL)
2477{
2478 CacheFile Cache;
2d11135a 2479 if (Cache.Open(false) == false)
36375005
AL
2480 return false;
2481
2d11135a 2482 if (CmdL.FileSize() <= 1)
b2e465d6 2483 return _error->Error(_("Must specify at least one package to fetch source for"));
2d11135a 2484
36375005 2485 // Read the source list
1bb8cd67
DK
2486 if (Cache.BuildSourceList() == false)
2487 return false;
2488 pkgSourceList *List = Cache.GetSourceList();
36375005
AL
2489
2490 // Create the text record parsers
2491 pkgRecords Recs(Cache);
1bb8cd67 2492 pkgSrcRecords SrcRecs(*List);
36375005
AL
2493 if (_error->PendingError() == true)
2494 return false;
2495
2496 // Create the download object
2497 AcqTextStatus Stat(ScreenWidth,_config->FindI("quiet",0));
1cd1c398 2498 pkgAcquire Fetcher;
4a53151a 2499 Fetcher.SetLog(&Stat);
fb0ee66e
AL
2500
2501 DscFile *Dsc = new DscFile[CmdL.FileSize()];
36375005 2502
092ae175
MV
2503 // insert all downloaded uris into this set to avoid downloading them
2504 // twice
2505 set<string> queued;
8545b536
DK
2506
2507 // Diff only mode only fetches .diff files
2508 bool const diffOnly = _config->FindB("APT::Get::Diff-Only", false);
2509 // Tar only mode only fetches .tar files
2510 bool const tarOnly = _config->FindB("APT::Get::Tar-Only", false);
2511 // Dsc only mode only fetches .dsc files
2512 bool const dscOnly = _config->FindB("APT::Get::Dsc-Only", false);
2513
36375005 2514 // Load the requestd sources into the fetcher
fb0ee66e
AL
2515 unsigned J = 0;
2516 for (const char **I = CmdL.FileList + 1; *I != 0; I++, J++)
36375005
AL
2517 {
2518 string Src;
b2e465d6 2519 pkgSrcRecords::Parser *Last = FindSrc(*I,Recs,SrcRecs,Src,*Cache);
36375005 2520
6070a346
DK
2521 if (Last == 0) {
2522 delete[] Dsc;
b2e465d6 2523 return _error->Error(_("Unable to find a source package for %s"),Src.c_str());
6070a346 2524 }
36375005 2525
3238423f
MV
2526 string srec = Last->AsStr();
2527 string::size_type pos = srec.find("\nVcs-");
774a6687 2528 while (pos != string::npos)
3238423f
MV
2529 {
2530 pos += strlen("\nVcs-");
2531 string vcs = srec.substr(pos,srec.find(":",pos)-pos);
774a6687
MV
2532 if(vcs == "Browser")
2533 {
2534 pos = srec.find("\nVcs-", pos);
2535 continue;
2536 }
3238423f
MV
2537 pos += vcs.length()+2;
2538 string::size_type epos = srec.find("\n", pos);
2539 string uri = srec.substr(pos,epos-pos).c_str();
b799e134 2540 ioprintf(c1out, _("NOTICE: '%s' packaging is maintained in "
3238423f 2541 "the '%s' version control system at:\n"
8756297c 2542 "%s\n"),
3238423f
MV
2543 Src.c_str(), vcs.c_str(), uri.c_str());
2544 if(vcs == "Bzr")
927677f0 2545 ioprintf(c1out,_("Please use:\n"
f3e3a2d4 2546 "bzr branch %s\n"
3d513bbd 2547 "to retrieve the latest (possibly unreleased) "
b799e134 2548 "updates to the package.\n"),
3238423f 2549 uri.c_str());
b799e134 2550 break;
3238423f
MV
2551 }
2552
36375005
AL
2553 // Back track
2554 vector<pkgSrcRecords::File> Lst;
6070a346
DK
2555 if (Last->Files(Lst) == false) {
2556 delete[] Dsc;
36375005 2557 return false;
6070a346 2558 }
36375005
AL
2559
2560 // Load them into the fetcher
2561 for (vector<pkgSrcRecords::File>::const_iterator I = Lst.begin();
f7f0d6c7 2562 I != Lst.end(); ++I)
36375005
AL
2563 {
2564 // Try to guess what sort of file it is we are getting.
b2e465d6 2565 if (I->Type == "dsc")
fb0ee66e 2566 {
fb0ee66e
AL
2567 Dsc[J].Package = Last->Package();
2568 Dsc[J].Version = Last->Version();
2569 Dsc[J].Dsc = flNotDir(I->Path);
2570 }
092ae175 2571
8545b536
DK
2572 // Handle the only options so that multiple can be used at once
2573 if (diffOnly == true || tarOnly == true || dscOnly == true)
2574 {
2575 if ((diffOnly == true && I->Type == "diff") ||
2576 (tarOnly == true && I->Type == "tar") ||
2577 (dscOnly == true && I->Type == "dsc"))
2578 ; // Fine, we want this file downloaded
2579 else
2580 continue;
2581 }
1979e742 2582
092ae175
MV
2583 // don't download the same uri twice (should this be moved to
2584 // the fetcher interface itself?)
2585 if(queued.find(Last->Index().ArchiveURI(I->Path)) != queued.end())
2586 continue;
2587 queued.insert(Last->Index().ArchiveURI(I->Path));
2588
2589 // check if we have a file with that md5 sum already localy
2590 if(!I->MD5Hash.empty() && FileExists(flNotDir(I->Path)))
2591 {
2592 FileFd Fd(flNotDir(I->Path), FileFd::ReadOnly);
2593 MD5Summation sum;
2594 sum.AddFD(Fd.Fd(), Fd.Size());
2595 Fd.Close();
2596 if((string)sum.Result() == I->MD5Hash)
2597 {
443cb67c 2598 ioprintf(c1out,_("Skipping already downloaded file '%s'\n"),
092ae175
MV
2599 flNotDir(I->Path).c_str());
2600 continue;
2601 }
2602 }
2603
b2e465d6
AL
2604 new pkgAcqFile(&Fetcher,Last->Index().ArchiveURI(I->Path),
2605 I->MD5Hash,I->Size,
2606 Last->Index().SourceInfo(*Last,*I),Src);
36375005
AL
2607 }
2608 }
2609
2610 // Display statistics
3a882565
DK
2611 unsigned long long FetchBytes = Fetcher.FetchNeeded();
2612 unsigned long long FetchPBytes = Fetcher.PartialPresent();
2613 unsigned long long DebBytes = Fetcher.TotalNeeded();
36375005
AL
2614
2615 // Check for enough free space
f332b62b 2616 struct statvfs Buf;
36375005 2617 string OutputDir = ".";
c1ce032a 2618 if (statvfs(OutputDir.c_str(),&Buf) != 0) {
6070a346 2619 delete[] Dsc;
c1ce032a
DK
2620 if (errno == EOVERFLOW)
2621 return _error->WarningE("statvfs",_("Couldn't determine free space in %s"),
2622 OutputDir.c_str());
2623 else
2624 return _error->Errno("statvfs",_("Couldn't determine free space in %s"),
2625 OutputDir.c_str());
2626 } else if (unsigned(Buf.f_bfree) < (FetchBytes - FetchPBytes)/Buf.f_bsize)
885d204b
OS
2627 {
2628 struct statfs Stat;
f64196e8
DK
2629 if (statfs(OutputDir.c_str(),&Stat) != 0
2630#if HAVE_STRUCT_STATFS_F_TYPE
2631 || unsigned(Stat.f_type) != RAMFS_MAGIC
2632#endif
6070a346
DK
2633 ) {
2634 delete[] Dsc;
885d204b
OS
2635 return _error->Error(_("You don't have enough free space in %s"),
2636 OutputDir.c_str());
6070a346
DK
2637 }
2638 }
36375005
AL
2639
2640 // Number of bytes
36375005 2641 if (DebBytes != FetchBytes)
4d8d8112
DK
2642 //TRANSLATOR: The required space between number and unit is already included
2643 // in the replacement strings, so %sB will be correctly translate in e.g. 1,5 MB
b2e465d6
AL
2644 ioprintf(c1out,_("Need to get %sB/%sB of source archives.\n"),
2645 SizeToStr(FetchBytes).c_str(),SizeToStr(DebBytes).c_str());
36375005 2646 else
4d8d8112
DK
2647 //TRANSLATOR: The required space between number and unit is already included
2648 // in the replacement string, so %sB will be correctly translate in e.g. 1,5 MB
b2e465d6
AL
2649 ioprintf(c1out,_("Need to get %sB of source archives.\n"),
2650 SizeToStr(DebBytes).c_str());
2651
2c0c53b3
AL
2652 if (_config->FindB("APT::Get::Simulate",false) == true)
2653 {
2654 for (unsigned I = 0; I != J; I++)
db0db9fe 2655 ioprintf(cout,_("Fetch source %s\n"),Dsc[I].Package.c_str());
3a4477a4 2656 delete[] Dsc;
2c0c53b3
AL
2657 return true;
2658 }
2659
36375005
AL
2660 // Just print out the uris an exit if the --print-uris flag was used
2661 if (_config->FindB("APT::Get::Print-URIs") == true)
2662 {
2663 pkgAcquire::UriIterator I = Fetcher.UriBegin();
f7f0d6c7 2664 for (; I != Fetcher.UriEnd(); ++I)
36375005 2665 cout << '\'' << I->URI << "' " << flNotDir(I->Owner->DestFile) << ' ' <<
495e5cb2 2666 I->Owner->FileSize << ' ' << I->Owner->HashSum() << endl;
3a4477a4 2667 delete[] Dsc;
36375005
AL
2668 return true;
2669 }
2670
2671 // Run it
024d1123 2672 if (Fetcher.Run() == pkgAcquire::Failed)
6070a346
DK
2673 {
2674 delete[] Dsc;
36375005 2675 return false;
6070a346 2676 }
36375005
AL
2677
2678 // Print error messages
fb0ee66e 2679 bool Failed = false;
f7f0d6c7 2680 for (pkgAcquire::ItemIterator I = Fetcher.ItemsBegin(); I != Fetcher.ItemsEnd(); ++I)
36375005
AL
2681 {
2682 if ((*I)->Status == pkgAcquire::Item::StatDone &&
2683 (*I)->Complete == true)
2684 continue;
2685
b2e465d6
AL
2686 fprintf(stderr,_("Failed to fetch %s %s\n"),(*I)->DescURI().c_str(),
2687 (*I)->ErrorText.c_str());
fb0ee66e 2688 Failed = true;
36375005 2689 }
fb0ee66e 2690 if (Failed == true)
6070a346
DK
2691 {
2692 delete[] Dsc;
b2e465d6 2693 return _error->Error(_("Failed to fetch some archives."));
6070a346
DK
2694 }
2695
fb0ee66e 2696 if (_config->FindB("APT::Get::Download-only",false) == true)
b2e465d6
AL
2697 {
2698 c1out << _("Download complete and in download only mode") << endl;
3a4477a4 2699 delete[] Dsc;
fb0ee66e 2700 return true;
b2e465d6
AL
2701 }
2702
fb0ee66e 2703 // Unpack the sources
54676e1a
AL
2704 pid_t Process = ExecFork();
2705
2706 if (Process == 0)
fb0ee66e 2707 {
827d04d3 2708 bool const fixBroken = _config->FindB("APT::Get::Fix-Broken", false);
f7f0d6c7 2709 for (unsigned I = 0; I != J; ++I)
fb0ee66e 2710 {
b2e465d6 2711 string Dir = Dsc[I].Package + '-' + Cache->VS().UpstreamVersion(Dsc[I].Version.c_str());
fb0ee66e 2712
17c0e8e1
AL
2713 // Diff only mode only fetches .diff files
2714 if (_config->FindB("APT::Get::Diff-Only",false) == true ||
a3eaf954
AL
2715 _config->FindB("APT::Get::Tar-Only",false) == true ||
2716 Dsc[I].Dsc.empty() == true)
17c0e8e1 2717 continue;
a3eaf954 2718
54676e1a
AL
2719 // See if the package is already unpacked
2720 struct stat Stat;
827d04d3 2721 if (fixBroken == false && stat(Dir.c_str(),&Stat) == 0 &&
54676e1a
AL
2722 S_ISDIR(Stat.st_mode) != 0)
2723 {
b2e465d6
AL
2724 ioprintf(c0out ,_("Skipping unpack of already unpacked source in %s\n"),
2725 Dir.c_str());
54676e1a
AL
2726 }
2727 else
2728 {
2729 // Call dpkg-source
2730 char S[500];
2731 snprintf(S,sizeof(S),"%s -x %s",
2732 _config->Find("Dir::Bin::dpkg-source","dpkg-source").c_str(),
2733 Dsc[I].Dsc.c_str());
2734 if (system(S) != 0)
2735 {
b2e465d6 2736 fprintf(stderr,_("Unpack command '%s' failed.\n"),S);
14cd494a 2737 fprintf(stderr,_("Check if the 'dpkg-dev' package is installed.\n"));
54676e1a
AL
2738 _exit(1);
2739 }
2740 }
2741
2742 // Try to compile it with dpkg-buildpackage
2743 if (_config->FindB("APT::Get::Compile",false) == true)
2744 {
234675b7
DK
2745 string buildopts = _config->Find("APT::Get::Host-Architecture");
2746 if (buildopts.empty() == false)
c5102538 2747 buildopts = "-a" + buildopts + " ";
234675b7
DK
2748 buildopts.append(_config->Find("DPkg::Build-Options","-b -uc"));
2749
54676e1a
AL
2750 // Call dpkg-buildpackage
2751 char S[500];
2752 snprintf(S,sizeof(S),"cd %s && %s %s",
2753 Dir.c_str(),
2754 _config->Find("Dir::Bin::dpkg-buildpackage","dpkg-buildpackage").c_str(),
234675b7 2755 buildopts.c_str());
54676e1a
AL
2756
2757 if (system(S) != 0)
2758 {
b2e465d6 2759 fprintf(stderr,_("Build command '%s' failed.\n"),S);
54676e1a
AL
2760 _exit(1);
2761 }
2762 }
2763 }
2764
2765 _exit(0);
2766 }
3a4477a4
DK
2767 delete[] Dsc;
2768
54676e1a
AL
2769 // Wait for the subprocess
2770 int Status = 0;
2771 while (waitpid(Process,&Status,0) != Process)
2772 {
2773 if (errno == EINTR)
2774 continue;
2775 return _error->Errno("waitpid","Couldn't wait for subprocess");
2776 }
2777
2778 if (WIFEXITED(Status) == 0 || WEXITSTATUS(Status) != 0)
b2e465d6
AL
2779 return _error->Error(_("Child process failed"));
2780
2781 return true;
2782}
2783 /*}}}*/
2784// DoBuildDep - Install/removes packages to satisfy build dependencies /*{{{*/
2785// ---------------------------------------------------------------------
2786/* This function will look at the build depends list of the given source
2787 package and install the necessary packages to make it true, or fail. */
2788bool DoBuildDep(CommandLine &CmdL)
2789{
2790 CacheFile Cache;
35180212
JAK
2791
2792 _config->Set("APT::Install-Recommends", false);
2793
b2e465d6
AL
2794 if (Cache.Open(true) == false)
2795 return false;
2796
2797 if (CmdL.FileSize() <= 1)
2798 return _error->Error(_("Must specify at least one package to check builddeps for"));
2799
2800 // Read the source list
1bb8cd67
DK
2801 if (Cache.BuildSourceList() == false)
2802 return false;
2803 pkgSourceList *List = Cache.GetSourceList();
54676e1a 2804
b2e465d6
AL
2805 // Create the text record parsers
2806 pkgRecords Recs(Cache);
1bb8cd67 2807 pkgSrcRecords SrcRecs(*List);
b2e465d6
AL
2808 if (_error->PendingError() == true)
2809 return false;
2810
2811 // Create the download object
2812 AcqTextStatus Stat(ScreenWidth,_config->FindI("quiet",0));
1cd1c398
DK
2813 pkgAcquire Fetcher;
2814 if (Fetcher.Setup(&Stat) == false)
2815 return false;
b2e465d6 2816
234675b7
DK
2817 bool StripMultiArch;
2818 string hostArch = _config->Find("APT::Get::Host-Architecture");
2819 if (hostArch.empty() == false)
2820 {
2821 std::vector<std::string> archs = APT::Configuration::getArchitectures();
2822 if (std::find(archs.begin(), archs.end(), hostArch) == archs.end())
2823 return _error->Error(_("No architecture information available for %s. See apt.conf(5) APT::Architectures for setup"), hostArch.c_str());
2824 StripMultiArch = false;
2825 }
2826 else
2827 StripMultiArch = true;
2828
b2e465d6
AL
2829 unsigned J = 0;
2830 for (const char **I = CmdL.FileList + 1; *I != 0; I++, J++)
2831 {
2832 string Src;
2833 pkgSrcRecords::Parser *Last = FindSrc(*I,Recs,SrcRecs,Src,*Cache);
2834 if (Last == 0)
2835 return _error->Error(_("Unable to find a source package for %s"),Src.c_str());
2836
2837 // Process the build-dependencies
2838 vector<pkgSrcRecords::Parser::BuildDepRec> BuildDeps;
65f99834
DK
2839 // FIXME: Can't specify architecture to use for [wildcard] matching, so switch default arch temporary
2840 if (hostArch.empty() == false)
2841 {
2842 std::string nativeArch = _config->Find("APT::Architecture");
2843 _config->Set("APT::Architecture", hostArch);
2844 bool Success = Last->BuildDepends(BuildDeps, _config->FindB("APT::Get::Arch-Only", false), StripMultiArch);
2845 _config->Set("APT::Architecture", nativeArch);
2846 if (Success == false)
2847 return _error->Error(_("Unable to get build-dependency information for %s"),Src.c_str());
2848 }
2849 else if (Last->BuildDepends(BuildDeps, _config->FindB("APT::Get::Arch-Only", false), StripMultiArch) == false)
2850 return _error->Error(_("Unable to get build-dependency information for %s"),Src.c_str());
b2e465d6 2851
7d6f9f8f
AL
2852 // Also ensure that build-essential packages are present
2853 Configuration::Item const *Opts = _config->Tree("APT::Build-Essential");
2854 if (Opts)
2855 Opts = Opts->Child;
2856 for (; Opts; Opts = Opts->Next)
2857 {
2858 if (Opts->Value.empty() == true)
2859 continue;
2860
2861 pkgSrcRecords::Parser::BuildDepRec rec;
2862 rec.Package = Opts->Value;
2863 rec.Type = pkgSrcRecords::Parser::BuildDependIndep;
2864 rec.Op = 0;
58d76831 2865 BuildDeps.push_back(rec);
7d6f9f8f
AL
2866 }
2867
f7f0d6c7 2868 if (BuildDeps.empty() == true)
b2e465d6
AL
2869 {
2870 ioprintf(c1out,_("%s has no build depends.\n"),Src.c_str());
2871 continue;
2872 }
234675b7 2873
b2e465d6 2874 // Install the requested packages
b2e465d6
AL
2875 vector <pkgSrcRecords::Parser::BuildDepRec>::iterator D;
2876 pkgProblemResolver Fix(Cache);
58d76831 2877 bool skipAlternatives = false; // skip remaining alternatives in an or group
f7f0d6c7 2878 for (D = BuildDeps.begin(); D != BuildDeps.end(); ++D)
b2e465d6 2879 {
58d76831
AL
2880 bool hasAlternatives = (((*D).Op & pkgCache::Dep::Or) == pkgCache::Dep::Or);
2881
2882 if (skipAlternatives == true)
2883 {
3fdb6f83
DK
2884 /*
2885 * if there are alternatives, we've already picked one, so skip
2886 * the rest
2887 *
2888 * TODO: this means that if there's a build-dep on A|B and B is
2889 * installed, we'll still try to install A; more importantly,
2890 * if A is currently broken, we cannot go back and try B. To fix
2891 * this would require we do a Resolve cycle for each package we
2892 * add to the install list. Ugh
2893 */
58d76831
AL
2894 if (!hasAlternatives)
2895 skipAlternatives = false; // end of or group
2896 continue;
2897 }
2898
aa2d22be
AL
2899 if ((*D).Type == pkgSrcRecords::Parser::BuildConflict ||
2900 (*D).Type == pkgSrcRecords::Parser::BuildConflictIndep)
d3fc0061 2901 {
e3a86238 2902 pkgCache::GrpIterator Grp = Cache->FindGrp((*D).Package);
aa2d22be 2903 // Build-conflicts on unknown packages are silently ignored
e3a86238 2904 if (Grp.end() == true)
aa2d22be
AL
2905 continue;
2906
e3a86238
DK
2907 for (pkgCache::PkgIterator Pkg = Grp.PackageList(); Pkg.end() == false; Pkg = Grp.NextPkg(Pkg))
2908 {
2909 pkgCache::VerIterator IV = (*Cache)[Pkg].InstVerIter(*Cache);
2910 /*
2911 * Remove if we have an installed version that satisfies the
2912 * version criteria
2913 */
2914 if (IV.end() == false &&
2915 Cache->VS().CheckDep(IV.VerStr(),(*D).Op,(*D).Version.c_str()) == true)
2916 TryToInstallBuildDep(Pkg,Cache,Fix,true,false);
2917 }
d3fc0061 2918 }
aa2d22be
AL
2919 else // BuildDep || BuildDepIndep
2920 {
58d76831
AL
2921 if (_config->FindB("Debug::BuildDeps",false) == true)
2922 cout << "Looking for " << (*D).Package << "...\n";
2923
234675b7
DK
2924 pkgCache::PkgIterator Pkg;
2925
2926 // Cross-Building?
c307a4f0 2927 if (StripMultiArch == false && D->Type != pkgSrcRecords::Parser::BuildDependIndep)
234675b7
DK
2928 {
2929 size_t const colon = D->Package.find(":");
666faa35
DK
2930 if (colon != string::npos)
2931 {
2932 if (strcmp(D->Package.c_str() + colon, ":any") == 0 || strcmp(D->Package.c_str() + colon, ":native") == 0)
2933 Pkg = Cache->FindPkg(D->Package.substr(0,colon));
2934 else
2935 Pkg = Cache->FindPkg(D->Package);
2936 }
234675b7 2937 else
666faa35 2938 Pkg = Cache->FindPkg(D->Package, hostArch);
234675b7 2939
234675b7 2940 // a bad version either is invalid or doesn't satify dependency
d5dea0be
DK
2941 #define BADVER(Ver) (Ver.end() == true || \
2942 (D->Version.empty() == false && \
2943 Cache->VS().CheckDep(Ver.VerStr(),D->Op,D->Version.c_str()) == false))
234675b7 2944
d5dea0be 2945 APT::VersionList verlist;
234675b7
DK
2946 if (Pkg.end() == false)
2947 {
d5dea0be
DK
2948 pkgCache::VerIterator Ver = (*Cache)[Pkg].InstVerIter(*Cache);
2949 if (BADVER(Ver) == false)
2950 verlist.insert(Ver);
2951 Ver = (*Cache)[Pkg].CandidateVerIter(*Cache);
2952 if (BADVER(Ver) == false)
2953 verlist.insert(Ver);
234675b7 2954 }
d5dea0be 2955 if (verlist.empty() == true)
234675b7 2956 {
666faa35
DK
2957 pkgCache::PkgIterator BuildPkg = Cache->FindPkg(D->Package, "native");
2958 if (BuildPkg.end() == false && Pkg != BuildPkg)
234675b7 2959 {
666faa35 2960 pkgCache::VerIterator Ver = (*Cache)[BuildPkg].InstVerIter(*Cache);
d5dea0be
DK
2961 if (BADVER(Ver) == false)
2962 verlist.insert(Ver);
666faa35 2963 Ver = (*Cache)[BuildPkg].CandidateVerIter(*Cache);
d5dea0be
DK
2964 if (BADVER(Ver) == false)
2965 verlist.insert(Ver);
234675b7
DK
2966 }
2967 }
d5dea0be
DK
2968 #undef BADVER
2969
2970 string forbidden;
2971 // We need to decide if host or build arch, so find a version we can look at
2972 APT::VersionList::const_iterator Ver = verlist.begin();
2973 for (; Ver != verlist.end(); ++Ver)
234675b7 2974 {
d5dea0be 2975 forbidden.clear();
737c7a7b
SL
2976 if (Ver->MultiArch == pkgCache::Version::None || Ver->MultiArch == pkgCache::Version::All)
2977 {
2978 if (colon == string::npos)
737c7a7b 2979 Pkg = Ver.ParentPkg().Group().FindPkg(hostArch);
a9a370d9
TG
2980 else if (strcmp(D->Package.c_str() + colon, ":any") == 0)
2981 forbidden = "Multi-Arch: none";
666faa35
DK
2982 else if (strcmp(D->Package.c_str() + colon, ":native") == 0)
2983 Pkg = Ver.ParentPkg().Group().FindPkg("native");
737c7a7b 2984 }
234675b7
DK
2985 else if (Ver->MultiArch == pkgCache::Version::Same)
2986 {
737c7a7b 2987 if (colon == string::npos)
234675b7
DK
2988 Pkg = Ver.ParentPkg().Group().FindPkg(hostArch);
2989 else if (strcmp(D->Package.c_str() + colon, ":any") == 0)
2990 forbidden = "Multi-Arch: same";
666faa35
DK
2991 else if (strcmp(D->Package.c_str() + colon, ":native") == 0)
2992 Pkg = Ver.ParentPkg().Group().FindPkg("native");
234675b7 2993 }
2a2a7ef4 2994 else if ((Ver->MultiArch & pkgCache::Version::Foreign) == pkgCache::Version::Foreign)
234675b7 2995 {
666faa35
DK
2996 if (colon == string::npos)
2997 Pkg = Ver.ParentPkg().Group().FindPkg("native");
2998 else if (strcmp(D->Package.c_str() + colon, ":any") == 0 ||
2999 strcmp(D->Package.c_str() + colon, ":native") == 0)
234675b7
DK
3000 forbidden = "Multi-Arch: foreign";
3001 }
2a2a7ef4 3002 else if ((Ver->MultiArch & pkgCache::Version::Allowed) == pkgCache::Version::Allowed)
234675b7
DK
3003 {
3004 if (colon == string::npos)
3005 Pkg = Ver.ParentPkg().Group().FindPkg(hostArch);
3006 else if (strcmp(D->Package.c_str() + colon, ":any") == 0)
3007 {
3008 // prefer any installed over preferred non-installed architectures
3009 pkgCache::GrpIterator Grp = Ver.ParentPkg().Group();
3010 // we don't check for version here as we are better of with upgrading than remove and install
3011 for (Pkg = Grp.PackageList(); Pkg.end() == false; Pkg = Grp.NextPkg(Pkg))
3012 if (Pkg.CurrentVer().end() == false)
3013 break;
3014 if (Pkg.end() == true)
3015 Pkg = Grp.FindPreferredPkg(true);
3016 }
666faa35
DK
3017 else if (strcmp(D->Package.c_str() + colon, ":native") == 0)
3018 Pkg = Ver.ParentPkg().Group().FindPkg("native");
234675b7 3019 }
d5dea0be 3020
234675b7
DK
3021 if (forbidden.empty() == false)
3022 {
3023 if (_config->FindB("Debug::BuildDeps",false) == true)
d5dea0be
DK
3024 cout << D->Package.substr(colon, string::npos) << " is not allowed from " << forbidden << " package " << (*D).Package << " (" << Ver.VerStr() << ")" << endl;
3025 continue;
3026 }
3027
3028 //we found a good version
3029 break;
3030 }
3031 if (Ver == verlist.end())
3032 {
3033 if (_config->FindB("Debug::BuildDeps",false) == true)
3034 cout << " No multiarch info as we have no satisfying installed nor candidate for " << D->Package << " on build or host arch" << endl;
3035
3036 if (forbidden.empty() == false)
3037 {
234675b7
DK
3038 if (hasAlternatives)
3039 continue;
3040 return _error->Error(_("%s dependency for %s can't be satisfied "
3041 "because %s is not allowed on '%s' packages"),
3042 Last->BuildDepType(D->Type), Src.c_str(),
a9a370d9 3043 D->Package.c_str(), forbidden.c_str());
234675b7
DK
3044 }
3045 }
234675b7
DK
3046 }
3047 else
3048 Pkg = Cache->FindPkg(D->Package);
3049
727d8712 3050 if (Pkg.end() == true || (Pkg->VersionList == 0 && Pkg->ProvidesList == 0))
aa2d22be 3051 {
58d76831
AL
3052 if (_config->FindB("Debug::BuildDeps",false) == true)
3053 cout << " (not found)" << (*D).Package << endl;
3054
3055 if (hasAlternatives)
3056 continue;
3057
3058 return _error->Error(_("%s dependency for %s cannot be satisfied "
3059 "because the package %s cannot be found"),
3060 Last->BuildDepType((*D).Type),Src.c_str(),
3061 (*D).Package.c_str());
aa2d22be
AL
3062 }
3063
e5002e30 3064 pkgCache::VerIterator IV = (*Cache)[Pkg].InstVerIter(*Cache);
91bee655
DK
3065 if (IV.end() == false)
3066 {
3067 if (_config->FindB("Debug::BuildDeps",false) == true)
3068 cout << " Is installed\n";
e5002e30 3069
91bee655
DK
3070 if (D->Version.empty() == true ||
3071 Cache->VS().CheckDep(IV.VerStr(),(*D).Op,(*D).Version.c_str()) == true)
3072 {
3073 skipAlternatives = hasAlternatives;
3074 continue;
3075 }
cfa5659c 3076
91bee655
DK
3077 if (_config->FindB("Debug::BuildDeps",false) == true)
3078 cout << " ...but the installed version doesn't meet the version requirement\n";
58d76831 3079
91bee655
DK
3080 if (((*D).Op & pkgCache::Dep::LessEq) == pkgCache::Dep::LessEq)
3081 return _error->Error(_("Failed to satisfy %s dependency for %s: Installed package %s is too new"),
3082 Last->BuildDepType((*D).Type), Src.c_str(), Pkg.FullName(true).c_str());
3083 }
58d76831 3084
fe027879
DK
3085 // Only consider virtual packages if there is no versioned dependency
3086 if ((*D).Version.empty() == true)
3087 {
3088 /*
3089 * If this is a virtual package, we need to check the list of
3090 * packages that provide it and see if any of those are
3091 * installed
3092 */
3093 pkgCache::PrvIterator Prv = Pkg.ProvidesList();
f7f0d6c7 3094 for (; Prv.end() != true; ++Prv)
fe027879
DK
3095 {
3096 if (_config->FindB("Debug::BuildDeps",false) == true)
3097 cout << " Checking provider " << Prv.OwnerPkg().FullName() << endl;
58d76831 3098
fe027879
DK
3099 if ((*Cache)[Prv.OwnerPkg()].InstVerIter(*Cache).end() == false)
3100 break;
3101 }
58d76831 3102
fe027879
DK
3103 if (Prv.end() == false)
3104 {
3105 if (_config->FindB("Debug::BuildDeps",false) == true)
3106 cout << " Is provided by installed package " << Prv.OwnerPkg().FullName() << endl;
3107 skipAlternatives = hasAlternatives;
3108 continue;
3109 }
3110 }
2baf02ca
DK
3111 else // versioned dependency
3112 {
3113 pkgCache::VerIterator CV = (*Cache)[Pkg].CandidateVerIter(*Cache);
3114 if (CV.end() == true ||
3115 Cache->VS().CheckDep(CV.VerStr(),(*D).Op,(*D).Version.c_str()) == false)
3116 {
3117 if (hasAlternatives)
3118 continue;
3119 else if (CV.end() == false)
3120 return _error->Error(_("%s dependency for %s cannot be satisfied "
3121 "because candidate version of package %s "
3122 "can't satisfy version requirements"),
3123 Last->BuildDepType(D->Type), Src.c_str(),
3124 D->Package.c_str());
3125 else
3126 return _error->Error(_("%s dependency for %s cannot be satisfied "
3127 "because package %s has no candidate version"),
3128 Last->BuildDepType(D->Type), Src.c_str(),
3129 D->Package.c_str());
3130 }
3131 }
58d76831 3132
f1f874bd 3133 if (TryToInstallBuildDep(Pkg,Cache,Fix,false,false,false) == true)
58d76831
AL
3134 {
3135 // We successfully installed something; skip remaining alternatives
3136 skipAlternatives = hasAlternatives;
d59228b0 3137 if(_config->FindB("APT::Get::Build-Dep-Automatic", false) == true)
496a05c6 3138 Cache->MarkAuto(Pkg, true);
58d76831
AL
3139 continue;
3140 }
3141 else if (hasAlternatives)
3142 {
3143 if (_config->FindB("Debug::BuildDeps",false) == true)
3144 cout << " Unsatisfiable, trying alternatives\n";
3145 continue;
3146 }
3147 else
3148 {
3149 return _error->Error(_("Failed to satisfy %s dependency for %s: %s"),
3150 Last->BuildDepType((*D).Type),
3151 Src.c_str(),
3152 (*D).Package.c_str());
3153 }
b2e465d6
AL
3154 }
3155 }
f3c736f9 3156
b2e465d6
AL
3157 if (Fix.Resolve(true) == false)
3158 _error->Discard();
3159
3160 // Now we check the state of the packages,
3161 if (Cache->BrokenCount() != 0)
0dae8ac5
DK
3162 {
3163 ShowBroken(cout, Cache, false);
3164 return _error->Error(_("Build-dependencies for %s could not be satisfied."),*I);
3165 }
b2e465d6
AL
3166 }
3167
3168 if (InstallPackages(Cache, false, true) == false)
3169 return _error->Error(_("Failed to process build dependencies"));
36375005
AL
3170 return true;
3171}
3172 /*}}}*/
a53b07bb
MV
3173// GetChangelogPath - return a path pointing to a changelog file or dir /*{{{*/
3174// ---------------------------------------------------------------------
3175/* This returns a "path" string for the changelog url construction.
3176 * Please note that its not complete, it either needs a "/changelog"
3177 * appended (for the packages.debian.org/changelogs site) or a
3178 * ".changelog" (for third party sites that store the changelog in the
3179 * pool/ next to the deb itself)
3180 * Example return: "pool/main/a/apt/apt_0.8.8ubuntu3"
3181 */
3182string GetChangelogPath(CacheFile &Cache,
3183 pkgCache::PkgIterator Pkg,
3184 pkgCache::VerIterator Ver)
3185{
3186 string path;
3187
3188 pkgRecords Recs(Cache);
3189 pkgRecords::Parser &rec=Recs.Lookup(Ver.FileList());
3190 string srcpkg = rec.SourcePkg().empty() ? Pkg.Name() : rec.SourcePkg();
c5d6a22c
MV
3191 string ver = Ver.VerStr();
3192 // if there is a source version it always wins
3193 if (rec.SourceVer() != "")
3194 ver = rec.SourceVer();
a53b07bb 3195 path = flNotFile(rec.FileName());
c5d6a22c 3196 path += srcpkg + "_" + StripEpoch(ver);
a53b07bb
MV
3197 return path;
3198}
3199 /*}}}*/
cdb9307c
MV
3200// GuessThirdPartyChangelogUri - return url /*{{{*/
3201// ---------------------------------------------------------------------
a53b07bb
MV
3202/* Contruct a changelog file path for third party sites that do not use
3203 * packages.debian.org/changelogs
3204 * This simply uses the ArchiveURI() of the source pkg and looks for
3205 * a .changelog file there, Example for "mediabuntu":
3206 * apt-get changelog mplayer-doc:
3207 * http://packages.medibuntu.org/pool/non-free/m/mplayer/mplayer_1.0~rc4~try1.dsfg1-1ubuntu1+medibuntu1.changelog
3208 */
cdb9307c
MV
3209bool GuessThirdPartyChangelogUri(CacheFile &Cache,
3210 pkgCache::PkgIterator Pkg,
3211 pkgCache::VerIterator Ver,
3212 string &out_uri)
3213{
cdb9307c 3214 // get the binary deb server path
cdb9307c
MV
3215 pkgCache::VerFileIterator Vf = Ver.FileList();
3216 if (Vf.end() == true)
3217 return false;
3218 pkgCache::PkgFileIterator F = Vf.File();
3219 pkgIndexFile *index;
a53b07bb 3220 pkgSourceList *SrcList = Cache.GetSourceList();
cdb9307c
MV
3221 if(SrcList->FindIndex(F, index) == false)
3222 return false;
a53b07bb 3223
cdb9307c 3224 // get archive uri for the binary deb
a53b07bb
MV
3225 string path_without_dot_changelog = GetChangelogPath(Cache, Pkg, Ver);
3226 out_uri = index->ArchiveURI(path_without_dot_changelog + ".changelog");
cdb9307c
MV
3227
3228 // now strip away the filename and add srcpkg_srcver.changelog
cdb9307c
MV
3229 return true;
3230}
fcb144b9 3231 /*}}}*/
a4c40430
MV
3232// DownloadChangelog - Download the changelog /*{{{*/
3233// ---------------------------------------------------------------------
a53b07bb
MV
3234bool DownloadChangelog(CacheFile &CacheFile, pkgAcquire &Fetcher,
3235 pkgCache::VerIterator Ver, string targetfile)
3236/* Download a changelog file for the given package version to
3237 * targetfile. This will first try the server from Apt::Changelogs::Server
3238 * (http://packages.debian.org/changelogs by default) and if that gives
3239 * a 404 tries to get it from the archive directly (see
3240 * GuessThirdPartyChangelogUri for details how)
3241 */
a4c40430 3242{
a53b07bb 3243 string path;
a4c40430 3244 string descr;
c2991635 3245 string server;
a53b07bb 3246 string changelog_uri;
a4c40430
MV
3247
3248 // data structures we need
a53b07bb 3249 pkgCache::PkgIterator Pkg = Ver.ParentPkg();
a4c40430 3250
a53b07bb 3251 // make the server root configurable
c2991635 3252 server = _config->Find("Apt::Changelogs::Server",
a53b07bb
MV
3253 "http://packages.debian.org/changelogs");
3254 path = GetChangelogPath(CacheFile, Pkg, Ver);
3255 strprintf(changelog_uri, "%s/%s/changelog", server.c_str(), path.c_str());
fcb144b9
DK
3256 if (_config->FindB("APT::Get::Print-URIs", false) == true)
3257 {
3258 std::cout << '\'' << changelog_uri << '\'' << std::endl;
3259 return true;
3260 }
3261
88573174 3262 strprintf(descr, _("Changelog for %s (%s)"), Pkg.Name(), changelog_uri.c_str());
a53b07bb 3263 // queue it
88573174 3264 new pkgAcqFile(&Fetcher, changelog_uri, "", 0, descr, Pkg.Name(), "ignored", targetfile);
d786352d 3265
fcb144b9
DK
3266 // try downloading it, if that fails, try third-party-changelogs location
3267 // FIXME: Fetcher.Run() is "Continue" even if I get a 404?!?
3268 Fetcher.Run();
cdb9307c
MV
3269 if (!FileExists(targetfile))
3270 {
3271 string third_party_uri;
a53b07bb 3272 if (GuessThirdPartyChangelogUri(CacheFile, Pkg, Ver, third_party_uri))
cdb9307c 3273 {
88573174
MV
3274 strprintf(descr, _("Changelog for %s (%s)"), Pkg.Name(), third_party_uri.c_str());
3275 new pkgAcqFile(&Fetcher, third_party_uri, "", 0, descr, Pkg.Name(), "ignored", targetfile);
fcb144b9 3276 Fetcher.Run();
cdb9307c
MV
3277 }
3278 }
4a6fe09c 3279
a4c40430 3280 if (FileExists(targetfile))
18ae8b29 3281 return true;
a4c40430
MV
3282
3283 // error
18ae8b29 3284 return _error->Error("changelog download failed");
a4c40430
MV
3285}
3286 /*}}}*/
3287// DisplayFileInPager - Display File with pager /*{{{*/
3288void DisplayFileInPager(string filename)
3289{
3290 pid_t Process = ExecFork();
3291 if (Process == 0)
3292 {
3293 const char *Args[3];
3294 Args[0] = "/usr/bin/sensible-pager";
3295 Args[1] = filename.c_str();
3296 Args[2] = 0;
3297 execvp(Args[0],(char **)Args);
3298 exit(100);
3299 }
3300
3301 // Wait for the subprocess
3302 ExecWait(Process, "sensible-pager", false);
3303}
3304 /*}}}*/
3305// DoChangelog - Get changelog from the command line /*{{{*/
3306// ---------------------------------------------------------------------
3307bool DoChangelog(CommandLine &CmdL)
3308{
3309 CacheFile Cache;
3310 if (Cache.ReadOnlyOpen() == false)
3311 return false;
3312
3313 APT::CacheSetHelper helper(c0out);
c4cca791
DK
3314 APT::VersionList verset = APT::VersionList::FromCommandLine(Cache,
3315 CmdL.FileList + 1, APT::VersionList::CANDIDATE, helper);
72dd5bec
DK
3316 if (verset.empty() == true)
3317 return false;
a4c40430 3318 pkgAcquire Fetcher;
fcb144b9
DK
3319
3320 if (_config->FindB("APT::Get::Print-URIs", false) == true)
a98b6615
DH
3321 {
3322 bool Success = true;
c4cca791 3323 for (APT::VersionList::const_iterator Ver = verset.begin();
fcb144b9 3324 Ver != verset.end(); ++Ver)
a98b6615
DH
3325 Success &= DownloadChangelog(Cache, Fetcher, Ver, "");
3326 return Success;
3327 }
fcb144b9 3328
8cc74fb1
MV
3329 AcqTextStatus Stat(ScreenWidth, _config->FindI("quiet",0));
3330 Fetcher.Setup(&Stat);
a4c40430 3331
72dd5bec
DK
3332 bool const downOnly = _config->FindB("APT::Get::Download-Only", false);
3333
3334 char tmpname[100];
3335 char* tmpdir = NULL;
3336 if (downOnly == false)
3337 {
3338 const char* const tmpDir = getenv("TMPDIR");
3339 if (tmpDir != NULL && *tmpDir != '\0')
3340 snprintf(tmpname, sizeof(tmpname), "%s/apt-changelog-XXXXXX", tmpDir);
3341 else
3342 strncpy(tmpname, "/tmp/apt-changelog-XXXXXX", sizeof(tmpname));
3343 tmpdir = mkdtemp(tmpname);
3344 if (tmpdir == NULL)
3345 return _error->Errno("mkdtemp", "mkdtemp failed");
18ae8b29 3346 }
72dd5bec 3347
c4cca791 3348 for (APT::VersionList::const_iterator Ver = verset.begin();
a4c40430
MV
3349 Ver != verset.end();
3350 ++Ver)
3351 {
72dd5bec
DK
3352 string changelogfile;
3353 if (downOnly == false)
3354 changelogfile.append(tmpname).append("changelog");
3355 else
3356 changelogfile.append(Ver.ParentPkg().Name()).append(".changelog");
3357 if (DownloadChangelog(Cache, Fetcher, Ver, changelogfile) && downOnly == false)
3358 {
a4c40430 3359 DisplayFileInPager(changelogfile);
72dd5bec
DK
3360 // cleanup temp file
3361 unlink(changelogfile.c_str());
3362 }
a4c40430 3363 }
18ae8b29 3364 // clenaup tmp dir
72dd5bec
DK
3365 if (tmpdir != NULL)
3366 rmdir(tmpdir);
4a6fe09c 3367 return true;
a4c40430
MV
3368}
3369 /*}}}*/
b2e465d6
AL
3370// DoMoo - Never Ask, Never Tell /*{{{*/
3371// ---------------------------------------------------------------------
3372/* */
3373bool DoMoo(CommandLine &CmdL)
3374{
3375 cout <<
3376 " (__) \n"
3377 " (oo) \n"
3378 " /------\\/ \n"
3379 " / | || \n"
3380 " * /\\---/\\ \n"
3381 " ~~ ~~ \n"
3382 "....\"Have you mooed today?\"...\n";
3383
3384 return true;
3385}
3386 /*}}}*/
0a8e3465
AL
3387// ShowHelp - Show a help screen /*{{{*/
3388// ---------------------------------------------------------------------
3389/* */
212ad54a 3390bool ShowHelp(CommandLine &CmdL)
0a8e3465 3391{
9179f697 3392 ioprintf(cout,_("%s %s for %s compiled on %s %s\n"),PACKAGE,PACKAGE_VERSION,
5b28c804 3393 COMMON_ARCH,__DATE__,__TIME__);
b2e465d6 3394
04aa15a8 3395 if (_config->FindB("version") == true)
b2e465d6 3396 {
db0db9fe 3397 cout << _("Supported modules:") << endl;
b2e465d6
AL
3398
3399 for (unsigned I = 0; I != pkgVersioningSystem::GlobalListLen; I++)
3400 {
3401 pkgVersioningSystem *VS = pkgVersioningSystem::GlobalList[I];
3402 if (_system != 0 && _system->VS == VS)
3403 cout << '*';
3404 else
3405 cout << ' ';
3406 cout << "Ver: " << VS->Label << endl;
3407
3408 /* Print out all the packaging systems that will work with
3409 this VS */
3410 for (unsigned J = 0; J != pkgSystem::GlobalListLen; J++)
3411 {
3412 pkgSystem *Sys = pkgSystem::GlobalList[J];
3413 if (_system == Sys)
3414 cout << '*';
3415 else
3416 cout << ' ';
3417 if (Sys->VS->TestCompatibility(*VS) == true)
3418 cout << "Pkg: " << Sys->Label << " (Priority " << Sys->Score(*_config) << ")" << endl;
3419 }
3420 }
3421
3422 for (unsigned I = 0; I != pkgSourceList::Type::GlobalListLen; I++)
3423 {
3424 pkgSourceList::Type *Type = pkgSourceList::Type::GlobalList[I];
3425 cout << " S.L: '" << Type->Name << "' " << Type->Label << endl;
3426 }
3427
3428 for (unsigned I = 0; I != pkgIndexFile::Type::GlobalListLen; I++)
3429 {
3430 pkgIndexFile::Type *Type = pkgIndexFile::Type::GlobalList[I];
3431 cout << " Idx: " << Type->Label << endl;
3432 }
3433
3434 return true;
3435 }
3436
3437 cout <<
3438 _("Usage: apt-get [options] command\n"
3439 " apt-get [options] install|remove pkg1 [pkg2 ...]\n"
3440 " apt-get [options] source pkg1 [pkg2 ...]\n"
3441 "\n"
3442 "apt-get is a simple command line interface for downloading and\n"
3443 "installing packages. The most frequently used commands are update\n"
3444 "and install.\n"
3445 "\n"
3446 "Commands:\n"
3447 " update - Retrieve new lists of packages\n"
3448 " upgrade - Perform an upgrade\n"
3449 " install - Install new packages (pkg is libc6 not libc6.deb)\n"
3450 " remove - Remove packages\n"
12bffed7 3451 " autoremove - Remove automatically all unused packages\n"
73fc19d0 3452 " purge - Remove packages and config files\n"
b2e465d6
AL
3453 " source - Download source archives\n"
3454 " build-dep - Configure build-dependencies for source packages\n"
3455 " dist-upgrade - Distribution upgrade, see apt-get(8)\n"
3456 " dselect-upgrade - Follow dselect selections\n"
3457 " clean - Erase downloaded archive files\n"
3458 " autoclean - Erase old downloaded archive files\n"
3459 " check - Verify that there are no broken dependencies\n"
5f967f2d
MV
3460 " changelog - Download and display the changelog for the given package\n"
3461 " download - Download the binary package into the current directory\n"
b2e465d6
AL
3462 "\n"
3463 "Options:\n"
3464 " -h This help text.\n"
3465 " -q Loggable output - no progress indicator\n"
3466 " -qq No output except for errors\n"
3467 " -d Download only - do NOT install or unpack archives\n"
3468 " -s No-act. Perform ordering simulation\n"
3469 " -y Assume Yes to all queries and do not prompt\n"
0748d509 3470 " -f Attempt to correct a system with broken dependencies in place\n"
b2e465d6
AL
3471 " -m Attempt to continue if archives are unlocatable\n"
3472 " -u Show a list of upgraded packages as well\n"
3473 " -b Build the source package after fetching it\n"
ac625538 3474 " -V Show verbose version numbers\n"
b2e465d6 3475 " -c=? Read this configuration file\n"
a2884e32 3476 " -o=? Set an arbitrary configuration option, eg -o dir::cache=/tmp\n"
b2e465d6
AL
3477 "See the apt-get(8), sources.list(5) and apt.conf(5) manual\n"
3478 "pages for more information and options.\n"
3479 " This APT has Super Cow Powers.\n");
3480 return true;
0a8e3465
AL
3481}
3482 /*}}}*/
d7827aca
AL
3483// SigWinch - Window size change signal handler /*{{{*/
3484// ---------------------------------------------------------------------
3485/* */
3486void SigWinch(int)
3487{
3488 // Riped from GNU ls
3489#ifdef TIOCGWINSZ
3490 struct winsize ws;
3491
3492 if (ioctl(1, TIOCGWINSZ, &ws) != -1 && ws.ws_col >= 5)
3493 ScreenWidth = ws.ws_col - 1;
3494#endif
3495}
3496 /*}}}*/
92fcbfc1 3497int main(int argc,const char *argv[]) /*{{{*/
0a8e3465
AL
3498{
3499 CommandLine::Args Args[] = {
3500 {'h',"help","help",0},
04aa15a8 3501 {'v',"version","version",0},
ac625538 3502 {'V',"verbose-versions","APT::Get::Show-Versions",0},
0a8e3465
AL
3503 {'q',"quiet","quiet",CommandLine::IntLevel},
3504 {'q',"silent","quiet",CommandLine::IntLevel},
3505 {'d',"download-only","APT::Get::Download-Only",0},
fb0ee66e
AL
3506 {'b',"compile","APT::Get::Compile",0},
3507 {'b',"build","APT::Get::Compile",0},
d150b09d
AL
3508 {'s',"simulate","APT::Get::Simulate",0},
3509 {'s',"just-print","APT::Get::Simulate",0},
3510 {'s',"recon","APT::Get::Simulate",0},
6df23d2f 3511 {'s',"dry-run","APT::Get::Simulate",0},
d150b09d
AL
3512 {'s',"no-act","APT::Get::Simulate",0},
3513 {'y',"yes","APT::Get::Assume-Yes",0},
d4cfaed3
DK
3514 {'y',"assume-yes","APT::Get::Assume-Yes",0},
3515 {0,"assume-no","APT::Get::Assume-No",0},
0a8e3465
AL
3516 {'f',"fix-broken","APT::Get::Fix-Broken",0},
3517 {'u',"show-upgraded","APT::Get::Show-Upgraded",0},
30e1eab5 3518 {'m',"ignore-missing","APT::Get::Fix-Missing",0},
b2e465d6
AL
3519 {'t',"target-release","APT::Default-Release",CommandLine::HasArg},
3520 {'t',"default-release","APT::Default-Release",CommandLine::HasArg},
234675b7 3521 {'a',"host-architecture","APT::Get::Host-Architecture",CommandLine::HasArg},
b2e465d6 3522 {0,"download","APT::Get::Download",0},
30e1eab5 3523 {0,"fix-missing","APT::Get::Fix-Missing",0},
b2e465d6
AL
3524 {0,"ignore-hold","APT::Ignore-Hold",0},
3525 {0,"upgrade","APT::Get::upgrade",0},
6cd9fbd7 3526 {0,"only-upgrade","APT::Get::Only-Upgrade",0},
83d89a9f 3527 {0,"force-yes","APT::Get::force-yes",0},
f7a08e33 3528 {0,"print-uris","APT::Get::Print-URIs",0},
5fafc0ef 3529 {0,"diff-only","APT::Get::Diff-Only",0},
a0895a74 3530 {0,"debian-only","APT::Get::Diff-Only",0},
1979e742
MV
3531 {0,"tar-only","APT::Get::Tar-Only",0},
3532 {0,"dsc-only","APT::Get::Dsc-Only",0},
fc4b5c9f 3533 {0,"purge","APT::Get::Purge",0},
9df71a5b 3534 {0,"list-cleanup","APT::Get::List-Cleanup",0},
d0c59649 3535 {0,"reinstall","APT::Get::ReInstall",0},
d150b09d 3536 {0,"trivial-only","APT::Get::Trivial-Only",0},
b2e465d6
AL
3537 {0,"remove","APT::Get::Remove",0},
3538 {0,"only-source","APT::Get::Only-Source",0},
45430cbf 3539 {0,"arch-only","APT::Get::Arch-Only",0},
f8ac1720 3540 {0,"auto-remove","APT::Get::AutomaticRemove",0},
7db98ffc 3541 {0,"allow-unauthenticated","APT::Get::AllowUnauthenticated",0},
e9ae3677 3542 {0,"install-recommends","APT::Install-Recommends",CommandLine::Boolean},
ef86a8a4 3543 {0,"install-suggests","APT::Install-Suggests",CommandLine::Boolean},
4ef9a929 3544 {0,"fix-policy","APT::Get::Fix-Policy-Broken",0},
98278a81 3545 {0,"solver","APT::Solver",CommandLine::HasArg},
0a8e3465
AL
3546 {'c',"config-file",0,CommandLine::ConfigFile},
3547 {'o',"option",0,CommandLine::ArbItem},
3548 {0,0,0,0}};
83d89a9f
AL
3549 CommandLine::Dispatch Cmds[] = {{"update",&DoUpdate},
3550 {"upgrade",&DoUpgrade},
3551 {"install",&DoInstall},
3552 {"remove",&DoInstall},
24401c09 3553 {"purge",&DoInstall},
74a05226 3554 {"autoremove",&DoInstall},
d63a1458
JAK
3555 {"markauto",&DoMarkAuto},
3556 {"unmarkauto",&DoMarkAuto},
83d89a9f
AL
3557 {"dist-upgrade",&DoDistUpgrade},
3558 {"dselect-upgrade",&DoDSelectUpgrade},
b2e465d6 3559 {"build-dep",&DoBuildDep},
83d89a9f 3560 {"clean",&DoClean},
1bc849af 3561 {"autoclean",&DoAutoClean},
83d89a9f 3562 {"check",&DoCheck},
67111687 3563 {"source",&DoSource},
459b5f5d 3564 {"download",&DoDownload},
a4c40430 3565 {"changelog",&DoChangelog},
b2e465d6 3566 {"moo",&DoMoo},
67111687 3567 {"help",&ShowHelp},
83d89a9f 3568 {0,0}};
67111687
AL
3569
3570 // Set up gettext support
3571 setlocale(LC_ALL,"");
3572 textdomain(PACKAGE);
3573
0a8e3465
AL
3574 // Parse the command line and initialize the package library
3575 CommandLine CmdL(Args,_config);
b2e465d6
AL
3576 if (pkgInitConfig(*_config) == false ||
3577 CmdL.Parse(argc,argv) == false ||
3578 pkgInitSystem(*_config,_system) == false)
0a8e3465 3579 {
b2e465d6
AL
3580 if (_config->FindB("version") == true)
3581 ShowHelp(CmdL);
3582
0a8e3465
AL
3583 _error->DumpErrors();
3584 return 100;
3585 }
3586
3587 // See if the help should be shown
3588 if (_config->FindB("help") == true ||
04aa15a8 3589 _config->FindB("version") == true ||
0a8e3465 3590 CmdL.FileSize() == 0)
b2e465d6
AL
3591 {
3592 ShowHelp(CmdL);
3593 return 0;
3594 }
55a5a46c
MV
3595
3596 // simulate user-friendly if apt-get has no root privileges
ede85dc0
DK
3597 if (getuid() != 0 && _config->FindB("APT::Get::Simulate") == true &&
3598 (CmdL.FileSize() == 0 ||
3599 (strcmp(CmdL.FileList[0], "source") != 0 && strcmp(CmdL.FileList[0], "download") != 0 &&
3600 strcmp(CmdL.FileList[0], "changelog") != 0)))
55a5a46c 3601 {
ecf59bfc
DK
3602 if (_config->FindB("APT::Get::Show-User-Simulation-Note",true) == true)
3603 cout << _("NOTE: This is only a simulation!\n"
3604 " apt-get needs root privileges for real execution.\n"
3605 " Keep also in mind that locking is deactivated,\n"
3606 " so don't depend on the relevance to the real current situation!"
3607 ) << std::endl;
55a5a46c
MV
3608 _config->Set("Debug::NoLocking",true);
3609 }
3610
a9a5908d 3611 // Deal with stdout not being a tty
c340d185 3612 if (!isatty(STDOUT_FILENO) && _config->FindI("quiet", -1) == -1)
a9a5908d 3613 _config->Set("quiet","1");
01b64152 3614
0a8e3465
AL
3615 // Setup the output streams
3616 c0out.rdbuf(cout.rdbuf());
3617 c1out.rdbuf(cout.rdbuf());
3618 c2out.rdbuf(cout.rdbuf());
3619 if (_config->FindI("quiet",0) > 0)
3620 c0out.rdbuf(devnull.rdbuf());
3621 if (_config->FindI("quiet",0) > 1)
3622 c1out.rdbuf(devnull.rdbuf());
d7827aca
AL
3623
3624 // Setup the signals
3625 signal(SIGPIPE,SIG_IGN);
3626 signal(SIGWINCH,SigWinch);
3627 SigWinch(0);
b2e465d6 3628
0a8e3465 3629 // Match the operation
83d89a9f 3630 CmdL.DispatchArg(Cmds);
0a8e3465
AL
3631
3632 // Print any errors or warnings found during parsing
65beb572
DK
3633 bool const Errors = _error->PendingError();
3634 if (_config->FindI("quiet",0) > 0)
0a8e3465 3635 _error->DumpErrors();
65beb572
DK
3636 else
3637 _error->DumpErrors(GlobalError::DEBUG);
3638 return Errors == true ? 100 : 0;
0a8e3465 3639}
92fcbfc1 3640 /*}}}*/