1 // Include Files /*{{{*/
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/iprogress.h>
33 #include <sys/ioctl.h>
35 #include <sys/statfs.h>
36 #include <sys/statvfs.h>
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"
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
)
61 if (_config
->FindB("APT::Get::Purge",false) == true)
63 pkgCache::PkgIterator I
= Cache
->PkgBegin();
64 for (; I
.end() == false; ++I
)
66 if (I
.Purge() == false && Cache
[I
].Mode
== pkgDepCache::ModeDelete
)
67 Cache
->MarkDelete(I
,true);
72 bool Essential
= false;
74 // Show all the various warning indicators
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
);
89 if (Cache
->BrokenCount() != 0)
91 ShowBroken(c1out
,Cache
,false);
92 return _error
->Error(_("Internal error, InstallPackages was called with broken packages!"));
95 if (Cache
->DelCount() == 0 && Cache
->InstCount() == 0 &&
96 Cache
->BadCount() == 0)
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."));
103 // Run the simulator ..
104 if (_config
->FindB("APT::Get::Simulate") == true)
106 pkgSimulate
PM(Cache
);
108 int status_fd
= _config
->FindI("APT::Status-Fd",-1);
109 APT::Progress::PackageManager
*progress
= NULL
;
111 progress
= new APT::Progress::PackageManagerProgressFd(status_fd
);
112 pkgPackageManager::OrderResult Res
= PM
.DoInstall(progress
);
115 if (Res
== pkgPackageManager::Failed
)
117 if (Res
!= pkgPackageManager::Completed
)
118 return _error
->Error(_("Internal error, Ordering didn't finish"));
122 // Create the text record parser
123 pkgRecords
Recs(Cache
);
124 if (_error
->PendingError() == true)
127 // Create the download object
129 AcqTextStatus
Stat(ScreenWidth
,_config
->FindI("quiet",0));
130 if (_config
->FindB("APT::Get::Print-URIs", false) == true)
132 // force a hashsum for compatibility reasons
133 _config
->CndSet("Acquire::ForceHash", "md5sum");
135 else if (Fetcher
.Setup(&Stat
, _config
->FindDir("Dir::Cache::Archives")) == false)
138 // Read the source list
139 if (Cache
.BuildSourceList() == false)
141 pkgSourceList
*List
= Cache
.GetSourceList();
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)
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())
155 c0out
<< DebBytes
<< ',' << Cache
->DebSize() << std::endl
;
156 c0out
<< _("How odd.. The sizes didn't match, email apt@packages.debian.org") << std::endl
;
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());
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());
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());
183 if (_error
->PendingError() == true)
186 /* Check for enough free space, but only if we are actually going to
188 if (_config
->FindB("APT::Get::Print-URIs") == false &&
189 _config
->FindB("APT::Get::Download",true) == true)
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"),
198 return _error
->Errno("statvfs",_("Couldn't determine free space in %s"),
200 } else if (unsigned(Buf
.f_bfree
) < (FetchBytes
- FetchPBytes
)/Buf
.f_bsize
)
203 if (statfs(OutputDir
.c_str(),&Stat
) != 0
204 #if HAVE_STRUCT_STATFS_F_TYPE
205 || unsigned(Stat
.f_type
) != RAMFS_MAGIC
208 return _error
->Error(_("You don't have enough free space in %s."),
214 if (_config
->FindI("quiet",0) >= 2 ||
215 _config
->FindB("APT::Get::Assume-Yes",false) == true)
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"));
221 if (Essential
== true && Safety
== true)
223 if (_config
->FindB("APT::Get::Trivial-Only",false) == true)
224 return _error
->Error(_("Trivial Only specified but this is not a trivial operation."));
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!");
230 _("You are about to do something potentially harmful.\n"
231 "To continue type in the phrase '%s'\n"
234 if (AnalPrompt(Prompt
) == false)
236 c2out
<< _("Abort.") << std::endl
;
242 // Prompt to continue
243 if (Ask
== true || Fail
== true)
245 if (_config
->FindB("APT::Get::Trivial-Only",false) == true)
246 return _error
->Error(_("Trivial Only specified but this is not a trivial operation."));
248 if (_config
->FindI("quiet",0) < 2 &&
249 _config
->FindB("APT::Get::Assume-Yes",false) == false)
251 c2out
<< _("Do you want to continue?") << std::flush
;
252 if (YnPrompt() == false)
254 c2out
<< _("Abort.") << std::endl
;
261 // Just print out the uris an exit if the --print-uris flag was used
262 if (_config
->FindB("APT::Get::Print-URIs") == true)
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
;
271 if (!CheckAuth(Fetcher
, true))
274 /* Unlock the dpkg lock if we are not going to be doing an install
276 if (_config
->FindB("APT::Get::Download-Only",false) == true)
282 bool Transient
= false;
283 if (_config
->FindB("APT::Get::Download",true) == false)
285 for (pkgAcquire::ItemIterator I
= Fetcher
.ItemsBegin(); I
< Fetcher
.ItemsEnd();)
287 if ((*I
)->Local
== true)
293 // Close the item and check if it was found in cache
295 if ((*I
)->Complete
== false)
298 // Clear it out of the fetch list
300 I
= Fetcher
.ItemsBegin();
305 if (AcquireRun(Fetcher
, 0, &Failed
, &Transient
) == false)
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)
318 if (_config
->FindB("APT::Get::Download-Only",false) == true)
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
;
326 if (Failed
== true && _config
->FindB("APT::Get::Fix-Missing",false) == false)
328 return _error
->Error(_("Unable to fetch some archives, maybe run apt-get update or try with --fix-missing?"));
331 if (Transient
== true && Failed
== true)
332 return _error
->Error(_("--fix-missing and media swapping is not currently supported"));
334 // Try to deal with missing package files
335 if (Failed
== true && PM
->FixMissing() == false)
337 c2out
<< _("Unable to correct missing packages.") << std::endl
;
338 return _error
->Error(_("Aborting install."));
343 // FIXME: make this a factory
344 // select the right progress
345 int status_fd
= _config
->FindI("APT::Status-Fd",-1);
347 APT::Progress::PackageManager
*progress
= NULL
;
349 progress
= new APT::Progress::PackageManagerProgressFd(status_fd
);
350 else if(_config
->FindB("Dpkg::Progress-Fancy", false) == true)
351 progress
= new APT::Progress::PackageManagerFancy();
352 else if (_config
->FindB("Dpkg::Progress",
353 _config
->FindB("DpkgPM::Progress", false)) == true)
354 progress
= new APT::Progress::PackageManagerText();
356 progress
= new APT::Progress::PackageManager();
357 pkgPackageManager::OrderResult Res
= PM
->DoInstall(progress
);
360 if (Res
== pkgPackageManager::Failed
|| _error
->PendingError() == true)
362 if (Res
== pkgPackageManager::Completed
)
365 // Reload the fetcher object and loop again for media swapping
367 if (PM
->GetArchives(&Fetcher
,List
,&Recs
) == false)
373 std::set
<std::string
> const disappearedPkgs
= PM
->GetDisappearedPackages();
374 if (disappearedPkgs
.empty() == true)
377 std::string disappear
;
378 for (std::set
<std::string
>::const_iterator d
= disappearedPkgs
.begin();
379 d
!= disappearedPkgs
.end(); ++d
)
380 disappear
.append(*d
).append(" ");
382 ShowList(c1out
, P_("The following package disappeared from your system as\n"
383 "all files have been overwritten by other packages:",
384 "The following packages disappeared from your system as\n"
385 "all files have been overwritten by other packages:", disappearedPkgs
.size()), disappear
, "");
386 c0out
<< _("Note: This is done automatically and on purpose by dpkg.") << std::endl
;
391 // DoAutomaticRemove - Remove all automatic unused packages /*{{{*/
392 // ---------------------------------------------------------------------
393 /* Remove unused automatic packages */
394 bool DoAutomaticRemove(CacheFile
&Cache
)
396 bool Debug
= _config
->FindI("Debug::pkgAutoRemove",false);
397 bool doAutoRemove
= _config
->FindB("APT::Get::AutomaticRemove", false);
398 bool hideAutoRemove
= _config
->FindB("APT::Get::HideAutoRemove");
400 pkgDepCache::ActionGroup
group(*Cache
);
402 std::cout
<< "DoAutomaticRemove()" << std::endl
;
404 if (doAutoRemove
== true &&
405 _config
->FindB("APT::Get::Remove",true) == false)
407 c1out
<< _("We are not supposed to delete stuff, can't start "
408 "AutoRemover") << std::endl
;
412 bool purgePkgs
= _config
->FindB("APT::Get::Purge", false);
413 bool smallList
= (hideAutoRemove
== false &&
414 strcasecmp(_config
->Find("APT::Get::HideAutoRemove","").c_str(),"small") == 0);
416 unsigned long autoRemoveCount
= 0;
417 APT::PackageSet tooMuch
;
418 APT::PackageList autoRemoveList
;
419 // look over the cache to see what can be removed
420 for (unsigned J
= 0; J
< Cache
->Head().PackageCount
; ++J
)
422 pkgCache::PkgIterator
Pkg(Cache
,Cache
.List
[J
]);
423 if (Cache
[Pkg
].Garbage
)
425 if(Pkg
.CurrentVer() != 0 || Cache
[Pkg
].Install())
427 std::cout
<< "We could delete %s" << Pkg
.FullName(true).c_str() << std::endl
;
431 if(Pkg
.CurrentVer() != 0 &&
432 Pkg
->CurrentState
!= pkgCache::State::ConfigFiles
)
433 Cache
->MarkDelete(Pkg
, purgePkgs
, 0, false);
435 Cache
->MarkKeep(Pkg
, false, false);
439 if (hideAutoRemove
== false && Cache
[Pkg
].Delete() == false)
440 autoRemoveList
.insert(Pkg
);
441 // if the package is a new install and already garbage we don't need to
442 // install it in the first place, so nuke it instead of show it
443 if (Cache
[Pkg
].Install() == true && Pkg
.CurrentVer() == 0)
445 if (Pkg
.CandVersion() != 0)
447 Cache
->MarkDelete(Pkg
, false, 0, false);
449 // only show stuff in the list that is not yet marked for removal
450 else if(hideAutoRemove
== false && Cache
[Pkg
].Delete() == false)
456 // we could have removed a new dependency of a garbage package,
457 // so check if a reverse depends is broken and if so install it again.
458 if (tooMuch
.empty() == false && (Cache
->BrokenCount() != 0 || Cache
->PolicyBrokenCount() != 0))
463 for (APT::PackageSet::const_iterator Pkg
= tooMuch
.begin();
464 Pkg
!= tooMuch
.end(); ++Pkg
)
468 for (pkgCache::PrvIterator Prv
= Cache
[Pkg
].CandidateVerIter(Cache
).ProvidesList();
469 Prv
.end() == false; ++Prv
)
470 too
.insert(Prv
.ParentPkg());
471 for (APT::PackageSet::const_iterator P
= too
.begin(); P
!= too
.end(); ++P
)
473 for (pkgCache::DepIterator R
= P
.RevDependsList();
474 R
.end() == false; ++R
)
476 if (R
.IsNegative() == true ||
477 Cache
->IsImportantDep(R
) == false)
479 pkgCache::PkgIterator N
= R
.ParentPkg();
480 if (N
.end() == true || (N
->CurrentVer
== 0 && (*Cache
)[N
].Install() == false))
483 std::clog
<< "Save " << Pkg
<< " as another installed garbage package depends on it" << std::endl
;
484 Cache
->MarkInstall(Pkg
, false, 0, false);
485 if (hideAutoRemove
== false)
497 } while (Changed
== true);
500 std::string autoremovelist
, autoremoveversions
;
501 if (smallList
== false && autoRemoveCount
!= 0)
503 for (APT::PackageList::const_iterator Pkg
= autoRemoveList
.begin(); Pkg
!= autoRemoveList
.end(); ++Pkg
)
505 if (Cache
[Pkg
].Garbage
== false)
507 autoremovelist
+= Pkg
.FullName(true) + " ";
508 autoremoveversions
+= std::string(Cache
[Pkg
].CandVersion
) + "\n";
512 // Now see if we had destroyed anything (if we had done anything)
513 if (Cache
->BrokenCount() != 0)
515 c1out
<< _("Hmm, seems like the AutoRemover destroyed something which really\n"
516 "shouldn't happen. Please file a bug report against apt.") << std::endl
;
518 c1out
<< _("The following information may help to resolve the situation:") << std::endl
;
520 ShowBroken(c1out
,Cache
,false);
522 return _error
->Error(_("Internal Error, AutoRemover broke stuff"));
525 // if we don't remove them, we should show them!
526 if (doAutoRemove
== false && (autoremovelist
.empty() == false || autoRemoveCount
!= 0))
528 if (smallList
== false)
529 ShowList(c1out
, P_("The following package was automatically installed and is no longer required:",
530 "The following packages were automatically installed and are no longer required:",
531 autoRemoveCount
), autoremovelist
, autoremoveversions
);
533 ioprintf(c1out
, P_("%lu package was automatically installed and is no longer required.\n",
534 "%lu packages were automatically installed and are no longer required.\n", autoRemoveCount
), autoRemoveCount
);
535 c1out
<< P_("Use 'apt-get autoremove' to remove it.", "Use 'apt-get autoremove' to remove them.", autoRemoveCount
) << std::endl
;
540 // DoCacheManipulationFromCommandLine /*{{{*/
541 static const unsigned short MOD_REMOVE
= 1;
542 static const unsigned short MOD_INSTALL
= 2;
544 bool DoCacheManipulationFromCommandLine(CommandLine
&CmdL
, CacheFile
&Cache
)
546 std::map
<unsigned short, APT::VersionSet
> verset
;
547 return DoCacheManipulationFromCommandLine(CmdL
, Cache
, verset
);
549 bool DoCacheManipulationFromCommandLine(CommandLine
&CmdL
, CacheFile
&Cache
,
550 std::map
<unsigned short, APT::VersionSet
> &verset
)
553 // Enter the special broken fixing mode if the user specified arguments
554 bool BrokenFix
= false;
555 if (Cache
->BrokenCount() != 0)
558 SPtr
<pkgProblemResolver
> Fix
;
559 if (_config
->FindB("APT::Get::CallResolver", true) == true)
560 Fix
= new pkgProblemResolver(Cache
);
562 unsigned short fallback
= MOD_INSTALL
;
563 if (strcasecmp(CmdL
.FileList
[0],"remove") == 0)
564 fallback
= MOD_REMOVE
;
565 else if (strcasecmp(CmdL
.FileList
[0], "purge") == 0)
567 _config
->Set("APT::Get::Purge", true);
568 fallback
= MOD_REMOVE
;
570 else if (strcasecmp(CmdL
.FileList
[0], "autoremove") == 0)
572 _config
->Set("APT::Get::AutomaticRemove", "true");
573 fallback
= MOD_REMOVE
;
576 std::list
<APT::VersionSet::Modifier
> mods
;
577 mods
.push_back(APT::VersionSet::Modifier(MOD_INSTALL
, "+",
578 APT::VersionSet::Modifier::POSTFIX
, APT::VersionSet::CANDIDATE
));
579 mods
.push_back(APT::VersionSet::Modifier(MOD_REMOVE
, "-",
580 APT::VersionSet::Modifier::POSTFIX
, APT::VersionSet::NEWEST
));
581 CacheSetHelperAPTGet
helper(c0out
);
582 verset
= APT::VersionSet::GroupedFromCommandLine(Cache
,
583 CmdL
.FileList
+ 1, mods
, fallback
, helper
);
585 if (_error
->PendingError() == true)
587 helper
.showVirtualPackageErrors(Cache
);
592 TryToInstall
InstallAction(Cache
, Fix
, BrokenFix
);
593 TryToRemove
RemoveAction(Cache
, Fix
);
595 // new scope for the ActionGroup
597 pkgDepCache::ActionGroup
group(Cache
);
598 unsigned short const order
[] = { MOD_REMOVE
, MOD_INSTALL
, 0 };
600 for (unsigned short i
= 0; order
[i
] != 0; ++i
)
602 if (order
[i
] == MOD_INSTALL
)
603 InstallAction
= std::for_each(verset
[MOD_INSTALL
].begin(), verset
[MOD_INSTALL
].end(), InstallAction
);
604 else if (order
[i
] == MOD_REMOVE
)
605 RemoveAction
= std::for_each(verset
[MOD_REMOVE
].begin(), verset
[MOD_REMOVE
].end(), RemoveAction
);
608 if (Fix
!= NULL
&& _config
->FindB("APT::Get::AutoSolving", true) == true)
610 for (unsigned short i
= 0; order
[i
] != 0; ++i
)
612 if (order
[i
] != MOD_INSTALL
)
614 InstallAction
.propergateReleaseCandiateSwitching(helper
.selectedByRelease
, c0out
);
615 InstallAction
.doAutoInstall();
619 if (_error
->PendingError() == true)
624 /* If we are in the Broken fixing mode we do not attempt to fix the
625 problems. This is if the user invoked install without -f and gave
627 if (BrokenFix
== true && Cache
->BrokenCount() != 0)
629 c1out
<< _("You might want to run 'apt-get -f install' to correct these:") << std::endl
;
630 ShowBroken(c1out
,Cache
,false);
631 return _error
->Error(_("Unmet dependencies. Try 'apt-get -f install' with no packages (or specify a solution)."));
636 // Call the scored problem resolver
640 // Now we check the state of the packages,
641 if (Cache
->BrokenCount() != 0)
644 _("Some packages could not be installed. This may mean that you have\n"
645 "requested an impossible situation or if you are using the unstable\n"
646 "distribution that some required packages have not yet been created\n"
647 "or been moved out of Incoming.") << std::endl
;
653 _("Since you only requested a single operation it is extremely likely that\n"
654 "the package is simply not installable and a bug report against\n"
655 "that package should be filed.") << std::endl;
659 c1out
<< _("The following information may help to resolve the situation:") << std::endl
;
661 ShowBroken(c1out
,Cache
,false);
662 if (_error
->PendingError() == true)
665 return _error
->Error(_("Broken packages"));
668 if (!DoAutomaticRemove(Cache
))
671 // if nothing changed in the cache, but only the automark information
672 // we write the StateFile here, otherwise it will be written in
674 if (InstallAction
.AutoMarkChanged
> 0 &&
675 Cache
->DelCount() == 0 && Cache
->InstCount() == 0 &&
676 Cache
->BadCount() == 0 &&
677 _config
->FindB("APT::Get::Simulate",false) == false)
678 Cache
->writeStateFile(NULL
);
683 // DoInstall - Install packages from the command line /*{{{*/
684 // ---------------------------------------------------------------------
685 /* Install named packages */
686 bool DoInstall(CommandLine
&CmdL
)
689 if (Cache
.OpenForInstall() == false ||
690 Cache
.CheckDeps(CmdL
.FileSize() != 1) == false)
693 std::map
<unsigned short, APT::VersionSet
> verset
;
695 if(!DoCacheManipulationFromCommandLine(CmdL
, Cache
, verset
))
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())
703 std::string VersionsList
;
704 for (unsigned J
= 0; J
< Cache
->Head().PackageCount
; J
++)
706 pkgCache::PkgIterator
I(Cache
,Cache
.List
[J
]);
707 if ((*Cache
)[I
].Install() == false)
709 pkgCache::VerIterator Cand
= Cache
[I
].CandidateVerIter(Cache
);
711 if (verset
[MOD_INSTALL
].find(Cand
) != verset
[MOD_INSTALL
].end())
714 List
+= I
.FullName(true) + " ";
715 VersionsList
+= std::string(Cache
[I
].CandVersion
) + "\n";
718 ShowList(c1out
,_("The following extra packages will be installed:"),List
,VersionsList
);
721 /* Print out a list of suggested and recommended packages */
723 std::string SuggestsList
, RecommendsList
;
724 std::string SuggestsVersions
, RecommendsVersions
;
725 for (unsigned J
= 0; J
< Cache
->Head().PackageCount
; J
++)
727 pkgCache::PkgIterator
Pkg(Cache
,Cache
.List
[J
]);
729 /* Just look at the ones we want to install */
730 if ((*Cache
)[Pkg
].Install() == false)
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; )
737 pkgCache::DepIterator Start
;
738 pkgCache::DepIterator End
;
739 D
.GlobOr(Start
,End
); // advances D
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;
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())
755 foundInstalledInOrGroup
=true;
759 /* Skip if we already saw it */
760 if (int(SuggestsList
.find(target
)) != -1 || int(RecommendsList
.find(target
)) != -1)
762 foundInstalledInOrGroup
=true;
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)
770 pkgCache::PrvIterator I
= Start
.TargetPkg().ProvidesList();
771 for (; I
.end() == false; ++I
)
773 pkgCache::PkgIterator Pkg
= I
.OwnerPkg();
774 if (Cache
[Pkg
].CandidateVerIter(Cache
) == I
.OwnerVer() &&
775 Pkg
.CurrentVer() != 0)
776 foundInstalledInOrGroup
=true;
780 if (Start
->Type
== pkgCache::Dep::Suggests
)
782 SuggestsOrList
+= target
;
783 SuggestsOrVersions
+= std::string(Cache
[Start
.TargetPkg()].CandVersion
) + "\n";
786 if (Start
->Type
== pkgCache::Dep::Recommends
)
788 RecommendsOrList
+= target
;
789 RecommendsOrVersions
+= std::string(Cache
[Start
.TargetPkg()].CandVersion
) + "\n";
797 if(foundInstalledInOrGroup
== false)
799 RecommendsList
+= RecommendsOrList
;
800 RecommendsVersions
+= RecommendsOrVersions
;
801 SuggestsList
+= SuggestsOrList
;
802 SuggestsVersions
+= SuggestsOrVersions
;
808 ShowList(c1out
,_("Suggested packages:"),SuggestsList
,SuggestsVersions
);
809 ShowList(c1out
,_("Recommended packages:"),RecommendsList
,RecommendsVersions
);
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);
818 return InstallPackages(Cache
,false);