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