fix install-progress location
[ntk/apt.git] / apt-private / private-install.cc
1 // Include Files /*{{{*/
2 #include <config.h>
3
4 #include <apt-pkg/aptconfiguration.h>
5 #include <apt-pkg/error.h>
6 #include <apt-pkg/cmndline.h>
7 #include <apt-pkg/init.h>
8 #include <apt-pkg/depcache.h>
9 #include <apt-pkg/sourcelist.h>
10 #include <apt-pkg/algorithms.h>
11 #include <apt-pkg/acquire-item.h>
12 #include <apt-pkg/strutl.h>
13 #include <apt-pkg/fileutl.h>
14 #include <apt-pkg/clean.h>
15 #include <apt-pkg/srcrecords.h>
16 #include <apt-pkg/version.h>
17 #include <apt-pkg/cachefile.h>
18 #include <apt-pkg/cacheset.h>
19 #include <apt-pkg/sptr.h>
20 #include <apt-pkg/md5.h>
21 #include <apt-pkg/versionmatch.h>
22 #include <apt-pkg/progress.h>
23 #include <apt-pkg/pkgsystem.h>
24 #include <apt-pkg/pkgrecords.h>
25 #include <apt-pkg/indexfile.h>
26 #include <apt-pkg/install-progress.h>
27
28 #include <set>
29 #include <locale.h>
30 #include <langinfo.h>
31 #include <fstream>
32 #include <termios.h>
33 #include <sys/ioctl.h>
34 #include <sys/stat.h>
35 #include <sys/statfs.h>
36 #include <sys/statvfs.h>
37 #include <signal.h>
38 #include <unistd.h>
39 #include <stdio.h>
40 #include <errno.h>
41 #include <regex.h>
42 #include <sys/wait.h>
43 #include <sstream>
44
45 #include "private-install.h"
46 #include "private-download.h"
47 #include "private-cachefile.h"
48 #include "private-output.h"
49 #include "private-cacheset.h"
50 #include "acqprogress.h"
51
52 #include <apti18n.h>
53 /*}}}*/
54
55 // InstallPackages - Actually download and install the packages /*{{{*/
56 // ---------------------------------------------------------------------
57 /* This displays the informative messages describing what is going to
58 happen and then calls the download routines */
59 bool InstallPackages(CacheFile &Cache,bool ShwKept,bool Ask, bool Safety)
60 {
61 if (_config->FindB("APT::Get::Purge",false) == true)
62 {
63 pkgCache::PkgIterator I = Cache->PkgBegin();
64 for (; I.end() == false; ++I)
65 {
66 if (I.Purge() == false && Cache[I].Mode == pkgDepCache::ModeDelete)
67 Cache->MarkDelete(I,true);
68 }
69 }
70
71 bool Fail = false;
72 bool Essential = false;
73
74 // Show all the various warning indicators
75 ShowDel(c1out,Cache);
76 ShowNew(c1out,Cache);
77 if (ShwKept == true)
78 ShowKept(c1out,Cache);
79 Fail |= !ShowHold(c1out,Cache);
80 if (_config->FindB("APT::Get::Show-Upgraded",true) == true)
81 ShowUpgraded(c1out,Cache);
82 Fail |= !ShowDowngraded(c1out,Cache);
83 if (_config->FindB("APT::Get::Download-Only",false) == false)
84 Essential = !ShowEssential(c1out,Cache);
85 Fail |= Essential;
86 Stats(c1out,Cache);
87
88 // Sanity check
89 if (Cache->BrokenCount() != 0)
90 {
91 ShowBroken(c1out,Cache,false);
92 return _error->Error(_("Internal error, InstallPackages was called with broken packages!"));
93 }
94
95 if (Cache->DelCount() == 0 && Cache->InstCount() == 0 &&
96 Cache->BadCount() == 0)
97 return true;
98
99 // No remove flag
100 if (Cache->DelCount() != 0 && _config->FindB("APT::Get::Remove",true) == false)
101 return _error->Error(_("Packages need to be removed but remove is disabled."));
102
103 // Run the simulator ..
104 if (_config->FindB("APT::Get::Simulate") == true)
105 {
106 pkgSimulate PM(Cache);
107
108 int status_fd = _config->FindI("APT::Status-Fd",-1);
109 APT::Progress::PackageManager *progress = NULL;
110 if (status_fd > 0)
111 progress = new APT::Progress::PackageManagerProgressFd(status_fd);
112 pkgPackageManager::OrderResult Res = PM.DoInstall(progress);
113 delete progress;
114
115 if (Res == pkgPackageManager::Failed)
116 return false;
117 if (Res != pkgPackageManager::Completed)
118 return _error->Error(_("Internal error, Ordering didn't finish"));
119 return true;
120 }
121
122 // Create the text record parser
123 pkgRecords Recs(Cache);
124 if (_error->PendingError() == true)
125 return false;
126
127 // Create the download object
128 pkgAcquire Fetcher;
129 AcqTextStatus Stat(ScreenWidth,_config->FindI("quiet",0));
130 if (_config->FindB("APT::Get::Print-URIs", false) == true)
131 {
132 // force a hashsum for compatibility reasons
133 _config->CndSet("Acquire::ForceHash", "md5sum");
134 }
135 else if (Fetcher.Setup(&Stat, _config->FindDir("Dir::Cache::Archives")) == false)
136 return false;
137
138 // Read the source list
139 if (Cache.BuildSourceList() == false)
140 return false;
141 pkgSourceList *List = Cache.GetSourceList();
142
143 // Create the package manager and prepare to download
144 SPtr<pkgPackageManager> PM= _system->CreatePM(Cache);
145 if (PM->GetArchives(&Fetcher,List,&Recs) == false ||
146 _error->PendingError() == true)
147 return false;
148
149 // Display statistics
150 unsigned long long FetchBytes = Fetcher.FetchNeeded();
151 unsigned long long FetchPBytes = Fetcher.PartialPresent();
152 unsigned long long DebBytes = Fetcher.TotalNeeded();
153 if (DebBytes != Cache->DebSize())
154 {
155 c0out << DebBytes << ',' << Cache->DebSize() << std::endl;
156 c0out << _("How odd.. The sizes didn't match, email apt@packages.debian.org") << std::endl;
157 }
158
159 // Number of bytes
160 if (DebBytes != FetchBytes)
161 //TRANSLATOR: The required space between number and unit is already included
162 // in the replacement strings, so %sB will be correctly translate in e.g. 1,5 MB
163 ioprintf(c1out,_("Need to get %sB/%sB of archives.\n"),
164 SizeToStr(FetchBytes).c_str(),SizeToStr(DebBytes).c_str());
165 else if (DebBytes != 0)
166 //TRANSLATOR: The required space between number and unit is already included
167 // in the replacement string, so %sB will be correctly translate in e.g. 1,5 MB
168 ioprintf(c1out,_("Need to get %sB of archives.\n"),
169 SizeToStr(DebBytes).c_str());
170
171 // Size delta
172 if (Cache->UsrSize() >= 0)
173 //TRANSLATOR: The required space between number and unit is already included
174 // in the replacement string, so %sB will be correctly translate in e.g. 1,5 MB
175 ioprintf(c1out,_("After this operation, %sB of additional disk space will be used.\n"),
176 SizeToStr(Cache->UsrSize()).c_str());
177 else
178 //TRANSLATOR: The required space between number and unit is already included
179 // in the replacement string, so %sB will be correctly translate in e.g. 1,5 MB
180 ioprintf(c1out,_("After this operation, %sB disk space will be freed.\n"),
181 SizeToStr(-1*Cache->UsrSize()).c_str());
182
183 if (_error->PendingError() == true)
184 return false;
185
186 /* Check for enough free space, but only if we are actually going to
187 download */
188 if (_config->FindB("APT::Get::Print-URIs") == false &&
189 _config->FindB("APT::Get::Download",true) == true)
190 {
191 struct statvfs Buf;
192 std::string OutputDir = _config->FindDir("Dir::Cache::Archives");
193 if (statvfs(OutputDir.c_str(),&Buf) != 0) {
194 if (errno == EOVERFLOW)
195 return _error->WarningE("statvfs",_("Couldn't determine free space in %s"),
196 OutputDir.c_str());
197 else
198 return _error->Errno("statvfs",_("Couldn't determine free space in %s"),
199 OutputDir.c_str());
200 } else if (unsigned(Buf.f_bfree) < (FetchBytes - FetchPBytes)/Buf.f_bsize)
201 {
202 struct statfs Stat;
203 if (statfs(OutputDir.c_str(),&Stat) != 0
204 #if HAVE_STRUCT_STATFS_F_TYPE
205 || unsigned(Stat.f_type) != RAMFS_MAGIC
206 #endif
207 )
208 return _error->Error(_("You don't have enough free space in %s."),
209 OutputDir.c_str());
210 }
211 }
212
213 // Fail safe check
214 if (_config->FindI("quiet",0) >= 2 ||
215 _config->FindB("APT::Get::Assume-Yes",false) == true)
216 {
217 if (Fail == true && _config->FindB("APT::Get::Force-Yes",false) == false)
218 return _error->Error(_("There are problems and -y was used without --force-yes"));
219 }
220
221 if (Essential == true && Safety == true)
222 {
223 if (_config->FindB("APT::Get::Trivial-Only",false) == true)
224 return _error->Error(_("Trivial Only specified but this is not a trivial operation."));
225
226 // TRANSLATOR: This string needs to be typed by the user as a confirmation, so be
227 // careful with hard to type or special characters (like non-breaking spaces)
228 const char *Prompt = _("Yes, do as I say!");
229 ioprintf(c2out,
230 _("You are about to do something potentially harmful.\n"
231 "To continue type in the phrase '%s'\n"
232 " ?] "),Prompt);
233 c2out << std::flush;
234 if (AnalPrompt(Prompt) == false)
235 {
236 c2out << _("Abort.") << std::endl;
237 exit(1);
238 }
239 }
240 else
241 {
242 // Prompt to continue
243 if (Ask == true || Fail == true)
244 {
245 if (_config->FindB("APT::Get::Trivial-Only",false) == true)
246 return _error->Error(_("Trivial Only specified but this is not a trivial operation."));
247
248 if (_config->FindI("quiet",0) < 2 &&
249 _config->FindB("APT::Get::Assume-Yes",false) == false)
250 {
251 c2out << _("Do you want to continue?") << std::flush;
252 if (YnPrompt() == false)
253 {
254 c2out << _("Abort.") << std::endl;
255 exit(1);
256 }
257 }
258 }
259 }
260
261 // Just print out the uris an exit if the --print-uris flag was used
262 if (_config->FindB("APT::Get::Print-URIs") == true)
263 {
264 pkgAcquire::UriIterator I = Fetcher.UriBegin();
265 for (; I != Fetcher.UriEnd(); ++I)
266 std::cout << '\'' << I->URI << "' " << flNotDir(I->Owner->DestFile) << ' ' <<
267 I->Owner->FileSize << ' ' << I->Owner->HashSum() << std::endl;
268 return true;
269 }
270
271 if (!CheckAuth(Fetcher, true))
272 return false;
273
274 /* Unlock the dpkg lock if we are not going to be doing an install
275 after. */
276 if (_config->FindB("APT::Get::Download-Only",false) == true)
277 _system->UnLock();
278
279 // Run it
280 while (1)
281 {
282 bool Transient = false;
283 if (_config->FindB("APT::Get::Download",true) == false)
284 {
285 for (pkgAcquire::ItemIterator I = Fetcher.ItemsBegin(); I < Fetcher.ItemsEnd();)
286 {
287 if ((*I)->Local == true)
288 {
289 ++I;
290 continue;
291 }
292
293 // Close the item and check if it was found in cache
294 (*I)->Finished();
295 if ((*I)->Complete == false)
296 Transient = true;
297
298 // Clear it out of the fetch list
299 delete *I;
300 I = Fetcher.ItemsBegin();
301 }
302 }
303
304 bool Failed = false;
305 if (AcquireRun(Fetcher, 0, &Failed, &Transient) == false)
306 return false;
307
308 /* If we are in no download mode and missing files and there were
309 'failures' then the user must specify -m. Furthermore, there
310 is no such thing as a transient error in no-download mode! */
311 if (Transient == true &&
312 _config->FindB("APT::Get::Download",true) == false)
313 {
314 Transient = false;
315 Failed = true;
316 }
317
318 if (_config->FindB("APT::Get::Download-Only",false) == true)
319 {
320 if (Failed == true && _config->FindB("APT::Get::Fix-Missing",false) == false)
321 return _error->Error(_("Some files failed to download"));
322 c1out << _("Download complete and in download only mode") << std::endl;
323 return true;
324 }
325
326 if (Failed == true && _config->FindB("APT::Get::Fix-Missing",false) == false)
327 {
328 return _error->Error(_("Unable to fetch some archives, maybe run apt-get update or try with --fix-missing?"));
329 }
330
331 if (Transient == true && Failed == true)
332 return _error->Error(_("--fix-missing and media swapping is not currently supported"));
333
334 // Try to deal with missing package files
335 if (Failed == true && PM->FixMissing() == false)
336 {
337 c2out << _("Unable to correct missing packages.") << std::endl;
338 return _error->Error(_("Aborting install."));
339 }
340
341 _system->UnLock();
342
343 // FIXME: make this a factory
344 // select the right progress
345 int status_fd = _config->FindI("APT::Status-Fd", -1);
346 int status_deb822_fd = _config->FindI("APT::Status-deb822-Fd", -1);
347
348 APT::Progress::PackageManager *progress = NULL;
349 if (status_deb822_fd > 0)
350 progress = new APT::Progress::PackageManagerProgressDeb822Fd(
351 status_deb822_fd);
352 else if (status_fd > 0)
353 progress = new APT::Progress::PackageManagerProgressFd(status_fd);
354 else if(_config->FindB("Dpkg::Progress-Fancy", false) == true)
355 progress = new APT::Progress::PackageManagerFancy();
356 else if (_config->FindB("Dpkg::Progress",
357 _config->FindB("DpkgPM::Progress", false)) == true)
358 progress = new APT::Progress::PackageManagerText();
359 else
360 progress = new APT::Progress::PackageManager();
361 pkgPackageManager::OrderResult Res = PM->DoInstall(progress);
362 delete progress;
363
364 if (Res == pkgPackageManager::Failed || _error->PendingError() == true)
365 return false;
366 if (Res == pkgPackageManager::Completed)
367 break;
368
369 // Reload the fetcher object and loop again for media swapping
370 Fetcher.Shutdown();
371 if (PM->GetArchives(&Fetcher,List,&Recs) == false)
372 return false;
373
374 _system->Lock();
375 }
376
377 std::set<std::string> const disappearedPkgs = PM->GetDisappearedPackages();
378 if (disappearedPkgs.empty() == true)
379 return true;
380
381 std::string disappear;
382 for (std::set<std::string>::const_iterator d = disappearedPkgs.begin();
383 d != disappearedPkgs.end(); ++d)
384 disappear.append(*d).append(" ");
385
386 ShowList(c1out, P_("The following package disappeared from your system as\n"
387 "all files have been overwritten by other packages:",
388 "The following packages disappeared from your system as\n"
389 "all files have been overwritten by other packages:", disappearedPkgs.size()), disappear, "");
390 c0out << _("Note: This is done automatically and on purpose by dpkg.") << std::endl;
391
392 return true;
393 }
394 /*}}}*/
395 // DoAutomaticRemove - Remove all automatic unused packages /*{{{*/
396 // ---------------------------------------------------------------------
397 /* Remove unused automatic packages */
398 bool DoAutomaticRemove(CacheFile &Cache)
399 {
400 bool Debug = _config->FindI("Debug::pkgAutoRemove",false);
401 bool doAutoRemove = _config->FindB("APT::Get::AutomaticRemove", false);
402 bool hideAutoRemove = _config->FindB("APT::Get::HideAutoRemove");
403
404 pkgDepCache::ActionGroup group(*Cache);
405 if(Debug)
406 std::cout << "DoAutomaticRemove()" << std::endl;
407
408 if (doAutoRemove == true &&
409 _config->FindB("APT::Get::Remove",true) == false)
410 {
411 c1out << _("We are not supposed to delete stuff, can't start "
412 "AutoRemover") << std::endl;
413 return false;
414 }
415
416 bool purgePkgs = _config->FindB("APT::Get::Purge", false);
417 bool smallList = (hideAutoRemove == false &&
418 strcasecmp(_config->Find("APT::Get::HideAutoRemove","").c_str(),"small") == 0);
419
420 unsigned long autoRemoveCount = 0;
421 APT::PackageSet tooMuch;
422 APT::PackageList autoRemoveList;
423 // look over the cache to see what can be removed
424 for (unsigned J = 0; J < Cache->Head().PackageCount; ++J)
425 {
426 pkgCache::PkgIterator Pkg(Cache,Cache.List[J]);
427 if (Cache[Pkg].Garbage)
428 {
429 if(Pkg.CurrentVer() != 0 || Cache[Pkg].Install())
430 if(Debug)
431 std::cout << "We could delete %s" << Pkg.FullName(true).c_str() << std::endl;
432
433 if (doAutoRemove)
434 {
435 if(Pkg.CurrentVer() != 0 &&
436 Pkg->CurrentState != pkgCache::State::ConfigFiles)
437 Cache->MarkDelete(Pkg, purgePkgs, 0, false);
438 else
439 Cache->MarkKeep(Pkg, false, false);
440 }
441 else
442 {
443 if (hideAutoRemove == false && Cache[Pkg].Delete() == false)
444 autoRemoveList.insert(Pkg);
445 // if the package is a new install and already garbage we don't need to
446 // install it in the first place, so nuke it instead of show it
447 if (Cache[Pkg].Install() == true && Pkg.CurrentVer() == 0)
448 {
449 if (Pkg.CandVersion() != 0)
450 tooMuch.insert(Pkg);
451 Cache->MarkDelete(Pkg, false, 0, false);
452 }
453 // only show stuff in the list that is not yet marked for removal
454 else if(hideAutoRemove == false && Cache[Pkg].Delete() == false)
455 ++autoRemoveCount;
456 }
457 }
458 }
459
460 // we could have removed a new dependency of a garbage package,
461 // so check if a reverse depends is broken and if so install it again.
462 if (tooMuch.empty() == false && (Cache->BrokenCount() != 0 || Cache->PolicyBrokenCount() != 0))
463 {
464 bool Changed;
465 do {
466 Changed = false;
467 for (APT::PackageSet::const_iterator Pkg = tooMuch.begin();
468 Pkg != tooMuch.end(); ++Pkg)
469 {
470 APT::PackageSet too;
471 too.insert(*Pkg);
472 for (pkgCache::PrvIterator Prv = Cache[Pkg].CandidateVerIter(Cache).ProvidesList();
473 Prv.end() == false; ++Prv)
474 too.insert(Prv.ParentPkg());
475 for (APT::PackageSet::const_iterator P = too.begin(); P != too.end(); ++P)
476 {
477 for (pkgCache::DepIterator R = P.RevDependsList();
478 R.end() == false; ++R)
479 {
480 if (R.IsNegative() == true ||
481 Cache->IsImportantDep(R) == false)
482 continue;
483 pkgCache::PkgIterator N = R.ParentPkg();
484 if (N.end() == true || (N->CurrentVer == 0 && (*Cache)[N].Install() == false))
485 continue;
486 if (Debug == true)
487 std::clog << "Save " << Pkg << " as another installed garbage package depends on it" << std::endl;
488 Cache->MarkInstall(Pkg, false, 0, false);
489 if (hideAutoRemove == false)
490 ++autoRemoveCount;
491 tooMuch.erase(Pkg);
492 Changed = true;
493 break;
494 }
495 if (Changed == true)
496 break;
497 }
498 if (Changed == true)
499 break;
500 }
501 } while (Changed == true);
502 }
503
504 std::string autoremovelist, autoremoveversions;
505 if (smallList == false && autoRemoveCount != 0)
506 {
507 for (APT::PackageList::const_iterator Pkg = autoRemoveList.begin(); Pkg != autoRemoveList.end(); ++Pkg)
508 {
509 if (Cache[Pkg].Garbage == false)
510 continue;
511 autoremovelist += Pkg.FullName(true) + " ";
512 autoremoveversions += std::string(Cache[Pkg].CandVersion) + "\n";
513 }
514 }
515
516 // Now see if we had destroyed anything (if we had done anything)
517 if (Cache->BrokenCount() != 0)
518 {
519 c1out << _("Hmm, seems like the AutoRemover destroyed something which really\n"
520 "shouldn't happen. Please file a bug report against apt.") << std::endl;
521 c1out << std::endl;
522 c1out << _("The following information may help to resolve the situation:") << std::endl;
523 c1out << std::endl;
524 ShowBroken(c1out,Cache,false);
525
526 return _error->Error(_("Internal Error, AutoRemover broke stuff"));
527 }
528
529 // if we don't remove them, we should show them!
530 if (doAutoRemove == false && (autoremovelist.empty() == false || autoRemoveCount != 0))
531 {
532 if (smallList == false)
533 ShowList(c1out, P_("The following package was automatically installed and is no longer required:",
534 "The following packages were automatically installed and are no longer required:",
535 autoRemoveCount), autoremovelist, autoremoveversions);
536 else
537 ioprintf(c1out, P_("%lu package was automatically installed and is no longer required.\n",
538 "%lu packages were automatically installed and are no longer required.\n", autoRemoveCount), autoRemoveCount);
539 c1out << P_("Use 'apt-get autoremove' to remove it.", "Use 'apt-get autoremove' to remove them.", autoRemoveCount) << std::endl;
540 }
541 return true;
542 }
543 /*}}}*/
544 // DoCacheManipulationFromCommandLine /*{{{*/
545 static const unsigned short MOD_REMOVE = 1;
546 static const unsigned short MOD_INSTALL = 2;
547
548 bool DoCacheManipulationFromCommandLine(CommandLine &CmdL, CacheFile &Cache)
549 {
550 std::map<unsigned short, APT::VersionSet> verset;
551 return DoCacheManipulationFromCommandLine(CmdL, Cache, verset);
552 }
553 bool DoCacheManipulationFromCommandLine(CommandLine &CmdL, CacheFile &Cache,
554 std::map<unsigned short, APT::VersionSet> &verset)
555 {
556
557 // Enter the special broken fixing mode if the user specified arguments
558 bool BrokenFix = false;
559 if (Cache->BrokenCount() != 0)
560 BrokenFix = true;
561
562 SPtr<pkgProblemResolver> Fix;
563 if (_config->FindB("APT::Get::CallResolver", true) == true)
564 Fix = new pkgProblemResolver(Cache);
565
566 unsigned short fallback = MOD_INSTALL;
567 if (strcasecmp(CmdL.FileList[0],"remove") == 0)
568 fallback = MOD_REMOVE;
569 else if (strcasecmp(CmdL.FileList[0], "purge") == 0)
570 {
571 _config->Set("APT::Get::Purge", true);
572 fallback = MOD_REMOVE;
573 }
574 else if (strcasecmp(CmdL.FileList[0], "autoremove") == 0)
575 {
576 _config->Set("APT::Get::AutomaticRemove", "true");
577 fallback = MOD_REMOVE;
578 }
579
580 std::list<APT::VersionSet::Modifier> mods;
581 mods.push_back(APT::VersionSet::Modifier(MOD_INSTALL, "+",
582 APT::VersionSet::Modifier::POSTFIX, APT::VersionSet::CANDIDATE));
583 mods.push_back(APT::VersionSet::Modifier(MOD_REMOVE, "-",
584 APT::VersionSet::Modifier::POSTFIX, APT::VersionSet::NEWEST));
585 CacheSetHelperAPTGet helper(c0out);
586 verset = APT::VersionSet::GroupedFromCommandLine(Cache,
587 CmdL.FileList + 1, mods, fallback, helper);
588
589 if (_error->PendingError() == true)
590 {
591 helper.showVirtualPackageErrors(Cache);
592 return false;
593 }
594
595
596 TryToInstall InstallAction(Cache, Fix, BrokenFix);
597 TryToRemove RemoveAction(Cache, Fix);
598
599 // new scope for the ActionGroup
600 {
601 pkgDepCache::ActionGroup group(Cache);
602 unsigned short const order[] = { MOD_REMOVE, MOD_INSTALL, 0 };
603
604 for (unsigned short i = 0; order[i] != 0; ++i)
605 {
606 if (order[i] == MOD_INSTALL)
607 InstallAction = std::for_each(verset[MOD_INSTALL].begin(), verset[MOD_INSTALL].end(), InstallAction);
608 else if (order[i] == MOD_REMOVE)
609 RemoveAction = std::for_each(verset[MOD_REMOVE].begin(), verset[MOD_REMOVE].end(), RemoveAction);
610 }
611
612 if (Fix != NULL && _config->FindB("APT::Get::AutoSolving", true) == true)
613 {
614 for (unsigned short i = 0; order[i] != 0; ++i)
615 {
616 if (order[i] != MOD_INSTALL)
617 continue;
618 InstallAction.propergateReleaseCandiateSwitching(helper.selectedByRelease, c0out);
619 InstallAction.doAutoInstall();
620 }
621 }
622
623 if (_error->PendingError() == true)
624 {
625 return false;
626 }
627
628 /* If we are in the Broken fixing mode we do not attempt to fix the
629 problems. This is if the user invoked install without -f and gave
630 packages */
631 if (BrokenFix == true && Cache->BrokenCount() != 0)
632 {
633 c1out << _("You might want to run 'apt-get -f install' to correct these:") << std::endl;
634 ShowBroken(c1out,Cache,false);
635 return _error->Error(_("Unmet dependencies. Try 'apt-get -f install' with no packages (or specify a solution)."));
636 }
637
638 if (Fix != NULL)
639 {
640 // Call the scored problem resolver
641 Fix->Resolve(true);
642 }
643
644 // Now we check the state of the packages,
645 if (Cache->BrokenCount() != 0)
646 {
647 c1out <<
648 _("Some packages could not be installed. This may mean that you have\n"
649 "requested an impossible situation or if you are using the unstable\n"
650 "distribution that some required packages have not yet been created\n"
651 "or been moved out of Incoming.") << std::endl;
652 /*
653 if (Packages == 1)
654 {
655 c1out << std::endl;
656 c1out <<
657 _("Since you only requested a single operation it is extremely likely that\n"
658 "the package is simply not installable and a bug report against\n"
659 "that package should be filed.") << std::endl;
660 }
661 */
662
663 c1out << _("The following information may help to resolve the situation:") << std::endl;
664 c1out << std::endl;
665 ShowBroken(c1out,Cache,false);
666 if (_error->PendingError() == true)
667 return false;
668 else
669 return _error->Error(_("Broken packages"));
670 }
671 }
672 if (!DoAutomaticRemove(Cache))
673 return false;
674
675 // if nothing changed in the cache, but only the automark information
676 // we write the StateFile here, otherwise it will be written in
677 // cache.commit()
678 if (InstallAction.AutoMarkChanged > 0 &&
679 Cache->DelCount() == 0 && Cache->InstCount() == 0 &&
680 Cache->BadCount() == 0 &&
681 _config->FindB("APT::Get::Simulate",false) == false)
682 Cache->writeStateFile(NULL);
683
684 return true;
685 }
686 /*}}}*/
687 // DoInstall - Install packages from the command line /*{{{*/
688 // ---------------------------------------------------------------------
689 /* Install named packages */
690 bool DoInstall(CommandLine &CmdL)
691 {
692 CacheFile Cache;
693 if (Cache.OpenForInstall() == false ||
694 Cache.CheckDeps(CmdL.FileSize() != 1) == false)
695 return false;
696
697 std::map<unsigned short, APT::VersionSet> verset;
698
699 if(!DoCacheManipulationFromCommandLine(CmdL, Cache, verset))
700 return false;
701
702 /* Print out a list of packages that are going to be installed extra
703 to what the user asked */
704 if (Cache->InstCount() != verset[MOD_INSTALL].size())
705 {
706 std::string List;
707 std::string VersionsList;
708 for (unsigned J = 0; J < Cache->Head().PackageCount; J++)
709 {
710 pkgCache::PkgIterator I(Cache,Cache.List[J]);
711 if ((*Cache)[I].Install() == false)
712 continue;
713 pkgCache::VerIterator Cand = Cache[I].CandidateVerIter(Cache);
714
715 if (verset[MOD_INSTALL].find(Cand) != verset[MOD_INSTALL].end())
716 continue;
717
718 List += I.FullName(true) + " ";
719 VersionsList += std::string(Cache[I].CandVersion) + "\n";
720 }
721
722 ShowList(c1out,_("The following extra packages will be installed:"),List,VersionsList);
723 }
724
725 /* Print out a list of suggested and recommended packages */
726 {
727 std::string SuggestsList, RecommendsList;
728 std::string SuggestsVersions, RecommendsVersions;
729 for (unsigned J = 0; J < Cache->Head().PackageCount; J++)
730 {
731 pkgCache::PkgIterator Pkg(Cache,Cache.List[J]);
732
733 /* Just look at the ones we want to install */
734 if ((*Cache)[Pkg].Install() == false)
735 continue;
736
737 // get the recommends/suggests for the candidate ver
738 pkgCache::VerIterator CV = (*Cache)[Pkg].CandidateVerIter(*Cache);
739 for (pkgCache::DepIterator D = CV.DependsList(); D.end() == false; )
740 {
741 pkgCache::DepIterator Start;
742 pkgCache::DepIterator End;
743 D.GlobOr(Start,End); // advances D
744
745 // FIXME: we really should display a or-group as a or-group to the user
746 // the problem is that ShowList is incapable of doing this
747 std::string RecommendsOrList,RecommendsOrVersions;
748 std::string SuggestsOrList,SuggestsOrVersions;
749 bool foundInstalledInOrGroup = false;
750 for(;;)
751 {
752 /* Skip if package is installed already, or is about to be */
753 std::string target = Start.TargetPkg().FullName(true) + " ";
754 pkgCache::PkgIterator const TarPkg = Start.TargetPkg();
755 if (TarPkg->SelectedState == pkgCache::State::Install ||
756 TarPkg->SelectedState == pkgCache::State::Hold ||
757 Cache[Start.TargetPkg()].Install())
758 {
759 foundInstalledInOrGroup=true;
760 break;
761 }
762
763 /* Skip if we already saw it */
764 if (int(SuggestsList.find(target)) != -1 || int(RecommendsList.find(target)) != -1)
765 {
766 foundInstalledInOrGroup=true;
767 break;
768 }
769
770 // this is a dep on a virtual pkg, check if any package that provides it
771 // should be installed
772 if(Start.TargetPkg().ProvidesList() != 0)
773 {
774 pkgCache::PrvIterator I = Start.TargetPkg().ProvidesList();
775 for (; I.end() == false; ++I)
776 {
777 pkgCache::PkgIterator Pkg = I.OwnerPkg();
778 if (Cache[Pkg].CandidateVerIter(Cache) == I.OwnerVer() &&
779 Pkg.CurrentVer() != 0)
780 foundInstalledInOrGroup=true;
781 }
782 }
783
784 if (Start->Type == pkgCache::Dep::Suggests)
785 {
786 SuggestsOrList += target;
787 SuggestsOrVersions += std::string(Cache[Start.TargetPkg()].CandVersion) + "\n";
788 }
789
790 if (Start->Type == pkgCache::Dep::Recommends)
791 {
792 RecommendsOrList += target;
793 RecommendsOrVersions += std::string(Cache[Start.TargetPkg()].CandVersion) + "\n";
794 }
795
796 if (Start >= End)
797 break;
798 ++Start;
799 }
800
801 if(foundInstalledInOrGroup == false)
802 {
803 RecommendsList += RecommendsOrList;
804 RecommendsVersions += RecommendsOrVersions;
805 SuggestsList += SuggestsOrList;
806 SuggestsVersions += SuggestsOrVersions;
807 }
808
809 }
810 }
811
812 ShowList(c1out,_("Suggested packages:"),SuggestsList,SuggestsVersions);
813 ShowList(c1out,_("Recommended packages:"),RecommendsList,RecommendsVersions);
814
815 }
816
817 // See if we need to prompt
818 // FIXME: check if really the packages in the set are going to be installed
819 if (Cache->InstCount() == verset[MOD_INSTALL].size() && Cache->DelCount() == 0)
820 return InstallPackages(Cache,false,false);
821
822 return InstallPackages(Cache,false);
823 }
824 /*}}}*/