1 // Include Files /*{{{*/
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>
26 #include <sys/statfs.h>
27 #include <sys/statvfs.h>
33 #include <apt-private/acqprogress.h>
34 #include <apt-private/private-install.h>
35 #include <apt-private/private-cachefile.h>
36 #include <apt-private/private-cacheset.h>
37 #include <apt-private/private-download.h>
38 #include <apt-private/private-output.h>
44 // InstallPackages - Actually download and install the packages /*{{{*/
45 // ---------------------------------------------------------------------
46 /* This displays the informative messages describing what is going to
47 happen and then calls the download routines */
48 bool InstallPackages(CacheFile
&Cache
,bool ShwKept
,bool Ask
, bool Safety
)
50 if (_config
->FindB("APT::Get::Purge",false) == true)
52 pkgCache::PkgIterator I
= Cache
->PkgBegin();
53 for (; I
.end() == false; ++I
)
55 if (I
.Purge() == false && Cache
[I
].Mode
== pkgDepCache::ModeDelete
)
56 Cache
->MarkDelete(I
,true);
61 bool Essential
= false;
63 // Show all the various warning indicators
67 ShowKept(c1out
,Cache
);
68 Fail
|= !ShowHold(c1out
,Cache
);
69 if (_config
->FindB("APT::Get::Show-Upgraded",true) == true)
70 ShowUpgraded(c1out
,Cache
);
71 Fail
|= !ShowDowngraded(c1out
,Cache
);
72 if (_config
->FindB("APT::Get::Download-Only",false) == false)
73 Essential
= !ShowEssential(c1out
,Cache
);
78 if (Cache
->BrokenCount() != 0)
80 ShowBroken(c1out
,Cache
,false);
81 return _error
->Error(_("Internal error, InstallPackages was called with broken packages!"));
84 if (Cache
->DelCount() == 0 && Cache
->InstCount() == 0 &&
85 Cache
->BadCount() == 0)
89 if (Cache
->DelCount() != 0 && _config
->FindB("APT::Get::Remove",true) == false)
90 return _error
->Error(_("Packages need to be removed but remove is disabled."));
92 // Run the simulator ..
93 if (_config
->FindB("APT::Get::Simulate") == true)
95 pkgSimulate
PM(Cache
);
97 #if (APT_PKG_MAJOR >= 4 && APT_PKG_MINOR >= 13)
98 APT::Progress::PackageManager
*progress
= APT::Progress::PackageManagerProgressFactory();
99 pkgPackageManager::OrderResult Res
= PM
.DoInstall(progress
);
102 int status_fd
= _config
->FindI("APT::Status-Fd",-1);
103 pkgPackageManager::OrderResult Res
= PM
.DoInstall(status_fd
);
106 if (Res
== pkgPackageManager::Failed
)
108 if (Res
!= pkgPackageManager::Completed
)
109 return _error
->Error(_("Internal error, Ordering didn't finish"));
113 // Create the text record parser
114 pkgRecords
Recs(Cache
);
115 if (_error
->PendingError() == true)
118 // Create the download object
120 AcqTextStatus
Stat(ScreenWidth
,_config
->FindI("quiet",0));
121 if (_config
->FindB("APT::Get::Print-URIs", false) == true)
123 // force a hashsum for compatibility reasons
124 _config
->CndSet("Acquire::ForceHash", "md5sum");
126 else if (Fetcher
.Setup(&Stat
, _config
->FindDir("Dir::Cache::Archives")) == false)
129 // Read the source list
130 if (Cache
.BuildSourceList() == false)
132 pkgSourceList
*List
= Cache
.GetSourceList();
134 // Create the package manager and prepare to download
135 SPtr
<pkgPackageManager
> PM
= _system
->CreatePM(Cache
);
136 if (PM
->GetArchives(&Fetcher
,List
,&Recs
) == false ||
137 _error
->PendingError() == true)
140 // Display statistics
141 unsigned long long FetchBytes
= Fetcher
.FetchNeeded();
142 unsigned long long FetchPBytes
= Fetcher
.PartialPresent();
143 unsigned long long DebBytes
= Fetcher
.TotalNeeded();
144 if (DebBytes
!= Cache
->DebSize())
146 c0out
<< DebBytes
<< ',' << Cache
->DebSize() << std::endl
;
147 c0out
<< _("How odd... The sizes didn't match, email apt@packages.debian.org") << std::endl
;
151 if (DebBytes
!= FetchBytes
)
152 //TRANSLATOR: The required space between number and unit is already included
153 // in the replacement strings, so %sB will be correctly translate in e.g. 1,5 MB
154 ioprintf(c1out
,_("Need to get %sB/%sB of archives.\n"),
155 SizeToStr(FetchBytes
).c_str(),SizeToStr(DebBytes
).c_str());
156 else if (DebBytes
!= 0)
157 //TRANSLATOR: The required space between number and unit is already included
158 // in the replacement string, so %sB will be correctly translate in e.g. 1,5 MB
159 ioprintf(c1out
,_("Need to get %sB of archives.\n"),
160 SizeToStr(DebBytes
).c_str());
163 if (Cache
->UsrSize() >= 0)
164 //TRANSLATOR: The required space between number and unit is already included
165 // in the replacement string, so %sB will be correctly translate in e.g. 1,5 MB
166 ioprintf(c1out
,_("After this operation, %sB of additional disk space will be used.\n"),
167 SizeToStr(Cache
->UsrSize()).c_str());
169 //TRANSLATOR: The required space between number and unit is already included
170 // in the replacement string, so %sB will be correctly translate in e.g. 1,5 MB
171 ioprintf(c1out
,_("After this operation, %sB disk space will be freed.\n"),
172 SizeToStr(-1*Cache
->UsrSize()).c_str());
174 if (_error
->PendingError() == true)
177 /* Check for enough free space, but only if we are actually going to
179 if (_config
->FindB("APT::Get::Print-URIs") == false &&
180 _config
->FindB("APT::Get::Download",true) == true)
183 std::string OutputDir
= _config
->FindDir("Dir::Cache::Archives");
184 if (statvfs(OutputDir
.c_str(),&Buf
) != 0) {
185 if (errno
== EOVERFLOW
)
186 return _error
->WarningE("statvfs",_("Couldn't determine free space in %s"),
189 return _error
->Errno("statvfs",_("Couldn't determine free space in %s"),
191 } else if (unsigned(Buf
.f_bfree
) < (FetchBytes
- FetchPBytes
)/Buf
.f_bsize
)
194 if (statfs(OutputDir
.c_str(),&Stat
) != 0
195 #if HAVE_STRUCT_STATFS_F_TYPE
196 || unsigned(Stat
.f_type
) != RAMFS_MAGIC
199 return _error
->Error(_("You don't have enough free space in %s."),
205 if (_config
->FindI("quiet",0) >= 2 ||
206 _config
->FindB("APT::Get::Assume-Yes",false) == true)
208 if (Fail
== true && _config
->FindB("APT::Get::Force-Yes",false) == false)
209 return _error
->Error(_("There are problems and -y was used without --force-yes"));
212 if (Essential
== true && Safety
== true)
214 if (_config
->FindB("APT::Get::Trivial-Only",false) == true)
215 return _error
->Error(_("Trivial Only specified but this is not a trivial operation."));
217 // TRANSLATOR: This string needs to be typed by the user as a confirmation, so be
218 // careful with hard to type or special characters (like non-breaking spaces)
219 const char *Prompt
= _("Yes, do as I say!");
221 _("You are about to do something potentially harmful.\n"
222 "To continue type in the phrase '%s'\n"
225 if (AnalPrompt(Prompt
) == false)
227 c2out
<< _("Abort.") << std::endl
;
233 // Prompt to continue
234 if (Ask
== true || Fail
== true)
236 if (_config
->FindB("APT::Get::Trivial-Only",false) == true)
237 return _error
->Error(_("Trivial Only specified but this is not a trivial operation."));
239 if (_config
->FindI("quiet",0) < 2 &&
240 _config
->FindB("APT::Get::Assume-Yes",false) == false)
242 c2out
<< _("Do you want to continue?") << std::flush
;
243 if (YnPrompt() == false)
245 c2out
<< _("Abort.") << std::endl
;
252 // Just print out the uris an exit if the --print-uris flag was used
253 if (_config
->FindB("APT::Get::Print-URIs") == true)
255 pkgAcquire::UriIterator I
= Fetcher
.UriBegin();
256 for (; I
!= Fetcher
.UriEnd(); ++I
)
257 std::cout
<< '\'' << I
->URI
<< "' " << flNotDir(I
->Owner
->DestFile
) << ' ' <<
258 I
->Owner
->FileSize
<< ' ' << I
->Owner
->HashSum() << std::endl
;
262 if (!CheckAuth(Fetcher
, true))
265 /* Unlock the dpkg lock if we are not going to be doing an install
267 if (_config
->FindB("APT::Get::Download-Only",false) == true)
273 bool Transient
= false;
274 if (_config
->FindB("APT::Get::Download",true) == false)
276 for (pkgAcquire::ItemIterator I
= Fetcher
.ItemsBegin(); I
< Fetcher
.ItemsEnd();)
278 if ((*I
)->Local
== true)
284 // Close the item and check if it was found in cache
286 if ((*I
)->Complete
== false)
289 // Clear it out of the fetch list
291 I
= Fetcher
.ItemsBegin();
296 if (AcquireRun(Fetcher
, 0, &Failed
, &Transient
) == false)
299 /* If we are in no download mode and missing files and there were
300 'failures' then the user must specify -m. Furthermore, there
301 is no such thing as a transient error in no-download mode! */
302 if (Transient
== true &&
303 _config
->FindB("APT::Get::Download",true) == false)
309 if (_config
->FindB("APT::Get::Download-Only",false) == true)
311 if (Failed
== true && _config
->FindB("APT::Get::Fix-Missing",false) == false)
312 return _error
->Error(_("Some files failed to download"));
313 c1out
<< _("Download complete and in download only mode") << std::endl
;
317 if (Failed
== true && _config
->FindB("APT::Get::Fix-Missing",false) == false)
319 return _error
->Error(_("Unable to fetch some archives, maybe run apt-get update or try with --fix-missing?"));
322 if (Transient
== true && Failed
== true)
323 return _error
->Error(_("--fix-missing and media swapping is not currently supported"));
325 // Try to deal with missing package files
326 if (Failed
== true && PM
->FixMissing() == false)
328 c2out
<< _("Unable to correct missing packages.") << std::endl
;
329 return _error
->Error(_("Aborting install."));
334 #if (APT_PKG_MAJOR >= 4 && APT_PKG_MINOR >= 13)
335 APT::Progress::PackageManager
*progress
= APT::Progress::PackageManagerProgressFactory();
336 pkgPackageManager::OrderResult Res
= PM
->DoInstall(progress
);
339 int status_fd
= _config
->FindI("APT::Status-Fd", -1);
340 pkgPackageManager::OrderResult Res
= PM
->DoInstall(status_fd
);
343 if (Res
== pkgPackageManager::Failed
|| _error
->PendingError() == true)
345 if (Res
== pkgPackageManager::Completed
)
348 // Reload the fetcher object and loop again for media swapping
350 if (PM
->GetArchives(&Fetcher
,List
,&Recs
) == false)
356 std::set
<std::string
> const disappearedPkgs
= PM
->GetDisappearedPackages();
357 if (disappearedPkgs
.empty() == true)
360 std::string disappear
;
361 for (std::set
<std::string
>::const_iterator d
= disappearedPkgs
.begin();
362 d
!= disappearedPkgs
.end(); ++d
)
363 disappear
.append(*d
).append(" ");
365 ShowList(c1out
, P_("The following package disappeared from your system as\n"
366 "all files have been overwritten by other packages:",
367 "The following packages disappeared from your system as\n"
368 "all files have been overwritten by other packages:", disappearedPkgs
.size()), disappear
, "");
369 c0out
<< _("Note: This is done automatically and on purpose by dpkg.") << std::endl
;
374 // DoAutomaticRemove - Remove all automatic unused packages /*{{{*/
375 // ---------------------------------------------------------------------
376 /* Remove unused automatic packages */
377 static bool DoAutomaticRemove(CacheFile
&Cache
)
379 bool Debug
= _config
->FindI("Debug::pkgAutoRemove",false);
380 bool doAutoRemove
= _config
->FindB("APT::Get::AutomaticRemove", false);
381 bool hideAutoRemove
= _config
->FindB("APT::Get::HideAutoRemove");
383 pkgDepCache::ActionGroup
group(*Cache
);
385 std::cout
<< "DoAutomaticRemove()" << std::endl
;
387 if (doAutoRemove
== true &&
388 _config
->FindB("APT::Get::Remove",true) == false)
390 c1out
<< _("We are not supposed to delete stuff, can't start "
391 "AutoRemover") << std::endl
;
395 bool purgePkgs
= _config
->FindB("APT::Get::Purge", false);
396 bool smallList
= (hideAutoRemove
== false &&
397 strcasecmp(_config
->Find("APT::Get::HideAutoRemove","").c_str(),"small") == 0);
399 unsigned long autoRemoveCount
= 0;
400 APT::PackageSet tooMuch
;
401 APT::PackageList autoRemoveList
;
402 // look over the cache to see what can be removed
403 for (unsigned J
= 0; J
< Cache
->Head().PackageCount
; ++J
)
405 pkgCache::PkgIterator
Pkg(Cache
,Cache
.List
[J
]);
406 if (Cache
[Pkg
].Garbage
)
408 if(Pkg
.CurrentVer() != 0 || Cache
[Pkg
].Install())
410 std::cout
<< "We could delete %s" << Pkg
.FullName(true).c_str() << std::endl
;
414 if(Pkg
.CurrentVer() != 0 &&
415 Pkg
->CurrentState
!= pkgCache::State::ConfigFiles
)
416 Cache
->MarkDelete(Pkg
, purgePkgs
, 0, false);
418 Cache
->MarkKeep(Pkg
, false, false);
422 if (hideAutoRemove
== false && Cache
[Pkg
].Delete() == false)
423 autoRemoveList
.insert(Pkg
);
424 // if the package is a new install and already garbage we don't need to
425 // install it in the first place, so nuke it instead of show it
426 if (Cache
[Pkg
].Install() == true && Pkg
.CurrentVer() == 0)
428 if (Pkg
.CandVersion() != 0)
430 Cache
->MarkDelete(Pkg
, false, 0, false);
432 // only show stuff in the list that is not yet marked for removal
433 else if(hideAutoRemove
== false && Cache
[Pkg
].Delete() == false)
439 // we could have removed a new dependency of a garbage package,
440 // so check if a reverse depends is broken and if so install it again.
441 if (tooMuch
.empty() == false && (Cache
->BrokenCount() != 0 || Cache
->PolicyBrokenCount() != 0))
446 for (APT::PackageSet::const_iterator Pkg
= tooMuch
.begin();
447 Pkg
!= tooMuch
.end(); ++Pkg
)
451 for (pkgCache::PrvIterator Prv
= Cache
[Pkg
].CandidateVerIter(Cache
).ProvidesList();
452 Prv
.end() == false; ++Prv
)
453 too
.insert(Prv
.ParentPkg());
454 for (APT::PackageSet::const_iterator P
= too
.begin(); P
!= too
.end(); ++P
)
456 for (pkgCache::DepIterator R
= P
.RevDependsList();
457 R
.end() == false; ++R
)
459 if (R
.IsNegative() == true ||
460 Cache
->IsImportantDep(R
) == false)
462 pkgCache::PkgIterator N
= R
.ParentPkg();
463 if (N
.end() == true || (N
->CurrentVer
== 0 && (*Cache
)[N
].Install() == false))
466 std::clog
<< "Save " << Pkg
<< " as another installed garbage package depends on it" << std::endl
;
467 Cache
->MarkInstall(Pkg
, false, 0, false);
468 if (hideAutoRemove
== false)
480 } while (Changed
== true);
483 std::string autoremovelist
, autoremoveversions
;
484 if (smallList
== false && autoRemoveCount
!= 0)
486 for (APT::PackageList::const_iterator Pkg
= autoRemoveList
.begin(); Pkg
!= autoRemoveList
.end(); ++Pkg
)
488 if (Cache
[Pkg
].Garbage
== false)
490 autoremovelist
+= Pkg
.FullName(true) + " ";
491 autoremoveversions
+= std::string(Cache
[Pkg
].CandVersion
) + "\n";
495 // Now see if we had destroyed anything (if we had done anything)
496 if (Cache
->BrokenCount() != 0)
498 c1out
<< _("Hmm, seems like the AutoRemover destroyed something which really\n"
499 "shouldn't happen. Please file a bug report against apt.") << std::endl
;
501 c1out
<< _("The following information may help to resolve the situation:") << std::endl
;
503 ShowBroken(c1out
,Cache
,false);
505 return _error
->Error(_("Internal Error, AutoRemover broke stuff"));
508 // if we don't remove them, we should show them!
509 if (doAutoRemove
== false && (autoremovelist
.empty() == false || autoRemoveCount
!= 0))
511 if (smallList
== false)
512 ShowList(c1out
, P_("The following package was automatically installed and is no longer required:",
513 "The following packages were automatically installed and are no longer required:",
514 autoRemoveCount
), autoremovelist
, autoremoveversions
);
516 ioprintf(c1out
, P_("%lu package was automatically installed and is no longer required.\n",
517 "%lu packages were automatically installed and are no longer required.\n", autoRemoveCount
), autoRemoveCount
);
518 c1out
<< P_("Use 'apt-get autoremove' to remove it.", "Use 'apt-get autoremove' to remove them.", autoRemoveCount
) << std::endl
;
523 // DoCacheManipulationFromCommandLine /*{{{*/
524 static const unsigned short MOD_REMOVE
= 1;
525 static const unsigned short MOD_INSTALL
= 2;
527 bool DoCacheManipulationFromCommandLine(CommandLine
&CmdL
, CacheFile
&Cache
)
529 std::map
<unsigned short, APT::VersionSet
> verset
;
530 return DoCacheManipulationFromCommandLine(CmdL
, Cache
, verset
);
532 bool DoCacheManipulationFromCommandLine(CommandLine
&CmdL
, CacheFile
&Cache
,
533 std::map
<unsigned short, APT::VersionSet
> &verset
)
536 // Enter the special broken fixing mode if the user specified arguments
537 bool BrokenFix
= false;
538 if (Cache
->BrokenCount() != 0)
541 SPtr
<pkgProblemResolver
> Fix
;
542 if (_config
->FindB("APT::Get::CallResolver", true) == true)
543 Fix
= new pkgProblemResolver(Cache
);
545 unsigned short fallback
= MOD_INSTALL
;
546 if (strcasecmp(CmdL
.FileList
[0],"remove") == 0)
547 fallback
= MOD_REMOVE
;
548 else if (strcasecmp(CmdL
.FileList
[0], "purge") == 0)
550 _config
->Set("APT::Get::Purge", true);
551 fallback
= MOD_REMOVE
;
553 else if (strcasecmp(CmdL
.FileList
[0], "autoremove") == 0)
555 _config
->Set("APT::Get::AutomaticRemove", "true");
556 fallback
= MOD_REMOVE
;
559 std::list
<APT::VersionSet::Modifier
> mods
;
560 mods
.push_back(APT::VersionSet::Modifier(MOD_INSTALL
, "+",
561 APT::VersionSet::Modifier::POSTFIX
, APT::VersionSet::CANDIDATE
));
562 mods
.push_back(APT::VersionSet::Modifier(MOD_REMOVE
, "-",
563 APT::VersionSet::Modifier::POSTFIX
, APT::VersionSet::NEWEST
));
564 CacheSetHelperAPTGet
helper(c0out
);
565 verset
= APT::VersionSet::GroupedFromCommandLine(Cache
,
566 CmdL
.FileList
+ 1, mods
, fallback
, helper
);
568 if (_error
->PendingError() == true)
570 helper
.showVirtualPackageErrors(Cache
);
575 TryToInstall
InstallAction(Cache
, Fix
, BrokenFix
);
576 TryToRemove
RemoveAction(Cache
, Fix
);
578 // new scope for the ActionGroup
580 pkgDepCache::ActionGroup
group(Cache
);
581 unsigned short const order
[] = { MOD_REMOVE
, MOD_INSTALL
, 0 };
583 for (unsigned short i
= 0; order
[i
] != 0; ++i
)
585 if (order
[i
] == MOD_INSTALL
)
586 InstallAction
= std::for_each(verset
[MOD_INSTALL
].begin(), verset
[MOD_INSTALL
].end(), InstallAction
);
587 else if (order
[i
] == MOD_REMOVE
)
588 RemoveAction
= std::for_each(verset
[MOD_REMOVE
].begin(), verset
[MOD_REMOVE
].end(), RemoveAction
);
591 if (Fix
!= NULL
&& _config
->FindB("APT::Get::AutoSolving", true) == true)
593 for (unsigned short i
= 0; order
[i
] != 0; ++i
)
595 if (order
[i
] != MOD_INSTALL
)
597 InstallAction
.propergateReleaseCandiateSwitching(helper
.selectedByRelease
, c0out
);
598 InstallAction
.doAutoInstall();
602 if (_error
->PendingError() == true)
607 /* If we are in the Broken fixing mode we do not attempt to fix the
608 problems. This is if the user invoked install without -f and gave
610 if (BrokenFix
== true && Cache
->BrokenCount() != 0)
612 c1out
<< _("You might want to run 'apt-get -f install' to correct these:") << std::endl
;
613 ShowBroken(c1out
,Cache
,false);
614 return _error
->Error(_("Unmet dependencies. Try 'apt-get -f install' with no packages (or specify a solution)."));
619 // Call the scored problem resolver
623 // Now we check the state of the packages,
624 if (Cache
->BrokenCount() != 0)
627 _("Some packages could not be installed. This may mean that you have\n"
628 "requested an impossible situation or if you are using the unstable\n"
629 "distribution that some required packages have not yet been created\n"
630 "or been moved out of Incoming.") << std::endl
;
636 _("Since you only requested a single operation it is extremely likely that\n"
637 "the package is simply not installable and a bug report against\n"
638 "that package should be filed.") << std::endl;
642 c1out
<< _("The following information may help to resolve the situation:") << std::endl
;
644 ShowBroken(c1out
,Cache
,false);
645 if (_error
->PendingError() == true)
648 return _error
->Error(_("Broken packages"));
651 if (!DoAutomaticRemove(Cache
))
654 // if nothing changed in the cache, but only the automark information
655 // we write the StateFile here, otherwise it will be written in
657 if (InstallAction
.AutoMarkChanged
> 0 &&
658 Cache
->DelCount() == 0 && Cache
->InstCount() == 0 &&
659 Cache
->BadCount() == 0 &&
660 _config
->FindB("APT::Get::Simulate",false) == false)
661 Cache
->writeStateFile(NULL
);
666 // DoInstall - Install packages from the command line /*{{{*/
667 // ---------------------------------------------------------------------
668 /* Install named packages */
669 bool DoInstall(CommandLine
&CmdL
)
672 if (Cache
.OpenForInstall() == false ||
673 Cache
.CheckDeps(CmdL
.FileSize() != 1) == false)
676 std::map
<unsigned short, APT::VersionSet
> verset
;
678 if(!DoCacheManipulationFromCommandLine(CmdL
, Cache
, verset
))
681 /* Print out a list of packages that are going to be installed extra
682 to what the user asked */
683 if (Cache
->InstCount() != verset
[MOD_INSTALL
].size())
686 std::string VersionsList
;
687 for (unsigned J
= 0; J
< Cache
->Head().PackageCount
; J
++)
689 pkgCache::PkgIterator
I(Cache
,Cache
.List
[J
]);
690 if ((*Cache
)[I
].Install() == false)
692 pkgCache::VerIterator Cand
= Cache
[I
].CandidateVerIter(Cache
);
694 if (verset
[MOD_INSTALL
].find(Cand
) != verset
[MOD_INSTALL
].end())
697 List
+= I
.FullName(true) + " ";
698 VersionsList
+= std::string(Cache
[I
].CandVersion
) + "\n";
701 ShowList(c1out
,_("The following extra packages will be installed:"),List
,VersionsList
);
704 /* Print out a list of suggested and recommended packages */
706 std::string SuggestsList
, RecommendsList
;
707 std::string SuggestsVersions
, RecommendsVersions
;
708 for (unsigned J
= 0; J
< Cache
->Head().PackageCount
; J
++)
710 pkgCache::PkgIterator
Pkg(Cache
,Cache
.List
[J
]);
712 /* Just look at the ones we want to install */
713 if ((*Cache
)[Pkg
].Install() == false)
716 // get the recommends/suggests for the candidate ver
717 pkgCache::VerIterator CV
= (*Cache
)[Pkg
].CandidateVerIter(*Cache
);
718 for (pkgCache::DepIterator D
= CV
.DependsList(); D
.end() == false; )
720 pkgCache::DepIterator Start
;
721 pkgCache::DepIterator End
;
722 D
.GlobOr(Start
,End
); // advances D
724 // FIXME: we really should display a or-group as a or-group to the user
725 // the problem is that ShowList is incapable of doing this
726 std::string RecommendsOrList
,RecommendsOrVersions
;
727 std::string SuggestsOrList
,SuggestsOrVersions
;
728 bool foundInstalledInOrGroup
= false;
731 /* Skip if package is installed already, or is about to be */
732 std::string target
= Start
.TargetPkg().FullName(true) + " ";
733 pkgCache::PkgIterator
const TarPkg
= Start
.TargetPkg();
734 if (TarPkg
->SelectedState
== pkgCache::State::Install
||
735 TarPkg
->SelectedState
== pkgCache::State::Hold
||
736 Cache
[Start
.TargetPkg()].Install())
738 foundInstalledInOrGroup
=true;
742 /* Skip if we already saw it */
743 if (int(SuggestsList
.find(target
)) != -1 || int(RecommendsList
.find(target
)) != -1)
745 foundInstalledInOrGroup
=true;
749 // this is a dep on a virtual pkg, check if any package that provides it
750 // should be installed
751 if(Start
.TargetPkg().ProvidesList() != 0)
753 pkgCache::PrvIterator I
= Start
.TargetPkg().ProvidesList();
754 for (; I
.end() == false; ++I
)
756 pkgCache::PkgIterator Pkg
= I
.OwnerPkg();
757 if (Cache
[Pkg
].CandidateVerIter(Cache
) == I
.OwnerVer() &&
758 Pkg
.CurrentVer() != 0)
759 foundInstalledInOrGroup
=true;
763 if (Start
->Type
== pkgCache::Dep::Suggests
)
765 SuggestsOrList
+= target
;
766 SuggestsOrVersions
+= std::string(Cache
[Start
.TargetPkg()].CandVersion
) + "\n";
769 if (Start
->Type
== pkgCache::Dep::Recommends
)
771 RecommendsOrList
+= target
;
772 RecommendsOrVersions
+= std::string(Cache
[Start
.TargetPkg()].CandVersion
) + "\n";
780 if(foundInstalledInOrGroup
== false)
782 RecommendsList
+= RecommendsOrList
;
783 RecommendsVersions
+= RecommendsOrVersions
;
784 SuggestsList
+= SuggestsOrList
;
785 SuggestsVersions
+= SuggestsOrVersions
;
791 ShowList(c1out
,_("Suggested packages:"),SuggestsList
,SuggestsVersions
);
792 ShowList(c1out
,_("Recommended packages:"),RecommendsList
,RecommendsVersions
);
796 // See if we need to prompt
797 // FIXME: check if really the packages in the set are going to be installed
798 if (Cache
->InstCount() == verset
[MOD_INSTALL
].size() && Cache
->DelCount() == 0)
799 return InstallPackages(Cache
,false,false);
801 return InstallPackages(Cache
,false);