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/install-progress.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);
346 int status_deb822_fd
= _config
->FindI("APT::Status-deb822-Fd", -1);
348 APT::Progress::PackageManager
*progress
= NULL
;
349 if (status_deb822_fd
> 0)
350 progress
= new APT::Progress::PackageManagerProgressDeb822Fd(
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();
360 progress
= new APT::Progress::PackageManager();
361 pkgPackageManager::OrderResult Res
= PM
->DoInstall(progress
);
364 if (Res
== pkgPackageManager::Failed
|| _error
->PendingError() == true)
366 if (Res
== pkgPackageManager::Completed
)
369 // Reload the fetcher object and loop again for media swapping
371 if (PM
->GetArchives(&Fetcher
,List
,&Recs
) == false)
377 std::set
<std::string
> const disappearedPkgs
= PM
->GetDisappearedPackages();
378 if (disappearedPkgs
.empty() == true)
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(" ");
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
;
395 // DoAutomaticRemove - Remove all automatic unused packages /*{{{*/
396 // ---------------------------------------------------------------------
397 /* Remove unused automatic packages */
398 bool DoAutomaticRemove(CacheFile
&Cache
)
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");
404 pkgDepCache::ActionGroup
group(*Cache
);
406 std::cout
<< "DoAutomaticRemove()" << std::endl
;
408 if (doAutoRemove
== true &&
409 _config
->FindB("APT::Get::Remove",true) == false)
411 c1out
<< _("We are not supposed to delete stuff, can't start "
412 "AutoRemover") << std::endl
;
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);
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
)
426 pkgCache::PkgIterator
Pkg(Cache
,Cache
.List
[J
]);
427 if (Cache
[Pkg
].Garbage
)
429 if(Pkg
.CurrentVer() != 0 || Cache
[Pkg
].Install())
431 std::cout
<< "We could delete %s" << Pkg
.FullName(true).c_str() << std::endl
;
435 if(Pkg
.CurrentVer() != 0 &&
436 Pkg
->CurrentState
!= pkgCache::State::ConfigFiles
)
437 Cache
->MarkDelete(Pkg
, purgePkgs
, 0, false);
439 Cache
->MarkKeep(Pkg
, false, false);
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)
449 if (Pkg
.CandVersion() != 0)
451 Cache
->MarkDelete(Pkg
, false, 0, false);
453 // only show stuff in the list that is not yet marked for removal
454 else if(hideAutoRemove
== false && Cache
[Pkg
].Delete() == false)
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))
467 for (APT::PackageSet::const_iterator Pkg
= tooMuch
.begin();
468 Pkg
!= tooMuch
.end(); ++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
)
477 for (pkgCache::DepIterator R
= P
.RevDependsList();
478 R
.end() == false; ++R
)
480 if (R
.IsNegative() == true ||
481 Cache
->IsImportantDep(R
) == false)
483 pkgCache::PkgIterator N
= R
.ParentPkg();
484 if (N
.end() == true || (N
->CurrentVer
== 0 && (*Cache
)[N
].Install() == false))
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)
501 } while (Changed
== true);
504 std::string autoremovelist
, autoremoveversions
;
505 if (smallList
== false && autoRemoveCount
!= 0)
507 for (APT::PackageList::const_iterator Pkg
= autoRemoveList
.begin(); Pkg
!= autoRemoveList
.end(); ++Pkg
)
509 if (Cache
[Pkg
].Garbage
== false)
511 autoremovelist
+= Pkg
.FullName(true) + " ";
512 autoremoveversions
+= std::string(Cache
[Pkg
].CandVersion
) + "\n";
516 // Now see if we had destroyed anything (if we had done anything)
517 if (Cache
->BrokenCount() != 0)
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
;
522 c1out
<< _("The following information may help to resolve the situation:") << std::endl
;
524 ShowBroken(c1out
,Cache
,false);
526 return _error
->Error(_("Internal Error, AutoRemover broke stuff"));
529 // if we don't remove them, we should show them!
530 if (doAutoRemove
== false && (autoremovelist
.empty() == false || autoRemoveCount
!= 0))
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
);
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
;
544 // DoCacheManipulationFromCommandLine /*{{{*/
545 static const unsigned short MOD_REMOVE
= 1;
546 static const unsigned short MOD_INSTALL
= 2;
548 bool DoCacheManipulationFromCommandLine(CommandLine
&CmdL
, CacheFile
&Cache
)
550 std::map
<unsigned short, APT::VersionSet
> verset
;
551 return DoCacheManipulationFromCommandLine(CmdL
, Cache
, verset
);
553 bool DoCacheManipulationFromCommandLine(CommandLine
&CmdL
, CacheFile
&Cache
,
554 std::map
<unsigned short, APT::VersionSet
> &verset
)
557 // Enter the special broken fixing mode if the user specified arguments
558 bool BrokenFix
= false;
559 if (Cache
->BrokenCount() != 0)
562 SPtr
<pkgProblemResolver
> Fix
;
563 if (_config
->FindB("APT::Get::CallResolver", true) == true)
564 Fix
= new pkgProblemResolver(Cache
);
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)
571 _config
->Set("APT::Get::Purge", true);
572 fallback
= MOD_REMOVE
;
574 else if (strcasecmp(CmdL
.FileList
[0], "autoremove") == 0)
576 _config
->Set("APT::Get::AutomaticRemove", "true");
577 fallback
= MOD_REMOVE
;
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
);
589 if (_error
->PendingError() == true)
591 helper
.showVirtualPackageErrors(Cache
);
596 TryToInstall
InstallAction(Cache
, Fix
, BrokenFix
);
597 TryToRemove
RemoveAction(Cache
, Fix
);
599 // new scope for the ActionGroup
601 pkgDepCache::ActionGroup
group(Cache
);
602 unsigned short const order
[] = { MOD_REMOVE
, MOD_INSTALL
, 0 };
604 for (unsigned short i
= 0; order
[i
] != 0; ++i
)
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
);
612 if (Fix
!= NULL
&& _config
->FindB("APT::Get::AutoSolving", true) == true)
614 for (unsigned short i
= 0; order
[i
] != 0; ++i
)
616 if (order
[i
] != MOD_INSTALL
)
618 InstallAction
.propergateReleaseCandiateSwitching(helper
.selectedByRelease
, c0out
);
619 InstallAction
.doAutoInstall();
623 if (_error
->PendingError() == true)
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
631 if (BrokenFix
== true && Cache
->BrokenCount() != 0)
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)."));
640 // Call the scored problem resolver
644 // Now we check the state of the packages,
645 if (Cache
->BrokenCount() != 0)
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
;
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;
663 c1out
<< _("The following information may help to resolve the situation:") << std::endl
;
665 ShowBroken(c1out
,Cache
,false);
666 if (_error
->PendingError() == true)
669 return _error
->Error(_("Broken packages"));
672 if (!DoAutomaticRemove(Cache
))
675 // if nothing changed in the cache, but only the automark information
676 // we write the StateFile here, otherwise it will be written in
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
);
687 // DoInstall - Install packages from the command line /*{{{*/
688 // ---------------------------------------------------------------------
689 /* Install named packages */
690 bool DoInstall(CommandLine
&CmdL
)
693 if (Cache
.OpenForInstall() == false ||
694 Cache
.CheckDeps(CmdL
.FileSize() != 1) == false)
697 std::map
<unsigned short, APT::VersionSet
> verset
;
699 if(!DoCacheManipulationFromCommandLine(CmdL
, Cache
, verset
))
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())
707 std::string VersionsList
;
708 for (unsigned J
= 0; J
< Cache
->Head().PackageCount
; J
++)
710 pkgCache::PkgIterator
I(Cache
,Cache
.List
[J
]);
711 if ((*Cache
)[I
].Install() == false)
713 pkgCache::VerIterator Cand
= Cache
[I
].CandidateVerIter(Cache
);
715 if (verset
[MOD_INSTALL
].find(Cand
) != verset
[MOD_INSTALL
].end())
718 List
+= I
.FullName(true) + " ";
719 VersionsList
+= std::string(Cache
[I
].CandVersion
) + "\n";
722 ShowList(c1out
,_("The following extra packages will be installed:"),List
,VersionsList
);
725 /* Print out a list of suggested and recommended packages */
727 std::string SuggestsList
, RecommendsList
;
728 std::string SuggestsVersions
, RecommendsVersions
;
729 for (unsigned J
= 0; J
< Cache
->Head().PackageCount
; J
++)
731 pkgCache::PkgIterator
Pkg(Cache
,Cache
.List
[J
]);
733 /* Just look at the ones we want to install */
734 if ((*Cache
)[Pkg
].Install() == false)
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; )
741 pkgCache::DepIterator Start
;
742 pkgCache::DepIterator End
;
743 D
.GlobOr(Start
,End
); // advances D
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;
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())
759 foundInstalledInOrGroup
=true;
763 /* Skip if we already saw it */
764 if (int(SuggestsList
.find(target
)) != -1 || int(RecommendsList
.find(target
)) != -1)
766 foundInstalledInOrGroup
=true;
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)
774 pkgCache::PrvIterator I
= Start
.TargetPkg().ProvidesList();
775 for (; I
.end() == false; ++I
)
777 pkgCache::PkgIterator Pkg
= I
.OwnerPkg();
778 if (Cache
[Pkg
].CandidateVerIter(Cache
) == I
.OwnerVer() &&
779 Pkg
.CurrentVer() != 0)
780 foundInstalledInOrGroup
=true;
784 if (Start
->Type
== pkgCache::Dep::Suggests
)
786 SuggestsOrList
+= target
;
787 SuggestsOrVersions
+= std::string(Cache
[Start
.TargetPkg()].CandVersion
) + "\n";
790 if (Start
->Type
== pkgCache::Dep::Recommends
)
792 RecommendsOrList
+= target
;
793 RecommendsOrVersions
+= std::string(Cache
[Start
.TargetPkg()].CandVersion
) + "\n";
801 if(foundInstalledInOrGroup
== false)
803 RecommendsList
+= RecommendsOrList
;
804 RecommendsVersions
+= RecommendsOrVersions
;
805 SuggestsList
+= SuggestsOrList
;
806 SuggestsVersions
+= SuggestsOrVersions
;
812 ShowList(c1out
,_("Suggested packages:"),SuggestsList
,SuggestsVersions
);
813 ShowList(c1out
,_("Recommended packages:"),RecommendsList
,RecommendsVersions
);
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);
822 return InstallPackages(Cache
,false);