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>
22 #include <apt-pkg/sourcelist.h>
24 // FIXME: include of deb specific header
25 #include <apt-pkg/debmetaindex.h>
30 #include <sys/statfs.h>
31 #include <sys/statvfs.h>
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>
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
)
54 if (_config
->FindB("APT::Get::Purge",false) == true)
56 pkgCache::PkgIterator I
= Cache
->PkgBegin();
57 for (; I
.end() == false; ++I
)
59 if (I
.Purge() == false && Cache
[I
].Mode
== pkgDepCache::ModeDelete
)
60 Cache
->MarkDelete(I
,true);
65 bool Essential
= false;
67 // Show all the various warning indicators
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
);
82 if (Cache
->BrokenCount() != 0)
84 ShowBroken(c1out
,Cache
,false);
85 return _error
->Error(_("Internal error, InstallPackages was called with broken packages!"));
88 if (Cache
->DelCount() == 0 && Cache
->InstCount() == 0 &&
89 Cache
->BadCount() == 0)
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."));
96 // Run the simulator ..
97 if (_config
->FindB("APT::Get::Simulate") == true)
99 pkgSimulate
PM(Cache
);
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
);
106 int status_fd
= _config
->FindI("APT::Status-Fd",-1);
107 pkgPackageManager::OrderResult Res
= PM
.DoInstall(status_fd
);
110 if (Res
== pkgPackageManager::Failed
)
112 if (Res
!= pkgPackageManager::Completed
)
113 return _error
->Error(_("Internal error, Ordering didn't finish"));
117 // Create the text record parser
118 pkgRecords
Recs(Cache
);
119 if (_error
->PendingError() == true)
122 // Create the download object
124 AcqTextStatus
Stat(ScreenWidth
,_config
->FindI("quiet",0));
125 if (_config
->FindB("APT::Get::Print-URIs", false) == true)
127 // force a hashsum for compatibility reasons
128 _config
->CndSet("Acquire::ForceHash", "md5sum");
130 else if (Fetcher
.Setup(&Stat
, _config
->FindDir("Dir::Cache::Archives")) == false)
133 // Read the source list
134 if (Cache
.BuildSourceList() == false)
136 pkgSourceList
*List
= Cache
.GetSourceList();
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)
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())
150 c0out
<< DebBytes
<< ',' << Cache
->DebSize() << std::endl
;
151 c0out
<< _("How odd... The sizes didn't match, email apt@packages.debian.org") << std::endl
;
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());
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());
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());
178 if (_error
->PendingError() == true)
181 /* Check for enough free space, but only if we are actually going to
183 if (_config
->FindB("APT::Get::Print-URIs") == false &&
184 _config
->FindB("APT::Get::Download",true) == true)
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"),
193 return _error
->Errno("statvfs",_("Couldn't determine free space in %s"),
195 } else if (unsigned(Buf
.f_bfree
) < (FetchBytes
- FetchPBytes
)/Buf
.f_bsize
)
198 if (statfs(OutputDir
.c_str(),&Stat
) != 0
199 #if HAVE_STRUCT_STATFS_F_TYPE
200 || unsigned(Stat
.f_type
) != RAMFS_MAGIC
203 return _error
->Error(_("You don't have enough free space in %s."),
209 if (_config
->FindI("quiet",0) >= 2 ||
210 _config
->FindB("APT::Get::Assume-Yes",false) == true)
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"));
216 if (Essential
== true && Safety
== true)
218 if (_config
->FindB("APT::Get::Trivial-Only",false) == true)
219 return _error
->Error(_("Trivial Only specified but this is not a trivial operation."));
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!");
225 _("You are about to do something potentially harmful.\n"
226 "To continue type in the phrase '%s'\n"
229 if (AnalPrompt(Prompt
) == false)
231 c2out
<< _("Abort.") << std::endl
;
237 // Prompt to continue
238 if (Ask
== true || Fail
== true)
240 if (_config
->FindB("APT::Get::Trivial-Only",false) == true)
241 return _error
->Error(_("Trivial Only specified but this is not a trivial operation."));
243 if (_config
->FindI("quiet",0) < 2 &&
244 _config
->FindB("APT::Get::Assume-Yes",false) == false)
246 c2out
<< _("Do you want to continue?") << std::flush
;
247 if (YnPrompt() == false)
249 c2out
<< _("Abort.") << std::endl
;
256 // Just print out the uris an exit if the --print-uris flag was used
257 if (_config
->FindB("APT::Get::Print-URIs") == true)
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
;
266 if (!CheckAuth(Fetcher
, true))
269 /* Unlock the dpkg lock if we are not going to be doing an install
271 if (_config
->FindB("APT::Get::Download-Only",false) == true)
277 bool Transient
= false;
278 if (_config
->FindB("APT::Get::Download",true) == false)
280 for (pkgAcquire::ItemIterator I
= Fetcher
.ItemsBegin(); I
< Fetcher
.ItemsEnd();)
282 if ((*I
)->Local
== true)
288 // Close the item and check if it was found in cache
290 if ((*I
)->Complete
== false)
293 // Clear it out of the fetch list
295 I
= Fetcher
.ItemsBegin();
300 if (AcquireRun(Fetcher
, 0, &Failed
, &Transient
) == false)
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)
313 if (_config
->FindB("APT::Get::Download-Only",false) == true)
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
;
321 if (Failed
== true && _config
->FindB("APT::Get::Fix-Missing",false) == false)
323 return _error
->Error(_("Unable to fetch some archives, maybe run apt-get update or try with --fix-missing?"));
326 if (Transient
== true && Failed
== true)
327 return _error
->Error(_("--fix-missing and media swapping is not currently supported"));
329 // Try to deal with missing package files
330 if (Failed
== true && PM
->FixMissing() == false)
332 c2out
<< _("Unable to correct missing packages.") << std::endl
;
333 return _error
->Error(_("Aborting install."));
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
);
343 int status_fd
= _config
->FindI("APT::Status-Fd", -1);
344 pkgPackageManager::OrderResult Res
= PM
->DoInstall(status_fd
);
347 if (Res
== pkgPackageManager::Failed
|| _error
->PendingError() == true)
349 if (Res
== pkgPackageManager::Completed
)
352 // Reload the fetcher object and loop again for media swapping
354 if (PM
->GetArchives(&Fetcher
,List
,&Recs
) == false)
360 std::set
<std::string
> const disappearedPkgs
= PM
->GetDisappearedPackages();
361 if (disappearedPkgs
.empty() == true)
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(" ");
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
;
378 // DoAutomaticRemove - Remove all automatic unused packages /*{{{*/
379 // ---------------------------------------------------------------------
380 /* Remove unused automatic packages */
381 static bool DoAutomaticRemove(CacheFile
&Cache
)
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");
387 pkgDepCache::ActionGroup
group(*Cache
);
389 std::cout
<< "DoAutomaticRemove()" << std::endl
;
391 if (doAutoRemove
== true &&
392 _config
->FindB("APT::Get::Remove",true) == false)
394 c1out
<< _("We are not supposed to delete stuff, can't start "
395 "AutoRemover") << std::endl
;
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);
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
)
409 pkgCache::PkgIterator
Pkg(Cache
,Cache
.List
[J
]);
410 if (Cache
[Pkg
].Garbage
)
412 if(Pkg
.CurrentVer() != 0 || Cache
[Pkg
].Install())
414 std::cout
<< "We could delete %s" << Pkg
.FullName(true).c_str() << std::endl
;
418 if(Pkg
.CurrentVer() != 0 &&
419 Pkg
->CurrentState
!= pkgCache::State::ConfigFiles
)
420 Cache
->MarkDelete(Pkg
, purgePkgs
, 0, false);
422 Cache
->MarkKeep(Pkg
, false, false);
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)
432 if (Pkg
.CandVersion() != 0)
434 Cache
->MarkDelete(Pkg
, false, 0, false);
436 // only show stuff in the list that is not yet marked for removal
437 else if(hideAutoRemove
== false && Cache
[Pkg
].Delete() == false)
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))
450 for (APT::PackageSet::const_iterator Pkg
= tooMuch
.begin();
451 Pkg
!= tooMuch
.end(); ++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
)
460 for (pkgCache::DepIterator R
= P
.RevDependsList();
461 R
.end() == false; ++R
)
463 if (R
.IsNegative() == true ||
464 Cache
->IsImportantDep(R
) == false)
466 pkgCache::PkgIterator N
= R
.ParentPkg();
467 if (N
.end() == true || (N
->CurrentVer
== 0 && (*Cache
)[N
].Install() == false))
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)
484 } while (Changed
== true);
487 std::string autoremovelist
, autoremoveversions
;
488 if (smallList
== false && autoRemoveCount
!= 0)
490 for (APT::PackageList::const_iterator Pkg
= autoRemoveList
.begin(); Pkg
!= autoRemoveList
.end(); ++Pkg
)
492 if (Cache
[Pkg
].Garbage
== false)
494 autoremovelist
+= Pkg
.FullName(true) + " ";
495 autoremoveversions
+= std::string(Cache
[Pkg
].CandVersion
) + "\n";
499 // Now see if we had destroyed anything (if we had done anything)
500 if (Cache
->BrokenCount() != 0)
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
;
505 c1out
<< _("The following information may help to resolve the situation:") << std::endl
;
507 ShowBroken(c1out
,Cache
,false);
509 return _error
->Error(_("Internal Error, AutoRemover broke stuff"));
512 // if we don't remove them, we should show them!
513 if (doAutoRemove
== false && (autoremovelist
.empty() == false || autoRemoveCount
!= 0))
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
);
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
;
527 // DoCacheManipulationFromCommandLine /*{{{*/
528 static const unsigned short MOD_REMOVE
= 1;
529 static const unsigned short MOD_INSTALL
= 2;
531 bool DoCacheManipulationFromCommandLine(CommandLine
&CmdL
, CacheFile
&Cache
)
533 std::map
<unsigned short, APT::VersionSet
> verset
;
534 return DoCacheManipulationFromCommandLine(CmdL
, Cache
, verset
);
536 bool DoCacheManipulationFromCommandLine(CommandLine
&CmdL
, CacheFile
&Cache
,
537 std::map
<unsigned short, APT::VersionSet
> &verset
)
540 // Enter the special broken fixing mode if the user specified arguments
541 bool BrokenFix
= false;
542 if (Cache
->BrokenCount() != 0)
545 SPtr
<pkgProblemResolver
> Fix
;
546 if (_config
->FindB("APT::Get::CallResolver", true) == true)
547 Fix
= new pkgProblemResolver(Cache
);
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)
554 _config
->Set("APT::Get::Purge", true);
555 fallback
= MOD_REMOVE
;
557 else if (strcasecmp(CmdL
.FileList
[0], "autoremove") == 0)
559 _config
->Set("APT::Get::AutomaticRemove", "true");
560 fallback
= MOD_REMOVE
;
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
);
572 if (_error
->PendingError() == true)
574 helper
.showVirtualPackageErrors(Cache
);
579 TryToInstall
InstallAction(Cache
, Fix
, BrokenFix
);
580 TryToRemove
RemoveAction(Cache
, Fix
);
582 // new scope for the ActionGroup
584 pkgDepCache::ActionGroup
group(Cache
);
585 unsigned short const order
[] = { MOD_REMOVE
, MOD_INSTALL
, 0 };
587 for (unsigned short i
= 0; order
[i
] != 0; ++i
)
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
);
595 if (Fix
!= NULL
&& _config
->FindB("APT::Get::AutoSolving", true) == true)
597 for (unsigned short i
= 0; order
[i
] != 0; ++i
)
599 if (order
[i
] != MOD_INSTALL
)
601 InstallAction
.propergateReleaseCandiateSwitching(helper
.selectedByRelease
, c0out
);
602 InstallAction
.doAutoInstall();
606 if (_error
->PendingError() == true)
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
614 if (BrokenFix
== true && Cache
->BrokenCount() != 0)
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)."));
623 // Call the scored problem resolver
627 // Now we check the state of the packages,
628 if (Cache
->BrokenCount() != 0)
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
;
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;
646 c1out
<< _("The following information may help to resolve the situation:") << std::endl
;
648 ShowBroken(c1out
,Cache
,false);
649 if (_error
->PendingError() == true)
652 return _error
->Error(_("Broken packages"));
655 if (!DoAutomaticRemove(Cache
))
658 // if nothing changed in the cache, but only the automark information
659 // we write the StateFile here, otherwise it will be written in
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
);
670 // DoInstall - Install packages from the command line /*{{{*/
671 // ---------------------------------------------------------------------
672 /* Install named packages */
673 bool DoInstall(CommandLine
&CmdL
)
676 // first check for local pkgs and add them to the cache
677 for (const char **I
= CmdL
.FileList
; *I
!= 0; I
++)
681 // FIMXE: direct usage of .deb specific stuff
682 metaIndex
*mi
= new debDebFileMetaIndex(*I
);
683 pkgSourceList
*sources
= Cache
.GetSourceList();
688 // then open the cache
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);