]>
git.saurik.com Git - apt.git/blob - apt-private/private-install.cc
cdca457553a0fb067556f7f735eb12892b9e6b88
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/upgrade.h>
23 #include <apt-pkg/install-progress.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_ABI >= 413
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
119 AcqTextStatus
Stat(std::cout
, ScreenWidth
,_config
->FindI("quiet",0));
120 pkgAcquire
Fetcher(&Stat
);
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
.GetLock(_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 if (CheckFreeSpaceBeforeDownload(_config
->FindDir("Dir::Cache::Archives"), (FetchBytes
- FetchPBytes
)) == false)
181 if (_config
->FindI("quiet",0) >= 2 ||
182 _config
->FindB("APT::Get::Assume-Yes",false) == true)
184 if (Fail
== true && _config
->FindB("APT::Get::Force-Yes",false) == false)
185 return _error
->Error(_("There are problems and -y was used without --force-yes"));
188 if (Essential
== true && Safety
== true)
190 if (_config
->FindB("APT::Get::Trivial-Only",false) == true)
191 return _error
->Error(_("Trivial Only specified but this is not a trivial operation."));
193 // TRANSLATOR: This string needs to be typed by the user as a confirmation, so be
194 // careful with hard to type or special characters (like non-breaking spaces)
195 const char *Prompt
= _("Yes, do as I say!");
197 _("You are about to do something potentially harmful.\n"
198 "To continue type in the phrase '%s'\n"
201 if (AnalPrompt(Prompt
) == false)
203 c2out
<< _("Abort.") << std::endl
;
209 // Prompt to continue
210 if (Ask
== true || Fail
== true)
212 if (_config
->FindB("APT::Get::Trivial-Only",false) == true)
213 return _error
->Error(_("Trivial Only specified but this is not a trivial operation."));
215 if (_config
->FindI("quiet",0) < 2 &&
216 _config
->FindB("APT::Get::Assume-Yes",false) == false)
218 c2out
<< _("Do you want to continue?") << std::flush
;
219 if (YnPrompt() == false)
221 c2out
<< _("Abort.") << std::endl
;
228 // Just print out the uris an exit if the --print-uris flag was used
229 if (_config
->FindB("APT::Get::Print-URIs") == true)
231 pkgAcquire::UriIterator I
= Fetcher
.UriBegin();
232 for (; I
!= Fetcher
.UriEnd(); ++I
)
233 std::cout
<< '\'' << I
->URI
<< "' " << flNotDir(I
->Owner
->DestFile
) << ' ' <<
234 I
->Owner
->FileSize
<< ' ' << I
->Owner
->HashSum() << std::endl
;
238 if (!CheckAuth(Fetcher
, true))
241 /* Unlock the dpkg lock if we are not going to be doing an install
243 if (_config
->FindB("APT::Get::Download-Only",false) == true)
249 bool Transient
= false;
250 if (_config
->FindB("APT::Get::Download",true) == false)
252 for (pkgAcquire::ItemIterator I
= Fetcher
.ItemsBegin(); I
< Fetcher
.ItemsEnd();)
254 if ((*I
)->Local
== true)
260 // Close the item and check if it was found in cache
262 if ((*I
)->Complete
== false)
265 // Clear it out of the fetch list
267 I
= Fetcher
.ItemsBegin();
272 if (AcquireRun(Fetcher
, 0, &Failed
, &Transient
) == false)
275 /* If we are in no download mode and missing files and there were
276 'failures' then the user must specify -m. Furthermore, there
277 is no such thing as a transient error in no-download mode! */
278 if (Transient
== true &&
279 _config
->FindB("APT::Get::Download",true) == false)
285 if (_config
->FindB("APT::Get::Download-Only",false) == true)
287 if (Failed
== true && _config
->FindB("APT::Get::Fix-Missing",false) == false)
288 return _error
->Error(_("Some files failed to download"));
289 c1out
<< _("Download complete and in download only mode") << std::endl
;
293 if (Failed
== true && _config
->FindB("APT::Get::Fix-Missing",false) == false)
295 return _error
->Error(_("Unable to fetch some archives, maybe run apt-get update or try with --fix-missing?"));
298 if (Transient
== true && Failed
== true)
299 return _error
->Error(_("--fix-missing and media swapping is not currently supported"));
301 // Try to deal with missing package files
302 if (Failed
== true && PM
->FixMissing() == false)
304 c2out
<< _("Unable to correct missing packages.") << std::endl
;
305 return _error
->Error(_("Aborting install."));
310 #if APT_PKG_ABI >= 413
311 APT::Progress::PackageManager
*progress
= APT::Progress::PackageManagerProgressFactory();
312 pkgPackageManager::OrderResult Res
= PM
->DoInstall(progress
);
315 int status_fd
= _config
->FindI("APT::Status-Fd", -1);
316 pkgPackageManager::OrderResult Res
= PM
->DoInstall(status_fd
);
319 if (Res
== pkgPackageManager::Failed
|| _error
->PendingError() == true)
321 if (Res
== pkgPackageManager::Completed
)
324 // Reload the fetcher object and loop again for media swapping
326 if (PM
->GetArchives(&Fetcher
,List
,&Recs
) == false)
332 std::set
<std::string
> const disappearedPkgs
= PM
->GetDisappearedPackages();
333 if (disappearedPkgs
.empty() == true)
336 std::string disappear
;
337 for (std::set
<std::string
>::const_iterator d
= disappearedPkgs
.begin();
338 d
!= disappearedPkgs
.end(); ++d
)
339 disappear
.append(*d
).append(" ");
341 ShowList(c1out
, P_("The following package disappeared from your system as\n"
342 "all files have been overwritten by other packages:",
343 "The following packages disappeared from your system as\n"
344 "all files have been overwritten by other packages:", disappearedPkgs
.size()), disappear
, "");
345 c0out
<< _("Note: This is done automatically and on purpose by dpkg.") << std::endl
;
350 // DoAutomaticRemove - Remove all automatic unused packages /*{{{*/
351 // ---------------------------------------------------------------------
352 /* Remove unused automatic packages */
353 static bool DoAutomaticRemove(CacheFile
&Cache
)
355 bool Debug
= _config
->FindI("Debug::pkgAutoRemove",false);
356 bool doAutoRemove
= _config
->FindB("APT::Get::AutomaticRemove", false);
357 bool hideAutoRemove
= _config
->FindB("APT::Get::HideAutoRemove");
359 pkgDepCache::ActionGroup
group(*Cache
);
361 std::cout
<< "DoAutomaticRemove()" << std::endl
;
363 if (doAutoRemove
== true &&
364 _config
->FindB("APT::Get::Remove",true) == false)
366 c1out
<< _("We are not supposed to delete stuff, can't start "
367 "AutoRemover") << std::endl
;
371 bool purgePkgs
= _config
->FindB("APT::Get::Purge", false);
372 bool smallList
= (hideAutoRemove
== false &&
373 strcasecmp(_config
->Find("APT::Get::HideAutoRemove","").c_str(),"small") == 0);
375 unsigned long autoRemoveCount
= 0;
376 APT::PackageSet tooMuch
;
377 SortedPackageUniverse
Universe(Cache
);
378 // look over the cache to see what can be removed
379 for (auto const &Pkg
: Universe
)
381 if (Cache
[Pkg
].Garbage
)
383 if(Pkg
.CurrentVer() != 0 || Cache
[Pkg
].Install())
385 std::cout
<< "We could delete %s" << Pkg
.FullName(true).c_str() << std::endl
;
389 if(Pkg
.CurrentVer() != 0 &&
390 Pkg
->CurrentState
!= pkgCache::State::ConfigFiles
)
391 Cache
->MarkDelete(Pkg
, purgePkgs
, 0, false);
393 Cache
->MarkKeep(Pkg
, false, false);
397 // if the package is a new install and already garbage we don't need to
398 // install it in the first place, so nuke it instead of show it
399 if (Cache
[Pkg
].Install() == true && Pkg
.CurrentVer() == 0)
401 if (Pkg
.CandVersion() != 0)
403 Cache
->MarkDelete(Pkg
, false, 0, false);
405 // only show stuff in the list that is not yet marked for removal
406 else if(hideAutoRemove
== false && Cache
[Pkg
].Delete() == false)
412 // we could have removed a new dependency of a garbage package,
413 // so check if a reverse depends is broken and if so install it again.
414 if (tooMuch
.empty() == false && (Cache
->BrokenCount() != 0 || Cache
->PolicyBrokenCount() != 0))
419 for (APT::PackageSet::iterator Pkg
= tooMuch
.begin();
420 Pkg
!= tooMuch
.end(); ++Pkg
)
424 for (pkgCache::PrvIterator Prv
= Cache
[Pkg
].CandidateVerIter(Cache
).ProvidesList();
425 Prv
.end() == false; ++Prv
)
426 too
.insert(Prv
.ParentPkg());
427 for (APT::PackageSet::const_iterator P
= too
.begin(); P
!= too
.end(); ++P
)
429 for (pkgCache::DepIterator R
= P
.RevDependsList();
430 R
.end() == false; ++R
)
432 if (R
.IsNegative() == true ||
433 Cache
->IsImportantDep(R
) == false)
435 pkgCache::PkgIterator N
= R
.ParentPkg();
436 if (N
.end() == true || (N
->CurrentVer
== 0 && (*Cache
)[N
].Install() == false))
439 std::clog
<< "Save " << Pkg
<< " as another installed garbage package depends on it" << std::endl
;
440 Cache
->MarkInstall(Pkg
, false, 0, false);
441 if (hideAutoRemove
== false)
453 } while (Changed
== true);
456 // Now see if we had destroyed anything (if we had done anything)
457 if (Cache
->BrokenCount() != 0)
459 c1out
<< _("Hmm, seems like the AutoRemover destroyed something which really\n"
460 "shouldn't happen. Please file a bug report against apt.") << std::endl
;
462 c1out
<< _("The following information may help to resolve the situation:") << std::endl
;
464 ShowBroken(c1out
,Cache
,false);
466 return _error
->Error(_("Internal Error, AutoRemover broke stuff"));
469 // if we don't remove them, we should show them!
470 if (doAutoRemove
== false && autoRemoveCount
!= 0)
472 if (smallList
== false)
474 SortedPackageUniverse
Universe(Cache
);
475 ShowList(c1out
, P_("The following package was automatically installed and is no longer required:",
476 "The following packages were automatically installed and are no longer required:",
477 autoRemoveCount
), Universe
,
478 [&Cache
](pkgCache::PkgIterator
const &Pkg
) { return (*Cache
)[Pkg
].Garbage
== true && (*Cache
)[Pkg
].Delete() == false; },
479 &PrettyFullName
, CandidateVersion(&Cache
));
482 ioprintf(c1out
, P_("%lu package was automatically installed and is no longer required.\n",
483 "%lu packages were automatically installed and are no longer required.\n", autoRemoveCount
), autoRemoveCount
);
484 c1out
<< P_("Use 'apt-get autoremove' to remove it.", "Use 'apt-get autoremove' to remove them.", autoRemoveCount
) << std::endl
;
489 // DoCacheManipulationFromCommandLine /*{{{*/
490 static const unsigned short MOD_REMOVE
= 1;
491 static const unsigned short MOD_INSTALL
= 2;
493 bool DoCacheManipulationFromCommandLine(CommandLine
&CmdL
, CacheFile
&Cache
, int UpgradeMode
)
495 std::map
<unsigned short, APT::VersionSet
> verset
;
496 return DoCacheManipulationFromCommandLine(CmdL
, Cache
, verset
, UpgradeMode
);
498 bool DoCacheManipulationFromCommandLine(CommandLine
&CmdL
, CacheFile
&Cache
,
499 std::map
<unsigned short, APT::VersionSet
> &verset
, int UpgradeMode
)
501 // Enter the special broken fixing mode if the user specified arguments
502 bool BrokenFix
= false;
503 if (Cache
->BrokenCount() != 0)
506 SPtr
<pkgProblemResolver
> Fix
;
507 if (_config
->FindB("APT::Get::CallResolver", true) == true)
508 Fix
= new pkgProblemResolver(Cache
);
510 unsigned short fallback
= MOD_INSTALL
;
511 if (strcasecmp(CmdL
.FileList
[0],"remove") == 0)
512 fallback
= MOD_REMOVE
;
513 else if (strcasecmp(CmdL
.FileList
[0], "purge") == 0)
515 _config
->Set("APT::Get::Purge", true);
516 fallback
= MOD_REMOVE
;
518 else if (strcasecmp(CmdL
.FileList
[0], "autoremove") == 0)
520 _config
->Set("APT::Get::AutomaticRemove", "true");
521 fallback
= MOD_REMOVE
;
524 std::list
<APT::VersionSet::Modifier
> mods
;
525 mods
.push_back(APT::VersionSet::Modifier(MOD_INSTALL
, "+",
526 APT::VersionSet::Modifier::POSTFIX
, APT::CacheSetHelper::CANDIDATE
));
527 mods
.push_back(APT::VersionSet::Modifier(MOD_REMOVE
, "-",
528 APT::VersionSet::Modifier::POSTFIX
, APT::CacheSetHelper::NEWEST
));
529 CacheSetHelperAPTGet
helper(c0out
);
530 verset
= APT::VersionSet::GroupedFromCommandLine(Cache
,
531 CmdL
.FileList
+ 1, mods
, fallback
, helper
);
533 if (_error
->PendingError() == true)
535 helper
.showVirtualPackageErrors(Cache
);
540 TryToInstall
InstallAction(Cache
, Fix
, BrokenFix
);
541 TryToRemove
RemoveAction(Cache
, Fix
);
543 // new scope for the ActionGroup
545 pkgDepCache::ActionGroup
group(Cache
);
546 unsigned short const order
[] = { MOD_REMOVE
, MOD_INSTALL
, 0 };
548 for (unsigned short i
= 0; order
[i
] != 0; ++i
)
550 if (order
[i
] == MOD_INSTALL
)
551 InstallAction
= std::for_each(verset
[MOD_INSTALL
].begin(), verset
[MOD_INSTALL
].end(), InstallAction
);
552 else if (order
[i
] == MOD_REMOVE
)
553 RemoveAction
= std::for_each(verset
[MOD_REMOVE
].begin(), verset
[MOD_REMOVE
].end(), RemoveAction
);
556 if (Fix
!= NULL
&& _config
->FindB("APT::Get::AutoSolving", true) == true)
558 for (unsigned short i
= 0; order
[i
] != 0; ++i
)
560 if (order
[i
] != MOD_INSTALL
)
562 InstallAction
.propergateReleaseCandiateSwitching(helper
.selectedByRelease
, c0out
);
563 InstallAction
.doAutoInstall();
567 if (_error
->PendingError() == true)
572 /* If we are in the Broken fixing mode we do not attempt to fix the
573 problems. This is if the user invoked install without -f and gave
575 if (BrokenFix
== true && Cache
->BrokenCount() != 0)
577 c1out
<< _("You might want to run 'apt-get -f install' to correct these:") << std::endl
;
578 ShowBroken(c1out
,Cache
,false);
579 return _error
->Error(_("Unmet dependencies. Try 'apt-get -f install' with no packages (or specify a solution)."));
584 // Call the scored problem resolver
585 OpTextProgress
Progress(*_config
);
586 bool const distUpgradeMode
= strcmp(CmdL
.FileList
[0], "dist-upgrade") == 0 || strcmp(CmdL
.FileList
[0], "full-upgrade") == 0;
588 bool resolver_fail
= false;
589 if (distUpgradeMode
== true || UpgradeMode
!= APT::Upgrade::ALLOW_EVERYTHING
)
590 resolver_fail
= APT::Upgrade::Upgrade(Cache
, UpgradeMode
, &Progress
);
592 resolver_fail
= Fix
->Resolve(true, &Progress
);
594 if (resolver_fail
== false && Cache
->BrokenCount() == 0)
598 // Now we check the state of the packages,
599 if (Cache
->BrokenCount() != 0)
602 _("Some packages could not be installed. This may mean that you have\n"
603 "requested an impossible situation or if you are using the unstable\n"
604 "distribution that some required packages have not yet been created\n"
605 "or been moved out of Incoming.") << std::endl
;
611 _("Since you only requested a single operation it is extremely likely that\n"
612 "the package is simply not installable and a bug report against\n"
613 "that package should be filed.") << std::endl;
617 c1out
<< _("The following information may help to resolve the situation:") << std::endl
;
619 ShowBroken(c1out
,Cache
,false);
620 if (_error
->PendingError() == true)
623 return _error
->Error(_("Broken packages"));
626 if (!DoAutomaticRemove(Cache
))
629 // if nothing changed in the cache, but only the automark information
630 // we write the StateFile here, otherwise it will be written in
632 if (InstallAction
.AutoMarkChanged
> 0 &&
633 Cache
->DelCount() == 0 && Cache
->InstCount() == 0 &&
634 Cache
->BadCount() == 0 &&
635 _config
->FindB("APT::Get::Simulate",false) == false)
636 Cache
->writeStateFile(NULL
);
641 // DoInstall - Install packages from the command line /*{{{*/
642 // ---------------------------------------------------------------------
643 /* Install named packages */
644 struct PkgIsExtraInstalled
{
645 pkgCacheFile
* const Cache
;
646 APT::VersionSet
const * const verset
;
647 PkgIsExtraInstalled(pkgCacheFile
* const Cache
, APT::VersionSet
const * const Container
) : Cache(Cache
), verset(Container
) {}
648 bool operator() (pkgCache::PkgIterator
const Pkg
)
650 if ((*Cache
)[Pkg
].Install() == false)
652 pkgCache::VerIterator
const Cand
= (*Cache
)[Pkg
].CandidateVerIter(*Cache
);
653 return verset
->find(Cand
) == verset
->end();
656 bool DoInstall(CommandLine
&CmdL
)
659 // first check for local pkgs and add them to the cache
660 for (const char **I
= CmdL
.FileList
; *I
!= 0; I
++)
664 // FIXME: make this more elegant
665 std::string TypeStr
= flExtension(*I
) + "-file";
666 pkgSourceList::Type
*Type
= pkgSourceList::Type::GetType(TypeStr
.c_str());
669 std::vector
<metaIndex
*> List
;
670 std::map
<std::string
, std::string
> Options
;
671 if(Type
->CreateItem(List
, *I
, "", "", Options
))
673 // we have our own CacheFile that gives us a SourceList
675 SourceList
*sources
= (SourceList
*)Cache
.GetSourceList();
676 sources
->AddMetaIndex(List
[0]);
682 // then open the cache
683 if (Cache
.OpenForInstall() == false ||
684 Cache
.CheckDeps(CmdL
.FileSize() != 1) == false)
687 std::map
<unsigned short, APT::VersionSet
> verset
;
689 if(!DoCacheManipulationFromCommandLine(CmdL
, Cache
, verset
, 0))
692 /* Print out a list of packages that are going to be installed extra
693 to what the user asked */
694 SortedPackageUniverse
Universe(Cache
);
695 if (Cache
->InstCount() != verset
[MOD_INSTALL
].size())
696 ShowList(c1out
, _("The following extra packages will be installed:"), Universe
,
697 PkgIsExtraInstalled(&Cache
, &verset
[MOD_INSTALL
]),
698 &PrettyFullName
, CandidateVersion(&Cache
));
700 /* Print out a list of suggested and recommended packages */
702 std::string SuggestsList
, RecommendsList
;
703 std::string SuggestsVersions
, RecommendsVersions
;
704 for (auto const &Pkg
: Universe
)
706 /* Just look at the ones we want to install */
707 if ((*Cache
)[Pkg
].Install() == false)
710 // get the recommends/suggests for the candidate ver
711 pkgCache::VerIterator CV
= (*Cache
)[Pkg
].CandidateVerIter(*Cache
);
712 for (pkgCache::DepIterator D
= CV
.DependsList(); D
.end() == false; )
714 pkgCache::DepIterator Start
;
715 pkgCache::DepIterator End
;
716 D
.GlobOr(Start
,End
); // advances D
718 // FIXME: we really should display a or-group as a or-group to the user
719 // the problem is that ShowList is incapable of doing this
720 std::string RecommendsOrList
,RecommendsOrVersions
;
721 std::string SuggestsOrList
,SuggestsOrVersions
;
722 bool foundInstalledInOrGroup
= false;
725 /* Skip if package is installed already, or is about to be */
726 pkgCache::PkgIterator
const TarPkg
= Start
.TargetPkg();
727 if (TarPkg
->SelectedState
== pkgCache::State::Install
||
728 TarPkg
->SelectedState
== pkgCache::State::Hold
||
729 Cache
[Start
.TargetPkg()].Install())
731 foundInstalledInOrGroup
=true;
735 /* Skip if we already saw it */
736 std::string target
= Start
.TargetPkg().FullName(true) + " ";
737 if (int(SuggestsList
.find(target
)) != -1 || int(RecommendsList
.find(target
)) != -1)
739 foundInstalledInOrGroup
=true;
743 // this is a dep on a virtual pkg, check if any package that provides it
744 // should be installed
745 if(Start
.TargetPkg().ProvidesList() != 0)
747 pkgCache::PrvIterator I
= Start
.TargetPkg().ProvidesList();
748 for (; I
.end() == false; ++I
)
750 pkgCache::PkgIterator Pkg
= I
.OwnerPkg();
751 if (Cache
[Pkg
].CandidateVerIter(Cache
) == I
.OwnerVer() &&
752 Pkg
.CurrentVer() != 0)
753 foundInstalledInOrGroup
=true;
757 if (Start
->Type
== pkgCache::Dep::Suggests
)
759 SuggestsOrList
+= target
;
760 SuggestsOrVersions
+= std::string(Cache
[Start
.TargetPkg()].CandVersion
) + "\n";
763 if (Start
->Type
== pkgCache::Dep::Recommends
)
765 RecommendsOrList
+= target
;
766 RecommendsOrVersions
+= std::string(Cache
[Start
.TargetPkg()].CandVersion
) + "\n";
774 if(foundInstalledInOrGroup
== false)
776 RecommendsList
+= RecommendsOrList
;
777 RecommendsVersions
+= RecommendsOrVersions
;
778 SuggestsList
+= SuggestsOrList
;
779 SuggestsVersions
+= SuggestsOrVersions
;
785 ShowList(c1out
,_("Suggested packages:"),SuggestsList
,SuggestsVersions
);
786 ShowList(c1out
,_("Recommended packages:"),RecommendsList
,RecommendsVersions
);
790 // See if we need to prompt
791 // FIXME: check if really the packages in the set are going to be installed
792 if (Cache
->InstCount() == verset
[MOD_INSTALL
].size() && Cache
->DelCount() == 0)
793 return InstallPackages(Cache
,false,false);
795 return InstallPackages(Cache
,false);
799 // TryToInstall - Mark a package for installation /*{{{*/
800 void TryToInstall::operator() (pkgCache::VerIterator
const &Ver
) {
801 pkgCache::PkgIterator Pkg
= Ver
.ParentPkg();
803 Cache
->GetDepCache()->SetCandidateVersion(Ver
);
804 pkgDepCache::StateCache
&State
= (*Cache
)[Pkg
];
806 // Handle the no-upgrade case
807 if (_config
->FindB("APT::Get::upgrade",true) == false && Pkg
->CurrentVer
!= 0)
808 ioprintf(c1out
,_("Skipping %s, it is already installed and upgrade is not set.\n"),
809 Pkg
.FullName(true).c_str());
810 // Ignore request for install if package would be new
811 else if (_config
->FindB("APT::Get::Only-Upgrade", false) == true && Pkg
->CurrentVer
== 0)
812 ioprintf(c1out
,_("Skipping %s, it is not installed and only upgrades are requested.\n"),
813 Pkg
.FullName(true).c_str());
819 Cache
->GetDepCache()->MarkInstall(Pkg
,false);
821 if (State
.Install() == false) {
822 if (_config
->FindB("APT::Get::ReInstall",false) == true) {
823 if (Pkg
->CurrentVer
== 0 || Pkg
.CurrentVer().Downloadable() == false)
824 ioprintf(c1out
,_("Reinstallation of %s is not possible, it cannot be downloaded.\n"),
825 Pkg
.FullName(true).c_str());
827 Cache
->GetDepCache()->SetReInstall(Pkg
, true);
829 ioprintf(c1out
,_("%s is already the newest version.\n"),
830 Pkg
.FullName(true).c_str());
833 // Install it with autoinstalling enabled (if we not respect the minial
834 // required deps or the policy)
835 if (FixBroken
== false)
836 doAutoInstallLater
.insert(Pkg
);
839 // see if we need to fix the auto-mark flag
840 // e.g. apt-get install foo
841 // where foo is marked automatic
842 if (State
.Install() == false &&
843 (State
.Flags
& pkgCache::Flag::Auto
) &&
844 _config
->FindB("APT::Get::ReInstall",false) == false &&
845 _config
->FindB("APT::Get::Only-Upgrade",false) == false &&
846 _config
->FindB("APT::Get::Download-Only",false) == false)
848 ioprintf(c1out
,_("%s set to manually installed.\n"),
849 Pkg
.FullName(true).c_str());
850 Cache
->GetDepCache()->MarkAuto(Pkg
,false);
855 bool TryToInstall::propergateReleaseCandiateSwitching(std::list
<std::pair
<pkgCache::VerIterator
, std::string
> > const &start
, std::ostream
&out
)/*{{{*/
857 for (std::list
<std::pair
<pkgCache::VerIterator
, std::string
> >::const_iterator s
= start
.begin();
858 s
!= start
.end(); ++s
)
859 Cache
->GetDepCache()->SetCandidateVersion(s
->first
);
862 // the Changed list contains:
863 // first: "new version"
864 // second: "what-caused the change"
865 std::list
<std::pair
<pkgCache::VerIterator
, pkgCache::VerIterator
> > Changed
;
866 for (std::list
<std::pair
<pkgCache::VerIterator
, std::string
> >::const_iterator s
= start
.begin();
867 s
!= start
.end(); ++s
)
869 Changed
.push_back(std::make_pair(s
->first
, pkgCache::VerIterator(*Cache
)));
870 // We continue here even if it failed to enhance the ShowBroken output
871 Success
&= Cache
->GetDepCache()->SetCandidateRelease(s
->first
, s
->second
, Changed
);
873 for (std::list
<std::pair
<pkgCache::VerIterator
, pkgCache::VerIterator
> >::const_iterator c
= Changed
.begin();
874 c
!= Changed
.end(); ++c
)
876 if (c
->second
.end() == true)
877 ioprintf(out
, _("Selected version '%s' (%s) for '%s'\n"),
878 c
->first
.VerStr(), c
->first
.RelStr().c_str(), c
->first
.ParentPkg().FullName(true).c_str());
879 else if (c
->first
.ParentPkg()->Group
!= c
->second
.ParentPkg()->Group
)
881 pkgCache::VerIterator V
= (*Cache
)[c
->first
.ParentPkg()].CandidateVerIter(*Cache
);
882 ioprintf(out
, _("Selected version '%s' (%s) for '%s' because of '%s'\n"), V
.VerStr(),
883 V
.RelStr().c_str(), V
.ParentPkg().FullName(true).c_str(), c
->second
.ParentPkg().FullName(true).c_str());
889 void TryToInstall::doAutoInstall() { /*{{{*/
890 for (APT::PackageSet::const_iterator P
= doAutoInstallLater
.begin();
891 P
!= doAutoInstallLater
.end(); ++P
) {
892 pkgDepCache::StateCache
&State
= (*Cache
)[P
];
893 if (State
.InstBroken() == false && State
.InstPolicyBroken() == false)
895 Cache
->GetDepCache()->MarkInstall(P
, true);
897 doAutoInstallLater
.clear();
900 // TryToRemove - Mark a package for removal /*{{{*/
901 void TryToRemove::operator() (pkgCache::VerIterator
const &Ver
)
903 pkgCache::PkgIterator Pkg
= Ver
.ParentPkg();
912 if ((Pkg
->CurrentVer
== 0 && PurgePkgs
== false) ||
913 (PurgePkgs
== true && Pkg
->CurrentState
== pkgCache::State::NotInstalled
))
915 pkgCache::GrpIterator Grp
= Pkg
.Group();
916 pkgCache::PkgIterator P
= Grp
.PackageList();
917 for (; P
.end() != true; P
= Grp
.NextPkg(P
))
921 if (P
->CurrentVer
!= 0 || (PurgePkgs
== true && P
->CurrentState
!= pkgCache::State::NotInstalled
))
923 // TRANSLATORS: Note, this is not an interactive question
924 ioprintf(c1out
,_("Package '%s' is not installed, so not removed. Did you mean '%s'?\n"),
925 Pkg
.FullName(true).c_str(), P
.FullName(true).c_str());
930 ioprintf(c1out
,_("Package '%s' is not installed, so not removed\n"),Pkg
.FullName(true).c_str());
932 // MarkInstall refuses to install packages on hold
933 Pkg
->SelectedState
= pkgCache::State::Hold
;
936 Cache
->GetDepCache()->MarkDelete(Pkg
, PurgePkgs
);