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
->FindDir("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::cout
<< "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
->FindDir("Dir::State") + "extended_states";
227 // if it does not exist, create a empty one
228 if(!FileExists(state
))
230 StateFile
.Open(state
, FileFd::WriteEmpty
);
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 bool const newAuto
= (PkgState
[pkg
->ID
].Flags
& Flag::Auto
);
261 if(_config
->FindB("Debug::pkgAutoRemove",false))
262 std::clog
<< "Update existing AutoInstall info: "
263 << pkg
.FullName() << std::endl
;
264 TFRewriteData rewrite
[3];
265 rewrite
[0].Tag
= "Architecture";
266 rewrite
[0].Rewrite
= pkg
.Arch();
267 rewrite
[0].NewTag
= 0;
268 rewrite
[1].Tag
= "Auto-Installed";
269 rewrite
[1].Rewrite
= newAuto
? "1" : "0";
270 rewrite
[1].NewTag
= 0;
272 TFRewrite(OutFile
, section
, nullreorderlist
, rewrite
);
273 fprintf(OutFile
,"\n");
274 pkgs_seen
.insert(pkg
.FullName());
277 // then write the ones we have not seen yet
278 std::ostringstream ostr
;
279 for(pkgCache::PkgIterator pkg
=Cache
->PkgBegin(); !pkg
.end(); pkg
++) {
280 if(PkgState
[pkg
->ID
].Flags
& Flag::Auto
) {
281 if (pkgs_seen
.find(pkg
.FullName()) != pkgs_seen
.end()) {
283 std::clog
<< "Skipping already written " << pkg
.FullName() << std::endl
;
286 // skip not installed ones if requested
287 if(InstalledOnly
&& pkg
->CurrentVer
== 0)
289 const char* const pkgarch
= pkg
.Arch();
290 if (strcmp(pkgarch
, "all") == 0)
293 std::clog
<< "Writing new AutoInstall: " << pkg
.FullName() << std::endl
;
294 ostr
.str(string(""));
295 ostr
<< "Package: " << pkg
.Name()
296 << "\nArchitecture: " << pkgarch
297 << "\nAuto-Installed: 1\n\n";
298 fprintf(OutFile
,"%s",ostr
.str().c_str());
303 // move the outfile over the real file and set permissions
304 rename(outfile
.c_str(), state
.c_str());
305 chmod(state
.c_str(), 0644);
310 // DepCache::CheckDep - Checks a single dependency /*{{{*/
311 // ---------------------------------------------------------------------
312 /* This first checks the dependency against the main target package and
313 then walks along the package provides list and checks if each provides
314 will be installed then checks the provides against the dep. Res will be
315 set to the package which was used to satisfy the dep. */
316 bool pkgDepCache::CheckDep(DepIterator Dep
,int Type
,PkgIterator
&Res
)
318 Res
= Dep
.TargetPkg();
320 /* Check simple depends. A depends -should- never self match but
321 we allow it anyhow because dpkg does. Technically it is a packaging
322 bug. Conflicts may never self match */
323 if (Dep
.TargetPkg() != Dep
.ParentPkg() ||
324 (Dep
->Type
!= Dep::Conflicts
&& Dep
->Type
!= Dep::DpkgBreaks
&& Dep
->Type
!= Dep::Obsoletes
))
326 PkgIterator Pkg
= Dep
.TargetPkg();
327 // Check the base package
328 if (Type
== NowVersion
&& Pkg
->CurrentVer
!= 0)
329 if (VS().CheckDep(Pkg
.CurrentVer().VerStr(),Dep
->CompareOp
,
330 Dep
.TargetVer()) == true)
333 if (Type
== InstallVersion
&& PkgState
[Pkg
->ID
].InstallVer
!= 0)
334 if (VS().CheckDep(PkgState
[Pkg
->ID
].InstVerIter(*this).VerStr(),
335 Dep
->CompareOp
,Dep
.TargetVer()) == true)
338 if (Type
== CandidateVersion
&& PkgState
[Pkg
->ID
].CandidateVer
!= 0)
339 if (VS().CheckDep(PkgState
[Pkg
->ID
].CandidateVerIter(*this).VerStr(),
340 Dep
->CompareOp
,Dep
.TargetVer()) == true)
344 if (Dep
->Type
== Dep::Obsoletes
)
347 // Check the providing packages
348 PrvIterator P
= Dep
.TargetPkg().ProvidesList();
349 PkgIterator Pkg
= Dep
.ParentPkg();
350 for (; P
.end() != true; P
++)
352 /* Provides may never be applied against the same package if it is
353 a conflicts. See the comment above. */
354 if (P
.OwnerPkg() == Pkg
&&
355 (Dep
->Type
== Dep::Conflicts
|| Dep
->Type
== Dep::DpkgBreaks
))
358 // Check if the provides is a hit
359 if (Type
== NowVersion
)
361 if (P
.OwnerPkg().CurrentVer() != P
.OwnerVer())
365 if (Type
== InstallVersion
)
367 StateCache
&State
= PkgState
[P
.OwnerPkg()->ID
];
368 if (State
.InstallVer
!= (Version
*)P
.OwnerVer())
372 if (Type
== CandidateVersion
)
374 StateCache
&State
= PkgState
[P
.OwnerPkg()->ID
];
375 if (State
.CandidateVer
!= (Version
*)P
.OwnerVer())
379 // Compare the versions.
380 if (VS().CheckDep(P
.ProvideVersion(),Dep
->CompareOp
,Dep
.TargetVer()) == true)
390 // DepCache::AddSizes - Add the packages sizes to the counters /*{{{*/
391 // ---------------------------------------------------------------------
392 /* Call with Mult = -1 to preform the inverse opration */
393 void pkgDepCache::AddSizes(const PkgIterator
&Pkg
,signed long Mult
)
395 StateCache
&P
= PkgState
[Pkg
->ID
];
397 if (Pkg
->VersionList
== 0)
400 if (Pkg
.State() == pkgCache::PkgIterator::NeedsConfigure
&&
404 // Compute the size data
405 if (P
.NewInstall() == true)
407 iUsrSize
+= (signed)(Mult
*P
.InstVerIter(*this)->InstalledSize
);
408 iDownloadSize
+= (signed)(Mult
*P
.InstVerIter(*this)->Size
);
413 if (Pkg
->CurrentVer
!= 0 &&
414 (P
.InstallVer
!= (Version
*)Pkg
.CurrentVer() ||
415 (P
.iFlags
& ReInstall
) == ReInstall
) && P
.InstallVer
!= 0)
417 iUsrSize
+= (signed)(Mult
*((signed)P
.InstVerIter(*this)->InstalledSize
-
418 (signed)Pkg
.CurrentVer()->InstalledSize
));
419 iDownloadSize
+= (signed)(Mult
*P
.InstVerIter(*this)->Size
);
424 if (Pkg
.State() == pkgCache::PkgIterator::NeedsUnpack
&&
427 iDownloadSize
+= (signed)(Mult
*P
.InstVerIter(*this)->Size
);
432 if (Pkg
->CurrentVer
!= 0 && P
.InstallVer
== 0)
434 iUsrSize
-= (signed)(Mult
*Pkg
.CurrentVer()->InstalledSize
);
439 // DepCache::AddStates - Add the package to the state counter /*{{{*/
440 // ---------------------------------------------------------------------
441 /* This routine is tricky to use, you must make sure that it is never
442 called twice for the same package. This means the Remove/Add section
443 should be as short as possible and not encompass any code that will
444 calld Remove/Add itself. Remember, dependencies can be circular so
445 while processing a dep for Pkg it is possible that Add/Remove
446 will be called on Pkg */
447 void pkgDepCache::AddStates(const PkgIterator
&Pkg
,int Add
)
449 StateCache
&State
= PkgState
[Pkg
->ID
];
451 // The Package is broken (either minimal dep or policy dep)
452 if ((State
.DepState
& DepInstMin
) != DepInstMin
)
454 if ((State
.DepState
& DepInstPolicy
) != DepInstPolicy
)
455 iPolicyBrokenCount
+= Add
;
458 if (Pkg
.State() != PkgIterator::NeedsNothing
)
462 if (Pkg
->CurrentVer
== 0)
464 if (State
.Mode
== ModeDelete
&&
465 (State
.iFlags
| Purge
) == Purge
&& Pkg
.Purge() == false)
468 if (State
.Mode
== ModeInstall
)
473 // Installed, no upgrade
474 if (State
.Status
== 0)
476 if (State
.Mode
== ModeDelete
)
479 if ((State
.iFlags
& ReInstall
) == ReInstall
)
485 // Alll 3 are possible
486 if (State
.Mode
== ModeDelete
)
488 if (State
.Mode
== ModeKeep
)
490 if (State
.Mode
== ModeInstall
)
494 // DepCache::BuildGroupOrs - Generate the Or group dep data /*{{{*/
495 // ---------------------------------------------------------------------
496 /* The or group results are stored in the last item of the or group. This
497 allows easy detection of the state of a whole or'd group. */
498 void pkgDepCache::BuildGroupOrs(VerIterator
const &V
)
500 unsigned char Group
= 0;
502 for (DepIterator D
= V
.DependsList(); D
.end() != true; D
++)
504 // Build the dependency state.
505 unsigned char &State
= DepState
[D
->ID
];
507 /* Invert for Conflicts. We have to do this twice to get the
508 right sense for a conflicts group */
509 if (D
->Type
== Dep::Conflicts
||
510 D
->Type
== Dep::DpkgBreaks
||
511 D
->Type
== Dep::Obsoletes
)
514 // Add to the group if we are within an or..
518 if ((D
->CompareOp
& Dep::Or
) != Dep::Or
)
521 // Invert for Conflicts
522 if (D
->Type
== Dep::Conflicts
||
523 D
->Type
== Dep::DpkgBreaks
||
524 D
->Type
== Dep::Obsoletes
)
529 // DepCache::VersionState - Perform a pass over a dependency list /*{{{*/
530 // ---------------------------------------------------------------------
531 /* This is used to run over a dependency list and determine the dep
532 state of the list, filtering it through both a Min check and a Policy
533 check. The return result will have SetMin/SetPolicy low if a check
534 fails. It uses the DepState cache for it's computations. */
535 unsigned char pkgDepCache::VersionState(DepIterator D
,unsigned char Check
,
536 unsigned char SetMin
,
537 unsigned char SetPolicy
)
539 unsigned char Dep
= 0xFF;
541 while (D
.end() != true)
543 // Compute a single dependency element (glob or)
544 DepIterator Start
= D
;
545 unsigned char State
= 0;
546 for (bool LastOR
= true; D
.end() == false && LastOR
== true; D
++)
548 State
|= DepState
[D
->ID
];
549 LastOR
= (D
->CompareOp
& Dep::Or
) == Dep::Or
;
552 // Minimum deps that must be satisfied to have a working package
553 if (Start
.IsCritical() == true)
554 if ((State
& Check
) != Check
)
557 // Policy deps that must be satisfied to install the package
558 if (IsImportantDep(Start
) == true &&
559 (State
& Check
) != Check
)
566 // DepCache::DependencyState - Compute the 3 results for a dep /*{{{*/
567 // ---------------------------------------------------------------------
568 /* This is the main dependency computation bit. It computes the 3 main
569 results for a dependencys, Now, Install and Candidate. Callers must
570 invert the result if dealing with conflicts. */
571 unsigned char pkgDepCache::DependencyState(DepIterator
&D
)
573 unsigned char State
= 0;
575 if (CheckDep(D
,NowVersion
) == true)
577 if (CheckDep(D
,InstallVersion
) == true)
579 if (CheckDep(D
,CandidateVersion
) == true)
585 // DepCache::UpdateVerState - Compute the Dep member of the state /*{{{*/
586 // ---------------------------------------------------------------------
587 /* This determines the combined dependency representation of a package
588 for its two states now and install. This is done by using the pre-generated
589 dependency information. */
590 void pkgDepCache::UpdateVerState(PkgIterator Pkg
)
592 // Empty deps are always true
593 StateCache
&State
= PkgState
[Pkg
->ID
];
594 State
.DepState
= 0xFF;
596 // Check the Current state
597 if (Pkg
->CurrentVer
!= 0)
599 DepIterator D
= Pkg
.CurrentVer().DependsList();
600 State
.DepState
&= VersionState(D
,DepNow
,DepNowMin
,DepNowPolicy
);
603 /* Check the candidate state. We do not compare against the whole as
604 a candidate state but check the candidate version against the
606 if (State
.CandidateVer
!= 0)
608 DepIterator D
= State
.CandidateVerIter(*this).DependsList();
609 State
.DepState
&= VersionState(D
,DepInstall
,DepCandMin
,DepCandPolicy
);
612 // Check target state which can only be current or installed
613 if (State
.InstallVer
!= 0)
615 DepIterator D
= State
.InstVerIter(*this).DependsList();
616 State
.DepState
&= VersionState(D
,DepInstall
,DepInstMin
,DepInstPolicy
);
620 // DepCache::RemovePseudoInstalledPkg - MultiArch helper for Update() /*{{{*/
621 // ---------------------------------------------------------------------
622 /* We "install" arch all packages for all archs if it is installed. Many
623 of these will be broken. This method will look at these broken Pkg and
625 bool pkgDepCache::RemovePseudoInstalledPkg(PkgIterator
&Pkg
, std::set
<unsigned long> &recheck
) {
626 if (unlikely(Pkg
->CurrentVer
== 0))
629 VerIterator V
= Pkg
.CurrentVer();
630 if (V
->MultiArch
!= Version::All
)
633 unsigned char const DepState
= VersionState(V
.DependsList(),DepInstall
,DepInstMin
,DepInstPolicy
);
634 if ((DepState
& DepInstMin
) == DepInstMin
)
637 // Dependencies for this arch all are not statisfied
638 // so we installed it only for our convenience: get right of it now.
643 PkgState
[Pkg
->ID
].InstallVer
= 0;
649 // After the remove previously satisfied pseudo pkg could be now
650 // no longer satisfied, so we need to recheck the reverse dependencies
651 for (DepIterator d
= Pkg
.RevDependsList(); d
.end() != true; ++d
)
653 PkgIterator
const P
= d
.ParentPkg();
654 if (P
->CurrentVer
!= 0)
655 recheck
.insert(P
.Index());
659 for (PrvIterator Prv
= V
.ProvidesList(); Prv
.end() != true; Prv
++)
660 for (DepIterator d
= Prv
.ParentPkg().RevDependsList();
661 d
.end() != true; ++d
)
663 PkgIterator
const P
= d
.ParentPkg();
664 if (P
->CurrentVer
!= 0)
665 recheck
.insert(P
.Index());
671 // DepCache::Update - Figure out all the state information /*{{{*/
672 // ---------------------------------------------------------------------
673 /* This will figure out the state of all the packages and all the
674 dependencies based on the current policy. */
675 void pkgDepCache::Update(OpProgress
*Prog
)
685 std::set
<unsigned long> recheck
;
687 // Perform the depends pass
689 bool const checkMultiArch
= APT::Configuration::getArchitectures().size() > 1;
690 unsigned long killed
= 0;
691 for (PkgIterator I
= PkgBegin(); I
.end() != true; I
++,Done
++)
693 if (Prog
!= 0 && Done%20
== 0)
694 Prog
->Progress(Done
);
695 for (VerIterator V
= I
.VersionList(); V
.end() != true; V
++)
697 unsigned char Group
= 0;
699 for (DepIterator D
= V
.DependsList(); D
.end() != true; D
++)
701 // Build the dependency state.
702 unsigned char &State
= DepState
[D
->ID
];
703 State
= DependencyState(D
);
705 // Add to the group if we are within an or..
708 if ((D
->CompareOp
& Dep::Or
) != Dep::Or
)
711 // Invert for Conflicts
712 if (D
->Type
== Dep::Conflicts
||
713 D
->Type
== Dep::DpkgBreaks
||
714 D
->Type
== Dep::Obsoletes
)
719 // Compute the package dependency state and size additions
724 if (checkMultiArch
!= true || I
->CurrentVer
== 0)
727 VerIterator
const V
= I
.CurrentVer();
728 if (V
->MultiArch
!= Version::All
)
731 recheck
.insert(I
.Index());
732 --Done
; // no progress if we need to recheck the package
735 if (checkMultiArch
== true) {
736 /* FIXME: recheck breaks proper progress reporting as we don't know
737 how many packages we need to recheck. To lower the effect
738 a bit we increase with a kill, but we should do something more clever… */
739 for(std::set
<unsigned long>::const_iterator p
= recheck
.begin();
740 p
!= recheck
.end(); ++p
) {
741 if (Prog
!= 0 && Done%20
== 0)
742 Prog
->Progress(Done
);
743 PkgIterator P
= PkgIterator(*Cache
, Cache
->PkgP
+ *p
);
744 if (RemovePseudoInstalledPkg(P
, recheck
) == true) {
753 Prog
->Progress(Done
);
758 // DepCache::Update - Update the deps list of a package /*{{{*/
759 // ---------------------------------------------------------------------
760 /* This is a helper for update that only does the dep portion of the scan.
761 It is mainly meant to scan reverse dependencies. */
762 void pkgDepCache::Update(DepIterator D
)
764 // Update the reverse deps
765 for (;D
.end() != true; D
++)
767 unsigned char &State
= DepState
[D
->ID
];
768 State
= DependencyState(D
);
770 // Invert for Conflicts
771 if (D
->Type
== Dep::Conflicts
||
772 D
->Type
== Dep::DpkgBreaks
||
773 D
->Type
== Dep::Obsoletes
)
776 RemoveStates(D
.ParentPkg());
777 BuildGroupOrs(D
.ParentVer());
778 UpdateVerState(D
.ParentPkg());
779 AddStates(D
.ParentPkg());
783 // DepCache::Update - Update the related deps of a package /*{{{*/
784 // ---------------------------------------------------------------------
785 /* This is called whenever the state of a package changes. It updates
786 all cached dependencies related to this package. */
787 void pkgDepCache::Update(PkgIterator
const &Pkg
)
789 // Recompute the dep of the package
794 // Update the reverse deps
795 Update(Pkg
.RevDependsList());
797 // Update the provides map for the current ver
798 if (Pkg
->CurrentVer
!= 0)
799 for (PrvIterator P
= Pkg
.CurrentVer().ProvidesList();
800 P
.end() != true; P
++)
801 Update(P
.ParentPkg().RevDependsList());
803 // Update the provides map for the candidate ver
804 if (PkgState
[Pkg
->ID
].CandidateVer
!= 0)
805 for (PrvIterator P
= PkgState
[Pkg
->ID
].CandidateVerIter(*this).ProvidesList();
806 P
.end() != true; P
++)
807 Update(P
.ParentPkg().RevDependsList());
810 // DepCache::MarkKeep - Put the package in the keep state /*{{{*/
811 // ---------------------------------------------------------------------
813 void pkgDepCache::MarkKeep(PkgIterator
const &Pkg
, bool Soft
, bool FromUser
,
816 // Simplifies other routines.
817 if (Pkg
.end() == true)
820 /* Reject an attempt to keep a non-source broken installed package, those
822 if (Pkg
.State() == PkgIterator::NeedsUnpack
&&
823 Pkg
.CurrentVer().Downloadable() == false)
826 /** \todo Can this be moved later in the method? */
827 ActionGroup
group(*this);
829 /* We changed the soft state all the time so the UI is a bit nicer
831 StateCache
&P
= PkgState
[Pkg
->ID
];
833 P
.iFlags
|= AutoKept
;
835 P
.iFlags
&= ~AutoKept
;
837 // Check that it is not already kept
838 if (P
.Mode
== ModeKeep
)
841 // We dont even try to keep virtual packages..
842 if (Pkg
->VersionList
== 0)
844 #if 0 // reseting the autoflag here means we lose the
845 // auto-mark information if a user selects a package for removal
846 // but changes his mind then and sets it for keep again
847 // - this makes sense as default when all Garbage dependencies
848 // are automatically marked for removal (as aptitude does).
849 // setting a package for keep then makes it no longer autoinstalled
850 // for all other use-case this action is rather suprising
851 if(FromUser
&& !P
.Marked
)
852 P
.Flags
&= ~Flag::Auto
;
855 if (DebugMarker
== true)
856 std::clog
<< OutputInDepth(Depth
) << "MarkKeep " << Pkg
<< " FU=" << FromUser
<< std::endl
;
862 if (Pkg
->CurrentVer
== 0)
865 P
.InstallVer
= Pkg
.CurrentVer();
874 // DepCache::MarkDelete - Put the package in the delete state /*{{{*/
875 // ---------------------------------------------------------------------
877 void pkgDepCache::MarkDelete(PkgIterator
const &Pkg
, bool rPurge
,
878 unsigned long Depth
, bool FromUser
)
880 // Simplifies other routines.
881 if (Pkg
.end() == true)
884 ActionGroup
group(*this);
886 // Check that it is not already marked for delete
887 StateCache
&P
= PkgState
[Pkg
->ID
];
888 P
.iFlags
&= ~(AutoKept
| Purge
);
892 if ((P
.Mode
== ModeDelete
|| P
.InstallVer
== 0) &&
893 (Pkg
.Purge() == true || rPurge
== false))
896 // We dont even try to delete virtual packages..
897 if (Pkg
->VersionList
== 0)
900 // check if we are allowed to install the package
901 if (IsDeleteOk(Pkg
,rPurge
,Depth
,FromUser
) == false)
904 if (DebugMarker
== true)
905 std::clog
<< OutputInDepth(Depth
) << "MarkDelete " << Pkg
<< " FU=" << FromUser
<< std::endl
;
910 if (Pkg
->CurrentVer
== 0 && (Pkg
.Purge() == true || rPurge
== false))
920 // if we remove the pseudo package, we also need to remove the "real"
921 if (Pkg
->CurrentVer
!= 0 && Pkg
.CurrentVer().Pseudo() == true)
922 MarkDelete(Pkg
.Group().FindPkg("all"), rPurge
, Depth
+1, FromUser
);
925 // DepCache::IsDeleteOk - check if it is ok to remove this package /*{{{*/
926 // ---------------------------------------------------------------------
927 /* The default implementation just honors dpkg hold
928 But an application using this library can override this method
929 to control the MarkDelete behaviour */
930 bool pkgDepCache::IsDeleteOk(PkgIterator
const &Pkg
,bool rPurge
,
931 unsigned long Depth
, bool FromUser
)
933 if (FromUser
== false && Pkg
->SelectedState
== pkgCache::State::Hold
&& _config
->FindB("APT::Ignore-Hold",false) == false)
935 if (DebugMarker
== true)
936 std::clog
<< OutputInDepth(Depth
) << "Hold prevents MarkDelete of " << Pkg
<< " FU=" << FromUser
<< std::endl
;
942 // DepCache::MarkInstall - Put the package in the install state /*{{{*/
943 // ---------------------------------------------------------------------
945 void pkgDepCache::MarkInstall(PkgIterator
const &Pkg
,bool AutoInst
,
946 unsigned long Depth
, bool FromUser
,
947 bool ForceImportantDeps
)
952 // Simplifies other routines.
953 if (Pkg
.end() == true)
956 ActionGroup
group(*this);
958 /* Check that it is not already marked for install and that it can be
960 StateCache
&P
= PkgState
[Pkg
->ID
];
961 P
.iFlags
&= ~AutoKept
;
962 if ((P
.InstPolicyBroken() == false && P
.InstBroken() == false) &&
963 (P
.Mode
== ModeInstall
||
964 P
.CandidateVer
== (Version
*)Pkg
.CurrentVer()))
966 if (P
.CandidateVer
== (Version
*)Pkg
.CurrentVer() && P
.InstallVer
== 0)
967 MarkKeep(Pkg
, false, FromUser
, Depth
+1);
971 // See if there is even any possible instalation candidate
972 if (P
.CandidateVer
== 0)
974 // We dont even try to install virtual packages..
975 if (Pkg
->VersionList
== 0)
978 // check if we are allowed to install the package
979 if (IsInstallOk(Pkg
,AutoInst
,Depth
,FromUser
) == false)
982 /* Target the candidate version and remove the autoflag. We reset the
983 autoflag below if this was called recursively. Otherwise the user
984 should have the ability to de-auto a package by changing its state */
988 P
.Mode
= ModeInstall
;
989 P
.InstallVer
= P
.CandidateVer
;
993 // Set it to manual if it's a new install or cancelling the
994 // removal of a garbage package.
995 if(P
.Status
== 2 || (!Pkg
.CurrentVer().end() && !P
.Marked
))
996 P
.Flags
&= ~Flag::Auto
;
1000 // Set it to auto if this is a new install.
1002 P
.Flags
|= Flag::Auto
;
1004 if (P
.CandidateVer
== (Version
*)Pkg
.CurrentVer())
1011 if (AutoInst
== false)
1014 if (DebugMarker
== true)
1015 std::clog
<< OutputInDepth(Depth
) << "MarkInstall " << Pkg
<< " FU=" << FromUser
<< std::endl
;
1017 DepIterator Dep
= P
.InstVerIter(*this).DependsList();
1018 for (; Dep
.end() != true;)
1021 DepIterator Start
= Dep
;
1024 for (bool LastOR
= true; Dep
.end() == false && LastOR
== true; Dep
++,Ors
++)
1026 LastOR
= (Dep
->CompareOp
& Dep::Or
) == Dep::Or
;
1028 if ((DepState
[Dep
->ID
] & DepInstall
) == DepInstall
)
1032 // Dep is satisfied okay.
1033 if (Result
== false)
1036 /* Check if this dep should be consider for install. If it is a user
1037 defined important dep and we are installed a new package then
1038 it will be installed. Otherwise we only check for important
1039 deps that have changed from the installed version
1041 if (IsImportantDep(Start
) == false)
1044 /* Check if any ImportantDep() (but not Critical) were added
1045 * since we installed the package. Also check for deps that
1046 * were satisfied in the past: for instance, if a version
1047 * restriction in a Recommends was tightened, upgrading the
1048 * package should follow that Recommends rather than causing the
1049 * dependency to be removed. (bug #470115)
1051 bool isNewImportantDep
= false;
1052 bool isPreviouslySatisfiedImportantDep
= false;
1053 if(!ForceImportantDeps
&& !Start
.IsCritical())
1056 VerIterator instVer
= Pkg
.CurrentVer();
1059 for (DepIterator D
= instVer
.DependsList(); D
.end() != true; D
++)
1061 //FIXME: deal better with or-groups(?)
1062 DepIterator LocalStart
= D
;
1064 if(IsImportantDep(D
) && !D
.IsCritical() &&
1065 Start
.TargetPkg() == D
.TargetPkg())
1067 if(!isPreviouslySatisfiedImportantDep
)
1070 while((D2
->CompareOp
& Dep::Or
) != 0)
1073 isPreviouslySatisfiedImportantDep
=
1074 (((*this)[D2
] & DepGNow
) != 0);
1080 // this is a new dep if it was not found to be already
1081 // a important dep of the installed pacakge
1082 isNewImportantDep
= !found
;
1085 if(isNewImportantDep
)
1086 if(DebugAutoInstall
== true)
1087 std::clog
<< OutputInDepth(Depth
) << "new important dependency: "
1088 << Start
.TargetPkg().Name() << std::endl
;
1089 if(isPreviouslySatisfiedImportantDep
)
1090 if(DebugAutoInstall
== true)
1091 std::clog
<< OutputInDepth(Depth
) << "previously satisfied important dependency on "
1092 << Start
.TargetPkg().Name() << std::endl
;
1094 // skip important deps if the package is already installed
1095 if (Pkg
->CurrentVer
!= 0 && Start
.IsCritical() == false
1096 && !isNewImportantDep
&& !isPreviouslySatisfiedImportantDep
1097 && !ForceImportantDeps
)
1100 /* If we are in an or group locate the first or that can
1101 succeed. We have already cached this.. */
1102 for (; Ors
> 1 && (DepState
[Start
->ID
] & DepCVer
) != DepCVer
; Ors
--)
1105 /* This bit is for processing the possibilty of an install/upgrade
1106 fixing the problem */
1107 SPtrArray
<Version
*> List
= Start
.AllTargets();
1108 if (Start
->Type
!= Dep::DpkgBreaks
&&
1109 (DepState
[Start
->ID
] & DepCVer
) == DepCVer
)
1111 // Right, find the best version to install..
1112 Version
**Cur
= List
;
1113 PkgIterator P
= Start
.TargetPkg();
1114 PkgIterator
InstPkg(*Cache
,0);
1116 // See if there are direct matches (at the start of the list)
1117 for (; *Cur
!= 0 && (*Cur
)->ParentPkg
== P
.Index(); Cur
++)
1119 PkgIterator
Pkg(*Cache
,Cache
->PkgP
+ (*Cur
)->ParentPkg
);
1120 if (PkgState
[Pkg
->ID
].CandidateVer
!= *Cur
)
1126 // Select the highest priority providing package
1127 if (InstPkg
.end() == true)
1129 pkgPrioSortList(*Cache
,Cur
);
1130 for (; *Cur
!= 0; Cur
++)
1132 PkgIterator
Pkg(*Cache
,Cache
->PkgP
+ (*Cur
)->ParentPkg
);
1133 if (PkgState
[Pkg
->ID
].CandidateVer
!= *Cur
)
1140 if (InstPkg
.end() == false)
1142 if(DebugAutoInstall
== true)
1143 std::clog
<< OutputInDepth(Depth
) << "Installing " << InstPkg
.Name()
1144 << " as " << Start
.DepType() << " of " << Pkg
.Name()
1146 // now check if we should consider it a automatic dependency or not
1147 if(Pkg
.Section() && ConfigValueInSubTree("APT::Never-MarkAuto-Sections", Pkg
.Section()))
1149 if(DebugAutoInstall
== true)
1150 std::clog
<< OutputInDepth(Depth
) << "Setting NOT as auto-installed (direct "
1151 << Start
.DepType() << " of pkg in APT::Never-MarkAuto-Sections)" << std::endl
;
1152 MarkInstall(InstPkg
,true,Depth
+ 1, true);
1156 // mark automatic dependency
1157 MarkInstall(InstPkg
,true,Depth
+ 1, false, ForceImportantDeps
);
1158 // Set the autoflag, after MarkInstall because MarkInstall unsets it
1159 if (P
->CurrentVer
== 0)
1160 PkgState
[InstPkg
->ID
].Flags
|= Flag::Auto
;
1166 /* For conflicts we just de-install the package and mark as auto,
1167 Conflicts may not have or groups. For dpkg's Breaks we try to
1168 upgrade the package. */
1169 if (Start
->Type
== Dep::Conflicts
|| Start
->Type
== Dep::Obsoletes
||
1170 Start
->Type
== Dep::DpkgBreaks
)
1172 for (Version
**I
= List
; *I
!= 0; I
++)
1174 VerIterator
Ver(*this,*I
);
1175 PkgIterator Pkg
= Ver
.ParentPkg();
1177 if (Start
->Type
!= Dep::DpkgBreaks
)
1178 MarkDelete(Pkg
,false,Depth
+ 1, false);
1179 else if (PkgState
[Pkg
->ID
].CandidateVer
!= *I
)
1180 MarkInstall(Pkg
,true,Depth
+ 1, false, ForceImportantDeps
);
1187 // DepCache::IsInstallOk - check if it is ok to install this package /*{{{*/
1188 // ---------------------------------------------------------------------
1189 /* The default implementation just honors dpkg hold
1190 But an application using this library can override this method
1191 to control the MarkInstall behaviour */
1192 bool pkgDepCache::IsInstallOk(PkgIterator
const &Pkg
,bool AutoInst
,
1193 unsigned long Depth
, bool FromUser
)
1195 if (FromUser
== false && Pkg
->SelectedState
== pkgCache::State::Hold
&& _config
->FindB("APT::Ignore-Hold",false) == false)
1197 if (DebugMarker
== true)
1198 std::clog
<< OutputInDepth(Depth
) << "Hold prevents MarkInstall of " << Pkg
<< " FU=" << FromUser
<< std::endl
;
1204 // DepCache::SetReInstall - Set the reinstallation flag /*{{{*/
1205 // ---------------------------------------------------------------------
1207 void pkgDepCache::SetReInstall(PkgIterator
const &Pkg
,bool To
)
1209 ActionGroup
group(*this);
1214 StateCache
&P
= PkgState
[Pkg
->ID
];
1216 P
.iFlags
|= ReInstall
;
1218 P
.iFlags
&= ~ReInstall
;
1224 // DepCache::SetCandidateVersion - Change the candidate version /*{{{*/
1225 // ---------------------------------------------------------------------
1227 void pkgDepCache::SetCandidateVersion(VerIterator TargetVer
)
1229 ActionGroup
group(*this);
1231 pkgCache::PkgIterator Pkg
= TargetVer
.ParentPkg();
1232 StateCache
&P
= PkgState
[Pkg
->ID
];
1237 if (P
.CandidateVer
== P
.InstallVer
)
1238 P
.InstallVer
= (Version
*)TargetVer
;
1239 P
.CandidateVer
= (Version
*)TargetVer
;
1240 P
.Update(Pkg
,*this);
1247 void pkgDepCache::MarkAuto(const PkgIterator
&Pkg
, bool Auto
)
1249 StateCache
&state
= PkgState
[Pkg
->ID
];
1251 ActionGroup
group(*this);
1254 state
.Flags
|= Flag::Auto
;
1256 state
.Flags
&= ~Flag::Auto
;
1259 // StateCache::Update - Compute the various static display things /*{{{*/
1260 // ---------------------------------------------------------------------
1261 /* This is called whenever the Candidate version changes. */
1262 void pkgDepCache::StateCache::Update(PkgIterator Pkg
,pkgCache
&Cache
)
1265 VerIterator Ver
= CandidateVerIter(Cache
);
1267 // Use a null string or the version string
1268 if (Ver
.end() == true)
1271 CandVersion
= Ver
.VerStr();
1273 // Find the current version
1275 if (Pkg
->CurrentVer
!= 0)
1276 CurVersion
= Pkg
.CurrentVer().VerStr();
1278 // Strip off the epochs for display
1279 CurVersion
= StripEpoch(CurVersion
);
1280 CandVersion
= StripEpoch(CandVersion
);
1282 // Figure out if its up or down or equal
1283 Status
= Ver
.CompareVer(Pkg
.CurrentVer());
1284 if (Pkg
->CurrentVer
== 0 || Pkg
->VersionList
== 0 || CandidateVer
== 0)
1288 // StateCache::StripEpoch - Remove the epoch specifier from the version /*{{{*/
1289 // ---------------------------------------------------------------------
1291 const char *pkgDepCache::StateCache::StripEpoch(const char *Ver
)
1297 for (const char *I
= Ver
; *I
!= 0; I
++)
1303 // Policy::GetCandidateVer - Returns the Candidate install version /*{{{*/
1304 // ---------------------------------------------------------------------
1305 /* The default just returns the highest available version that is not
1306 a source and automatic. */
1307 pkgCache::VerIterator
pkgDepCache::Policy::GetCandidateVer(PkgIterator Pkg
)
1309 /* Not source/not automatic versions cannot be a candidate version
1310 unless they are already installed */
1311 VerIterator
Last(*(pkgCache
*)this,0);
1313 for (VerIterator I
= Pkg
.VersionList(); I
.end() == false; I
++)
1315 if (Pkg
.CurrentVer() == I
)
1318 for (VerFileIterator J
= I
.FileList(); J
.end() == false; J
++)
1320 if ((J
.File()->Flags
& Flag::NotSource
) != 0)
1323 /* Stash the highest version of a not-automatic source, we use it
1324 if there is nothing better */
1325 if ((J
.File()->Flags
& Flag::NotAutomatic
) != 0)
1327 if (Last
.end() == true)
1339 // Policy::IsImportantDep - True if the dependency is important /*{{{*/
1340 // ---------------------------------------------------------------------
1342 bool pkgDepCache::Policy::IsImportantDep(DepIterator Dep
)
1344 if(Dep
.IsCritical())
1346 else if(Dep
->Type
== pkgCache::Dep::Recommends
)
1348 if ( _config
->FindB("APT::Install-Recommends", false))
1350 // we suport a special mode to only install-recommends for certain
1352 // FIXME: this is a meant as a temporarly solution until the
1353 // recommends are cleaned up
1354 const char *sec
= Dep
.ParentVer().Section();
1355 if (sec
&& ConfigValueInSubTree("APT::Install-Recommends-Sections", sec
))
1358 else if(Dep
->Type
== pkgCache::Dep::Suggests
)
1359 return _config
->FindB("APT::Install-Suggests", false);
1364 pkgDepCache::DefaultRootSetFunc::DefaultRootSetFunc() /*{{{*/
1365 : constructedSuccessfully(false)
1367 Configuration::Item
const *Opts
;
1368 Opts
= _config
->Tree("APT::NeverAutoRemove");
1369 if (Opts
!= 0 && Opts
->Child
!= 0)
1372 for (; Opts
!= 0; Opts
= Opts
->Next
)
1374 if (Opts
->Value
.empty() == true)
1377 regex_t
*p
= new regex_t
;
1378 if(regcomp(p
,Opts
->Value
.c_str(),
1379 REG_EXTENDED
| REG_ICASE
| REG_NOSUB
) != 0)
1383 _error
->Error("Regex compilation error for APT::NeverAutoRemove");
1387 rootSetRegexp
.push_back(p
);
1391 constructedSuccessfully
= true;
1394 pkgDepCache::DefaultRootSetFunc::~DefaultRootSetFunc() /*{{{*/
1396 for(unsigned int i
= 0; i
< rootSetRegexp
.size(); i
++)
1398 regfree(rootSetRegexp
[i
]);
1399 delete rootSetRegexp
[i
];
1403 bool pkgDepCache::DefaultRootSetFunc::InRootSet(const pkgCache::PkgIterator
&pkg
) /*{{{*/
1405 for(unsigned int i
= 0; i
< rootSetRegexp
.size(); i
++)
1406 if (regexec(rootSetRegexp
[i
], pkg
.Name(), 0, 0, 0) == 0)
1412 pkgDepCache::InRootSetFunc
*pkgDepCache::GetRootSetFunc() /*{{{*/
1414 DefaultRootSetFunc
*f
= new DefaultRootSetFunc
;
1415 if(f
->wasConstructedSuccessfully())
1424 bool pkgDepCache::MarkFollowsRecommends()
1426 return _config
->FindB("APT::AutoRemove::RecommendsImportant", true);
1429 bool pkgDepCache::MarkFollowsSuggests()
1431 return _config
->FindB("APT::AutoRemove::SuggestsImportant", false);
1434 // pkgDepCache::MarkRequired - the main mark algorithm /*{{{*/
1435 bool pkgDepCache::MarkRequired(InRootSetFunc
&userFunc
)
1437 bool follow_recommends
;
1438 bool follow_suggests
;
1439 bool debug_autoremove
= _config
->FindB("Debug::pkgAutoRemove",false);
1442 for(PkgIterator p
= PkgBegin(); !p
.end(); ++p
)
1444 PkgState
[p
->ID
].Marked
= false;
1445 PkgState
[p
->ID
].Garbage
= false;
1448 if(debug_autoremove
&& PkgState
[p
->ID
].Flags
& Flag::Auto
)
1449 std::clog
<< "AutoDep: " << p
.FullName() << std::endl
;
1453 follow_recommends
= MarkFollowsRecommends();
1454 follow_suggests
= MarkFollowsSuggests();
1458 // do the mark part, this is the core bit of the algorithm
1459 for(PkgIterator p
= PkgBegin(); !p
.end(); ++p
)
1461 if(!(PkgState
[p
->ID
].Flags
& Flag::Auto
) ||
1462 (p
->Flags
& Flag::Essential
) ||
1463 userFunc
.InRootSet(p
))
1466 // the package is installed (and set to keep)
1467 if(PkgState
[p
->ID
].Keep() && !p
.CurrentVer().end())
1468 MarkPackage(p
, p
.CurrentVer(),
1469 follow_recommends
, follow_suggests
);
1470 // the package is to be installed
1471 else if(PkgState
[p
->ID
].Install())
1472 MarkPackage(p
, PkgState
[p
->ID
].InstVerIter(*this),
1473 follow_recommends
, follow_suggests
);
1480 // MarkPackage - mark a single package in Mark-and-Sweep /*{{{*/
1481 void pkgDepCache::MarkPackage(const pkgCache::PkgIterator
&pkg
,
1482 const pkgCache::VerIterator
&ver
,
1483 bool const &follow_recommends
,
1484 bool const &follow_suggests
)
1486 pkgDepCache::StateCache
&state
= PkgState
[pkg
->ID
];
1488 // if we are marked already we are done
1492 VerIterator
const currver
= pkg
.CurrentVer();
1493 VerIterator
const candver
= state
.CandidateVerIter(*this);
1494 VerIterator
const instver
= state
.InstVerIter(*this);
1497 // If a package was garbage-collected but is now being marked, we
1498 // should re-select it
1499 // For cases when a pkg is set to upgrade and this trigger the
1500 // removal of a no-longer used dependency. if the pkg is set to
1501 // keep again later it will result in broken deps
1502 if(state
.Delete() && state
.RemoveReason
= Unused
)
1505 mark_install(pkg
, false, false, NULL
);
1506 else if(ver
==pkg
.CurrentVer())
1507 MarkKeep(pkg
, false, false);
1509 instver
=state
.InstVerIter(*this);
1513 // For packages that are not going to be removed, ignore versions
1514 // other than the InstVer. For packages that are going to be
1515 // removed, ignore versions other than the current version.
1516 if(!(ver
== instver
&& !instver
.end()) &&
1517 !(ver
== currver
&& instver
.end() && !ver
.end()))
1520 bool const debug_autoremove
= _config
->FindB("Debug::pkgAutoRemove", false);
1522 if(debug_autoremove
)
1524 std::clog
<< "Marking: " << pkg
.FullName();
1526 std::clog
<< " " << ver
.VerStr();
1528 std::clog
<< ", Curr=" << currver
.VerStr();
1530 std::clog
<< ", Inst=" << instver
.VerStr();
1531 std::clog
<< std::endl
;
1536 if(ver
.end() == true)
1539 // If the version belongs to a Multi-Arch all package
1540 // we will mark all others in this Group with this version also
1541 // Beware: We compare versions here the lazy way: string comparision
1542 // this is bad if multiple repositories provide different versions
1543 // of the package with an identical version number - but even in this
1544 // case the dependencies are likely the same.
1545 if (ver
->MultiArch
== pkgCache::Version::All
&&
1546 strcmp(ver
.Arch(true), "all") == 0)
1548 GrpIterator G
= pkg
.Group();
1549 const char* const VerStr
= ver
.VerStr();
1550 for (PkgIterator P
= G
.FindPkg("any");
1551 P
.end() != true; P
= G
.NextPkg(P
))
1553 for (VerIterator V
= P
.VersionList();
1554 V
.end() != true; ++V
)
1556 if (strcmp(VerStr
, V
.VerStr()) != 0)
1558 MarkPackage(P
, V
, follow_recommends
, follow_suggests
);
1564 for(DepIterator d
= ver
.DependsList(); !d
.end(); ++d
)
1566 if(d
->Type
== Dep::Depends
||
1567 d
->Type
== Dep::PreDepends
||
1568 (follow_recommends
&&
1569 d
->Type
== Dep::Recommends
) ||
1571 d
->Type
== Dep::Suggests
))
1573 // Try all versions of this package.
1574 for(VerIterator V
= d
.TargetPkg().VersionList();
1577 if(_system
->VS
->CheckDep(V
.VerStr(), d
->CompareOp
, d
.TargetVer()))
1579 if(debug_autoremove
)
1581 std::clog
<< "Following dep: " << d
.ParentPkg().FullName()
1582 << " " << d
.ParentVer().VerStr() << " "
1583 << d
.DepType() << " " << d
.TargetPkg().FullName();
1584 if((d
->CompareOp
& ~pkgCache::Dep::Or
) != pkgCache::Dep::NoOp
)
1586 std::clog
<< " (" << d
.CompType() << " "
1587 << d
.TargetVer() << ")";
1589 std::clog
<< std::endl
;
1591 MarkPackage(V
.ParentPkg(), V
,
1592 follow_recommends
, follow_suggests
);
1595 // Now try virtual packages
1596 for(PrvIterator prv
=d
.TargetPkg().ProvidesList();
1599 if(_system
->VS
->CheckDep(prv
.ProvideVersion(), d
->CompareOp
,
1602 if(debug_autoremove
)
1604 std::clog
<< "Following dep: " << d
.ParentPkg().FullName() << " "
1605 << d
.ParentVer().VerStr() << " "
1606 << d
.DepType() << " " << d
.TargetPkg().FullName() << " ";
1607 if((d
->CompareOp
& ~pkgCache::Dep::Or
) != pkgCache::Dep::NoOp
)
1609 std::clog
<< " (" << d
.CompType() << " "
1610 << d
.TargetVer() << ")";
1612 std::clog
<< ", provided by "
1613 << prv
.OwnerPkg().FullName() << " "
1614 << prv
.OwnerVer().VerStr()
1618 MarkPackage(prv
.OwnerPkg(), prv
.OwnerVer(),
1619 follow_recommends
, follow_suggests
);
1626 bool pkgDepCache::Sweep() /*{{{*/
1628 bool debug_autoremove
= _config
->FindB("Debug::pkgAutoRemove",false);
1631 for(PkgIterator p
=PkgBegin(); !p
.end(); ++p
)
1633 StateCache
&state
=PkgState
[p
->ID
];
1635 // skip required packages
1636 if (!p
.CurrentVer().end() &&
1637 (p
.CurrentVer()->Priority
== pkgCache::State::Required
))
1640 // if it is not marked and it is installed, it's garbage
1641 if(!state
.Marked
&& (!p
.CurrentVer().end() || state
.Install()))
1644 if(debug_autoremove
)
1645 std::cout
<< "Garbage: " << p
.FullName() << std::endl
;