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>
26 #include <sys/statfs.h>
27 #include <sys/statvfs.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_MAJOR >= 4 && APT_PKG_MINOR >= 13)
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
120 AcqTextStatus
Stat(ScreenWidth
,_config
->FindI("quiet",0));
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
.Setup(&Stat
, _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 /* Check for enough free space, but only if we are actually going to
179 if (_config
->FindB("APT::Get::Print-URIs") == false &&
180 _config
->FindB("APT::Get::Download",true) == true)
183 std::string OutputDir
= _config
->FindDir("Dir::Cache::Archives");
184 if (statvfs(OutputDir
.c_str(),&Buf
) != 0) {
185 if (errno
== EOVERFLOW
)
186 return _error
->WarningE("statvfs",_("Couldn't determine free space in %s"),
189 return _error
->Errno("statvfs",_("Couldn't determine free space in %s"),
191 } else if (unsigned(Buf
.f_bfree
) < (FetchBytes
- FetchPBytes
)/Buf
.f_bsize
)
194 if (statfs(OutputDir
.c_str(),&Stat
) != 0
195 #if HAVE_STRUCT_STATFS_F_TYPE
196 || unsigned(Stat
.f_type
) != RAMFS_MAGIC
199 return _error
->Error(_("You don't have enough free space in %s."),
205 if (_config
->FindI("quiet",0) >= 2 ||
206 _config
->FindB("APT::Get::Assume-Yes",false) == true)
208 if (Fail
== true && _config
->FindB("APT::Get::Force-Yes",false) == false)
209 return _error
->Error(_("There are problems and -y was used without --force-yes"));
212 if (Essential
== true && Safety
== true)
214 if (_config
->FindB("APT::Get::Trivial-Only",false) == true)
215 return _error
->Error(_("Trivial Only specified but this is not a trivial operation."));
217 // TRANSLATOR: This string needs to be typed by the user as a confirmation, so be
218 // careful with hard to type or special characters (like non-breaking spaces)
219 const char *Prompt
= _("Yes, do as I say!");
221 _("You are about to do something potentially harmful.\n"
222 "To continue type in the phrase '%s'\n"
225 if (AnalPrompt(Prompt
) == false)
227 c2out
<< _("Abort.") << std::endl
;
233 // Prompt to continue
234 if (Ask
== true || Fail
== true)
236 if (_config
->FindB("APT::Get::Trivial-Only",false) == true)
237 return _error
->Error(_("Trivial Only specified but this is not a trivial operation."));
239 if (_config
->FindI("quiet",0) < 2 &&
240 _config
->FindB("APT::Get::Assume-Yes",false) == false)
242 c2out
<< _("Do you want to continue?") << std::flush
;
243 if (YnPrompt() == false)
245 c2out
<< _("Abort.") << std::endl
;
252 // Just print out the uris an exit if the --print-uris flag was used
253 if (_config
->FindB("APT::Get::Print-URIs") == true)
255 pkgAcquire::UriIterator I
= Fetcher
.UriBegin();
256 for (; I
!= Fetcher
.UriEnd(); ++I
)
257 std::cout
<< '\'' << I
->URI
<< "' " << flNotDir(I
->Owner
->DestFile
) << ' ' <<
258 I
->Owner
->FileSize
<< ' ' << I
->Owner
->HashSum() << std::endl
;
262 if (!CheckAuth(Fetcher
, true))
265 /* Unlock the dpkg lock if we are not going to be doing an install
267 if (_config
->FindB("APT::Get::Download-Only",false) == true)
273 bool Transient
= false;
274 if (_config
->FindB("APT::Get::Download",true) == false)
276 for (pkgAcquire::ItemIterator I
= Fetcher
.ItemsBegin(); I
< Fetcher
.ItemsEnd();)
278 if ((*I
)->Local
== true)
284 // Close the item and check if it was found in cache
286 if ((*I
)->Complete
== false)
289 // Clear it out of the fetch list
291 I
= Fetcher
.ItemsBegin();
296 if (AcquireRun(Fetcher
, 0, &Failed
, &Transient
) == false)
299 /* If we are in no download mode and missing files and there were
300 'failures' then the user must specify -m. Furthermore, there
301 is no such thing as a transient error in no-download mode! */
302 if (Transient
== true &&
303 _config
->FindB("APT::Get::Download",true) == false)
309 if (_config
->FindB("APT::Get::Download-Only",false) == true)
311 if (Failed
== true && _config
->FindB("APT::Get::Fix-Missing",false) == false)
312 return _error
->Error(_("Some files failed to download"));
313 c1out
<< _("Download complete and in download only mode") << std::endl
;
317 if (Failed
== true && _config
->FindB("APT::Get::Fix-Missing",false) == false)
319 return _error
->Error(_("Unable to fetch some archives, maybe run apt-get update or try with --fix-missing?"));
322 if (Transient
== true && Failed
== true)
323 return _error
->Error(_("--fix-missing and media swapping is not currently supported"));
325 // Try to deal with missing package files
326 if (Failed
== true && PM
->FixMissing() == false)
328 c2out
<< _("Unable to correct missing packages.") << std::endl
;
329 return _error
->Error(_("Aborting install."));
334 #if (APT_PKG_MAJOR >= 4 && APT_PKG_MINOR >= 13)
335 APT::Progress::PackageManager
*progress
= APT::Progress::PackageManagerProgressFactory();
336 pkgPackageManager::OrderResult Res
= PM
->DoInstall(progress
);
339 int status_fd
= _config
->FindI("APT::Status-Fd", -1);
340 pkgPackageManager::OrderResult Res
= PM
->DoInstall(status_fd
);
343 if (Res
== pkgPackageManager::Failed
|| _error
->PendingError() == true)
345 if (Res
== pkgPackageManager::Completed
)
348 // Reload the fetcher object and loop again for media swapping
350 if (PM
->GetArchives(&Fetcher
,List
,&Recs
) == false)
356 std::set
<std::string
> const disappearedPkgs
= PM
->GetDisappearedPackages();
357 if (disappearedPkgs
.empty() == true)
360 std::string disappear
;
361 for (std::set
<std::string
>::const_iterator d
= disappearedPkgs
.begin();
362 d
!= disappearedPkgs
.end(); ++d
)
363 disappear
.append(*d
).append(" ");
365 ShowList(c1out
, P_("The following package disappeared from your system as\n"
366 "all files have been overwritten by other packages:",
367 "The following packages disappeared from your system as\n"
368 "all files have been overwritten by other packages:", disappearedPkgs
.size()), disappear
, "");
369 c0out
<< _("Note: This is done automatically and on purpose by dpkg.") << std::endl
;
374 // DoAutomaticRemove - Remove all automatic unused packages /*{{{*/
375 // ---------------------------------------------------------------------
376 /* Remove unused automatic packages */
377 static bool DoAutomaticRemove(CacheFile
&Cache
)
379 bool Debug
= _config
->FindI("Debug::pkgAutoRemove",false);
380 bool doAutoRemove
= _config
->FindB("APT::Get::AutomaticRemove", false);
381 bool hideAutoRemove
= _config
->FindB("APT::Get::HideAutoRemove");
383 pkgDepCache::ActionGroup
group(*Cache
);
385 std::cout
<< "DoAutomaticRemove()" << std::endl
;
387 if (doAutoRemove
== true &&
388 _config
->FindB("APT::Get::Remove",true) == false)
390 c1out
<< _("We are not supposed to delete stuff, can't start "
391 "AutoRemover") << std::endl
;
395 bool purgePkgs
= _config
->FindB("APT::Get::Purge", false);
396 bool smallList
= (hideAutoRemove
== false &&
397 strcasecmp(_config
->Find("APT::Get::HideAutoRemove","").c_str(),"small") == 0);
399 unsigned long autoRemoveCount
= 0;
400 APT::PackageSet tooMuch
;
401 APT::PackageList autoRemoveList
;
402 // look over the cache to see what can be removed
403 for (unsigned J
= 0; J
< Cache
->Head().PackageCount
; ++J
)
405 pkgCache::PkgIterator
Pkg(Cache
,Cache
.List
[J
]);
406 if (Cache
[Pkg
].Garbage
)
408 if(Pkg
.CurrentVer() != 0 || Cache
[Pkg
].Install())
410 std::cout
<< "We could delete %s" << Pkg
.FullName(true).c_str() << std::endl
;
414 if(Pkg
.CurrentVer() != 0 &&
415 Pkg
->CurrentState
!= pkgCache::State::ConfigFiles
)
416 Cache
->MarkDelete(Pkg
, purgePkgs
, 0, false);
418 Cache
->MarkKeep(Pkg
, false, false);
422 if (hideAutoRemove
== false && Cache
[Pkg
].Delete() == false)
423 autoRemoveList
.insert(Pkg
);
424 // if the package is a new install and already garbage we don't need to
425 // install it in the first place, so nuke it instead of show it
426 if (Cache
[Pkg
].Install() == true && Pkg
.CurrentVer() == 0)
428 if (Pkg
.CandVersion() != 0)
430 Cache
->MarkDelete(Pkg
, false, 0, false);
432 // only show stuff in the list that is not yet marked for removal
433 else if(hideAutoRemove
== false && Cache
[Pkg
].Delete() == false)
439 // we could have removed a new dependency of a garbage package,
440 // so check if a reverse depends is broken and if so install it again.
441 if (tooMuch
.empty() == false && (Cache
->BrokenCount() != 0 || Cache
->PolicyBrokenCount() != 0))
446 for (APT::PackageSet::const_iterator Pkg
= tooMuch
.begin();
447 Pkg
!= tooMuch
.end(); ++Pkg
)
451 for (pkgCache::PrvIterator Prv
= Cache
[Pkg
].CandidateVerIter(Cache
).ProvidesList();
452 Prv
.end() == false; ++Prv
)
453 too
.insert(Prv
.ParentPkg());
454 for (APT::PackageSet::const_iterator P
= too
.begin(); P
!= too
.end(); ++P
)
456 for (pkgCache::DepIterator R
= P
.RevDependsList();
457 R
.end() == false; ++R
)
459 if (R
.IsNegative() == true ||
460 Cache
->IsImportantDep(R
) == false)
462 pkgCache::PkgIterator N
= R
.ParentPkg();
463 if (N
.end() == true || (N
->CurrentVer
== 0 && (*Cache
)[N
].Install() == false))
466 std::clog
<< "Save " << Pkg
<< " as another installed garbage package depends on it" << std::endl
;
467 Cache
->MarkInstall(Pkg
, false, 0, false);
468 if (hideAutoRemove
== false)
480 } while (Changed
== true);
483 std::string autoremovelist
, autoremoveversions
;
484 if (smallList
== false && autoRemoveCount
!= 0)
486 for (APT::PackageList::const_iterator Pkg
= autoRemoveList
.begin(); Pkg
!= autoRemoveList
.end(); ++Pkg
)
488 if (Cache
[Pkg
].Garbage
== false)
490 autoremovelist
+= Pkg
.FullName(true) + " ";
491 autoremoveversions
+= std::string(Cache
[Pkg
].CandVersion
) + "\n";
495 // Now see if we had destroyed anything (if we had done anything)
496 if (Cache
->BrokenCount() != 0)
498 c1out
<< _("Hmm, seems like the AutoRemover destroyed something which really\n"
499 "shouldn't happen. Please file a bug report against apt.") << std::endl
;
501 c1out
<< _("The following information may help to resolve the situation:") << std::endl
;
503 ShowBroken(c1out
,Cache
,false);
505 return _error
->Error(_("Internal Error, AutoRemover broke stuff"));
508 // if we don't remove them, we should show them!
509 if (doAutoRemove
== false && (autoremovelist
.empty() == false || autoRemoveCount
!= 0))
511 if (smallList
== false)
512 ShowList(c1out
, P_("The following package was automatically installed and is no longer required:",
513 "The following packages were automatically installed and are no longer required:",
514 autoRemoveCount
), autoremovelist
, autoremoveversions
);
516 ioprintf(c1out
, P_("%lu package was automatically installed and is no longer required.\n",
517 "%lu packages were automatically installed and are no longer required.\n", autoRemoveCount
), autoRemoveCount
);
518 c1out
<< P_("Use 'apt-get autoremove' to remove it.", "Use 'apt-get autoremove' to remove them.", autoRemoveCount
) << std::endl
;
523 // DoCacheManipulationFromCommandLine /*{{{*/
524 static const unsigned short MOD_REMOVE
= 1;
525 static const unsigned short MOD_INSTALL
= 2;
527 bool DoCacheManipulationFromCommandLine(CommandLine
&CmdL
, CacheFile
&Cache
)
529 std::map
<unsigned short, APT::VersionSet
> verset
;
530 return DoCacheManipulationFromCommandLine(CmdL
, Cache
, verset
);
532 bool DoCacheManipulationFromCommandLine(CommandLine
&CmdL
, CacheFile
&Cache
,
533 std::map
<unsigned short, APT::VersionSet
> &verset
)
536 // Enter the special broken fixing mode if the user specified arguments
537 bool BrokenFix
= false;
538 if (Cache
->BrokenCount() != 0)
541 SPtr
<pkgProblemResolver
> Fix
;
542 if (_config
->FindB("APT::Get::CallResolver", true) == true)
543 Fix
= new pkgProblemResolver(Cache
);
545 unsigned short fallback
= MOD_INSTALL
;
546 if (strcasecmp(CmdL
.FileList
[0],"remove") == 0)
547 fallback
= MOD_REMOVE
;
548 else if (strcasecmp(CmdL
.FileList
[0], "purge") == 0)
550 _config
->Set("APT::Get::Purge", true);
551 fallback
= MOD_REMOVE
;
553 else if (strcasecmp(CmdL
.FileList
[0], "autoremove") == 0)
555 _config
->Set("APT::Get::AutomaticRemove", "true");
556 fallback
= MOD_REMOVE
;
559 std::list
<APT::VersionSet::Modifier
> mods
;
560 mods
.push_back(APT::VersionSet::Modifier(MOD_INSTALL
, "+",
561 APT::VersionSet::Modifier::POSTFIX
, APT::VersionSet::CANDIDATE
));
562 mods
.push_back(APT::VersionSet::Modifier(MOD_REMOVE
, "-",
563 APT::VersionSet::Modifier::POSTFIX
, APT::VersionSet::NEWEST
));
564 CacheSetHelperAPTGet
helper(c0out
);
565 verset
= APT::VersionSet::GroupedFromCommandLine(Cache
,
566 CmdL
.FileList
+ 1, mods
, fallback
, helper
);
568 if (_error
->PendingError() == true)
570 helper
.showVirtualPackageErrors(Cache
);
575 TryToInstall
InstallAction(Cache
, Fix
, BrokenFix
);
576 TryToRemove
RemoveAction(Cache
, Fix
);
578 // new scope for the ActionGroup
580 pkgDepCache::ActionGroup
group(Cache
);
581 unsigned short const order
[] = { MOD_REMOVE
, MOD_INSTALL
, 0 };
583 for (unsigned short i
= 0; order
[i
] != 0; ++i
)
585 if (order
[i
] == MOD_INSTALL
)
586 InstallAction
= std::for_each(verset
[MOD_INSTALL
].begin(), verset
[MOD_INSTALL
].end(), InstallAction
);
587 else if (order
[i
] == MOD_REMOVE
)
588 RemoveAction
= std::for_each(verset
[MOD_REMOVE
].begin(), verset
[MOD_REMOVE
].end(), RemoveAction
);
591 if (Fix
!= NULL
&& _config
->FindB("APT::Get::AutoSolving", true) == true)
593 for (unsigned short i
= 0; order
[i
] != 0; ++i
)
595 if (order
[i
] != MOD_INSTALL
)
597 InstallAction
.propergateReleaseCandiateSwitching(helper
.selectedByRelease
, c0out
);
598 InstallAction
.doAutoInstall();
602 if (_error
->PendingError() == true)
607 /* If we are in the Broken fixing mode we do not attempt to fix the
608 problems. This is if the user invoked install without -f and gave
610 if (BrokenFix
== true && Cache
->BrokenCount() != 0)
612 c1out
<< _("You might want to run 'apt-get -f install' to correct these:") << std::endl
;
613 ShowBroken(c1out
,Cache
,false);
614 return _error
->Error(_("Unmet dependencies. Try 'apt-get -f install' with no packages (or specify a solution)."));
619 // Call the scored problem resolver
620 if (Fix
->Resolve(true) == false && Cache
->BrokenCount() == 0)
624 // Now we check the state of the packages,
625 if (Cache
->BrokenCount() != 0)
628 _("Some packages could not be installed. This may mean that you have\n"
629 "requested an impossible situation or if you are using the unstable\n"
630 "distribution that some required packages have not yet been created\n"
631 "or been moved out of Incoming.") << std::endl
;
637 _("Since you only requested a single operation it is extremely likely that\n"
638 "the package is simply not installable and a bug report against\n"
639 "that package should be filed.") << std::endl;
643 c1out
<< _("The following information may help to resolve the situation:") << std::endl
;
645 ShowBroken(c1out
,Cache
,false);
646 if (_error
->PendingError() == true)
649 return _error
->Error(_("Broken packages"));
652 if (!DoAutomaticRemove(Cache
))
655 // if nothing changed in the cache, but only the automark information
656 // we write the StateFile here, otherwise it will be written in
658 if (InstallAction
.AutoMarkChanged
> 0 &&
659 Cache
->DelCount() == 0 && Cache
->InstCount() == 0 &&
660 Cache
->BadCount() == 0 &&
661 _config
->FindB("APT::Get::Simulate",false) == false)
662 Cache
->writeStateFile(NULL
);
667 // DoInstall - Install packages from the command line /*{{{*/
668 // ---------------------------------------------------------------------
669 /* Install named packages */
670 bool DoInstall(CommandLine
&CmdL
)
673 if (Cache
.OpenForInstall() == false ||
674 Cache
.CheckDeps(CmdL
.FileSize() != 1) == false)
677 std::map
<unsigned short, APT::VersionSet
> verset
;
679 if(!DoCacheManipulationFromCommandLine(CmdL
, Cache
, verset
))
682 /* Print out a list of packages that are going to be installed extra
683 to what the user asked */
684 if (Cache
->InstCount() != verset
[MOD_INSTALL
].size())
687 std::string VersionsList
;
688 for (unsigned J
= 0; J
< Cache
->Head().PackageCount
; J
++)
690 pkgCache::PkgIterator
I(Cache
,Cache
.List
[J
]);
691 if ((*Cache
)[I
].Install() == false)
693 pkgCache::VerIterator Cand
= Cache
[I
].CandidateVerIter(Cache
);
695 if (verset
[MOD_INSTALL
].find(Cand
) != verset
[MOD_INSTALL
].end())
698 List
+= I
.FullName(true) + " ";
699 VersionsList
+= std::string(Cache
[I
].CandVersion
) + "\n";
702 ShowList(c1out
,_("The following extra packages will be installed:"),List
,VersionsList
);
705 /* Print out a list of suggested and recommended packages */
707 std::string SuggestsList
, RecommendsList
;
708 std::string SuggestsVersions
, RecommendsVersions
;
709 for (unsigned J
= 0; J
< Cache
->Head().PackageCount
; J
++)
711 pkgCache::PkgIterator
Pkg(Cache
,Cache
.List
[J
]);
713 /* Just look at the ones we want to install */
714 if ((*Cache
)[Pkg
].Install() == false)
717 // get the recommends/suggests for the candidate ver
718 pkgCache::VerIterator CV
= (*Cache
)[Pkg
].CandidateVerIter(*Cache
);
719 for (pkgCache::DepIterator D
= CV
.DependsList(); D
.end() == false; )
721 pkgCache::DepIterator Start
;
722 pkgCache::DepIterator End
;
723 D
.GlobOr(Start
,End
); // advances D
725 // FIXME: we really should display a or-group as a or-group to the user
726 // the problem is that ShowList is incapable of doing this
727 std::string RecommendsOrList
,RecommendsOrVersions
;
728 std::string SuggestsOrList
,SuggestsOrVersions
;
729 bool foundInstalledInOrGroup
= false;
732 /* Skip if package is installed already, or is about to be */
733 std::string target
= Start
.TargetPkg().FullName(true) + " ";
734 pkgCache::PkgIterator
const TarPkg
= Start
.TargetPkg();
735 if (TarPkg
->SelectedState
== pkgCache::State::Install
||
736 TarPkg
->SelectedState
== pkgCache::State::Hold
||
737 Cache
[Start
.TargetPkg()].Install())
739 foundInstalledInOrGroup
=true;
743 /* Skip if we already saw it */
744 if (int(SuggestsList
.find(target
)) != -1 || int(RecommendsList
.find(target
)) != -1)
746 foundInstalledInOrGroup
=true;
750 // this is a dep on a virtual pkg, check if any package that provides it
751 // should be installed
752 if(Start
.TargetPkg().ProvidesList() != 0)
754 pkgCache::PrvIterator I
= Start
.TargetPkg().ProvidesList();
755 for (; I
.end() == false; ++I
)
757 pkgCache::PkgIterator Pkg
= I
.OwnerPkg();
758 if (Cache
[Pkg
].CandidateVerIter(Cache
) == I
.OwnerVer() &&
759 Pkg
.CurrentVer() != 0)
760 foundInstalledInOrGroup
=true;
764 if (Start
->Type
== pkgCache::Dep::Suggests
)
766 SuggestsOrList
+= target
;
767 SuggestsOrVersions
+= std::string(Cache
[Start
.TargetPkg()].CandVersion
) + "\n";
770 if (Start
->Type
== pkgCache::Dep::Recommends
)
772 RecommendsOrList
+= target
;
773 RecommendsOrVersions
+= std::string(Cache
[Start
.TargetPkg()].CandVersion
) + "\n";
781 if(foundInstalledInOrGroup
== false)
783 RecommendsList
+= RecommendsOrList
;
784 RecommendsVersions
+= RecommendsOrVersions
;
785 SuggestsList
+= SuggestsOrList
;
786 SuggestsVersions
+= SuggestsOrVersions
;
792 ShowList(c1out
,_("Suggested packages:"),SuggestsList
,SuggestsVersions
);
793 ShowList(c1out
,_("Recommended packages:"),RecommendsList
,RecommendsVersions
);
797 // See if we need to prompt
798 // FIXME: check if really the packages in the set are going to be installed
799 if (Cache
->InstCount() == verset
[MOD_INSTALL
].size() && Cache
->DelCount() == 0)
800 return InstallPackages(Cache
,false,false);
802 return InstallPackages(Cache
,false);
806 // TryToInstall - Mark a package for installation /*{{{*/
807 void TryToInstall::operator() (pkgCache::VerIterator
const &Ver
) {
808 pkgCache::PkgIterator Pkg
= Ver
.ParentPkg();
810 Cache
->GetDepCache()->SetCandidateVersion(Ver
);
811 pkgDepCache::StateCache
&State
= (*Cache
)[Pkg
];
813 // Handle the no-upgrade case
814 if (_config
->FindB("APT::Get::upgrade",true) == false && Pkg
->CurrentVer
!= 0)
815 ioprintf(c1out
,_("Skipping %s, it is already installed and upgrade is not set.\n"),
816 Pkg
.FullName(true).c_str());
817 // Ignore request for install if package would be new
818 else if (_config
->FindB("APT::Get::Only-Upgrade", false) == true && Pkg
->CurrentVer
== 0)
819 ioprintf(c1out
,_("Skipping %s, it is not installed and only upgrades are requested.\n"),
820 Pkg
.FullName(true).c_str());
826 Cache
->GetDepCache()->MarkInstall(Pkg
,false);
828 if (State
.Install() == false) {
829 if (_config
->FindB("APT::Get::ReInstall",false) == true) {
830 if (Pkg
->CurrentVer
== 0 || Pkg
.CurrentVer().Downloadable() == false)
831 ioprintf(c1out
,_("Reinstallation of %s is not possible, it cannot be downloaded.\n"),
832 Pkg
.FullName(true).c_str());
834 Cache
->GetDepCache()->SetReInstall(Pkg
, true);
836 ioprintf(c1out
,_("%s is already the newest version.\n"),
837 Pkg
.FullName(true).c_str());
840 // Install it with autoinstalling enabled (if we not respect the minial
841 // required deps or the policy)
842 if (FixBroken
== false)
843 doAutoInstallLater
.insert(Pkg
);
846 // see if we need to fix the auto-mark flag
847 // e.g. apt-get install foo
848 // where foo is marked automatic
849 if (State
.Install() == false &&
850 (State
.Flags
& pkgCache::Flag::Auto
) &&
851 _config
->FindB("APT::Get::ReInstall",false) == false &&
852 _config
->FindB("APT::Get::Only-Upgrade",false) == false &&
853 _config
->FindB("APT::Get::Download-Only",false) == false)
855 ioprintf(c1out
,_("%s set to manually installed.\n"),
856 Pkg
.FullName(true).c_str());
857 Cache
->GetDepCache()->MarkAuto(Pkg
,false);
862 bool TryToInstall::propergateReleaseCandiateSwitching(std::list
<std::pair
<pkgCache::VerIterator
, std::string
> > const &start
, std::ostream
&out
)/*{{{*/
864 for (std::list
<std::pair
<pkgCache::VerIterator
, std::string
> >::const_iterator s
= start
.begin();
865 s
!= start
.end(); ++s
)
866 Cache
->GetDepCache()->SetCandidateVersion(s
->first
);
869 // the Changed list contains:
870 // first: "new version"
871 // second: "what-caused the change"
872 std::list
<std::pair
<pkgCache::VerIterator
, pkgCache::VerIterator
> > Changed
;
873 for (std::list
<std::pair
<pkgCache::VerIterator
, std::string
> >::const_iterator s
= start
.begin();
874 s
!= start
.end(); ++s
)
876 Changed
.push_back(std::make_pair(s
->first
, pkgCache::VerIterator(*Cache
)));
877 // We continue here even if it failed to enhance the ShowBroken output
878 Success
&= Cache
->GetDepCache()->SetCandidateRelease(s
->first
, s
->second
, Changed
);
880 for (std::list
<std::pair
<pkgCache::VerIterator
, pkgCache::VerIterator
> >::const_iterator c
= Changed
.begin();
881 c
!= Changed
.end(); ++c
)
883 if (c
->second
.end() == true)
884 ioprintf(out
, _("Selected version '%s' (%s) for '%s'\n"),
885 c
->first
.VerStr(), c
->first
.RelStr().c_str(), c
->first
.ParentPkg().FullName(true).c_str());
886 else if (c
->first
.ParentPkg()->Group
!= c
->second
.ParentPkg()->Group
)
888 pkgCache::VerIterator V
= (*Cache
)[c
->first
.ParentPkg()].CandidateVerIter(*Cache
);
889 ioprintf(out
, _("Selected version '%s' (%s) for '%s' because of '%s'\n"), V
.VerStr(),
890 V
.RelStr().c_str(), V
.ParentPkg().FullName(true).c_str(), c
->second
.ParentPkg().FullName(true).c_str());
896 void TryToInstall::doAutoInstall() { /*{{{*/
897 for (APT::PackageSet::const_iterator P
= doAutoInstallLater
.begin();
898 P
!= doAutoInstallLater
.end(); ++P
) {
899 pkgDepCache::StateCache
&State
= (*Cache
)[P
];
900 if (State
.InstBroken() == false && State
.InstPolicyBroken() == false)
902 Cache
->GetDepCache()->MarkInstall(P
, true);
904 doAutoInstallLater
.clear();
907 // TryToRemove - Mark a package for removal /*{{{*/
908 void TryToRemove::operator() (pkgCache::VerIterator
const &Ver
)
910 pkgCache::PkgIterator Pkg
= Ver
.ParentPkg();
919 if ((Pkg
->CurrentVer
== 0 && PurgePkgs
== false) ||
920 (PurgePkgs
== true && Pkg
->CurrentState
== pkgCache::State::NotInstalled
))
922 pkgCache::GrpIterator Grp
= Pkg
.Group();
923 pkgCache::PkgIterator P
= Grp
.PackageList();
924 for (; P
.end() != true; P
= Grp
.NextPkg(P
))
928 if (P
->CurrentVer
!= 0 || (PurgePkgs
== true && P
->CurrentState
!= pkgCache::State::NotInstalled
))
930 // TRANSLATORS: Note, this is not an interactive question
931 ioprintf(c1out
,_("Package '%s' is not installed, so not removed. Did you mean '%s'?\n"),
932 Pkg
.FullName(true).c_str(), P
.FullName(true).c_str());
937 ioprintf(c1out
,_("Package '%s' is not installed, so not removed\n"),Pkg
.FullName(true).c_str());
939 // MarkInstall refuses to install packages on hold
940 Pkg
->SelectedState
= pkgCache::State::Hold
;
943 Cache
->GetDepCache()->MarkDelete(Pkg
, PurgePkgs
);