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 /*{{{*/
13 #include <apt-pkg/depcache.h>
14 #include <apt-pkg/version.h>
15 #include <apt-pkg/versionmatch.h>
16 #include <apt-pkg/error.h>
17 #include <apt-pkg/sptr.h>
18 #include <apt-pkg/algorithms.h>
19 #include <apt-pkg/fileutl.h>
20 #include <apt-pkg/strutl.h>
21 #include <apt-pkg/configuration.h>
22 #include <apt-pkg/aptconfiguration.h>
23 #include <apt-pkg/pkgsystem.h>
24 #include <apt-pkg/tagfile.h>
25 #include <apt-pkg/progress.h>
38 // helper for Install-Recommends-Sections and Never-MarkAuto-Sections /*{{{*/
40 ConfigValueInSubTree(const char* SubTree
, const char *needle
)
42 Configuration::Item
const *Opts
;
43 Opts
= _config
->Tree(SubTree
);
44 if (Opts
!= 0 && Opts
->Child
!= 0)
47 for (; Opts
!= 0; Opts
= Opts
->Next
)
49 if (Opts
->Value
.empty() == true)
51 if (strcmp(needle
, Opts
->Value
.c_str()) == 0)
58 pkgDepCache::ActionGroup::ActionGroup(pkgDepCache
&cache
) : /*{{{*/
59 cache(cache
), released(false)
64 void pkgDepCache::ActionGroup::release()
68 if(cache
.group_level
== 0)
69 std::cerr
<< "W: Unbalanced action groups, expect badness" << std::endl
;
74 if(cache
.group_level
== 0)
82 pkgDepCache::ActionGroup::~ActionGroup()
87 // DepCache::pkgDepCache - Constructors /*{{{*/
88 // ---------------------------------------------------------------------
90 pkgDepCache::pkgDepCache(pkgCache
*pCache
,Policy
*Plcy
) :
91 group_level(0), Cache(pCache
), PkgState(0), DepState(0)
93 DebugMarker
= _config
->FindB("Debug::pkgDepCache::Marker", false);
94 DebugAutoInstall
= _config
->FindB("Debug::pkgDepCache::AutoInstall", false);
98 delLocalPolicy
= LocalPolicy
= new Policy
;
101 // DepCache::~pkgDepCache - Destructor /*{{{*/
102 // ---------------------------------------------------------------------
104 pkgDepCache::~pkgDepCache()
108 delete delLocalPolicy
;
111 // DepCache::Init - Generate the initial extra structures. /*{{{*/
112 // ---------------------------------------------------------------------
113 /* This allocats the extension buffers and initializes them. */
114 bool pkgDepCache::Init(OpProgress
*Prog
)
116 // Suppress mark updates during this operation (just in case) and
117 // run a mark operation when Init terminates.
118 ActionGroup
actions(*this);
122 PkgState
= new StateCache
[Head().PackageCount
];
123 DepState
= new unsigned char[Head().DependsCount
];
124 memset(PkgState
,0,sizeof(*PkgState
)*Head().PackageCount
);
125 memset(DepState
,0,sizeof(*DepState
)*Head().DependsCount
);
129 Prog
->OverallProgress(0,2*Head().PackageCount
,Head().PackageCount
,
130 _("Building dependency tree"));
131 Prog
->SubProgress(Head().PackageCount
,_("Candidate versions"));
134 /* Set the current state of everything. In this state all of the
135 packages are kept exactly as is. See AllUpgrade */
137 for (PkgIterator I
= PkgBegin(); I
.end() != true; ++I
, ++Done
)
139 if (Prog
!= 0 && Done%20
== 0)
140 Prog
->Progress(Done
);
142 // Find the proper cache slot
143 StateCache
&State
= PkgState
[I
->ID
];
146 // Figure out the install version
147 State
.CandidateVer
= GetCandidateVer(I
);
148 State
.InstallVer
= I
.CurrentVer();
149 State
.Mode
= ModeKeep
;
151 State
.Update(I
,*this);
157 Prog
->OverallProgress(Head().PackageCount
,2*Head().PackageCount
,
159 _("Building dependency tree"));
160 Prog
->SubProgress(Head().PackageCount
,_("Dependency generation"));
171 bool pkgDepCache::readStateFile(OpProgress
*Prog
) /*{{{*/
174 string
const state
= _config
->FindFile("Dir::State::extended_states");
175 if(RealFileExists(state
)) {
176 state_file
.Open(state
, FileFd::ReadOnly
);
177 off_t
const file_size
= state_file
.Size();
179 Prog
->OverallProgress(0, file_size
, 1,
180 _("Reading state information"));
182 pkgTagFile
tagfile(&state_file
);
183 pkgTagSection section
;
185 bool const debug_autoremove
= _config
->FindB("Debug::pkgAutoRemove",false);
186 while(tagfile
.Step(section
)) {
187 string
const pkgname
= section
.FindS("Package");
188 string pkgarch
= section
.FindS("Architecture");
189 if (pkgarch
.empty() == true)
191 pkgCache::PkgIterator pkg
= Cache
->FindPkg(pkgname
, pkgarch
);
192 // Silently ignore unknown packages and packages with no actual version.
193 if(pkg
.end() == true || pkg
->VersionList
== 0)
196 short const reason
= section
.FindI("Auto-Installed", 0);
199 PkgState
[pkg
->ID
].Flags
|= Flag::Auto
;
200 if (unlikely(debug_autoremove
))
201 std::clog
<< "Auto-Installed : " << pkg
.FullName() << std::endl
;
202 if (pkgarch
== "any")
204 pkgCache::GrpIterator G
= pkg
.Group();
205 for (pkg
= G
.NextPkg(pkg
); pkg
.end() != true; pkg
= G
.NextPkg(pkg
))
206 if (pkg
->VersionList
!= 0)
207 PkgState
[pkg
->ID
].Flags
|= Flag::Auto
;
210 amt
+= section
.size();
212 Prog
->OverallProgress(amt
, file_size
, 1,
213 _("Reading state information"));
216 Prog
->OverallProgress(file_size
, file_size
, 1,
217 _("Reading state information"));
223 bool pkgDepCache::writeStateFile(OpProgress
*prog
, bool InstalledOnly
) /*{{{*/
225 bool const debug_autoremove
= _config
->FindB("Debug::pkgAutoRemove",false);
228 std::clog
<< "pkgDepCache::writeStateFile()" << std::endl
;
231 string
const state
= _config
->FindFile("Dir::State::extended_states");
233 // if it does not exist, create a empty one
234 if(!RealFileExists(state
))
236 StateFile
.Open(state
, FileFd::WriteAtomic
);
241 if(!StateFile
.Open(state
, FileFd::ReadOnly
))
242 return _error
->Error(_("Failed to open StateFile %s"),
246 string
const outfile
= state
+ ".tmp";
247 if((OutFile
= fopen(outfile
.c_str(),"w")) == NULL
)
248 return _error
->Error(_("Failed to write temporary StateFile %s"),
251 // first merge with the existing sections
252 pkgTagFile
tagfile(&StateFile
);
253 pkgTagSection section
;
254 std::set
<string
> pkgs_seen
;
255 const char *nullreorderlist
[] = {0};
256 while(tagfile
.Step(section
)) {
257 string
const pkgname
= section
.FindS("Package");
258 string pkgarch
= section
.FindS("Architecture");
259 if (pkgarch
.empty() == true)
261 // Silently ignore unknown packages and packages with no actual
263 pkgCache::PkgIterator pkg
= Cache
->FindPkg(pkgname
, pkgarch
);
264 if(pkg
.end() || pkg
.VersionList().end())
266 StateCache
const &P
= PkgState
[pkg
->ID
];
267 bool newAuto
= (P
.Flags
& Flag::Auto
);
268 // skip not installed or now-removed ones if requested
269 if (InstalledOnly
&& (
270 (pkg
->CurrentVer
== 0 && P
.Mode
!= ModeInstall
) ||
271 (pkg
->CurrentVer
!= 0 && P
.Mode
== ModeDelete
)))
273 // The section is obsolete if it contains no other tag
274 unsigned int const count
= section
.Count();
276 (count
== 2 && section
.Exists("Auto-Installed")) ||
277 (count
== 3 && section
.Exists("Auto-Installed") && section
.Exists("Architecture")))
282 if(_config
->FindB("Debug::pkgAutoRemove",false))
283 std::clog
<< "Update existing AutoInstall info: "
284 << pkg
.FullName() << std::endl
;
285 TFRewriteData rewrite
[3];
286 rewrite
[0].Tag
= "Architecture";
287 rewrite
[0].Rewrite
= pkg
.Arch();
288 rewrite
[0].NewTag
= 0;
289 rewrite
[1].Tag
= "Auto-Installed";
290 rewrite
[1].Rewrite
= newAuto
? "1" : "0";
291 rewrite
[1].NewTag
= 0;
293 TFRewrite(OutFile
, section
, nullreorderlist
, rewrite
);
294 fprintf(OutFile
,"\n");
295 pkgs_seen
.insert(pkg
.FullName());
298 // then write the ones we have not seen yet
299 std::ostringstream ostr
;
300 for(pkgCache::PkgIterator pkg
=Cache
->PkgBegin(); !pkg
.end(); ++pkg
) {
301 StateCache
const &P
= PkgState
[pkg
->ID
];
302 if(P
.Flags
& Flag::Auto
) {
303 if (pkgs_seen
.find(pkg
.FullName()) != pkgs_seen
.end()) {
305 std::clog
<< "Skipping already written " << pkg
.FullName() << std::endl
;
308 // skip not installed ones if requested
309 if (InstalledOnly
&& (
310 (pkg
->CurrentVer
== 0 && P
.Mode
!= ModeInstall
) ||
311 (pkg
->CurrentVer
!= 0 && P
.Mode
== ModeDelete
)))
313 const char* const pkgarch
= pkg
.Arch();
314 if (strcmp(pkgarch
, "all") == 0)
317 std::clog
<< "Writing new AutoInstall: " << pkg
.FullName() << std::endl
;
318 ostr
.str(string(""));
319 ostr
<< "Package: " << pkg
.Name()
320 << "\nArchitecture: " << pkgarch
321 << "\nAuto-Installed: 1\n\n";
322 fprintf(OutFile
,"%s",ostr
.str().c_str());
327 // move the outfile over the real file and set permissions
328 rename(outfile
.c_str(), state
.c_str());
329 chmod(state
.c_str(), 0644);
334 // DepCache::CheckDep - Checks a single dependency /*{{{*/
335 // ---------------------------------------------------------------------
336 /* This first checks the dependency against the main target package and
337 then walks along the package provides list and checks if each provides
338 will be installed then checks the provides against the dep. Res will be
339 set to the package which was used to satisfy the dep. */
340 bool pkgDepCache::CheckDep(DepIterator Dep
,int Type
,PkgIterator
&Res
)
342 Res
= Dep
.TargetPkg();
344 /* Check simple depends. A depends -should- never self match but
345 we allow it anyhow because dpkg does. Technically it is a packaging
346 bug. Conflicts may never self match */
347 if (Dep
.TargetPkg() != Dep
.ParentPkg() || Dep
.IsNegative() == false)
349 PkgIterator Pkg
= Dep
.TargetPkg();
350 // Check the base package
351 if (Type
== NowVersion
&& Pkg
->CurrentVer
!= 0)
352 if (VS().CheckDep(Pkg
.CurrentVer().VerStr(),Dep
->CompareOp
,
353 Dep
.TargetVer()) == true)
356 if (Type
== InstallVersion
&& PkgState
[Pkg
->ID
].InstallVer
!= 0)
357 if (VS().CheckDep(PkgState
[Pkg
->ID
].InstVerIter(*this).VerStr(),
358 Dep
->CompareOp
,Dep
.TargetVer()) == true)
361 if (Type
== CandidateVersion
&& PkgState
[Pkg
->ID
].CandidateVer
!= 0)
362 if (VS().CheckDep(PkgState
[Pkg
->ID
].CandidateVerIter(*this).VerStr(),
363 Dep
->CompareOp
,Dep
.TargetVer()) == true)
367 if (Dep
->Type
== Dep::Obsoletes
)
370 // Check the providing packages
371 PrvIterator P
= Dep
.TargetPkg().ProvidesList();
372 PkgIterator Pkg
= Dep
.ParentPkg();
373 for (; P
.end() != true; ++P
)
375 /* Provides may never be applied against the same package (or group)
376 if it is a conflicts. See the comment above. */
377 if (P
.OwnerPkg()->Group
== Pkg
->Group
&& Dep
.IsNegative() == true)
380 // Check if the provides is a hit
381 if (Type
== NowVersion
)
383 if (P
.OwnerPkg().CurrentVer() != P
.OwnerVer())
387 if (Type
== InstallVersion
)
389 StateCache
&State
= PkgState
[P
.OwnerPkg()->ID
];
390 if (State
.InstallVer
!= (Version
*)P
.OwnerVer())
394 if (Type
== CandidateVersion
)
396 StateCache
&State
= PkgState
[P
.OwnerPkg()->ID
];
397 if (State
.CandidateVer
!= (Version
*)P
.OwnerVer())
401 // Compare the versions.
402 if (VS().CheckDep(P
.ProvideVersion(),Dep
->CompareOp
,Dep
.TargetVer()) == true)
412 // DepCache::AddSizes - Add the packages sizes to the counters /*{{{*/
413 // ---------------------------------------------------------------------
414 /* Call with Inverse = true to preform the inverse opration */
415 void pkgDepCache::AddSizes(const PkgIterator
&Pkg
, bool const Inverse
)
417 StateCache
&P
= PkgState
[Pkg
->ID
];
419 if (Pkg
->VersionList
== 0)
422 if (Pkg
.State() == pkgCache::PkgIterator::NeedsConfigure
&&
426 // Compute the size data
427 if (P
.NewInstall() == true)
429 if (Inverse
== false) {
430 iUsrSize
+= P
.InstVerIter(*this)->InstalledSize
;
431 iDownloadSize
+= P
.InstVerIter(*this)->Size
;
433 iUsrSize
-= P
.InstVerIter(*this)->InstalledSize
;
434 iDownloadSize
-= P
.InstVerIter(*this)->Size
;
440 if (Pkg
->CurrentVer
!= 0 &&
441 (P
.InstallVer
!= (Version
*)Pkg
.CurrentVer() ||
442 (P
.iFlags
& ReInstall
) == ReInstall
) && P
.InstallVer
!= 0)
444 if (Inverse
== false) {
445 iUsrSize
-= Pkg
.CurrentVer()->InstalledSize
;
446 iUsrSize
+= P
.InstVerIter(*this)->InstalledSize
;
447 iDownloadSize
+= P
.InstVerIter(*this)->Size
;
449 iUsrSize
-= P
.InstVerIter(*this)->InstalledSize
;
450 iUsrSize
+= Pkg
.CurrentVer()->InstalledSize
;
451 iDownloadSize
-= P
.InstVerIter(*this)->Size
;
457 if (Pkg
.State() == pkgCache::PkgIterator::NeedsUnpack
&&
460 if (Inverse
== false)
461 iDownloadSize
+= P
.InstVerIter(*this)->Size
;
463 iDownloadSize
-= P
.InstVerIter(*this)->Size
;
468 if (Pkg
->CurrentVer
!= 0 && P
.InstallVer
== 0)
470 if (Inverse
== false)
471 iUsrSize
-= Pkg
.CurrentVer()->InstalledSize
;
473 iUsrSize
+= Pkg
.CurrentVer()->InstalledSize
;
478 // DepCache::AddStates - Add the package to the state counter /*{{{*/
479 // ---------------------------------------------------------------------
480 /* This routine is tricky to use, you must make sure that it is never
481 called twice for the same package. This means the Remove/Add section
482 should be as short as possible and not encompass any code that will
483 calld Remove/Add itself. Remember, dependencies can be circular so
484 while processing a dep for Pkg it is possible that Add/Remove
485 will be called on Pkg */
486 void pkgDepCache::AddStates(const PkgIterator
&Pkg
, bool const Invert
)
488 signed char const Add
= (Invert
== false) ? 1 : -1;
489 StateCache
&State
= PkgState
[Pkg
->ID
];
491 // The Package is broken (either minimal dep or policy dep)
492 if ((State
.DepState
& DepInstMin
) != DepInstMin
)
494 if ((State
.DepState
& DepInstPolicy
) != DepInstPolicy
)
495 iPolicyBrokenCount
+= Add
;
498 if (Pkg
.State() != PkgIterator::NeedsNothing
)
502 if (Pkg
->CurrentVer
== 0)
504 if (State
.Mode
== ModeDelete
&&
505 (State
.iFlags
& Purge
) == Purge
&& Pkg
.Purge() == false)
508 if (State
.Mode
== ModeInstall
)
513 // Installed, no upgrade
514 if (State
.Status
== 0)
516 if (State
.Mode
== ModeDelete
)
519 if ((State
.iFlags
& ReInstall
) == ReInstall
)
525 // Alll 3 are possible
526 if (State
.Mode
== ModeDelete
)
528 if (State
.Mode
== ModeKeep
)
530 if (State
.Mode
== ModeInstall
)
534 // DepCache::BuildGroupOrs - Generate the Or group dep data /*{{{*/
535 // ---------------------------------------------------------------------
536 /* The or group results are stored in the last item of the or group. This
537 allows easy detection of the state of a whole or'd group. */
538 void pkgDepCache::BuildGroupOrs(VerIterator
const &V
)
540 unsigned char Group
= 0;
542 for (DepIterator D
= V
.DependsList(); D
.end() != true; ++D
)
544 // Build the dependency state.
545 unsigned char &State
= DepState
[D
->ID
];
547 /* Invert for Conflicts. We have to do this twice to get the
548 right sense for a conflicts group */
549 if (D
.IsNegative() == true)
552 // Add to the group if we are within an or..
556 if ((D
->CompareOp
& Dep::Or
) != Dep::Or
)
559 // Invert for Conflicts
560 if (D
.IsNegative() == true)
565 // DepCache::VersionState - Perform a pass over a dependency list /*{{{*/
566 // ---------------------------------------------------------------------
567 /* This is used to run over a dependency list and determine the dep
568 state of the list, filtering it through both a Min check and a Policy
569 check. The return result will have SetMin/SetPolicy low if a check
570 fails. It uses the DepState cache for it's computations. */
571 unsigned char pkgDepCache::VersionState(DepIterator D
,unsigned char Check
,
572 unsigned char SetMin
,
573 unsigned char SetPolicy
)
575 unsigned char Dep
= 0xFF;
577 while (D
.end() != true)
579 // Compute a single dependency element (glob or)
580 DepIterator Start
= D
;
581 unsigned char State
= 0;
582 for (bool LastOR
= true; D
.end() == false && LastOR
== true; ++D
)
584 State
|= DepState
[D
->ID
];
585 LastOR
= (D
->CompareOp
& Dep::Or
) == Dep::Or
;
588 // Minimum deps that must be satisfied to have a working package
589 if (Start
.IsCritical() == true)
590 if ((State
& Check
) != Check
)
593 // Policy deps that must be satisfied to install the package
594 if (IsImportantDep(Start
) == true &&
595 (State
& Check
) != Check
)
602 // DepCache::DependencyState - Compute the 3 results for a dep /*{{{*/
603 // ---------------------------------------------------------------------
604 /* This is the main dependency computation bit. It computes the 3 main
605 results for a dependencys, Now, Install and Candidate. Callers must
606 invert the result if dealing with conflicts. */
607 unsigned char pkgDepCache::DependencyState(DepIterator
&D
)
609 unsigned char State
= 0;
611 if (CheckDep(D
,NowVersion
) == true)
613 if (CheckDep(D
,InstallVersion
) == true)
615 if (CheckDep(D
,CandidateVersion
) == true)
621 // DepCache::UpdateVerState - Compute the Dep member of the state /*{{{*/
622 // ---------------------------------------------------------------------
623 /* This determines the combined dependency representation of a package
624 for its two states now and install. This is done by using the pre-generated
625 dependency information. */
626 void pkgDepCache::UpdateVerState(PkgIterator Pkg
)
628 // Empty deps are always true
629 StateCache
&State
= PkgState
[Pkg
->ID
];
630 State
.DepState
= 0xFF;
632 // Check the Current state
633 if (Pkg
->CurrentVer
!= 0)
635 DepIterator D
= Pkg
.CurrentVer().DependsList();
636 State
.DepState
&= VersionState(D
,DepNow
,DepNowMin
,DepNowPolicy
);
639 /* Check the candidate state. We do not compare against the whole as
640 a candidate state but check the candidate version against the
642 if (State
.CandidateVer
!= 0)
644 DepIterator D
= State
.CandidateVerIter(*this).DependsList();
645 State
.DepState
&= VersionState(D
,DepInstall
,DepCandMin
,DepCandPolicy
);
648 // Check target state which can only be current or installed
649 if (State
.InstallVer
!= 0)
651 DepIterator D
= State
.InstVerIter(*this).DependsList();
652 State
.DepState
&= VersionState(D
,DepInstall
,DepInstMin
,DepInstPolicy
);
656 // DepCache::Update - Figure out all the state information /*{{{*/
657 // ---------------------------------------------------------------------
658 /* This will figure out the state of all the packages and all the
659 dependencies based on the current policy. */
660 void pkgDepCache::Update(OpProgress
*Prog
)
670 // Perform the depends pass
672 for (PkgIterator I
= PkgBegin(); I
.end() != true; ++I
, ++Done
)
674 if (Prog
!= 0 && Done%20
== 0)
675 Prog
->Progress(Done
);
676 for (VerIterator V
= I
.VersionList(); V
.end() != true; ++V
)
678 unsigned char Group
= 0;
680 for (DepIterator D
= V
.DependsList(); D
.end() != true; ++D
)
682 // Build the dependency state.
683 unsigned char &State
= DepState
[D
->ID
];
684 State
= DependencyState(D
);
686 // Add to the group if we are within an or..
689 if ((D
->CompareOp
& Dep::Or
) != Dep::Or
)
692 // Invert for Conflicts
693 if (D
.IsNegative() == true)
698 // Compute the package dependency state and size additions
705 Prog
->Progress(Done
);
710 // DepCache::Update - Update the deps list of a package /*{{{*/
711 // ---------------------------------------------------------------------
712 /* This is a helper for update that only does the dep portion of the scan.
713 It is mainly meant to scan reverse dependencies. */
714 void pkgDepCache::Update(DepIterator D
)
716 // Update the reverse deps
717 for (;D
.end() != true; ++D
)
719 unsigned char &State
= DepState
[D
->ID
];
720 State
= DependencyState(D
);
722 // Invert for Conflicts
723 if (D
.IsNegative() == true)
726 RemoveStates(D
.ParentPkg());
727 BuildGroupOrs(D
.ParentVer());
728 UpdateVerState(D
.ParentPkg());
729 AddStates(D
.ParentPkg());
733 // DepCache::Update - Update the related deps of a package /*{{{*/
734 // ---------------------------------------------------------------------
735 /* This is called whenever the state of a package changes. It updates
736 all cached dependencies related to this package. */
737 void pkgDepCache::Update(PkgIterator
const &Pkg
)
739 // Recompute the dep of the package
744 // Update the reverse deps
745 Update(Pkg
.RevDependsList());
747 // Update the provides map for the current ver
748 if (Pkg
->CurrentVer
!= 0)
749 for (PrvIterator P
= Pkg
.CurrentVer().ProvidesList();
750 P
.end() != true; ++P
)
751 Update(P
.ParentPkg().RevDependsList());
753 // Update the provides map for the candidate ver
754 if (PkgState
[Pkg
->ID
].CandidateVer
!= 0)
755 for (PrvIterator P
= PkgState
[Pkg
->ID
].CandidateVerIter(*this).ProvidesList();
756 P
.end() != true; ++P
)
757 Update(P
.ParentPkg().RevDependsList());
760 // DepCache::MarkKeep - Put the package in the keep state /*{{{*/
761 // ---------------------------------------------------------------------
763 bool pkgDepCache::MarkKeep(PkgIterator
const &Pkg
, bool Soft
, bool FromUser
,
766 if (IsModeChangeOk(ModeKeep
, Pkg
, Depth
, FromUser
) == false)
769 /* Reject an attempt to keep a non-source broken installed package, those
771 if (Pkg
.State() == PkgIterator::NeedsUnpack
&&
772 Pkg
.CurrentVer().Downloadable() == false)
775 /* We changed the soft state all the time so the UI is a bit nicer
777 StateCache
&P
= PkgState
[Pkg
->ID
];
779 // Check that it is not already kept
780 if (P
.Mode
== ModeKeep
)
784 P
.iFlags
|= AutoKept
;
786 P
.iFlags
&= ~AutoKept
;
788 ActionGroup
group(*this);
790 #if 0 // reseting the autoflag here means we lose the
791 // auto-mark information if a user selects a package for removal
792 // but changes his mind then and sets it for keep again
793 // - this makes sense as default when all Garbage dependencies
794 // are automatically marked for removal (as aptitude does).
795 // setting a package for keep then makes it no longer autoinstalled
796 // for all other use-case this action is rather suprising
797 if(FromUser
&& !P
.Marked
)
798 P
.Flags
&= ~Flag::Auto
;
801 if (DebugMarker
== true)
802 std::clog
<< OutputInDepth(Depth
) << "MarkKeep " << Pkg
<< " FU=" << FromUser
<< std::endl
;
808 if (Pkg
->CurrentVer
== 0)
811 P
.InstallVer
= Pkg
.CurrentVer();
820 // DepCache::MarkDelete - Put the package in the delete state /*{{{*/
821 // ---------------------------------------------------------------------
823 bool pkgDepCache::MarkDelete(PkgIterator
const &Pkg
, bool rPurge
,
824 unsigned long Depth
, bool FromUser
)
826 if (IsModeChangeOk(ModeDelete
, Pkg
, Depth
, FromUser
) == false)
829 StateCache
&P
= PkgState
[Pkg
->ID
];
831 // Check that it is not already marked for delete
832 if ((P
.Mode
== ModeDelete
|| P
.InstallVer
== 0) &&
833 (Pkg
.Purge() == true || rPurge
== false))
836 // check if we are allowed to remove the package
837 if (IsDeleteOk(Pkg
,rPurge
,Depth
,FromUser
) == false)
840 P
.iFlags
&= ~(AutoKept
| Purge
);
844 ActionGroup
group(*this);
846 if (DebugMarker
== true)
847 std::clog
<< OutputInDepth(Depth
) << (rPurge
? "MarkPurge " : "MarkDelete ") << Pkg
<< " FU=" << FromUser
<< std::endl
;
852 if (Pkg
->CurrentVer
== 0 && (Pkg
.Purge() == true || rPurge
== false))
865 // DepCache::IsDeleteOk - check if it is ok to remove this package /*{{{*/
866 // ---------------------------------------------------------------------
867 /* The default implementation tries to prevent deletion of install requests.
868 dpkg holds are enforced by the private IsModeChangeOk */
869 bool pkgDepCache::IsDeleteOk(PkgIterator
const &Pkg
,bool rPurge
,
870 unsigned long Depth
, bool FromUser
)
872 if (FromUser
== false && Pkg
->CurrentVer
== 0)
874 StateCache
&P
= PkgState
[Pkg
->ID
];
875 if (P
.InstallVer
!= 0 && P
.Status
== 2 && (P
.Flags
& Flag::Auto
) != Flag::Auto
)
877 if (DebugMarker
== true)
878 std::clog
<< OutputInDepth(Depth
) << "Manual install request prevents MarkDelete of " << Pkg
<< std::endl
;
885 // DepCache::IsModeChangeOk - check if it is ok to change the mode /*{{{*/
886 // ---------------------------------------------------------------------
887 /* this is used by all Mark methods on the very first line to check sanity
888 and prevents mode changes for packages on hold for example.
889 If you want to check Mode specific stuff you can use the virtual public
890 Is<Mode>Ok methods instead */
891 char const* PrintMode(char const mode
)
895 case pkgDepCache::ModeInstall
: return "Install";
896 case pkgDepCache::ModeKeep
: return "Keep";
897 case pkgDepCache::ModeDelete
: return "Delete";
898 default: return "UNKNOWN";
901 bool pkgDepCache::IsModeChangeOk(ModeList
const mode
, PkgIterator
const &Pkg
,
902 unsigned long const Depth
, bool const FromUser
)
904 // we are not trying to hard…
905 if (unlikely(Depth
> 100))
909 if (unlikely(Pkg
.end() == true || Pkg
->VersionList
== 0))
912 // the user is always right
913 if (FromUser
== true)
916 StateCache
&P
= PkgState
[Pkg
->ID
];
918 // if previous state was set by user only user can reset it
919 if ((P
.iFlags
& Protected
) == Protected
)
921 if (unlikely(DebugMarker
== true) && P
.Mode
!= mode
)
922 std::clog
<< OutputInDepth(Depth
) << "Ignore Mark" << PrintMode(mode
)
923 << " of " << Pkg
<< " as its mode (" << PrintMode(P
.Mode
)
924 << ") is protected" << std::endl
;
927 // enforce dpkg holds
928 else if (mode
!= ModeKeep
&& Pkg
->SelectedState
== pkgCache::State::Hold
&&
929 _config
->FindB("APT::Ignore-Hold",false) == false)
931 if (unlikely(DebugMarker
== true) && P
.Mode
!= mode
)
932 std::clog
<< OutputInDepth(Depth
) << "Hold prevents Mark" << PrintMode(mode
)
933 << " of " << Pkg
<< std::endl
;
940 // DepCache::MarkInstall - Put the package in the install state /*{{{*/
941 // ---------------------------------------------------------------------
943 bool pkgDepCache::MarkInstall(PkgIterator
const &Pkg
,bool AutoInst
,
944 unsigned long Depth
, bool FromUser
,
945 bool ForceImportantDeps
)
947 if (IsModeChangeOk(ModeInstall
, Pkg
, Depth
, FromUser
) == false)
950 StateCache
&P
= PkgState
[Pkg
->ID
];
952 // See if there is even any possible instalation candidate
953 if (P
.CandidateVer
== 0)
956 /* Check that it is not already marked for install and that it can be
958 if ((P
.InstPolicyBroken() == false && P
.InstBroken() == false) &&
959 (P
.Mode
== ModeInstall
||
960 P
.CandidateVer
== (Version
*)Pkg
.CurrentVer()))
962 if (P
.CandidateVer
== (Version
*)Pkg
.CurrentVer() && P
.InstallVer
== 0)
963 return MarkKeep(Pkg
, false, FromUser
, Depth
+1);
967 // check if we are allowed to install the package
968 if (IsInstallOk(Pkg
,AutoInst
,Depth
,FromUser
) == false)
971 ActionGroup
group(*this);
972 P
.iFlags
&= ~AutoKept
;
974 /* Target the candidate version and remove the autoflag. We reset the
975 autoflag below if this was called recursively. Otherwise the user
976 should have the ability to de-auto a package by changing its state */
980 P
.Mode
= ModeInstall
;
981 P
.InstallVer
= P
.CandidateVer
;
985 // Set it to manual if it's a new install or already installed,
986 // but only if its not marked by the autoremover (aptitude depend on this behavior)
987 // or if we do automatic installation (aptitude never does it)
988 if(P
.Status
== 2 || (Pkg
->CurrentVer
!= 0 && (AutoInst
== true || P
.Marked
== false)))
989 P
.Flags
&= ~Flag::Auto
;
993 // Set it to auto if this is a new install.
995 P
.Flags
|= Flag::Auto
;
997 if (P
.CandidateVer
== (Version
*)Pkg
.CurrentVer())
1004 if (AutoInst
== false || _config
->Find("APT::Solver", "internal") != "internal")
1007 if (DebugMarker
== true)
1008 std::clog
<< OutputInDepth(Depth
) << "MarkInstall " << Pkg
<< " FU=" << FromUser
<< std::endl
;
1010 DepIterator Dep
= P
.InstVerIter(*this).DependsList();
1011 for (; Dep
.end() != true;)
1014 DepIterator Start
= Dep
;
1017 for (bool LastOR
= true; Dep
.end() == false && LastOR
== true; ++Dep
, ++Ors
)
1019 LastOR
= (Dep
->CompareOp
& Dep::Or
) == Dep::Or
;
1021 if ((DepState
[Dep
->ID
] & DepInstall
) == DepInstall
)
1025 // Dep is satisfied okay.
1026 if (Result
== false)
1029 /* Check if this dep should be consider for install. If it is a user
1030 defined important dep and we are installed a new package then
1031 it will be installed. Otherwise we only check for important
1032 deps that have changed from the installed version
1034 if (IsImportantDep(Start
) == false)
1037 /* If we are in an or group locate the first or that can
1038 succeed. We have already cached this.. */
1039 for (; Ors
> 1 && (DepState
[Start
->ID
] & DepCVer
) != DepCVer
; --Ors
)
1041 if (Ors
== 1 && (DepState
[Start
->ID
] &DepCVer
) != DepCVer
&& Start
.IsNegative() == false)
1043 if(DebugAutoInstall
== true)
1044 std::clog
<< OutputInDepth(Depth
) << Start
<< " can't be satisfied!" << std::endl
;
1045 if (Start
.IsCritical() == false)
1047 // if the dependency was critical, we can't install it, so remove it again
1048 MarkDelete(Pkg
,false,Depth
+ 1, false);
1052 /* Check if any ImportantDep() (but not Critical) were added
1053 * since we installed the package. Also check for deps that
1054 * were satisfied in the past: for instance, if a version
1055 * restriction in a Recommends was tightened, upgrading the
1056 * package should follow that Recommends rather than causing the
1057 * dependency to be removed. (bug #470115)
1059 if (Pkg
->CurrentVer
!= 0 && ForceImportantDeps
== false && Start
.IsCritical() == false)
1061 bool isNewImportantDep
= true;
1062 bool isPreviouslySatisfiedImportantDep
= false;
1063 for (DepIterator D
= Pkg
.CurrentVer().DependsList(); D
.end() != true; ++D
)
1065 //FIXME: Should we handle or-group better here?
1066 // We do not check if the package we look for is part of the same or-group
1067 // we might find while searching, but could that really be a problem?
1068 if (D
.IsCritical() == true || IsImportantDep(D
) == false ||
1069 Start
.TargetPkg() != D
.TargetPkg())
1072 isNewImportantDep
= false;
1074 while ((D
->CompareOp
& Dep::Or
) != 0)
1077 isPreviouslySatisfiedImportantDep
= (((*this)[D
] & DepGNow
) != 0);
1078 if (isPreviouslySatisfiedImportantDep
== true)
1082 if(isNewImportantDep
== true)
1084 if (DebugAutoInstall
== true)
1085 std::clog
<< OutputInDepth(Depth
) << "new important dependency: "
1086 << Start
.TargetPkg().FullName() << std::endl
;
1088 else if(isPreviouslySatisfiedImportantDep
== true)
1090 if (DebugAutoInstall
== true)
1091 std::clog
<< OutputInDepth(Depth
) << "previously satisfied important dependency on "
1092 << Start
.TargetPkg().FullName() << std::endl
;
1096 if (DebugAutoInstall
== true)
1097 std::clog
<< OutputInDepth(Depth
) << "ignore old unsatisfied important dependency on "
1098 << Start
.TargetPkg().FullName() << std::endl
;
1103 /* This bit is for processing the possibilty of an install/upgrade
1104 fixing the problem */
1105 SPtrArray
<Version
*> List
= Start
.AllTargets();
1106 if (Start
->Type
!= Dep::DpkgBreaks
&&
1107 (DepState
[Start
->ID
] & DepCVer
) == DepCVer
)
1109 // Right, find the best version to install..
1110 Version
**Cur
= List
;
1111 PkgIterator P
= Start
.TargetPkg();
1112 PkgIterator
InstPkg(*Cache
,0);
1114 // See if there are direct matches (at the start of the list)
1115 for (; *Cur
!= 0 && (*Cur
)->ParentPkg
== P
.Index(); Cur
++)
1117 PkgIterator
Pkg(*Cache
,Cache
->PkgP
+ (*Cur
)->ParentPkg
);
1118 if (PkgState
[Pkg
->ID
].CandidateVer
!= *Cur
)
1124 // Select the highest priority providing package
1125 if (InstPkg
.end() == true)
1127 pkgPrioSortList(*Cache
,Cur
);
1128 for (; *Cur
!= 0; Cur
++)
1130 PkgIterator
Pkg(*Cache
,Cache
->PkgP
+ (*Cur
)->ParentPkg
);
1131 if (PkgState
[Pkg
->ID
].CandidateVer
!= *Cur
)
1138 if (InstPkg
.end() == false)
1140 if(DebugAutoInstall
== true)
1141 std::clog
<< OutputInDepth(Depth
) << "Installing " << InstPkg
.Name()
1142 << " as " << Start
.DepType() << " of " << Pkg
.Name()
1144 // now check if we should consider it a automatic dependency or not
1145 if(Pkg
.Section() && ConfigValueInSubTree("APT::Never-MarkAuto-Sections", Pkg
.Section()))
1147 if(DebugAutoInstall
== true)
1148 std::clog
<< OutputInDepth(Depth
) << "Setting NOT as auto-installed (direct "
1149 << Start
.DepType() << " of pkg in APT::Never-MarkAuto-Sections)" << std::endl
;
1150 MarkInstall(InstPkg
,true,Depth
+ 1, true);
1154 // mark automatic dependency
1155 MarkInstall(InstPkg
,true,Depth
+ 1, false, ForceImportantDeps
);
1156 // Set the autoflag, after MarkInstall because MarkInstall unsets it
1157 if (P
->CurrentVer
== 0)
1158 PkgState
[InstPkg
->ID
].Flags
|= Flag::Auto
;
1164 /* For conflicts we just de-install the package and mark as auto,
1165 Conflicts may not have or groups. For dpkg's Breaks we try to
1166 upgrade the package. */
1167 if (Start
.IsNegative() == true)
1169 for (Version
**I
= List
; *I
!= 0; I
++)
1171 VerIterator
Ver(*this,*I
);
1172 PkgIterator Pkg
= Ver
.ParentPkg();
1174 /* The List includes all packages providing this dependency,
1175 even providers which are not installed, so skip them. */
1176 if (PkgState
[Pkg
->ID
].InstallVer
== 0)
1179 if (PkgState
[Pkg
->ID
].CandidateVer
!= *I
&&
1180 Start
->Type
== Dep::DpkgBreaks
&&
1181 MarkInstall(Pkg
,true,Depth
+ 1, false, ForceImportantDeps
) == true)
1183 else if (MarkDelete(Pkg
,false,Depth
+ 1, false) == false)
1190 return Dep
.end() == true;
1193 // DepCache::IsInstallOk - check if it is ok to install this package /*{{{*/
1194 // ---------------------------------------------------------------------
1195 /* The default implementation does nothing.
1196 dpkg holds are enforced by the private IsModeChangeOk */
1197 bool pkgDepCache::IsInstallOk(PkgIterator
const &Pkg
,bool AutoInst
,
1198 unsigned long Depth
, bool FromUser
)
1203 // DepCache::SetReInstall - Set the reinstallation flag /*{{{*/
1204 // ---------------------------------------------------------------------
1206 void pkgDepCache::SetReInstall(PkgIterator
const &Pkg
,bool To
)
1208 if (unlikely(Pkg
.end() == true))
1211 ActionGroup
group(*this);
1216 StateCache
&P
= PkgState
[Pkg
->ID
];
1218 P
.iFlags
|= ReInstall
;
1220 P
.iFlags
&= ~ReInstall
;
1226 // DepCache::SetCandidateVersion - Change the candidate version /*{{{*/
1227 // ---------------------------------------------------------------------
1229 void pkgDepCache::SetCandidateVersion(VerIterator TargetVer
)
1231 pkgCache::PkgIterator Pkg
= TargetVer
.ParentPkg();
1232 StateCache
&P
= PkgState
[Pkg
->ID
];
1234 if (P
.CandidateVer
== TargetVer
)
1237 ActionGroup
group(*this);
1242 if (P
.CandidateVer
== P
.InstallVer
&& P
.Install() == true)
1243 P
.InstallVer
= (Version
*)TargetVer
;
1244 P
.CandidateVer
= (Version
*)TargetVer
;
1245 P
.Update(Pkg
,*this);
1253 // DepCache::SetCandidateRelease - Change the candidate version /*{{{*/
1254 // ---------------------------------------------------------------------
1255 /* changes the candidate of a package and walks over all its dependencies
1256 to check if it needs to change the candidate of the dependency, too,
1257 to reach a installable versionstate */
1258 bool pkgDepCache::SetCandidateRelease(pkgCache::VerIterator TargetVer
,
1259 std::string
const &TargetRel
)
1261 std::list
<std::pair
<pkgCache::VerIterator
, pkgCache::VerIterator
> > Changed
;
1262 return SetCandidateRelease(TargetVer
, TargetRel
, Changed
);
1264 bool pkgDepCache::SetCandidateRelease(pkgCache::VerIterator TargetVer
,
1265 std::string
const &TargetRel
,
1266 std::list
<std::pair
<pkgCache::VerIterator
, pkgCache::VerIterator
> > &Changed
)
1268 ActionGroup
group(*this);
1269 SetCandidateVersion(TargetVer
);
1271 if (TargetRel
== "installed" || TargetRel
== "candidate") // both doesn't make sense in this context
1274 pkgVersionMatch
Match(TargetRel
, pkgVersionMatch::Release
);
1275 // save the position of the last element we will not undo - if we have to
1276 std::list
<std::pair
<pkgCache::VerIterator
, pkgCache::VerIterator
> >::iterator newChanged
= --(Changed
.end());
1278 for (pkgCache::DepIterator D
= TargetVer
.DependsList(); D
.end() == false; ++D
)
1280 if (D
->Type
!= pkgCache::Dep::PreDepends
&& D
->Type
!= pkgCache::Dep::Depends
&&
1281 ((D
->Type
!= pkgCache::Dep::Recommends
&& D
->Type
!= pkgCache::Dep::Suggests
) ||
1282 IsImportantDep(D
) == false))
1285 // walk over an or-group and check if we need to do anything
1286 // for simpilicity no or-group is handled as a or-group including one dependency
1287 pkgCache::DepIterator Start
= D
;
1288 bool itsFine
= false;
1289 for (bool stillOr
= true; stillOr
== true; ++Start
)
1291 stillOr
= (Start
->CompareOp
& Dep::Or
) == Dep::Or
;
1292 pkgCache::PkgIterator
const P
= Start
.TargetPkg();
1293 // virtual packages can't be a solution
1294 if (P
.end() == true || (P
->ProvidesList
== 0 && P
->VersionList
== 0))
1296 pkgCache::VerIterator
const Cand
= PkgState
[P
->ID
].CandidateVerIter(*this);
1297 // no versioned dependency - but is it installable?
1298 if (Start
.TargetVer() == 0 || Start
.TargetVer()[0] == '\0')
1300 // Check if one of the providers is installable
1301 if (P
->ProvidesList
!= 0)
1303 pkgCache::PrvIterator Prv
= P
.ProvidesList();
1304 for (; Prv
.end() == false; ++Prv
)
1306 pkgCache::VerIterator
const C
= PkgState
[Prv
.OwnerPkg()->ID
].CandidateVerIter(*this);
1307 if (C
.end() == true || C
!= Prv
.OwnerVer() ||
1308 (VersionState(C
.DependsList(), DepInstall
, DepCandMin
, DepCandPolicy
) & DepCandMin
) != DepCandMin
)
1312 if (Prv
.end() == true)
1315 // no providers, so check if we have an installable candidate version
1316 else if (Cand
.end() == true ||
1317 (VersionState(Cand
.DependsList(), DepInstall
, DepCandMin
, DepCandPolicy
) & DepCandMin
) != DepCandMin
)
1322 if (Cand
.end() == true)
1324 // check if the current candidate is enough for the versioned dependency - and installable?
1325 if (VS().CheckDep(P
.CandVersion(), Start
->CompareOp
, Start
.TargetVer()) == true &&
1326 (VersionState(Cand
.DependsList(), DepInstall
, DepCandMin
, DepCandPolicy
) & DepCandMin
) == DepCandMin
)
1333 if (itsFine
== true) {
1334 // something in the or-group was fine, skip all other members
1335 for (; (D
->CompareOp
& Dep::Or
) == Dep::Or
; ++D
);
1339 // walk again over the or-group and check each if a candidate switch would help
1341 for (bool stillOr
= true; stillOr
== true; ++D
)
1343 stillOr
= (D
->CompareOp
& Dep::Or
) == Dep::Or
;
1344 // changing candidate will not help if the dependency is not versioned
1345 if (D
.TargetVer() == 0 || D
.TargetVer()[0] == '\0')
1347 if (stillOr
== true)
1352 pkgCache::VerIterator V
;
1353 if (TargetRel
== "newest")
1354 V
= D
.TargetPkg().VersionList();
1356 V
= Match
.Find(D
.TargetPkg());
1358 // check if the version from this release could satisfy the dependency
1359 if (V
.end() == true || VS().CheckDep(V
.VerStr(), D
->CompareOp
, D
.TargetVer()) == false)
1361 if (stillOr
== true)
1366 pkgCache::VerIterator oldCand
= PkgState
[D
.TargetPkg()->ID
].CandidateVerIter(*this);
1369 // Do we already touched this Version? If so, their versioned dependencies are okay, no need to check again
1370 for (std::list
<std::pair
<pkgCache::VerIterator
, pkgCache::VerIterator
> >::const_iterator c
= Changed
.begin();
1371 c
!= Changed
.end(); ++c
)
1373 if (c
->first
->ParentPkg
!= V
->ParentPkg
)
1380 if (itsFine
== false)
1382 // change the candidate
1383 Changed
.push_back(make_pair(oldCand
, TargetVer
));
1384 if (SetCandidateRelease(V
, TargetRel
, Changed
) == false)
1386 if (stillOr
== false)
1388 // undo the candidate changing
1389 SetCandidateVersion(oldCand
);
1396 // something in the or-group was fine, skip all other members
1397 for (; (D
->CompareOp
& Dep::Or
) == Dep::Or
; ++D
);
1401 if (itsFine
== false && (D
->Type
== pkgCache::Dep::PreDepends
|| D
->Type
== pkgCache::Dep::Depends
))
1403 // undo all changes which aren't lead to a solution
1404 for (std::list
<std::pair
<pkgCache::VerIterator
, pkgCache::VerIterator
> >::const_iterator c
= ++newChanged
;
1405 c
!= Changed
.end(); ++c
)
1406 SetCandidateVersion(c
->first
);
1407 Changed
.erase(newChanged
, Changed
.end());
1414 // DepCache::MarkAuto - set the Auto flag for a package /*{{{*/
1415 // ---------------------------------------------------------------------
1417 void pkgDepCache::MarkAuto(const PkgIterator
&Pkg
, bool Auto
)
1419 StateCache
&state
= PkgState
[Pkg
->ID
];
1421 ActionGroup
group(*this);
1424 state
.Flags
|= Flag::Auto
;
1426 state
.Flags
&= ~Flag::Auto
;
1429 // StateCache::Update - Compute the various static display things /*{{{*/
1430 // ---------------------------------------------------------------------
1431 /* This is called whenever the Candidate version changes. */
1432 void pkgDepCache::StateCache::Update(PkgIterator Pkg
,pkgCache
&Cache
)
1435 VerIterator Ver
= CandidateVerIter(Cache
);
1437 // Use a null string or the version string
1438 if (Ver
.end() == true)
1441 CandVersion
= Ver
.VerStr();
1443 // Find the current version
1445 if (Pkg
->CurrentVer
!= 0)
1446 CurVersion
= Pkg
.CurrentVer().VerStr();
1448 // Strip off the epochs for display
1449 CurVersion
= StripEpoch(CurVersion
);
1450 CandVersion
= StripEpoch(CandVersion
);
1452 // Figure out if its up or down or equal
1453 Status
= Ver
.CompareVer(Pkg
.CurrentVer());
1454 if (Pkg
->CurrentVer
== 0 || Pkg
->VersionList
== 0 || CandidateVer
== 0)
1458 // StateCache::StripEpoch - Remove the epoch specifier from the version /*{{{*/
1459 // ---------------------------------------------------------------------
1461 const char *pkgDepCache::StateCache::StripEpoch(const char *Ver
)
1467 for (const char *I
= Ver
; *I
!= 0; I
++)
1473 // Policy::GetCandidateVer - Returns the Candidate install version /*{{{*/
1474 // ---------------------------------------------------------------------
1475 /* The default just returns the highest available version that is not
1476 a source and automatic. */
1477 pkgCache::VerIterator
pkgDepCache::Policy::GetCandidateVer(PkgIterator
const &Pkg
)
1479 /* Not source/not automatic versions cannot be a candidate version
1480 unless they are already installed */
1481 VerIterator
Last(*(pkgCache
*)this,0);
1483 for (VerIterator I
= Pkg
.VersionList(); I
.end() == false; ++I
)
1485 if (Pkg
.CurrentVer() == I
)
1488 for (VerFileIterator J
= I
.FileList(); J
.end() == false; ++J
)
1490 if ((J
.File()->Flags
& Flag::NotSource
) != 0)
1493 /* Stash the highest version of a not-automatic source, we use it
1494 if there is nothing better */
1495 if ((J
.File()->Flags
& Flag::NotAutomatic
) != 0 ||
1496 (J
.File()->Flags
& Flag::ButAutomaticUpgrades
) != 0)
1498 if (Last
.end() == true)
1510 // Policy::IsImportantDep - True if the dependency is important /*{{{*/
1511 // ---------------------------------------------------------------------
1513 bool pkgDepCache::Policy::IsImportantDep(DepIterator
const &Dep
)
1515 if(Dep
.IsCritical())
1517 else if(Dep
->Type
== pkgCache::Dep::Recommends
)
1519 if (InstallRecommends
)
1521 // we suport a special mode to only install-recommends for certain
1523 // FIXME: this is a meant as a temporarly solution until the
1524 // recommends are cleaned up
1525 const char *sec
= Dep
.ParentVer().Section();
1526 if (sec
&& ConfigValueInSubTree("APT::Install-Recommends-Sections", sec
))
1529 else if(Dep
->Type
== pkgCache::Dep::Suggests
)
1530 return InstallSuggests
;
1535 // Policy::GetPriority - Get the priority of the package pin /*{{{*/
1536 signed short pkgDepCache::Policy::GetPriority(pkgCache::PkgIterator
const &Pkg
)
1538 signed short pkgDepCache::Policy::GetPriority(pkgCache::PkgFileIterator
const &File
)
1541 pkgDepCache::InRootSetFunc
*pkgDepCache::GetRootSetFunc() /*{{{*/
1543 DefaultRootSetFunc
*f
= new DefaultRootSetFunc
;
1544 if(f
->wasConstructedSuccessfully())
1553 bool pkgDepCache::MarkFollowsRecommends()
1555 return _config
->FindB("APT::AutoRemove::RecommendsImportant", true);
1558 bool pkgDepCache::MarkFollowsSuggests()
1560 return _config
->FindB("APT::AutoRemove::SuggestsImportant", true);
1563 // pkgDepCache::MarkRequired - the main mark algorithm /*{{{*/
1564 bool pkgDepCache::MarkRequired(InRootSetFunc
&userFunc
)
1566 if (_config
->Find("APT::Solver", "internal") != "internal")
1569 bool follow_recommends
;
1570 bool follow_suggests
;
1571 bool debug_autoremove
= _config
->FindB("Debug::pkgAutoRemove",false);
1574 for(PkgIterator p
= PkgBegin(); !p
.end(); ++p
)
1576 PkgState
[p
->ID
].Marked
= false;
1577 PkgState
[p
->ID
].Garbage
= false;
1580 if(debug_autoremove
&& PkgState
[p
->ID
].Flags
& Flag::Auto
)
1581 std::clog
<< "AutoDep: " << p
.FullName() << std::endl
;
1585 follow_recommends
= MarkFollowsRecommends();
1586 follow_suggests
= MarkFollowsSuggests();
1590 // do the mark part, this is the core bit of the algorithm
1591 for(PkgIterator p
= PkgBegin(); !p
.end(); ++p
)
1593 if(!(PkgState
[p
->ID
].Flags
& Flag::Auto
) ||
1594 (p
->Flags
& Flag::Essential
) ||
1595 userFunc
.InRootSet(p
) ||
1596 // be nice even then a required package violates the policy (#583517)
1597 // and do the full mark process also for required packages
1598 (p
.CurrentVer().end() != true &&
1599 p
.CurrentVer()->Priority
== pkgCache::State::Required
))
1601 // the package is installed (and set to keep)
1602 if(PkgState
[p
->ID
].Keep() && !p
.CurrentVer().end())
1603 MarkPackage(p
, p
.CurrentVer(),
1604 follow_recommends
, follow_suggests
);
1605 // the package is to be installed
1606 else if(PkgState
[p
->ID
].Install())
1607 MarkPackage(p
, PkgState
[p
->ID
].InstVerIter(*this),
1608 follow_recommends
, follow_suggests
);
1615 // MarkPackage - mark a single package in Mark-and-Sweep /*{{{*/
1616 void pkgDepCache::MarkPackage(const pkgCache::PkgIterator
&pkg
,
1617 const pkgCache::VerIterator
&ver
,
1618 bool const &follow_recommends
,
1619 bool const &follow_suggests
)
1621 pkgDepCache::StateCache
&state
= PkgState
[pkg
->ID
];
1623 // if we are marked already we are done
1627 VerIterator
const currver
= pkg
.CurrentVer();
1628 VerIterator
const instver
= state
.InstVerIter(*this);
1631 VerIterator
const candver
= state
.CandidateVerIter(*this);
1633 // If a package was garbage-collected but is now being marked, we
1634 // should re-select it
1635 // For cases when a pkg is set to upgrade and this trigger the
1636 // removal of a no-longer used dependency. if the pkg is set to
1637 // keep again later it will result in broken deps
1638 if(state
.Delete() && state
.RemoveReason
= Unused
)
1641 mark_install(pkg
, false, false, NULL
);
1642 else if(ver
==pkg
.CurrentVer())
1643 MarkKeep(pkg
, false, false);
1645 instver
=state
.InstVerIter(*this);
1649 // For packages that are not going to be removed, ignore versions
1650 // other than the InstVer. For packages that are going to be
1651 // removed, ignore versions other than the current version.
1652 if(!(ver
== instver
&& !instver
.end()) &&
1653 !(ver
== currver
&& instver
.end() && !ver
.end()))
1656 bool const debug_autoremove
= _config
->FindB("Debug::pkgAutoRemove", false);
1658 if(debug_autoremove
)
1660 std::clog
<< "Marking: " << pkg
.FullName();
1662 std::clog
<< " " << ver
.VerStr();
1664 std::clog
<< ", Curr=" << currver
.VerStr();
1666 std::clog
<< ", Inst=" << instver
.VerStr();
1667 std::clog
<< std::endl
;
1672 if(ver
.end() == true)
1675 for(DepIterator d
= ver
.DependsList(); !d
.end(); ++d
)
1677 if(d
->Type
== Dep::Depends
||
1678 d
->Type
== Dep::PreDepends
||
1679 (follow_recommends
&&
1680 d
->Type
== Dep::Recommends
) ||
1682 d
->Type
== Dep::Suggests
))
1684 // Try all versions of this package.
1685 for(VerIterator V
= d
.TargetPkg().VersionList();
1688 if(_system
->VS
->CheckDep(V
.VerStr(), d
->CompareOp
, d
.TargetVer()))
1690 if(debug_autoremove
)
1692 std::clog
<< "Following dep: " << d
.ParentPkg().FullName()
1693 << " " << d
.ParentVer().VerStr() << " "
1694 << d
.DepType() << " " << d
.TargetPkg().FullName();
1695 if((d
->CompareOp
& ~pkgCache::Dep::Or
) != pkgCache::Dep::NoOp
)
1697 std::clog
<< " (" << d
.CompType() << " "
1698 << d
.TargetVer() << ")";
1700 std::clog
<< std::endl
;
1702 MarkPackage(V
.ParentPkg(), V
,
1703 follow_recommends
, follow_suggests
);
1706 // Now try virtual packages
1707 for(PrvIterator prv
=d
.TargetPkg().ProvidesList();
1710 if(_system
->VS
->CheckDep(prv
.ProvideVersion(), d
->CompareOp
,
1713 if(debug_autoremove
)
1715 std::clog
<< "Following dep: " << d
.ParentPkg().FullName() << " "
1716 << d
.ParentVer().VerStr() << " "
1717 << d
.DepType() << " " << d
.TargetPkg().FullName() << " ";
1718 if((d
->CompareOp
& ~pkgCache::Dep::Or
) != pkgCache::Dep::NoOp
)
1720 std::clog
<< " (" << d
.CompType() << " "
1721 << d
.TargetVer() << ")";
1723 std::clog
<< ", provided by "
1724 << prv
.OwnerPkg().FullName() << " "
1725 << prv
.OwnerVer().VerStr()
1729 MarkPackage(prv
.OwnerPkg(), prv
.OwnerVer(),
1730 follow_recommends
, follow_suggests
);
1737 bool pkgDepCache::Sweep() /*{{{*/
1739 bool debug_autoremove
= _config
->FindB("Debug::pkgAutoRemove",false);
1742 for(PkgIterator p
=PkgBegin(); !p
.end(); ++p
)
1744 StateCache
&state
=PkgState
[p
->ID
];
1746 // skip required packages
1747 if (!p
.CurrentVer().end() &&
1748 (p
.CurrentVer()->Priority
== pkgCache::State::Required
))
1751 // if it is not marked and it is installed, it's garbage
1752 if(!state
.Marked
&& (!p
.CurrentVer().end() || state
.Install()))
1755 if(debug_autoremove
)
1756 std::clog
<< "Garbage: " << p
.FullName() << std::endl
;