1 // -*- mode: cpp; mode: fold -*-
3 // $Id: depcache.cc,v 1.25 2001/05/27 05:36:04 jgg Exp $
4 /* ######################################################################
6 Dependency Cache - Caches Dependency information.
8 ##################################################################### */
10 // Include Files /*{{{*/
11 #include <apt-pkg/depcache.h>
12 #include <apt-pkg/version.h>
13 #include <apt-pkg/error.h>
14 #include <apt-pkg/sptr.h>
15 #include <apt-pkg/algorithms.h>
17 #include <apt-pkg/fileutl.h>
18 #include <apt-pkg/strutl.h>
19 #include <apt-pkg/configuration.h>
20 #include <apt-pkg/aptconfiguration.h>
21 #include <apt-pkg/pkgsystem.h>
22 #include <apt-pkg/tagfile.h>
32 // helper for Install-Recommends-Sections and Never-MarkAuto-Sections /*{{{*/
34 ConfigValueInSubTree(const char* SubTree
, const char *needle
)
36 Configuration::Item
const *Opts
;
37 Opts
= _config
->Tree(SubTree
);
38 if (Opts
!= 0 && Opts
->Child
!= 0)
41 for (; Opts
!= 0; Opts
= Opts
->Next
)
43 if (Opts
->Value
.empty() == true)
45 if (strcmp(needle
, Opts
->Value
.c_str()) == 0)
52 pkgDepCache::ActionGroup::ActionGroup(pkgDepCache
&cache
) : /*{{{*/
53 cache(cache
), released(false)
58 void pkgDepCache::ActionGroup::release()
62 if(cache
.group_level
== 0)
63 std::cerr
<< "W: Unbalanced action groups, expect badness" << std::endl
;
68 if(cache
.group_level
== 0)
76 pkgDepCache::ActionGroup::~ActionGroup()
81 // DepCache::pkgDepCache - Constructors /*{{{*/
82 // ---------------------------------------------------------------------
84 pkgDepCache::pkgDepCache(pkgCache
*pCache
,Policy
*Plcy
) :
85 group_level(0), Cache(pCache
), PkgState(0), DepState(0)
87 DebugMarker
= _config
->FindB("Debug::pkgDepCache::Marker", false);
88 DebugAutoInstall
= _config
->FindB("Debug::pkgDepCache::AutoInstall", false);
92 delLocalPolicy
= LocalPolicy
= new Policy
;
95 // DepCache::~pkgDepCache - Destructor /*{{{*/
96 // ---------------------------------------------------------------------
98 pkgDepCache::~pkgDepCache()
102 delete delLocalPolicy
;
105 // DepCache::Init - Generate the initial extra structures. /*{{{*/
106 // ---------------------------------------------------------------------
107 /* This allocats the extension buffers and initializes them. */
108 bool pkgDepCache::Init(OpProgress
*Prog
)
110 // Suppress mark updates during this operation (just in case) and
111 // run a mark operation when Init terminates.
112 ActionGroup
actions(*this);
116 PkgState
= new StateCache
[Head().PackageCount
];
117 DepState
= new unsigned char[Head().DependsCount
];
118 memset(PkgState
,0,sizeof(*PkgState
)*Head().PackageCount
);
119 memset(DepState
,0,sizeof(*DepState
)*Head().DependsCount
);
123 Prog
->OverallProgress(0,2*Head().PackageCount
,Head().PackageCount
,
124 _("Building dependency tree"));
125 Prog
->SubProgress(Head().PackageCount
,_("Candidate versions"));
128 /* Set the current state of everything. In this state all of the
129 packages are kept exactly as is. See AllUpgrade */
131 for (PkgIterator I
= PkgBegin(); I
.end() != true; I
++,Done
++)
133 if (Prog
!= 0 && Done%20
== 0)
134 Prog
->Progress(Done
);
136 // Find the proper cache slot
137 StateCache
&State
= PkgState
[I
->ID
];
140 // Figure out the install version
141 State
.CandidateVer
= GetCandidateVer(I
);
142 State
.InstallVer
= I
.CurrentVer();
143 State
.Mode
= ModeKeep
;
145 State
.Update(I
,*this);
151 Prog
->OverallProgress(Head().PackageCount
,2*Head().PackageCount
,
153 _("Building dependency tree"));
154 Prog
->SubProgress(Head().PackageCount
,_("Dependency generation"));
165 bool pkgDepCache::readStateFile(OpProgress
*Prog
) /*{{{*/
168 string
const state
= _config
->FindFile("Dir::State::extended_states");
169 if(FileExists(state
)) {
170 state_file
.Open(state
, FileFd::ReadOnly
);
171 int const file_size
= state_file
.Size();
173 Prog
->OverallProgress(0, file_size
, 1,
174 _("Reading state information"));
176 pkgTagFile
tagfile(&state_file
);
177 pkgTagSection section
;
179 bool const debug_autoremove
= _config
->FindB("Debug::pkgAutoRemove",false);
180 while(tagfile
.Step(section
)) {
181 string
const pkgname
= section
.FindS("Package");
182 string pkgarch
= section
.FindS("Architecture");
183 if (pkgarch
.empty() == true)
185 pkgCache::PkgIterator pkg
= Cache
->FindPkg(pkgname
, pkgarch
);
186 // Silently ignore unknown packages and packages with no actual version.
187 if(pkg
.end() == true || pkg
->VersionList
== 0)
190 short const reason
= section
.FindI("Auto-Installed", 0);
193 PkgState
[pkg
->ID
].Flags
|= Flag::Auto
;
194 if (unlikely(debug_autoremove
))
195 std::clog
<< "Auto-Installed : " << pkg
.FullName() << std::endl
;
196 if (pkgarch
== "any")
198 pkgCache::GrpIterator G
= pkg
.Group();
199 for (pkg
= G
.NextPkg(pkg
); pkg
.end() != true; pkg
= G
.NextPkg(pkg
))
200 if (pkg
->VersionList
!= 0)
201 PkgState
[pkg
->ID
].Flags
|= Flag::Auto
;
204 amt
+= section
.size();
206 Prog
->OverallProgress(amt
, file_size
, 1,
207 _("Reading state information"));
210 Prog
->OverallProgress(file_size
, file_size
, 1,
211 _("Reading state information"));
217 bool pkgDepCache::writeStateFile(OpProgress
*prog
, bool InstalledOnly
) /*{{{*/
219 bool const debug_autoremove
= _config
->FindB("Debug::pkgAutoRemove",false);
222 std::clog
<< "pkgDepCache::writeStateFile()" << std::endl
;
225 string
const state
= _config
->FindFile("Dir::State::extended_states");
227 // if it does not exist, create a empty one
228 if(!FileExists(state
))
230 StateFile
.Open(state
, FileFd::WriteAtomic
);
235 if(!StateFile
.Open(state
, FileFd::ReadOnly
))
236 return _error
->Error(_("Failed to open StateFile %s"),
240 string
const outfile
= state
+ ".tmp";
241 if((OutFile
= fopen(outfile
.c_str(),"w")) == NULL
)
242 return _error
->Error(_("Failed to write temporary StateFile %s"),
245 // first merge with the existing sections
246 pkgTagFile
tagfile(&StateFile
);
247 pkgTagSection section
;
248 std::set
<string
> pkgs_seen
;
249 const char *nullreorderlist
[] = {0};
250 while(tagfile
.Step(section
)) {
251 string
const pkgname
= section
.FindS("Package");
252 string pkgarch
= section
.FindS("Architecture");
253 if (pkgarch
.empty() == true)
255 // Silently ignore unknown packages and packages with no actual
257 pkgCache::PkgIterator pkg
= Cache
->FindPkg(pkgname
, pkgarch
);
258 if(pkg
.end() || pkg
.VersionList().end())
260 StateCache
const &P
= PkgState
[pkg
->ID
];
261 bool newAuto
= (P
.Flags
& Flag::Auto
);
262 // skip not installed or now-removed ones if requested
263 if (InstalledOnly
&& (
264 (pkg
->CurrentVer
== 0 && P
.Mode
!= ModeInstall
) ||
265 (pkg
->CurrentVer
!= 0 && P
.Mode
== ModeDelete
)))
267 // The section is obsolete if it contains no other tag
268 unsigned int const count
= section
.Count();
270 (count
== 2 && section
.Exists("Auto-Installed")) ||
271 (count
== 3 && section
.Exists("Auto-Installed") && section
.Exists("Architecture")))
276 if(_config
->FindB("Debug::pkgAutoRemove",false))
277 std::clog
<< "Update existing AutoInstall info: "
278 << pkg
.FullName() << std::endl
;
279 TFRewriteData rewrite
[3];
280 rewrite
[0].Tag
= "Architecture";
281 rewrite
[0].Rewrite
= pkg
.Arch();
282 rewrite
[0].NewTag
= 0;
283 rewrite
[1].Tag
= "Auto-Installed";
284 rewrite
[1].Rewrite
= newAuto
? "1" : "0";
285 rewrite
[1].NewTag
= 0;
287 TFRewrite(OutFile
, section
, nullreorderlist
, rewrite
);
288 fprintf(OutFile
,"\n");
289 pkgs_seen
.insert(pkg
.FullName());
292 // then write the ones we have not seen yet
293 std::ostringstream ostr
;
294 for(pkgCache::PkgIterator pkg
=Cache
->PkgBegin(); !pkg
.end(); pkg
++) {
295 StateCache
const &P
= PkgState
[pkg
->ID
];
296 if(P
.Flags
& Flag::Auto
) {
297 if (pkgs_seen
.find(pkg
.FullName()) != pkgs_seen
.end()) {
299 std::clog
<< "Skipping already written " << pkg
.FullName() << std::endl
;
302 // skip not installed ones if requested
303 if (InstalledOnly
&& (
304 (pkg
->CurrentVer
== 0 && P
.Mode
!= ModeInstall
) ||
305 (pkg
->CurrentVer
!= 0 && P
.Mode
== ModeDelete
)))
307 const char* const pkgarch
= pkg
.Arch();
308 if (strcmp(pkgarch
, "all") == 0)
311 std::clog
<< "Writing new AutoInstall: " << pkg
.FullName() << std::endl
;
312 ostr
.str(string(""));
313 ostr
<< "Package: " << pkg
.Name()
314 << "\nArchitecture: " << pkgarch
315 << "\nAuto-Installed: 1\n\n";
316 fprintf(OutFile
,"%s",ostr
.str().c_str());
321 // move the outfile over the real file and set permissions
322 rename(outfile
.c_str(), state
.c_str());
323 chmod(state
.c_str(), 0644);
328 // DepCache::CheckDep - Checks a single dependency /*{{{*/
329 // ---------------------------------------------------------------------
330 /* This first checks the dependency against the main target package and
331 then walks along the package provides list and checks if each provides
332 will be installed then checks the provides against the dep. Res will be
333 set to the package which was used to satisfy the dep. */
334 bool pkgDepCache::CheckDep(DepIterator Dep
,int Type
,PkgIterator
&Res
)
336 Res
= Dep
.TargetPkg();
338 /* Check simple depends. A depends -should- never self match but
339 we allow it anyhow because dpkg does. Technically it is a packaging
340 bug. Conflicts may never self match */
341 if (Dep
.TargetPkg()->Group
!= Dep
.ParentPkg()->Group
||
342 (Dep
->Type
!= Dep::Conflicts
&& Dep
->Type
!= Dep::DpkgBreaks
&& Dep
->Type
!= Dep::Obsoletes
))
344 PkgIterator Pkg
= Dep
.TargetPkg();
345 // Check the base package
346 if (Type
== NowVersion
&& Pkg
->CurrentVer
!= 0)
347 if (VS().CheckDep(Pkg
.CurrentVer().VerStr(),Dep
->CompareOp
,
348 Dep
.TargetVer()) == true)
351 if (Type
== InstallVersion
&& PkgState
[Pkg
->ID
].InstallVer
!= 0)
352 if (VS().CheckDep(PkgState
[Pkg
->ID
].InstVerIter(*this).VerStr(),
353 Dep
->CompareOp
,Dep
.TargetVer()) == true)
356 if (Type
== CandidateVersion
&& PkgState
[Pkg
->ID
].CandidateVer
!= 0)
357 if (VS().CheckDep(PkgState
[Pkg
->ID
].CandidateVerIter(*this).VerStr(),
358 Dep
->CompareOp
,Dep
.TargetVer()) == true)
362 if (Dep
->Type
== Dep::Obsoletes
)
365 // Check the providing packages
366 PrvIterator P
= Dep
.TargetPkg().ProvidesList();
367 PkgIterator Pkg
= Dep
.ParentPkg();
368 for (; P
.end() != true; P
++)
370 /* Provides may never be applied against the same package (or group)
371 if it is a conflicts. See the comment above. */
372 if (P
.OwnerPkg()->Group
== Pkg
->Group
&&
373 (Dep
->Type
== Dep::Conflicts
|| Dep
->Type
== Dep::DpkgBreaks
))
376 // Check if the provides is a hit
377 if (Type
== NowVersion
)
379 if (P
.OwnerPkg().CurrentVer() != P
.OwnerVer())
383 if (Type
== InstallVersion
)
385 StateCache
&State
= PkgState
[P
.OwnerPkg()->ID
];
386 if (State
.InstallVer
!= (Version
*)P
.OwnerVer())
390 if (Type
== CandidateVersion
)
392 StateCache
&State
= PkgState
[P
.OwnerPkg()->ID
];
393 if (State
.CandidateVer
!= (Version
*)P
.OwnerVer())
397 // Compare the versions.
398 if (VS().CheckDep(P
.ProvideVersion(),Dep
->CompareOp
,Dep
.TargetVer()) == true)
408 // DepCache::AddSizes - Add the packages sizes to the counters /*{{{*/
409 // ---------------------------------------------------------------------
410 /* Call with Mult = -1 to preform the inverse opration
411 The Mult increases the complexity of the calulations here and is unused -
412 or do we really have a usecase for removing the size of a package two
413 times? So let us replace it with a simple bool and be done with it… */
414 __deprecated
void pkgDepCache::AddSizes(const PkgIterator
&Pkg
,signed long Mult
)
416 StateCache
&P
= PkgState
[Pkg
->ID
];
418 if (Pkg
->VersionList
== 0)
421 if (Pkg
.State() == pkgCache::PkgIterator::NeedsConfigure
&&
425 // Compute the size data
426 if (P
.NewInstall() == true)
428 iUsrSize
+= (signed long long)(Mult
*P
.InstVerIter(*this)->InstalledSize
);
429 iDownloadSize
+= (signed long long)(Mult
*P
.InstVerIter(*this)->Size
);
434 if (Pkg
->CurrentVer
!= 0 &&
435 (P
.InstallVer
!= (Version
*)Pkg
.CurrentVer() ||
436 (P
.iFlags
& ReInstall
) == ReInstall
) && P
.InstallVer
!= 0)
438 iUsrSize
+= (signed long long)(Mult
*((signed long long)P
.InstVerIter(*this)->InstalledSize
-
439 (signed long long)Pkg
.CurrentVer()->InstalledSize
));
440 iDownloadSize
+= (signed long long)(Mult
*P
.InstVerIter(*this)->Size
);
445 if (Pkg
.State() == pkgCache::PkgIterator::NeedsUnpack
&&
448 iDownloadSize
+= (signed long long)(Mult
*P
.InstVerIter(*this)->Size
);
453 if (Pkg
->CurrentVer
!= 0 && P
.InstallVer
== 0)
455 iUsrSize
-= (signed long long)(Mult
*Pkg
.CurrentVer()->InstalledSize
);
460 // DepCache::AddSizes - Add the packages sizes to the counters /*{{{*/
461 // ---------------------------------------------------------------------
462 /* Call with Inverse = true to preform the inverse opration */
463 void pkgDepCache::AddSizes(const PkgIterator
&Pkg
, bool const &Inverse
)
465 StateCache
&P
= PkgState
[Pkg
->ID
];
467 if (Pkg
->VersionList
== 0)
470 if (Pkg
.State() == pkgCache::PkgIterator::NeedsConfigure
&&
474 // Compute the size data
475 if (P
.NewInstall() == true)
477 if (Inverse
== false) {
478 iUsrSize
+= P
.InstVerIter(*this)->InstalledSize
;
479 iDownloadSize
+= P
.InstVerIter(*this)->Size
;
481 iUsrSize
-= P
.InstVerIter(*this)->InstalledSize
;
482 iDownloadSize
-= P
.InstVerIter(*this)->Size
;
488 if (Pkg
->CurrentVer
!= 0 &&
489 (P
.InstallVer
!= (Version
*)Pkg
.CurrentVer() ||
490 (P
.iFlags
& ReInstall
) == ReInstall
) && P
.InstallVer
!= 0)
492 if (Inverse
== false) {
493 iUsrSize
-= Pkg
.CurrentVer()->InstalledSize
;
494 iUsrSize
+= P
.InstVerIter(*this)->InstalledSize
;
495 iDownloadSize
+= P
.InstVerIter(*this)->Size
;
497 iUsrSize
-= P
.InstVerIter(*this)->InstalledSize
;
498 iUsrSize
+= Pkg
.CurrentVer()->InstalledSize
;
499 iDownloadSize
-= P
.InstVerIter(*this)->Size
;
505 if (Pkg
.State() == pkgCache::PkgIterator::NeedsUnpack
&&
508 if (Inverse
== false)
509 iDownloadSize
+= P
.InstVerIter(*this)->Size
;
511 iDownloadSize
-= P
.InstVerIter(*this)->Size
;
516 if (Pkg
->CurrentVer
!= 0 && P
.InstallVer
== 0)
518 if (Inverse
== false)
519 iUsrSize
-= Pkg
.CurrentVer()->InstalledSize
;
521 iUsrSize
+= Pkg
.CurrentVer()->InstalledSize
;
526 // DepCache::AddStates - Add the package to the state counter /*{{{*/
527 // ---------------------------------------------------------------------
528 /* This routine is tricky to use, you must make sure that it is never
529 called twice for the same package. This means the Remove/Add section
530 should be as short as possible and not encompass any code that will
531 calld Remove/Add itself. Remember, dependencies can be circular so
532 while processing a dep for Pkg it is possible that Add/Remove
533 will be called on Pkg */
534 void pkgDepCache::AddStates(const PkgIterator
&Pkg
,int Add
)
536 StateCache
&State
= PkgState
[Pkg
->ID
];
538 // The Package is broken (either minimal dep or policy dep)
539 if ((State
.DepState
& DepInstMin
) != DepInstMin
)
541 if ((State
.DepState
& DepInstPolicy
) != DepInstPolicy
)
542 iPolicyBrokenCount
+= Add
;
545 if (Pkg
.State() != PkgIterator::NeedsNothing
)
549 if (Pkg
->CurrentVer
== 0)
551 if (State
.Mode
== ModeDelete
&&
552 (State
.iFlags
| Purge
) == Purge
&& Pkg
.Purge() == false)
555 if (State
.Mode
== ModeInstall
)
560 // Installed, no upgrade
561 if (State
.Status
== 0)
563 if (State
.Mode
== ModeDelete
)
566 if ((State
.iFlags
& ReInstall
) == ReInstall
)
572 // Alll 3 are possible
573 if (State
.Mode
== ModeDelete
)
575 if (State
.Mode
== ModeKeep
)
577 if (State
.Mode
== ModeInstall
)
581 // DepCache::BuildGroupOrs - Generate the Or group dep data /*{{{*/
582 // ---------------------------------------------------------------------
583 /* The or group results are stored in the last item of the or group. This
584 allows easy detection of the state of a whole or'd group. */
585 void pkgDepCache::BuildGroupOrs(VerIterator
const &V
)
587 unsigned char Group
= 0;
589 for (DepIterator D
= V
.DependsList(); D
.end() != true; D
++)
591 // Build the dependency state.
592 unsigned char &State
= DepState
[D
->ID
];
594 /* Invert for Conflicts. We have to do this twice to get the
595 right sense for a conflicts group */
596 if (D
->Type
== Dep::Conflicts
||
597 D
->Type
== Dep::DpkgBreaks
||
598 D
->Type
== Dep::Obsoletes
)
601 // Add to the group if we are within an or..
605 if ((D
->CompareOp
& Dep::Or
) != Dep::Or
)
608 // Invert for Conflicts
609 if (D
->Type
== Dep::Conflicts
||
610 D
->Type
== Dep::DpkgBreaks
||
611 D
->Type
== Dep::Obsoletes
)
616 // DepCache::VersionState - Perform a pass over a dependency list /*{{{*/
617 // ---------------------------------------------------------------------
618 /* This is used to run over a dependency list and determine the dep
619 state of the list, filtering it through both a Min check and a Policy
620 check. The return result will have SetMin/SetPolicy low if a check
621 fails. It uses the DepState cache for it's computations. */
622 unsigned char pkgDepCache::VersionState(DepIterator D
,unsigned char Check
,
623 unsigned char SetMin
,
624 unsigned char SetPolicy
)
626 unsigned char Dep
= 0xFF;
628 while (D
.end() != true)
630 // Compute a single dependency element (glob or)
631 DepIterator Start
= D
;
632 unsigned char State
= 0;
633 for (bool LastOR
= true; D
.end() == false && LastOR
== true; D
++)
635 State
|= DepState
[D
->ID
];
636 LastOR
= (D
->CompareOp
& Dep::Or
) == Dep::Or
;
639 // Minimum deps that must be satisfied to have a working package
640 if (Start
.IsCritical() == true)
641 if ((State
& Check
) != Check
)
644 // Policy deps that must be satisfied to install the package
645 if (IsImportantDep(Start
) == true &&
646 (State
& Check
) != Check
)
653 // DepCache::DependencyState - Compute the 3 results for a dep /*{{{*/
654 // ---------------------------------------------------------------------
655 /* This is the main dependency computation bit. It computes the 3 main
656 results for a dependencys, Now, Install and Candidate. Callers must
657 invert the result if dealing with conflicts. */
658 unsigned char pkgDepCache::DependencyState(DepIterator
&D
)
660 unsigned char State
= 0;
662 if (CheckDep(D
,NowVersion
) == true)
664 if (CheckDep(D
,InstallVersion
) == true)
666 if (CheckDep(D
,CandidateVersion
) == true)
672 // DepCache::UpdateVerState - Compute the Dep member of the state /*{{{*/
673 // ---------------------------------------------------------------------
674 /* This determines the combined dependency representation of a package
675 for its two states now and install. This is done by using the pre-generated
676 dependency information. */
677 void pkgDepCache::UpdateVerState(PkgIterator Pkg
)
679 // Empty deps are always true
680 StateCache
&State
= PkgState
[Pkg
->ID
];
681 State
.DepState
= 0xFF;
683 // Check the Current state
684 if (Pkg
->CurrentVer
!= 0)
686 DepIterator D
= Pkg
.CurrentVer().DependsList();
687 State
.DepState
&= VersionState(D
,DepNow
,DepNowMin
,DepNowPolicy
);
690 /* Check the candidate state. We do not compare against the whole as
691 a candidate state but check the candidate version against the
693 if (State
.CandidateVer
!= 0)
695 DepIterator D
= State
.CandidateVerIter(*this).DependsList();
696 State
.DepState
&= VersionState(D
,DepInstall
,DepCandMin
,DepCandPolicy
);
699 // Check target state which can only be current or installed
700 if (State
.InstallVer
!= 0)
702 DepIterator D
= State
.InstVerIter(*this).DependsList();
703 State
.DepState
&= VersionState(D
,DepInstall
,DepInstMin
,DepInstPolicy
);
707 // DepCache::RemovePseudoInstalledPkg - MultiArch helper for Update() /*{{{*/
708 // ---------------------------------------------------------------------
709 /* We "install" arch all packages for all archs if it is installed. Many
710 of these will be broken. This method will look at these broken Pkg and
712 bool pkgDepCache::RemovePseudoInstalledPkg(PkgIterator
&Pkg
, std::set
<unsigned long> &recheck
) {
713 if (unlikely(Pkg
->CurrentVer
== 0))
716 VerIterator V
= Pkg
.CurrentVer();
717 if (V
->MultiArch
!= Version::All
)
720 // Never ever kill an "all" package - they have no dependency so they can't be broken
721 if (strcmp(Pkg
.Arch(),"all") == 0)
724 unsigned char const CurDepState
= VersionState(V
.DependsList(),DepInstall
,DepInstMin
,DepInstPolicy
);
725 if ((CurDepState
& DepInstMin
) == DepInstMin
) {
726 // okay, the package isn't broken, but is the package also required?
727 // If it has no real dependencies, no installed rdepends and doesn't
728 // provide something of value, we will kill it as not required.
729 // These pseudopackages have otherwise interesting effects if they get
730 // a new dependency in a newer version…
731 for (pkgCache::DepIterator D
= V
.DependsList();
732 D
.end() != true; ++D
)
733 if (D
.IsCritical() == true && D
.ParentPkg()->Group
!= Pkg
->Group
)
735 for (DepIterator D
= Pkg
.RevDependsList(); D
.end() != true; ++D
)
737 if (D
.IsCritical() == false)
739 PkgIterator
const P
= D
.ParentPkg();
740 if (P
->Group
== Pkg
->Group
)
742 if (P
->CurrentVer
!= 0)
745 for (PrvIterator Prv
= V
.ProvidesList(); Prv
.end() != true; Prv
++)
746 for (DepIterator d
= Prv
.ParentPkg().RevDependsList();
747 d
.end() != true; ++d
)
749 PkgIterator
const P
= d
.ParentPkg();
750 if (P
->CurrentVer
!= 0 &&
751 P
->Group
!= Pkg
->Group
)
756 // Dependencies for this arch all package are not statisfied
757 // so we installed it only for our convenience: get right of it now.
762 PkgState
[Pkg
->ID
].InstallVer
= 0;
768 // After the remove previously satisfied pseudo pkg could be now
769 // no longer satisfied, so we need to recheck the reverse dependencies
770 for (DepIterator d
= Pkg
.RevDependsList(); d
.end() != true; ++d
)
772 PkgIterator
const P
= d
.ParentPkg();
773 if (P
->CurrentVer
!= 0)
774 recheck
.insert(P
.Index());
777 for (DepIterator d
= V
.DependsList(); d
.end() != true; ++d
)
779 PkgIterator
const P
= d
.TargetPkg();
780 for (PrvIterator Prv
= P
.ProvidesList(); Prv
.end() != true; ++Prv
)
782 PkgIterator
const O
= Prv
.OwnerPkg();
783 if (O
->CurrentVer
!= 0)
784 recheck
.insert(O
.Index());
787 if (P
->CurrentVer
!= 0)
788 recheck
.insert(P
.Index());
791 for (PrvIterator Prv
= V
.ProvidesList(); Prv
.end() != true; Prv
++)
793 for (DepIterator d
= Prv
.ParentPkg().RevDependsList();
794 d
.end() != true; ++d
)
796 PkgIterator
const P
= d
.ParentPkg();
797 if (P
->CurrentVer
== 0)
800 recheck
.insert(P
.Index());
808 // DepCache::Update - Figure out all the state information /*{{{*/
809 // ---------------------------------------------------------------------
810 /* This will figure out the state of all the packages and all the
811 dependencies based on the current policy. */
812 void pkgDepCache::Update(OpProgress
*Prog
)
822 std::set
<unsigned long> recheck
;
824 // Perform the depends pass
826 bool const checkMultiArch
= APT::Configuration::getArchitectures().size() > 1;
827 unsigned long killed
= 0;
828 for (PkgIterator I
= PkgBegin(); I
.end() != true; I
++,Done
++)
830 if (Prog
!= 0 && Done%20
== 0)
831 Prog
->Progress(Done
);
832 for (VerIterator V
= I
.VersionList(); V
.end() != true; V
++)
834 unsigned char Group
= 0;
836 for (DepIterator D
= V
.DependsList(); D
.end() != true; D
++)
838 // Build the dependency state.
839 unsigned char &State
= DepState
[D
->ID
];
840 State
= DependencyState(D
);
842 // Add to the group if we are within an or..
845 if ((D
->CompareOp
& Dep::Or
) != Dep::Or
)
848 // Invert for Conflicts
849 if (D
->Type
== Dep::Conflicts
||
850 D
->Type
== Dep::DpkgBreaks
||
851 D
->Type
== Dep::Obsoletes
)
856 // Compute the package dependency state and size additions
861 if (checkMultiArch
!= true || I
->CurrentVer
== 0)
864 VerIterator
const V
= I
.CurrentVer();
865 if (V
->MultiArch
!= Version::All
)
868 recheck
.insert(I
.Index());
869 --Done
; // no progress if we need to recheck the package
872 if (checkMultiArch
== true) {
873 /* FIXME: recheck breaks proper progress reporting as we don't know
874 how many packages we need to recheck. To lower the effect
875 a bit we increase with a kill, but we should do something more clever… */
876 while(recheck
.empty() == false)
877 for (std::set
<unsigned long>::const_iterator p
= recheck
.begin();
878 p
!= recheck
.end();) {
879 if (Prog
!= 0 && Done%20
== 0)
880 Prog
->Progress(Done
);
881 PkgIterator P
= PkgIterator(*Cache
, Cache
->PkgP
+ *p
);
882 if (RemovePseudoInstalledPkg(P
, recheck
) == true) {
889 /* Okay, we have killed a great amount of pseudopackages -
890 we have killed so many that we have now arch "all" packages
891 without an installed pseudo package, but we NEED an installed
892 pseudo package, so we will search now for a pseudo package
893 we can install without breaking everything. */
894 for (GrpIterator G
= Cache
->GrpBegin(); G
.end() != true; ++G
)
896 PkgIterator P
= G
.FindPkg("all");
899 if (P
->CurrentVer
== 0)
901 bool installed
= false;
902 for (P
= G
.FindPkg("any"); P
.end() != true; P
= G
.NextPkg(P
))
904 if (strcmp(P
.Arch(), "all") == 0)
906 if (P
->CurrentVer
== 0)
911 if (installed
== false)
912 recheck
.insert(G
.Index());
915 while (recheck
.empty() != true)
917 std::set
<unsigned long>::const_iterator g
= recheck
.begin();
918 unsigned long const G
= *g
;
920 if (unlikely(ReInstallPseudoForGroup(G
, recheck
) == false))
921 _error
->Warning(_("Internal error, group '%s' has no installable pseudo package"), GrpIterator(*Cache
, Cache
->GrpP
+ G
).Name());
926 Prog
->Progress(Done
);
931 // DepCache::ReInstallPseudoForGroup - MultiArch helper for Update() /*{{{*/
932 // ---------------------------------------------------------------------
933 /* RemovePseudoInstalledPkg() is very successful. It even kills packages
934 to an amount that no pseudo package is left, but we need a pseudo package
935 for upgrading senarios so we need to reinstall one pseudopackage which
936 doesn't break everything. Thankfully we can't have architecture depending
937 negative dependencies so this problem is already eliminated */
938 bool pkgDepCache::ReInstallPseudoForGroup(pkgCache::PkgIterator
const &P
, std::set
<unsigned long> &recheck
)
940 if (P
->CurrentVer
!= 0)
942 // recursive call for packages which provide this package
943 for (pkgCache::PrvIterator Prv
= P
.ProvidesList(); Prv
.end() != true; ++Prv
)
944 ReInstallPseudoForGroup(Prv
.OwnerPkg(), recheck
);
945 // check if we actually need to look at this group
946 unsigned long const G
= P
->Group
;
947 std::set
<unsigned long>::const_iterator Pi
= recheck
.find(G
);
948 if (Pi
== recheck
.end())
950 recheck
.erase(Pi
); // remove here, so we can't fall into an endless loop
951 if (unlikely(ReInstallPseudoForGroup(G
, recheck
) == false))
958 bool pkgDepCache::ReInstallPseudoForGroup(unsigned long const &G
, std::set
<unsigned long> &recheck
)
960 std::vector
<std::string
> static const Archs
= APT::Configuration::getArchitectures();
961 pkgCache::GrpIterator
Grp(*Cache
, Cache
->GrpP
+ G
);
962 if (unlikely(Grp
.end() == true))
964 for (std::vector
<std::string
>::const_iterator a
= Archs
.begin();
965 a
!= Archs
.end(); ++a
)
967 pkgCache::PkgIterator P
= Grp
.FindPkg(*a
);
970 pkgCache::VerIterator allV
= Grp
.FindPkg("all").CurrentVer();
971 for (VerIterator V
= P
.VersionList(); V
.end() != true; ++V
)
973 // search for the same version as the all package
974 if (allV
->Hash
!= V
->Hash
|| strcmp(allV
.VerStr(),V
.VerStr()) != 0)
976 unsigned char const CurDepState
= VersionState(V
.DependsList(),DepInstall
,DepInstMin
,DepInstPolicy
);
977 // If it is broken, try to install dependencies first before retry
978 if ((CurDepState
& DepInstMin
) != DepInstMin
)
980 for (pkgCache::DepIterator D
= V
.DependsList(); D
.end() != true; ++D
)
982 if (D
->Type
!= pkgCache::Dep::PreDepends
&& D
->Type
!= pkgCache::Dep::Depends
)
984 ReInstallPseudoForGroup(D
.TargetPkg(), recheck
);
986 unsigned char const CurDepState
= VersionState(V
.DependsList(),DepInstall
,DepInstMin
,DepInstPolicy
);
987 // if package ist still broken… try another arch
988 if ((CurDepState
& DepInstMin
) != DepInstMin
)
991 // dependencies satisfied: reinstall the package
994 P
->CurrentVer
= V
.Index();
995 PkgState
[P
->ID
].InstallVer
= V
;
1005 // DepCache::Update - Update the deps list of a package /*{{{*/
1006 // ---------------------------------------------------------------------
1007 /* This is a helper for update that only does the dep portion of the scan.
1008 It is mainly meant to scan reverse dependencies. */
1009 void pkgDepCache::Update(DepIterator D
)
1011 // Update the reverse deps
1012 for (;D
.end() != true; D
++)
1014 unsigned char &State
= DepState
[D
->ID
];
1015 State
= DependencyState(D
);
1017 // Invert for Conflicts
1018 if (D
->Type
== Dep::Conflicts
||
1019 D
->Type
== Dep::DpkgBreaks
||
1020 D
->Type
== Dep::Obsoletes
)
1023 RemoveStates(D
.ParentPkg());
1024 BuildGroupOrs(D
.ParentVer());
1025 UpdateVerState(D
.ParentPkg());
1026 AddStates(D
.ParentPkg());
1030 // DepCache::Update - Update the related deps of a package /*{{{*/
1031 // ---------------------------------------------------------------------
1032 /* This is called whenever the state of a package changes. It updates
1033 all cached dependencies related to this package. */
1034 void pkgDepCache::Update(PkgIterator
const &Pkg
)
1036 // Recompute the dep of the package
1038 UpdateVerState(Pkg
);
1041 // Update the reverse deps
1042 Update(Pkg
.RevDependsList());
1044 // Update the provides map for the current ver
1045 if (Pkg
->CurrentVer
!= 0)
1046 for (PrvIterator P
= Pkg
.CurrentVer().ProvidesList();
1047 P
.end() != true; P
++)
1048 Update(P
.ParentPkg().RevDependsList());
1050 // Update the provides map for the candidate ver
1051 if (PkgState
[Pkg
->ID
].CandidateVer
!= 0)
1052 for (PrvIterator P
= PkgState
[Pkg
->ID
].CandidateVerIter(*this).ProvidesList();
1053 P
.end() != true; P
++)
1054 Update(P
.ParentPkg().RevDependsList());
1057 // DepCache::MarkKeep - Put the package in the keep state /*{{{*/
1058 // ---------------------------------------------------------------------
1060 void pkgDepCache::MarkKeep(PkgIterator
const &Pkg
, bool Soft
, bool FromUser
,
1061 unsigned long Depth
)
1063 // Simplifies other routines.
1064 if (Pkg
.end() == true)
1067 /* Reject an attempt to keep a non-source broken installed package, those
1069 if (Pkg
.State() == PkgIterator::NeedsUnpack
&&
1070 Pkg
.CurrentVer().Downloadable() == false)
1073 /** \todo Can this be moved later in the method? */
1074 ActionGroup
group(*this);
1076 /* We changed the soft state all the time so the UI is a bit nicer
1078 StateCache
&P
= PkgState
[Pkg
->ID
];
1080 P
.iFlags
|= AutoKept
;
1082 P
.iFlags
&= ~AutoKept
;
1084 // Check that it is not already kept
1085 if (P
.Mode
== ModeKeep
)
1088 // We dont even try to keep virtual packages..
1089 if (Pkg
->VersionList
== 0)
1091 #if 0 // reseting the autoflag here means we lose the
1092 // auto-mark information if a user selects a package for removal
1093 // but changes his mind then and sets it for keep again
1094 // - this makes sense as default when all Garbage dependencies
1095 // are automatically marked for removal (as aptitude does).
1096 // setting a package for keep then makes it no longer autoinstalled
1097 // for all other use-case this action is rather suprising
1098 if(FromUser
&& !P
.Marked
)
1099 P
.Flags
&= ~Flag::Auto
;
1102 if (DebugMarker
== true)
1103 std::clog
<< OutputInDepth(Depth
) << "MarkKeep " << Pkg
<< " FU=" << FromUser
<< std::endl
;
1109 if (Pkg
->CurrentVer
== 0)
1112 P
.InstallVer
= Pkg
.CurrentVer();
1121 // DepCache::MarkDelete - Put the package in the delete state /*{{{*/
1122 // ---------------------------------------------------------------------
1124 void pkgDepCache::MarkDelete(PkgIterator
const &Pkg
, bool rPurge
,
1125 unsigned long Depth
, bool FromUser
)
1127 // Simplifies other routines.
1128 if (Pkg
.end() == true)
1131 ActionGroup
group(*this);
1133 // Check that it is not already marked for delete
1134 StateCache
&P
= PkgState
[Pkg
->ID
];
1135 P
.iFlags
&= ~(AutoKept
| Purge
);
1139 if ((P
.Mode
== ModeDelete
|| P
.InstallVer
== 0) &&
1140 (Pkg
.Purge() == true || rPurge
== false))
1143 // We dont even try to delete virtual packages..
1144 if (Pkg
->VersionList
== 0)
1147 // check if we are allowed to install the package
1148 if (IsDeleteOk(Pkg
,rPurge
,Depth
,FromUser
) == false)
1151 if (DebugMarker
== true)
1152 std::clog
<< OutputInDepth(Depth
) << (rPurge
? "MarkPurge " : "MarkDelete ") << Pkg
<< " FU=" << FromUser
<< std::endl
;
1157 if (Pkg
->CurrentVer
== 0 && (Pkg
.Purge() == true || rPurge
== false))
1160 P
.Mode
= ModeDelete
;
1167 // if we remove the pseudo package, we also need to remove the "real"
1168 if (Pkg
->CurrentVer
!= 0 && Pkg
.CurrentVer().Pseudo() == true)
1169 MarkDelete(Pkg
.Group().FindPkg("all"), rPurge
, Depth
+1, FromUser
);
1170 else if (rPurge
== true && Pkg
->CurrentVer
== 0 &&
1171 Pkg
->CurrentState
!= pkgCache::State::NotInstalled
&&
1172 strcmp(Pkg
.Arch(), "all") != 0)
1174 PkgIterator
const allPkg
= Pkg
.Group().FindPkg("all");
1175 if (allPkg
.end() == false && allPkg
->CurrentVer
== 0 &&
1176 allPkg
->CurrentState
!= pkgCache::State::NotInstalled
)
1177 MarkDelete(allPkg
, rPurge
, Depth
+1, FromUser
);
1181 // DepCache::IsDeleteOk - check if it is ok to remove this package /*{{{*/
1182 // ---------------------------------------------------------------------
1183 /* The default implementation just honors dpkg hold
1184 But an application using this library can override this method
1185 to control the MarkDelete behaviour */
1186 bool pkgDepCache::IsDeleteOk(PkgIterator
const &Pkg
,bool rPurge
,
1187 unsigned long Depth
, bool FromUser
)
1189 if (FromUser
== false && Pkg
->SelectedState
== pkgCache::State::Hold
&& _config
->FindB("APT::Ignore-Hold",false) == false)
1191 if (DebugMarker
== true)
1192 std::clog
<< OutputInDepth(Depth
) << "Hold prevents MarkDelete of " << Pkg
<< " FU=" << FromUser
<< std::endl
;
1195 else if (FromUser
== false && Pkg
->CurrentVer
== 0)
1197 StateCache
&P
= PkgState
[Pkg
->ID
];
1198 if (P
.InstallVer
!= 0 && P
.Status
== 2 && (P
.Flags
& Flag::Auto
) != Flag::Auto
)
1200 if (DebugMarker
== true)
1201 std::clog
<< OutputInDepth(Depth
) << "Manual install request prevents MarkDelete of " << Pkg
<< std::endl
;
1208 // DepCache::MarkInstall - Put the package in the install state /*{{{*/
1209 // ---------------------------------------------------------------------
1211 void pkgDepCache::MarkInstall(PkgIterator
const &Pkg
,bool AutoInst
,
1212 unsigned long Depth
, bool FromUser
,
1213 bool ForceImportantDeps
)
1218 // Simplifies other routines.
1219 if (Pkg
.end() == true)
1222 ActionGroup
group(*this);
1224 /* Check that it is not already marked for install and that it can be
1226 StateCache
&P
= PkgState
[Pkg
->ID
];
1227 P
.iFlags
&= ~AutoKept
;
1228 if ((P
.InstPolicyBroken() == false && P
.InstBroken() == false) &&
1229 (P
.Mode
== ModeInstall
||
1230 P
.CandidateVer
== (Version
*)Pkg
.CurrentVer()))
1232 if (P
.CandidateVer
== (Version
*)Pkg
.CurrentVer() && P
.InstallVer
== 0)
1233 MarkKeep(Pkg
, false, FromUser
, Depth
+1);
1237 // See if there is even any possible instalation candidate
1238 if (P
.CandidateVer
== 0)
1240 // We dont even try to install virtual packages..
1241 if (Pkg
->VersionList
== 0)
1244 // check if we are allowed to install the package
1245 if (IsInstallOk(Pkg
,AutoInst
,Depth
,FromUser
) == false)
1248 /* Target the candidate version and remove the autoflag. We reset the
1249 autoflag below if this was called recursively. Otherwise the user
1250 should have the ability to de-auto a package by changing its state */
1254 P
.Mode
= ModeInstall
;
1255 P
.InstallVer
= P
.CandidateVer
;
1259 // Set it to manual if it's a new install or cancelling the
1260 // removal of a garbage package.
1261 if(P
.Status
== 2 || (!Pkg
.CurrentVer().end() && !P
.Marked
))
1262 P
.Flags
&= ~Flag::Auto
;
1266 // Set it to auto if this is a new install.
1268 P
.Flags
|= Flag::Auto
;
1270 if (P
.CandidateVer
== (Version
*)Pkg
.CurrentVer())
1277 // always trigger the install of the all package for a pseudo package
1278 if (P
.CandidateVerIter(*Cache
).Pseudo() == true)
1279 MarkInstall(Pkg
.Group().FindPkg("all"), AutoInst
, Depth
, FromUser
, ForceImportantDeps
);
1281 if (AutoInst
== false)
1284 if (DebugMarker
== true)
1285 std::clog
<< OutputInDepth(Depth
) << "MarkInstall " << Pkg
<< " FU=" << FromUser
<< std::endl
;
1287 DepIterator Dep
= P
.InstVerIter(*this).DependsList();
1288 for (; Dep
.end() != true;)
1291 DepIterator Start
= Dep
;
1294 for (bool LastOR
= true; Dep
.end() == false && LastOR
== true; Dep
++,Ors
++)
1296 LastOR
= (Dep
->CompareOp
& Dep::Or
) == Dep::Or
;
1298 if ((DepState
[Dep
->ID
] & DepInstall
) == DepInstall
)
1302 // Dep is satisfied okay.
1303 if (Result
== false)
1306 /* Check if this dep should be consider for install. If it is a user
1307 defined important dep and we are installed a new package then
1308 it will be installed. Otherwise we only check for important
1309 deps that have changed from the installed version
1311 if (IsImportantDep(Start
) == false)
1314 /* Check if any ImportantDep() (but not Critical) were added
1315 * since we installed the package. Also check for deps that
1316 * were satisfied in the past: for instance, if a version
1317 * restriction in a Recommends was tightened, upgrading the
1318 * package should follow that Recommends rather than causing the
1319 * dependency to be removed. (bug #470115)
1321 bool isNewImportantDep
= false;
1322 bool isPreviouslySatisfiedImportantDep
= false;
1323 if(!ForceImportantDeps
&& !Start
.IsCritical())
1326 VerIterator instVer
= Pkg
.CurrentVer();
1329 for (DepIterator D
= instVer
.DependsList(); D
.end() != true; D
++)
1331 //FIXME: deal better with or-groups(?)
1332 DepIterator LocalStart
= D
;
1334 if(IsImportantDep(D
) && !D
.IsCritical() &&
1335 Start
.TargetPkg() == D
.TargetPkg())
1337 if(!isPreviouslySatisfiedImportantDep
)
1340 while((D2
->CompareOp
& Dep::Or
) != 0)
1343 isPreviouslySatisfiedImportantDep
=
1344 (((*this)[D2
] & DepGNow
) != 0);
1350 // this is a new dep if it was not found to be already
1351 // a important dep of the installed pacakge
1352 isNewImportantDep
= !found
;
1355 if(isNewImportantDep
)
1356 if(DebugAutoInstall
== true)
1357 std::clog
<< OutputInDepth(Depth
) << "new important dependency: "
1358 << Start
.TargetPkg().Name() << std::endl
;
1359 if(isPreviouslySatisfiedImportantDep
)
1360 if(DebugAutoInstall
== true)
1361 std::clog
<< OutputInDepth(Depth
) << "previously satisfied important dependency on "
1362 << Start
.TargetPkg().Name() << std::endl
;
1364 // skip important deps if the package is already installed
1365 if (Pkg
->CurrentVer
!= 0 && Start
.IsCritical() == false
1366 && !isNewImportantDep
&& !isPreviouslySatisfiedImportantDep
1367 && !ForceImportantDeps
)
1370 /* If we are in an or group locate the first or that can
1371 succeed. We have already cached this.. */
1372 for (; Ors
> 1 && (DepState
[Start
->ID
] & DepCVer
) != DepCVer
; Ors
--)
1375 /* This bit is for processing the possibilty of an install/upgrade
1376 fixing the problem */
1377 SPtrArray
<Version
*> List
= Start
.AllTargets();
1378 if (Start
->Type
!= Dep::DpkgBreaks
&&
1379 (DepState
[Start
->ID
] & DepCVer
) == DepCVer
)
1381 // Right, find the best version to install..
1382 Version
**Cur
= List
;
1383 PkgIterator P
= Start
.TargetPkg();
1384 PkgIterator
InstPkg(*Cache
,0);
1386 // See if there are direct matches (at the start of the list)
1387 for (; *Cur
!= 0 && (*Cur
)->ParentPkg
== P
.Index(); Cur
++)
1389 PkgIterator
Pkg(*Cache
,Cache
->PkgP
+ (*Cur
)->ParentPkg
);
1390 if (PkgState
[Pkg
->ID
].CandidateVer
!= *Cur
)
1396 // Select the highest priority providing package
1397 if (InstPkg
.end() == true)
1399 pkgPrioSortList(*Cache
,Cur
);
1400 for (; *Cur
!= 0; Cur
++)
1402 PkgIterator
Pkg(*Cache
,Cache
->PkgP
+ (*Cur
)->ParentPkg
);
1403 if (PkgState
[Pkg
->ID
].CandidateVer
!= *Cur
)
1410 if (InstPkg
.end() == false)
1412 if(DebugAutoInstall
== true)
1413 std::clog
<< OutputInDepth(Depth
) << "Installing " << InstPkg
.Name()
1414 << " as " << Start
.DepType() << " of " << Pkg
.Name()
1416 // now check if we should consider it a automatic dependency or not
1417 if(Pkg
.Section() && ConfigValueInSubTree("APT::Never-MarkAuto-Sections", Pkg
.Section()))
1419 if(DebugAutoInstall
== true)
1420 std::clog
<< OutputInDepth(Depth
) << "Setting NOT as auto-installed (direct "
1421 << Start
.DepType() << " of pkg in APT::Never-MarkAuto-Sections)" << std::endl
;
1422 MarkInstall(InstPkg
,true,Depth
+ 1, true);
1426 // mark automatic dependency
1427 MarkInstall(InstPkg
,true,Depth
+ 1, false, ForceImportantDeps
);
1428 // Set the autoflag, after MarkInstall because MarkInstall unsets it
1429 if (P
->CurrentVer
== 0)
1430 PkgState
[InstPkg
->ID
].Flags
|= Flag::Auto
;
1436 /* For conflicts we just de-install the package and mark as auto,
1437 Conflicts may not have or groups. For dpkg's Breaks we try to
1438 upgrade the package. */
1439 if (Start
->Type
== Dep::Conflicts
|| Start
->Type
== Dep::Obsoletes
||
1440 Start
->Type
== Dep::DpkgBreaks
)
1442 for (Version
**I
= List
; *I
!= 0; I
++)
1444 VerIterator
Ver(*this,*I
);
1445 PkgIterator Pkg
= Ver
.ParentPkg();
1447 /* The List includes all packages providing this dependency,
1448 even providers which are not installed, so skip them. */
1449 if (PkgState
[Pkg
->ID
].InstallVer
== 0)
1452 if (PkgState
[Pkg
->ID
].CandidateVer
!= *I
&&
1453 Start
->Type
== Dep::DpkgBreaks
)
1454 MarkInstall(Pkg
,true,Depth
+ 1, false, ForceImportantDeps
);
1456 MarkDelete(Pkg
,false,Depth
+ 1, false);
1463 // DepCache::IsInstallOk - check if it is ok to install this package /*{{{*/
1464 // ---------------------------------------------------------------------
1465 /* The default implementation just honors dpkg hold
1466 But an application using this library can override this method
1467 to control the MarkInstall behaviour */
1468 bool pkgDepCache::IsInstallOk(PkgIterator
const &Pkg
,bool AutoInst
,
1469 unsigned long Depth
, bool FromUser
)
1471 if (FromUser
== false && Pkg
->SelectedState
== pkgCache::State::Hold
&& _config
->FindB("APT::Ignore-Hold",false) == false)
1473 if (DebugMarker
== true)
1474 std::clog
<< OutputInDepth(Depth
) << "Hold prevents MarkInstall of " << Pkg
<< " FU=" << FromUser
<< std::endl
;
1480 // DepCache::SetReInstall - Set the reinstallation flag /*{{{*/
1481 // ---------------------------------------------------------------------
1483 void pkgDepCache::SetReInstall(PkgIterator
const &Pkg
,bool To
)
1485 if (unlikely(Pkg
.end() == true))
1488 ActionGroup
group(*this);
1493 StateCache
&P
= PkgState
[Pkg
->ID
];
1495 P
.iFlags
|= ReInstall
;
1497 P
.iFlags
&= ~ReInstall
;
1502 if (unlikely(Pkg
.CurrentVer().end() == true) || Pkg
.CurrentVer().Pseudo() == false)
1505 SetReInstall(Pkg
.Group().FindPkg("all"), To
);
1508 // DepCache::SetCandidateVersion - Change the candidate version /*{{{*/
1509 // ---------------------------------------------------------------------
1511 void pkgDepCache::SetCandidateVersion(VerIterator TargetVer
, bool const &Pseudo
)
1513 ActionGroup
group(*this);
1515 pkgCache::PkgIterator Pkg
= TargetVer
.ParentPkg();
1516 StateCache
&P
= PkgState
[Pkg
->ID
];
1521 if (P
.CandidateVer
== P
.InstallVer
)
1522 P
.InstallVer
= (Version
*)TargetVer
;
1523 P
.CandidateVer
= (Version
*)TargetVer
;
1524 P
.Update(Pkg
,*this);
1530 if (TargetVer
.Pseudo() == false || Pseudo
== false)
1533 // the version was pseudo: set all other pseudos also
1534 pkgCache::GrpIterator Grp
= Pkg
.Group();
1535 for (Pkg
= Grp
.FindPkg("any"); Pkg
.end() == false; ++Pkg
)
1537 StateCache
&P
= PkgState
[Pkg
->ID
];
1538 if (TargetVer
.SimilarVer(P
.CandidateVerIter(*this)) == true ||
1539 (P
.CandidateVerIter(*this).Pseudo() == false &&
1540 strcmp(Pkg
.Arch(), "all") != 0))
1543 for (pkgCache::VerIterator Ver
= Pkg
.VersionList(); Ver
.end() == false; ++Ver
)
1545 if (TargetVer
.SimilarVer(Ver
) == false)
1547 SetCandidateVersion(Ver
, false);
1553 void pkgDepCache::MarkAuto(const PkgIterator
&Pkg
, bool Auto
)
1555 StateCache
&state
= PkgState
[Pkg
->ID
];
1557 ActionGroup
group(*this);
1560 state
.Flags
|= Flag::Auto
;
1562 state
.Flags
&= ~Flag::Auto
;
1565 // StateCache::Update - Compute the various static display things /*{{{*/
1566 // ---------------------------------------------------------------------
1567 /* This is called whenever the Candidate version changes. */
1568 void pkgDepCache::StateCache::Update(PkgIterator Pkg
,pkgCache
&Cache
)
1571 VerIterator Ver
= CandidateVerIter(Cache
);
1573 // Use a null string or the version string
1574 if (Ver
.end() == true)
1577 CandVersion
= Ver
.VerStr();
1579 // Find the current version
1581 if (Pkg
->CurrentVer
!= 0)
1582 CurVersion
= Pkg
.CurrentVer().VerStr();
1584 // Strip off the epochs for display
1585 CurVersion
= StripEpoch(CurVersion
);
1586 CandVersion
= StripEpoch(CandVersion
);
1588 // Figure out if its up or down or equal
1589 Status
= Ver
.CompareVer(Pkg
.CurrentVer());
1590 if (Pkg
->CurrentVer
== 0 || Pkg
->VersionList
== 0 || CandidateVer
== 0)
1594 // StateCache::StripEpoch - Remove the epoch specifier from the version /*{{{*/
1595 // ---------------------------------------------------------------------
1597 const char *pkgDepCache::StateCache::StripEpoch(const char *Ver
)
1603 for (const char *I
= Ver
; *I
!= 0; I
++)
1609 // Policy::GetCandidateVer - Returns the Candidate install version /*{{{*/
1610 // ---------------------------------------------------------------------
1611 /* The default just returns the highest available version that is not
1612 a source and automatic. */
1613 pkgCache::VerIterator
pkgDepCache::Policy::GetCandidateVer(PkgIterator
const &Pkg
)
1615 /* Not source/not automatic versions cannot be a candidate version
1616 unless they are already installed */
1617 VerIterator
Last(*(pkgCache
*)this,0);
1619 for (VerIterator I
= Pkg
.VersionList(); I
.end() == false; I
++)
1621 if (Pkg
.CurrentVer() == I
)
1624 for (VerFileIterator J
= I
.FileList(); J
.end() == false; J
++)
1626 if ((J
.File()->Flags
& Flag::NotSource
) != 0)
1629 /* Stash the highest version of a not-automatic source, we use it
1630 if there is nothing better */
1631 if ((J
.File()->Flags
& Flag::NotAutomatic
) != 0 ||
1632 (J
.File()->Flags
& Flag::ButAutomaticUpgrades
) != 0)
1634 if (Last
.end() == true)
1646 // Policy::IsImportantDep - True if the dependency is important /*{{{*/
1647 // ---------------------------------------------------------------------
1649 bool pkgDepCache::Policy::IsImportantDep(DepIterator
const &Dep
)
1651 if(Dep
.IsCritical())
1653 else if(Dep
->Type
== pkgCache::Dep::Recommends
)
1655 if ( _config
->FindB("APT::Install-Recommends", false))
1657 // we suport a special mode to only install-recommends for certain
1659 // FIXME: this is a meant as a temporarly solution until the
1660 // recommends are cleaned up
1661 const char *sec
= Dep
.ParentVer().Section();
1662 if (sec
&& ConfigValueInSubTree("APT::Install-Recommends-Sections", sec
))
1665 else if(Dep
->Type
== pkgCache::Dep::Suggests
)
1666 return _config
->FindB("APT::Install-Suggests", false);
1671 pkgDepCache::InRootSetFunc
*pkgDepCache::GetRootSetFunc() /*{{{*/
1673 DefaultRootSetFunc
*f
= new DefaultRootSetFunc
;
1674 if(f
->wasConstructedSuccessfully())
1683 bool pkgDepCache::MarkFollowsRecommends()
1685 return _config
->FindB("APT::AutoRemove::RecommendsImportant", true);
1688 bool pkgDepCache::MarkFollowsSuggests()
1690 return _config
->FindB("APT::AutoRemove::SuggestsImportant", false);
1693 // pkgDepCache::MarkRequired - the main mark algorithm /*{{{*/
1694 bool pkgDepCache::MarkRequired(InRootSetFunc
&userFunc
)
1696 bool follow_recommends
;
1697 bool follow_suggests
;
1698 bool debug_autoremove
= _config
->FindB("Debug::pkgAutoRemove",false);
1701 for(PkgIterator p
= PkgBegin(); !p
.end(); ++p
)
1703 PkgState
[p
->ID
].Marked
= false;
1704 PkgState
[p
->ID
].Garbage
= false;
1707 if(debug_autoremove
&& PkgState
[p
->ID
].Flags
& Flag::Auto
)
1708 std::clog
<< "AutoDep: " << p
.FullName() << std::endl
;
1712 follow_recommends
= MarkFollowsRecommends();
1713 follow_suggests
= MarkFollowsSuggests();
1717 // do the mark part, this is the core bit of the algorithm
1718 for(PkgIterator p
= PkgBegin(); !p
.end(); ++p
)
1720 if(!(PkgState
[p
->ID
].Flags
& Flag::Auto
) ||
1721 (p
->Flags
& Flag::Essential
) ||
1722 userFunc
.InRootSet(p
) ||
1723 // be nice even then a required package violates the policy (#583517)
1724 // and do the full mark process also for required packages
1725 (p
.CurrentVer().end() != true &&
1726 p
.CurrentVer()->Priority
== pkgCache::State::Required
))
1728 // the package is installed (and set to keep)
1729 if(PkgState
[p
->ID
].Keep() && !p
.CurrentVer().end())
1730 MarkPackage(p
, p
.CurrentVer(),
1731 follow_recommends
, follow_suggests
);
1732 // the package is to be installed
1733 else if(PkgState
[p
->ID
].Install())
1734 MarkPackage(p
, PkgState
[p
->ID
].InstVerIter(*this),
1735 follow_recommends
, follow_suggests
);
1742 // MarkPackage - mark a single package in Mark-and-Sweep /*{{{*/
1743 void pkgDepCache::MarkPackage(const pkgCache::PkgIterator
&pkg
,
1744 const pkgCache::VerIterator
&ver
,
1745 bool const &follow_recommends
,
1746 bool const &follow_suggests
)
1748 pkgDepCache::StateCache
&state
= PkgState
[pkg
->ID
];
1750 // if we are marked already we are done
1754 VerIterator
const currver
= pkg
.CurrentVer();
1755 VerIterator
const candver
= state
.CandidateVerIter(*this);
1756 VerIterator
const instver
= state
.InstVerIter(*this);
1759 // If a package was garbage-collected but is now being marked, we
1760 // should re-select it
1761 // For cases when a pkg is set to upgrade and this trigger the
1762 // removal of a no-longer used dependency. if the pkg is set to
1763 // keep again later it will result in broken deps
1764 if(state
.Delete() && state
.RemoveReason
= Unused
)
1767 mark_install(pkg
, false, false, NULL
);
1768 else if(ver
==pkg
.CurrentVer())
1769 MarkKeep(pkg
, false, false);
1771 instver
=state
.InstVerIter(*this);
1775 // For packages that are not going to be removed, ignore versions
1776 // other than the InstVer. For packages that are going to be
1777 // removed, ignore versions other than the current version.
1778 if(!(ver
== instver
&& !instver
.end()) &&
1779 !(ver
== currver
&& instver
.end() && !ver
.end()))
1782 bool const debug_autoremove
= _config
->FindB("Debug::pkgAutoRemove", false);
1784 if(debug_autoremove
)
1786 std::clog
<< "Marking: " << pkg
.FullName();
1788 std::clog
<< " " << ver
.VerStr();
1790 std::clog
<< ", Curr=" << currver
.VerStr();
1792 std::clog
<< ", Inst=" << instver
.VerStr();
1793 std::clog
<< std::endl
;
1798 if(ver
.end() == true)
1801 // If the version belongs to a Multi-Arch all package
1802 // we will mark all others in this Group with this version also
1803 if (ver
->MultiArch
== pkgCache::Version::All
&&
1804 strcmp(ver
.Arch(true), "all") == 0)
1806 GrpIterator G
= pkg
.Group();
1807 const char* const VerStr
= ver
.VerStr();
1808 for (PkgIterator P
= G
.FindPkg("any");
1809 P
.end() != true; P
= G
.NextPkg(P
))
1811 for (VerIterator V
= P
.VersionList();
1812 V
.end() != true; ++V
)
1814 if (ver
->Hash
!= V
->Hash
||
1815 strcmp(VerStr
, V
.VerStr()) != 0)
1817 MarkPackage(P
, V
, follow_recommends
, follow_suggests
);
1823 for(DepIterator d
= ver
.DependsList(); !d
.end(); ++d
)
1825 if(d
->Type
== Dep::Depends
||
1826 d
->Type
== Dep::PreDepends
||
1827 (follow_recommends
&&
1828 d
->Type
== Dep::Recommends
) ||
1830 d
->Type
== Dep::Suggests
))
1832 // Try all versions of this package.
1833 for(VerIterator V
= d
.TargetPkg().VersionList();
1836 if(_system
->VS
->CheckDep(V
.VerStr(), d
->CompareOp
, d
.TargetVer()))
1838 if(debug_autoremove
)
1840 std::clog
<< "Following dep: " << d
.ParentPkg().FullName()
1841 << " " << d
.ParentVer().VerStr() << " "
1842 << d
.DepType() << " " << d
.TargetPkg().FullName();
1843 if((d
->CompareOp
& ~pkgCache::Dep::Or
) != pkgCache::Dep::NoOp
)
1845 std::clog
<< " (" << d
.CompType() << " "
1846 << d
.TargetVer() << ")";
1848 std::clog
<< std::endl
;
1850 MarkPackage(V
.ParentPkg(), V
,
1851 follow_recommends
, follow_suggests
);
1854 // Now try virtual packages
1855 for(PrvIterator prv
=d
.TargetPkg().ProvidesList();
1858 if(_system
->VS
->CheckDep(prv
.ProvideVersion(), d
->CompareOp
,
1861 if(debug_autoremove
)
1863 std::clog
<< "Following dep: " << d
.ParentPkg().FullName() << " "
1864 << d
.ParentVer().VerStr() << " "
1865 << d
.DepType() << " " << d
.TargetPkg().FullName() << " ";
1866 if((d
->CompareOp
& ~pkgCache::Dep::Or
) != pkgCache::Dep::NoOp
)
1868 std::clog
<< " (" << d
.CompType() << " "
1869 << d
.TargetVer() << ")";
1871 std::clog
<< ", provided by "
1872 << prv
.OwnerPkg().FullName() << " "
1873 << prv
.OwnerVer().VerStr()
1877 MarkPackage(prv
.OwnerPkg(), prv
.OwnerVer(),
1878 follow_recommends
, follow_suggests
);
1885 bool pkgDepCache::Sweep() /*{{{*/
1887 bool debug_autoremove
= _config
->FindB("Debug::pkgAutoRemove",false);
1890 for(PkgIterator p
=PkgBegin(); !p
.end(); ++p
)
1892 StateCache
&state
=PkgState
[p
->ID
];
1894 // skip required packages
1895 if (!p
.CurrentVer().end() &&
1896 (p
.CurrentVer()->Priority
== pkgCache::State::Required
))
1899 // if it is not marked and it is installed, it's garbage
1900 if(!state
.Marked
&& (!p
.CurrentVer().end() || state
.Install()))
1903 if(debug_autoremove
)
1904 std::clog
<< "Garbage: " << p
.FullName() << std::endl
;