]>
git.saurik.com Git - apt.git/blob - apt-private/private-install.cc
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>
24 #include <apt-pkg/debindexfile.h>
34 #include <apt-private/acqprogress.h>
35 #include <apt-private/private-install.h>
36 #include <apt-private/private-cachefile.h>
37 #include <apt-private/private-cacheset.h>
38 #include <apt-private/private-download.h>
39 #include <apt-private/private-output.h>
45 // InstallPackages - Actually download and install the packages /*{{{*/
46 // ---------------------------------------------------------------------
47 /* This displays the informative messages describing what is going to
48 happen and then calls the download routines */
49 bool InstallPackages(CacheFile
&Cache
,bool ShwKept
,bool Ask
, bool Safety
)
51 if (_config
->FindB("APT::Get::Purge",false) == true)
53 pkgCache::PkgIterator I
= Cache
->PkgBegin();
54 for (; I
.end() == false; ++I
)
56 if (I
.Purge() == false && Cache
[I
].Mode
== pkgDepCache::ModeDelete
)
57 Cache
->MarkDelete(I
,true);
62 bool Downgrade
= false;
63 bool Essential
= false;
65 // Show all the various warning indicators
69 ShowKept(c1out
,Cache
);
70 Hold
= !ShowHold(c1out
,Cache
);
71 if (_config
->FindB("APT::Get::Show-Upgraded",true) == true)
72 ShowUpgraded(c1out
,Cache
);
73 Downgrade
= !ShowDowngraded(c1out
,Cache
);
75 if (_config
->FindB("APT::Get::Download-Only",false) == false)
76 Essential
= !ShowEssential(c1out
,Cache
);
78 // All kinds of failures
79 bool Fail
= (Essential
|| Downgrade
|| Hold
);
84 if (Cache
->BrokenCount() != 0)
86 ShowBroken(c1out
,Cache
,false);
87 return _error
->Error(_("Internal error, InstallPackages was called with broken packages!"));
90 if (Cache
->DelCount() == 0 && Cache
->InstCount() == 0 &&
91 Cache
->BadCount() == 0)
95 if (Cache
->DelCount() != 0 && _config
->FindB("APT::Get::Remove",true) == false)
96 return _error
->Error(_("Packages need to be removed but remove is disabled."));
99 if (_config
->FindI("quiet",0) >= 2 ||
100 _config
->FindB("APT::Get::Assume-Yes",false) == true)
102 if (_config
->FindB("APT::Get::Force-Yes",false) == true) {
103 _error
->Warning(_("--force-yes is deprecated, use one of the options starting with --allow instead."));
106 if (Fail
== true && _config
->FindB("APT::Get::Force-Yes",false) == false) {
107 if (Essential
== true && _config
->FindB("APT::Get::allow-remove-essential", false) == false)
108 return _error
->Error(_("Essential packages were removed and -y was used without --allow-remove-essential."));
109 if (Downgrade
== true && _config
->FindB("APT::Get::allow-downgrades", false) == false)
110 return _error
->Error(_("Packages were downgraded and -y was used without --allow-downgrades."));
111 if (Hold
== true && _config
->FindB("APT::Get::allow-change-held-packages", false) == false)
112 return _error
->Error(_("Held packages were changed and -y was used without --allow-change-held-packages."));
116 // Run the simulator ..
117 if (_config
->FindB("APT::Get::Simulate") == true)
119 pkgSimulate
PM(Cache
);
121 APT::Progress::PackageManager
*progress
= APT::Progress::PackageManagerProgressFactory();
122 pkgPackageManager::OrderResult Res
= PM
.DoInstall(progress
);
125 if (Res
== pkgPackageManager::Failed
)
127 if (Res
!= pkgPackageManager::Completed
)
128 return _error
->Error(_("Internal error, Ordering didn't finish"));
132 // Create the text record parser
133 pkgRecords
Recs(Cache
);
134 if (_error
->PendingError() == true)
137 // Create the download object
138 AcqTextStatus
Stat(std::cout
, ScreenWidth
,_config
->FindI("quiet",0));
139 pkgAcquire
Fetcher(&Stat
);
140 if (_config
->FindB("APT::Get::Print-URIs", false) == true)
142 // force a hashsum for compatibility reasons
143 _config
->CndSet("Acquire::ForceHash", "md5sum");
145 else if (Fetcher
.GetLock(_config
->FindDir("Dir::Cache::Archives")) == false)
148 // Read the source list
149 if (Cache
.BuildSourceList() == false)
151 pkgSourceList
*List
= Cache
.GetSourceList();
153 // Create the package manager and prepare to download
154 std::unique_ptr
<pkgPackageManager
> PM(_system
->CreatePM(Cache
));
155 if (PM
->GetArchives(&Fetcher
,List
,&Recs
) == false ||
156 _error
->PendingError() == true)
159 // Display statistics
160 unsigned long long FetchBytes
= Fetcher
.FetchNeeded();
161 unsigned long long FetchPBytes
= Fetcher
.PartialPresent();
162 unsigned long long DebBytes
= Fetcher
.TotalNeeded();
163 if (DebBytes
!= Cache
->DebSize())
165 c0out
<< DebBytes
<< ',' << Cache
->DebSize() << std::endl
;
166 c0out
<< _("How odd... The sizes didn't match, email apt@packages.debian.org") << std::endl
;
170 if (DebBytes
!= FetchBytes
)
171 //TRANSLATOR: The required space between number and unit is already included
172 // in the replacement strings, so %sB will be correctly translate in e.g. 1,5 MB
173 ioprintf(c1out
,_("Need to get %sB/%sB of archives.\n"),
174 SizeToStr(FetchBytes
).c_str(),SizeToStr(DebBytes
).c_str());
175 else if (DebBytes
!= 0)
176 //TRANSLATOR: The required space between number and unit is already included
177 // in the replacement string, so %sB will be correctly translate in e.g. 1,5 MB
178 ioprintf(c1out
,_("Need to get %sB of archives.\n"),
179 SizeToStr(DebBytes
).c_str());
182 if (Cache
->UsrSize() >= 0)
183 //TRANSLATOR: The required space between number and unit is already included
184 // in the replacement string, so %sB will be correctly translate in e.g. 1,5 MB
185 ioprintf(c1out
,_("After this operation, %sB of additional disk space will be used.\n"),
186 SizeToStr(Cache
->UsrSize()).c_str());
188 //TRANSLATOR: The required space between number and unit is already included
189 // in the replacement string, so %sB will be correctly translate in e.g. 1,5 MB
190 ioprintf(c1out
,_("After this operation, %sB disk space will be freed.\n"),
191 SizeToStr(-1*Cache
->UsrSize()).c_str());
193 if (_error
->PendingError() == true)
196 if (CheckFreeSpaceBeforeDownload(_config
->FindDir("Dir::Cache::Archives"), (FetchBytes
- FetchPBytes
)) == false)
199 if (Essential
== true && Safety
== true && _config
->FindB("APT::Get::allow-remove-essential", false) == false)
201 if (_config
->FindB("APT::Get::Trivial-Only",false) == true)
202 return _error
->Error(_("Trivial Only specified but this is not a trivial operation."));
204 // TRANSLATOR: This string needs to be typed by the user as a confirmation, so be
205 // careful with hard to type or special characters (like non-breaking spaces)
206 const char *Prompt
= _("Yes, do as I say!");
208 _("You are about to do something potentially harmful.\n"
209 "To continue type in the phrase '%s'\n"
212 if (AnalPrompt(Prompt
) == false)
214 c2out
<< _("Abort.") << std::endl
;
220 // Prompt to continue
221 if (Ask
== true || Fail
== 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 if (_config
->FindI("quiet",0) < 2 &&
227 _config
->FindB("APT::Get::Assume-Yes",false) == false)
229 c2out
<< _("Do you want to continue?") << std::flush
;
230 if (YnPrompt() == false)
232 c2out
<< _("Abort.") << std::endl
;
239 // Just print out the uris an exit if the --print-uris flag was used
240 if (_config
->FindB("APT::Get::Print-URIs") == true)
242 pkgAcquire::UriIterator I
= Fetcher
.UriBegin();
243 for (; I
!= Fetcher
.UriEnd(); ++I
)
244 std::cout
<< '\'' << I
->URI
<< "' " << flNotDir(I
->Owner
->DestFile
) << ' ' <<
245 I
->Owner
->FileSize
<< ' ' << I
->Owner
->HashSum() << std::endl
;
249 if (!CheckAuth(Fetcher
, true))
252 /* Unlock the dpkg lock if we are not going to be doing an install
254 if (_config
->FindB("APT::Get::Download-Only",false) == true)
260 bool Transient
= false;
261 if (_config
->FindB("APT::Get::Download",true) == false)
263 for (pkgAcquire::ItemIterator I
= Fetcher
.ItemsBegin(); I
< Fetcher
.ItemsEnd();)
265 if ((*I
)->Local
== true)
271 // Close the item and check if it was found in cache
273 if ((*I
)->Complete
== false)
276 // Clear it out of the fetch list
278 I
= Fetcher
.ItemsBegin();
283 if (AcquireRun(Fetcher
, 0, &Failed
, &Transient
) == false)
286 /* If we are in no download mode and missing files and there were
287 'failures' then the user must specify -m. Furthermore, there
288 is no such thing as a transient error in no-download mode! */
289 if (Transient
== true &&
290 _config
->FindB("APT::Get::Download",true) == false)
296 if (_config
->FindB("APT::Get::Download-Only",false) == true)
298 if (Failed
== true && _config
->FindB("APT::Get::Fix-Missing",false) == false)
299 return _error
->Error(_("Some files failed to download"));
300 c1out
<< _("Download complete and in download only mode") << std::endl
;
304 if (Failed
== true && _config
->FindB("APT::Get::Fix-Missing",false) == false)
306 return _error
->Error(_("Unable to fetch some archives, maybe run apt-get update or try with --fix-missing?"));
309 if (Transient
== true && Failed
== true)
310 return _error
->Error(_("--fix-missing and media swapping is not currently supported"));
312 // Try to deal with missing package files
313 if (Failed
== true && PM
->FixMissing() == false)
315 c2out
<< _("Unable to correct missing packages.") << std::endl
;
316 return _error
->Error(_("Aborting install."));
321 APT::Progress::PackageManager
*progress
= APT::Progress::PackageManagerProgressFactory();
322 pkgPackageManager::OrderResult Res
= PM
->DoInstall(progress
);
325 if (Res
== pkgPackageManager::Failed
|| _error
->PendingError() == true)
327 if (Res
== pkgPackageManager::Completed
)
330 // Reload the fetcher object and loop again for media swapping
332 if (PM
->GetArchives(&Fetcher
,List
,&Recs
) == false)
338 std::set
<std::string
> const disappearedPkgs
= PM
->GetDisappearedPackages();
339 if (disappearedPkgs
.empty() == false)
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()), disappearedPkgs
,
345 [](std::string
const &Pkg
) { return Pkg
.empty() == false; },
346 [](std::string
const &Pkg
) { return Pkg
; },
347 [](std::string
const &) { return std::string(); });
348 c0out
<< _("Note: This is done automatically and on purpose by dpkg.") << std::endl
;
354 // DoAutomaticRemove - Remove all automatic unused packages /*{{{*/
355 // ---------------------------------------------------------------------
356 /* Remove unused automatic packages */
357 static bool DoAutomaticRemove(CacheFile
&Cache
)
359 bool Debug
= _config
->FindI("Debug::pkgAutoRemove",false);
360 bool doAutoRemove
= _config
->FindB("APT::Get::AutomaticRemove", false);
361 bool hideAutoRemove
= _config
->FindB("APT::Get::HideAutoRemove");
363 pkgDepCache::ActionGroup
group(*Cache
);
365 std::cout
<< "DoAutomaticRemove()" << std::endl
;
367 if (doAutoRemove
== true &&
368 _config
->FindB("APT::Get::Remove",true) == false)
370 c1out
<< _("We are not supposed to delete stuff, can't start "
371 "AutoRemover") << std::endl
;
375 bool purgePkgs
= _config
->FindB("APT::Get::Purge", false);
376 bool smallList
= (hideAutoRemove
== false &&
377 strcasecmp(_config
->Find("APT::Get::HideAutoRemove","").c_str(),"small") == 0);
379 unsigned long autoRemoveCount
= 0;
380 APT::PackageSet tooMuch
;
381 SortedPackageUniverse
Universe(Cache
);
382 // look over the cache to see what can be removed
383 for (auto const &Pkg
: Universe
)
385 if (Cache
[Pkg
].Garbage
)
387 if(Pkg
.CurrentVer() != 0 || Cache
[Pkg
].Install())
389 std::cout
<< "We could delete %s" << Pkg
.FullName(true).c_str() << std::endl
;
393 if(Pkg
.CurrentVer() != 0 &&
394 Pkg
->CurrentState
!= pkgCache::State::ConfigFiles
)
395 Cache
->MarkDelete(Pkg
, purgePkgs
, 0, false);
397 Cache
->MarkKeep(Pkg
, false, false);
401 // if the package is a new install and already garbage we don't need to
402 // install it in the first place, so nuke it instead of show it
403 if (Cache
[Pkg
].Install() == true && Pkg
.CurrentVer() == 0)
405 if (Pkg
.CandVersion() != 0)
407 Cache
->MarkDelete(Pkg
, false, 0, false);
409 // only show stuff in the list that is not yet marked for removal
410 else if(hideAutoRemove
== false && Cache
[Pkg
].Delete() == false)
416 // we could have removed a new dependency of a garbage package,
417 // so check if a reverse depends is broken and if so install it again.
418 if (tooMuch
.empty() == false && (Cache
->BrokenCount() != 0 || Cache
->PolicyBrokenCount() != 0))
423 for (APT::PackageSet::iterator Pkg
= tooMuch
.begin();
424 Pkg
!= tooMuch
.end(); ++Pkg
)
428 for (pkgCache::PrvIterator Prv
= Cache
[Pkg
].CandidateVerIter(Cache
).ProvidesList();
429 Prv
.end() == false; ++Prv
)
430 too
.insert(Prv
.ParentPkg());
431 for (APT::PackageSet::const_iterator P
= too
.begin(); P
!= too
.end(); ++P
)
433 for (pkgCache::DepIterator R
= P
.RevDependsList();
434 R
.end() == false; ++R
)
436 if (R
.IsNegative() == true ||
437 Cache
->IsImportantDep(R
) == false)
439 pkgCache::PkgIterator N
= R
.ParentPkg();
440 if (N
.end() == true || (N
->CurrentVer
== 0 && (*Cache
)[N
].Install() == false))
443 std::clog
<< "Save " << Pkg
<< " as another installed garbage package depends on it" << std::endl
;
444 Cache
->MarkInstall(Pkg
, false, 0, false);
445 if (hideAutoRemove
== false)
457 } while (Changed
== true);
460 // Now see if we had destroyed anything (if we had done anything)
461 if (Cache
->BrokenCount() != 0)
463 c1out
<< _("Hmm, seems like the AutoRemover destroyed something which really\n"
464 "shouldn't happen. Please file a bug report against apt.") << std::endl
;
466 c1out
<< _("The following information may help to resolve the situation:") << std::endl
;
468 ShowBroken(c1out
,Cache
,false);
470 return _error
->Error(_("Internal Error, AutoRemover broke stuff"));
473 // if we don't remove them, we should show them!
474 if (doAutoRemove
== false && autoRemoveCount
!= 0)
476 if (smallList
== false)
478 SortedPackageUniverse
Universe(Cache
);
479 ShowList(c1out
, P_("The following package was automatically installed and is no longer required:",
480 "The following packages were automatically installed and are no longer required:",
481 autoRemoveCount
), Universe
,
482 [&Cache
](pkgCache::PkgIterator
const &Pkg
) { return (*Cache
)[Pkg
].Garbage
== true && (*Cache
)[Pkg
].Delete() == false; },
483 &PrettyFullName
, CandidateVersion(&Cache
));
486 ioprintf(c1out
, P_("%lu package was automatically installed and is no longer required.\n",
487 "%lu packages were automatically installed and are no longer required.\n", autoRemoveCount
), autoRemoveCount
);
488 c1out
<< P_("Use 'apt-get autoremove' to remove it.", "Use 'apt-get autoremove' to remove them.", autoRemoveCount
) << std::endl
;
493 // DoCacheManipulationFromCommandLine /*{{{*/
494 static const unsigned short MOD_REMOVE
= 1;
495 static const unsigned short MOD_INSTALL
= 2;
497 bool DoCacheManipulationFromCommandLine(CommandLine
&CmdL
, CacheFile
&Cache
, int UpgradeMode
)
499 std::map
<unsigned short, APT::VersionSet
> verset
;
500 return DoCacheManipulationFromCommandLine(CmdL
, Cache
, verset
, UpgradeMode
);
502 bool DoCacheManipulationFromCommandLine(CommandLine
&CmdL
, CacheFile
&Cache
,
503 std::map
<unsigned short, APT::VersionSet
> &verset
, int UpgradeMode
)
505 // Enter the special broken fixing mode if the user specified arguments
506 bool BrokenFix
= false;
507 if (Cache
->BrokenCount() != 0)
510 std::unique_ptr
<pkgProblemResolver
> Fix(nullptr);
511 if (_config
->FindB("APT::Get::CallResolver", true) == true)
512 Fix
.reset(new pkgProblemResolver(Cache
));
514 unsigned short fallback
= MOD_INSTALL
;
515 if (strcasecmp(CmdL
.FileList
[0],"remove") == 0)
516 fallback
= MOD_REMOVE
;
517 else if (strcasecmp(CmdL
.FileList
[0], "purge") == 0)
519 _config
->Set("APT::Get::Purge", true);
520 fallback
= MOD_REMOVE
;
522 else if (strcasecmp(CmdL
.FileList
[0], "autoremove") == 0 ||
523 strcasecmp(CmdL
.FileList
[0], "auto-remove") == 0)
525 _config
->Set("APT::Get::AutomaticRemove", "true");
526 fallback
= MOD_REMOVE
;
529 std::list
<APT::VersionSet::Modifier
> mods
;
530 mods
.push_back(APT::VersionSet::Modifier(MOD_INSTALL
, "+",
531 APT::VersionSet::Modifier::POSTFIX
, APT::CacheSetHelper::CANDIDATE
));
532 mods
.push_back(APT::VersionSet::Modifier(MOD_REMOVE
, "-",
533 APT::VersionSet::Modifier::POSTFIX
, APT::CacheSetHelper::NEWEST
));
534 CacheSetHelperAPTGet
helper(c0out
);
535 verset
= APT::VersionSet::GroupedFromCommandLine(Cache
,
536 CmdL
.FileList
+ 1, mods
, fallback
, helper
);
538 if (_error
->PendingError() == true)
540 helper
.showVirtualPackageErrors(Cache
);
545 TryToInstall
InstallAction(Cache
, Fix
.get(), BrokenFix
);
546 TryToRemove
RemoveAction(Cache
, Fix
.get());
548 // new scope for the ActionGroup
550 pkgDepCache::ActionGroup
group(Cache
);
551 unsigned short const order
[] = { MOD_REMOVE
, MOD_INSTALL
, 0 };
553 for (unsigned short i
= 0; order
[i
] != 0; ++i
)
555 if (order
[i
] == MOD_INSTALL
)
556 InstallAction
= std::for_each(verset
[MOD_INSTALL
].begin(), verset
[MOD_INSTALL
].end(), InstallAction
);
557 else if (order
[i
] == MOD_REMOVE
)
558 RemoveAction
= std::for_each(verset
[MOD_REMOVE
].begin(), verset
[MOD_REMOVE
].end(), RemoveAction
);
561 if (Fix
!= NULL
&& _config
->FindB("APT::Get::AutoSolving", true) == true)
563 for (unsigned short i
= 0; order
[i
] != 0; ++i
)
565 if (order
[i
] != MOD_INSTALL
)
567 InstallAction
.propergateReleaseCandiateSwitching(helper
.selectedByRelease
, c0out
);
568 InstallAction
.doAutoInstall();
572 if (_error
->PendingError() == true)
577 /* If we are in the Broken fixing mode we do not attempt to fix the
578 problems. This is if the user invoked install without -f and gave
580 if (BrokenFix
== true && Cache
->BrokenCount() != 0)
582 c1out
<< _("You might want to run 'apt-get -f install' to correct these:") << std::endl
;
583 ShowBroken(c1out
,Cache
,false);
584 return _error
->Error(_("Unmet dependencies. Try 'apt-get -f install' with no packages (or specify a solution)."));
589 // Call the scored problem resolver
590 OpTextProgress
Progress(*_config
);
591 bool const distUpgradeMode
= strcmp(CmdL
.FileList
[0], "dist-upgrade") == 0 || strcmp(CmdL
.FileList
[0], "full-upgrade") == 0;
593 bool resolver_fail
= false;
594 if (distUpgradeMode
== true || UpgradeMode
!= APT::Upgrade::ALLOW_EVERYTHING
)
595 resolver_fail
= APT::Upgrade::Upgrade(Cache
, UpgradeMode
, &Progress
);
597 resolver_fail
= Fix
->Resolve(true, &Progress
);
599 if (resolver_fail
== false && Cache
->BrokenCount() == 0)
603 // Now we check the state of the packages,
604 if (Cache
->BrokenCount() != 0)
607 _("Some packages could not be installed. This may mean that you have\n"
608 "requested an impossible situation or if you are using the unstable\n"
609 "distribution that some required packages have not yet been created\n"
610 "or been moved out of Incoming.") << std::endl
;
616 _("Since you only requested a single operation it is extremely likely that\n"
617 "the package is simply not installable and a bug report against\n"
618 "that package should be filed.") << std::endl;
622 c1out
<< _("The following information may help to resolve the situation:") << std::endl
;
624 ShowBroken(c1out
,Cache
,false);
625 if (_error
->PendingError() == true)
628 return _error
->Error(_("Broken packages"));
631 if (!DoAutomaticRemove(Cache
))
634 // if nothing changed in the cache, but only the automark information
635 // we write the StateFile here, otherwise it will be written in
637 if (InstallAction
.AutoMarkChanged
> 0 &&
638 Cache
->DelCount() == 0 && Cache
->InstCount() == 0 &&
639 Cache
->BadCount() == 0 &&
640 _config
->FindB("APT::Get::Simulate",false) == false)
641 Cache
->writeStateFile(NULL
);
646 // DoInstall - Install packages from the command line /*{{{*/
647 // ---------------------------------------------------------------------
648 /* Install named packages */
649 struct PkgIsExtraInstalled
{
650 pkgCacheFile
* const Cache
;
651 APT::VersionSet
const * const verset
;
652 PkgIsExtraInstalled(pkgCacheFile
* const Cache
, APT::VersionSet
const * const Container
) : Cache(Cache
), verset(Container
) {}
653 bool operator() (pkgCache::PkgIterator
const Pkg
)
655 if ((*Cache
)[Pkg
].Install() == false)
657 pkgCache::VerIterator
const Cand
= (*Cache
)[Pkg
].CandidateVerIter(*Cache
);
658 return verset
->find(Cand
) == verset
->end();
661 bool DoInstall(CommandLine
&CmdL
)
664 // first check for local pkgs and add them to the cache
665 for (const char **I
= CmdL
.FileList
; *I
!= 0; I
++)
667 if(FileExists(*I
) && flExtension(*I
) == "deb")
668 Cache
.GetSourceList()->AddVolatileFile(new debDebPkgFileIndex(*I
));
671 // then open the cache
672 if (Cache
.OpenForInstall() == false ||
673 Cache
.CheckDeps(CmdL
.FileSize() != 1) == false)
676 std::map
<unsigned short, APT::VersionSet
> verset
;
678 if(!DoCacheManipulationFromCommandLine(CmdL
, Cache
, verset
, 0))
681 /* Print out a list of packages that are going to be installed extra
682 to what the user asked */
683 SortedPackageUniverse
Universe(Cache
);
684 if (Cache
->InstCount() != verset
[MOD_INSTALL
].size())
685 ShowList(c1out
, _("The following extra packages will be installed:"), Universe
,
686 PkgIsExtraInstalled(&Cache
, &verset
[MOD_INSTALL
]),
687 &PrettyFullName
, CandidateVersion(&Cache
));
689 /* Print out a list of suggested and recommended packages */
691 std::list
<std::string
> Recommends
, Suggests
, SingleRecommends
, SingleSuggests
;
692 for (auto const &Pkg
: Universe
)
694 /* Just look at the ones we want to install */
695 if ((*Cache
)[Pkg
].Install() == false)
698 // get the recommends/suggests for the candidate ver
699 pkgCache::VerIterator CV
= (*Cache
)[Pkg
].CandidateVerIter(*Cache
);
700 for (pkgCache::DepIterator D
= CV
.DependsList(); D
.end() == false; )
702 pkgCache::DepIterator Start
;
703 pkgCache::DepIterator End
;
704 D
.GlobOr(Start
,End
); // advances D
705 if (Start
->Type
!= pkgCache::Dep::Recommends
&& Start
->Type
!= pkgCache::Dep::Suggests
)
709 // Skip if we already saw this
711 for (pkgCache::DepIterator I
= Start
; I
!= D
; ++I
)
713 if (target
.empty() == false)
714 target
.append(" | ");
715 target
.append(I
.TargetPkg().FullName(true));
717 std::list
<std::string
> &Type
= Start
->Type
== pkgCache::Dep::Recommends
? SingleRecommends
: SingleSuggests
;
718 if (std::find(Type
.begin(), Type
.end(), target
) != Type
.end())
720 Type
.push_back(target
);
723 std::list
<std::string
> OrList
;
724 bool foundInstalledInOrGroup
= false;
725 for (pkgCache::DepIterator I
= Start
; I
!= D
; ++I
)
728 // satisfying package is installed and not marked for deletion
729 APT::VersionList installed
= APT::VersionList::FromDependency(Cache
, I
, APT::CacheSetHelper::INSTALLED
);
730 if (std::find_if(installed
.begin(), installed
.end(),
731 [&Cache
](pkgCache::VerIterator
const &Ver
) { return Cache
[Ver
.ParentPkg()].Delete() == false; }) != installed
.end())
733 foundInstalledInOrGroup
= true;
739 // satisfying package is upgraded to/new install
740 APT::VersionList upgrades
= APT::VersionList::FromDependency(Cache
, I
, APT::CacheSetHelper::CANDIDATE
);
741 if (std::find_if(upgrades
.begin(), upgrades
.end(),
742 [&Cache
](pkgCache::VerIterator
const &Ver
) { return Cache
[Ver
.ParentPkg()].Upgrade(); }) != upgrades
.end())
744 foundInstalledInOrGroup
= true;
750 OrList
.push_back(I
.TargetPkg().FullName(true));
752 OrList
.push_back("| " + I
.TargetPkg().FullName(true));
755 if(foundInstalledInOrGroup
== false)
757 std::list
<std::string
> &Type
= Start
->Type
== pkgCache::Dep::Recommends
? Recommends
: Suggests
;
758 std::move(OrList
.begin(), OrList
.end(), std::back_inserter(Type
));
762 auto always_true
= [](std::string
const&) { return true; };
763 auto string_ident
= [](std::string
const&str
) { return str
; };
764 auto verbose_show_candidate
=
765 [&Cache
](std::string str
)
767 if (APT::String::Startswith(str
, "| "))
769 pkgCache::PkgIterator
const Pkg
= Cache
->FindPkg(str
);
770 if (Pkg
.end() == true)
772 return (*Cache
)[Pkg
].CandVersion
;
774 ShowList(c1out
,_("Suggested packages:"), Suggests
,
775 always_true
, string_ident
, verbose_show_candidate
);
776 ShowList(c1out
,_("Recommended packages:"), Recommends
,
777 always_true
, string_ident
, verbose_show_candidate
);
780 // See if we need to prompt
781 // FIXME: check if really the packages in the set are going to be installed
782 if (Cache
->InstCount() == verset
[MOD_INSTALL
].size() && Cache
->DelCount() == 0)
783 return InstallPackages(Cache
,false,false);
785 return InstallPackages(Cache
,false);
789 // TryToInstall - Mark a package for installation /*{{{*/
790 void TryToInstall::operator() (pkgCache::VerIterator
const &Ver
) {
791 pkgCache::PkgIterator Pkg
= Ver
.ParentPkg();
793 Cache
->GetDepCache()->SetCandidateVersion(Ver
);
794 pkgDepCache::StateCache
&State
= (*Cache
)[Pkg
];
796 // Handle the no-upgrade case
797 if (_config
->FindB("APT::Get::upgrade",true) == false && Pkg
->CurrentVer
!= 0)
798 ioprintf(c1out
,_("Skipping %s, it is already installed and upgrade is not set.\n"),
799 Pkg
.FullName(true).c_str());
800 // Ignore request for install if package would be new
801 else if (_config
->FindB("APT::Get::Only-Upgrade", false) == true && Pkg
->CurrentVer
== 0)
802 ioprintf(c1out
,_("Skipping %s, it is not installed and only upgrades are requested.\n"),
803 Pkg
.FullName(true).c_str());
809 Cache
->GetDepCache()->MarkInstall(Pkg
,false);
811 if (State
.Install() == false) {
812 if (_config
->FindB("APT::Get::ReInstall",false) == true) {
813 if (Pkg
->CurrentVer
== 0 || Pkg
.CurrentVer().Downloadable() == false)
814 ioprintf(c1out
,_("Reinstallation of %s is not possible, it cannot be downloaded.\n"),
815 Pkg
.FullName(true).c_str());
817 Cache
->GetDepCache()->SetReInstall(Pkg
, true);
819 ioprintf(c1out
,_("%s is already the newest version.\n"),
820 Pkg
.FullName(true).c_str());
823 // Install it with autoinstalling enabled (if we not respect the minial
824 // required deps or the policy)
825 if (FixBroken
== false)
826 doAutoInstallLater
.insert(Pkg
);
829 // see if we need to fix the auto-mark flag
830 // e.g. apt-get install foo
831 // where foo is marked automatic
832 if (State
.Install() == false &&
833 (State
.Flags
& pkgCache::Flag::Auto
) &&
834 _config
->FindB("APT::Get::ReInstall",false) == false &&
835 _config
->FindB("APT::Get::Only-Upgrade",false) == false &&
836 _config
->FindB("APT::Get::Download-Only",false) == false)
838 ioprintf(c1out
,_("%s set to manually installed.\n"),
839 Pkg
.FullName(true).c_str());
840 Cache
->GetDepCache()->MarkAuto(Pkg
,false);
845 bool TryToInstall::propergateReleaseCandiateSwitching(std::list
<std::pair
<pkgCache::VerIterator
, std::string
> > const &start
, std::ostream
&out
)/*{{{*/
847 for (std::list
<std::pair
<pkgCache::VerIterator
, std::string
> >::const_iterator s
= start
.begin();
848 s
!= start
.end(); ++s
)
849 Cache
->GetDepCache()->SetCandidateVersion(s
->first
);
852 // the Changed list contains:
853 // first: "new version"
854 // second: "what-caused the change"
855 std::list
<std::pair
<pkgCache::VerIterator
, pkgCache::VerIterator
> > Changed
;
856 for (std::list
<std::pair
<pkgCache::VerIterator
, std::string
> >::const_iterator s
= start
.begin();
857 s
!= start
.end(); ++s
)
859 Changed
.push_back(std::make_pair(s
->first
, pkgCache::VerIterator(*Cache
)));
860 // We continue here even if it failed to enhance the ShowBroken output
861 Success
&= Cache
->GetDepCache()->SetCandidateRelease(s
->first
, s
->second
, Changed
);
863 for (std::list
<std::pair
<pkgCache::VerIterator
, pkgCache::VerIterator
> >::const_iterator c
= Changed
.begin();
864 c
!= Changed
.end(); ++c
)
866 if (c
->second
.end() == true)
867 ioprintf(out
, _("Selected version '%s' (%s) for '%s'\n"),
868 c
->first
.VerStr(), c
->first
.RelStr().c_str(), c
->first
.ParentPkg().FullName(true).c_str());
869 else if (c
->first
.ParentPkg()->Group
!= c
->second
.ParentPkg()->Group
)
871 pkgCache::VerIterator V
= (*Cache
)[c
->first
.ParentPkg()].CandidateVerIter(*Cache
);
872 ioprintf(out
, _("Selected version '%s' (%s) for '%s' because of '%s'\n"), V
.VerStr(),
873 V
.RelStr().c_str(), V
.ParentPkg().FullName(true).c_str(), c
->second
.ParentPkg().FullName(true).c_str());
879 void TryToInstall::doAutoInstall() { /*{{{*/
880 for (APT::PackageSet::const_iterator P
= doAutoInstallLater
.begin();
881 P
!= doAutoInstallLater
.end(); ++P
) {
882 pkgDepCache::StateCache
&State
= (*Cache
)[P
];
883 if (State
.InstBroken() == false && State
.InstPolicyBroken() == false)
885 Cache
->GetDepCache()->MarkInstall(P
, true);
887 doAutoInstallLater
.clear();
890 // TryToRemove - Mark a package for removal /*{{{*/
891 void TryToRemove::operator() (pkgCache::VerIterator
const &Ver
)
893 pkgCache::PkgIterator Pkg
= Ver
.ParentPkg();
902 if ((Pkg
->CurrentVer
== 0 && PurgePkgs
== false) ||
903 (PurgePkgs
== true && Pkg
->CurrentState
== pkgCache::State::NotInstalled
))
905 pkgCache::GrpIterator Grp
= Pkg
.Group();
906 pkgCache::PkgIterator P
= Grp
.PackageList();
907 for (; P
.end() != true; P
= Grp
.NextPkg(P
))
911 if (P
->CurrentVer
!= 0 || (PurgePkgs
== true && P
->CurrentState
!= pkgCache::State::NotInstalled
))
913 // TRANSLATORS: Note, this is not an interactive question
914 ioprintf(c1out
,_("Package '%s' is not installed, so not removed. Did you mean '%s'?\n"),
915 Pkg
.FullName(true).c_str(), P
.FullName(true).c_str());
920 ioprintf(c1out
,_("Package '%s' is not installed, so not removed\n"),Pkg
.FullName(true).c_str());
922 // MarkInstall refuses to install packages on hold
923 Pkg
->SelectedState
= pkgCache::State::Hold
;
926 Cache
->GetDepCache()->MarkDelete(Pkg
, PurgePkgs
);