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 // Status == 2 means this applies for new installs only
876 if (P
.InstallVer
!= 0 && P
.Status
== 2 && (P
.Flags
& Flag::Auto
) != Flag::Auto
)
878 if (DebugMarker
== true)
879 std::clog
<< OutputInDepth(Depth
) << "Manual install request prevents MarkDelete of " << Pkg
<< std::endl
;
886 // DepCache::IsModeChangeOk - check if it is ok to change the mode /*{{{*/
887 // ---------------------------------------------------------------------
888 /* this is used by all Mark methods on the very first line to check sanity
889 and prevents mode changes for packages on hold for example.
890 If you want to check Mode specific stuff you can use the virtual public
891 Is<Mode>Ok methods instead */
892 char const* PrintMode(char const mode
)
896 case pkgDepCache::ModeInstall
: return "Install";
897 case pkgDepCache::ModeKeep
: return "Keep";
898 case pkgDepCache::ModeDelete
: return "Delete";
899 default: return "UNKNOWN";
902 bool pkgDepCache::IsModeChangeOk(ModeList
const mode
, PkgIterator
const &Pkg
,
903 unsigned long const Depth
, bool const FromUser
)
905 // we are not trying to hard…
906 if (unlikely(Depth
> 100))
910 if (unlikely(Pkg
.end() == true || Pkg
->VersionList
== 0))
913 // the user is always right
914 if (FromUser
== true)
917 StateCache
&P
= PkgState
[Pkg
->ID
];
919 // if previous state was set by user only user can reset it
920 if ((P
.iFlags
& Protected
) == Protected
)
922 if (unlikely(DebugMarker
== true) && P
.Mode
!= mode
)
923 std::clog
<< OutputInDepth(Depth
) << "Ignore Mark" << PrintMode(mode
)
924 << " of " << Pkg
<< " as its mode (" << PrintMode(P
.Mode
)
925 << ") is protected" << std::endl
;
928 // enforce dpkg holds
929 else if (mode
!= ModeKeep
&& Pkg
->SelectedState
== pkgCache::State::Hold
&&
930 _config
->FindB("APT::Ignore-Hold",false) == false)
932 if (unlikely(DebugMarker
== true) && P
.Mode
!= mode
)
933 std::clog
<< OutputInDepth(Depth
) << "Hold prevents Mark" << PrintMode(mode
)
934 << " of " << Pkg
<< std::endl
;
941 // DepCache::MarkInstall - Put the package in the install state /*{{{*/
942 // ---------------------------------------------------------------------
944 bool pkgDepCache::MarkInstall(PkgIterator
const &Pkg
,bool AutoInst
,
945 unsigned long Depth
, bool FromUser
,
946 bool ForceImportantDeps
)
948 if (IsModeChangeOk(ModeInstall
, Pkg
, Depth
, FromUser
) == false)
951 StateCache
&P
= PkgState
[Pkg
->ID
];
953 // See if there is even any possible instalation candidate
954 if (P
.CandidateVer
== 0)
957 /* Check that it is not already marked for install and that it can be
959 if ((P
.InstPolicyBroken() == false && P
.InstBroken() == false) &&
960 (P
.Mode
== ModeInstall
||
961 P
.CandidateVer
== (Version
*)Pkg
.CurrentVer()))
963 if (P
.CandidateVer
== (Version
*)Pkg
.CurrentVer() && P
.InstallVer
== 0)
964 return MarkKeep(Pkg
, false, FromUser
, Depth
+1);
968 // check if we are allowed to install the package
969 if (IsInstallOk(Pkg
,AutoInst
,Depth
,FromUser
) == false)
972 ActionGroup
group(*this);
973 P
.iFlags
&= ~AutoKept
;
975 /* Target the candidate version and remove the autoflag. We reset the
976 autoflag below if this was called recursively. Otherwise the user
977 should have the ability to de-auto a package by changing its state */
981 P
.Mode
= ModeInstall
;
982 P
.InstallVer
= P
.CandidateVer
;
986 // Set it to manual if it's a new install or already installed,
987 // but only if its not marked by the autoremover (aptitude depend on this behavior)
988 // or if we do automatic installation (aptitude never does it)
989 if(P
.Status
== 2 || (Pkg
->CurrentVer
!= 0 && (AutoInst
== true || P
.Marked
== false)))
990 P
.Flags
&= ~Flag::Auto
;
994 // Set it to auto if this is a new install.
996 P
.Flags
|= Flag::Auto
;
998 if (P
.CandidateVer
== (Version
*)Pkg
.CurrentVer())
1005 if (AutoInst
== false || _config
->Find("APT::Solver", "internal") != "internal")
1008 if (DebugMarker
== true)
1009 std::clog
<< OutputInDepth(Depth
) << "MarkInstall " << Pkg
<< " FU=" << FromUser
<< std::endl
;
1011 DepIterator Dep
= P
.InstVerIter(*this).DependsList();
1012 for (; Dep
.end() != true;)
1015 DepIterator Start
= Dep
;
1018 for (bool LastOR
= true; Dep
.end() == false && LastOR
== true; ++Dep
, ++Ors
)
1020 LastOR
= (Dep
->CompareOp
& Dep::Or
) == Dep::Or
;
1022 if ((DepState
[Dep
->ID
] & DepInstall
) == DepInstall
)
1026 // Dep is satisfied okay.
1027 if (Result
== false)
1030 /* Check if this dep should be consider for install. If it is a user
1031 defined important dep and we are installed a new package then
1032 it will be installed. Otherwise we only check for important
1033 deps that have changed from the installed version
1035 if (IsImportantDep(Start
) == false)
1038 /* If we are in an or group locate the first or that can
1039 succeed. We have already cached this.. */
1040 for (; Ors
> 1 && (DepState
[Start
->ID
] & DepCVer
) != DepCVer
; --Ors
)
1042 if (Ors
== 1 && (DepState
[Start
->ID
] &DepCVer
) != DepCVer
&& Start
.IsNegative() == false)
1044 if(DebugAutoInstall
== true)
1045 std::clog
<< OutputInDepth(Depth
) << Start
<< " can't be satisfied!" << std::endl
;
1046 if (Start
.IsCritical() == false)
1048 // if the dependency was critical, we can't install it, so remove it again
1049 MarkDelete(Pkg
,false,Depth
+ 1, false);
1053 /* Check if any ImportantDep() (but not Critical) were added
1054 * since we installed the package. Also check for deps that
1055 * were satisfied in the past: for instance, if a version
1056 * restriction in a Recommends was tightened, upgrading the
1057 * package should follow that Recommends rather than causing the
1058 * dependency to be removed. (bug #470115)
1060 if (Pkg
->CurrentVer
!= 0 && ForceImportantDeps
== false && Start
.IsCritical() == false)
1062 bool isNewImportantDep
= true;
1063 bool isPreviouslySatisfiedImportantDep
= false;
1064 for (DepIterator D
= Pkg
.CurrentVer().DependsList(); D
.end() != true; ++D
)
1066 //FIXME: Should we handle or-group better here?
1067 // We do not check if the package we look for is part of the same or-group
1068 // we might find while searching, but could that really be a problem?
1069 if (D
.IsCritical() == true || IsImportantDep(D
) == false ||
1070 Start
.TargetPkg() != D
.TargetPkg())
1073 isNewImportantDep
= false;
1075 while ((D
->CompareOp
& Dep::Or
) != 0)
1078 isPreviouslySatisfiedImportantDep
= (((*this)[D
] & DepGNow
) != 0);
1079 if (isPreviouslySatisfiedImportantDep
== true)
1083 if(isNewImportantDep
== true)
1085 if (DebugAutoInstall
== true)
1086 std::clog
<< OutputInDepth(Depth
) << "new important dependency: "
1087 << Start
.TargetPkg().FullName() << std::endl
;
1089 else if(isPreviouslySatisfiedImportantDep
== true)
1091 if (DebugAutoInstall
== true)
1092 std::clog
<< OutputInDepth(Depth
) << "previously satisfied important dependency on "
1093 << Start
.TargetPkg().FullName() << std::endl
;
1097 if (DebugAutoInstall
== true)
1098 std::clog
<< OutputInDepth(Depth
) << "ignore old unsatisfied important dependency on "
1099 << Start
.TargetPkg().FullName() << std::endl
;
1104 /* This bit is for processing the possibilty of an install/upgrade
1105 fixing the problem */
1106 SPtrArray
<Version
*> List
= Start
.AllTargets();
1107 if (Start
->Type
!= Dep::DpkgBreaks
&&
1108 (DepState
[Start
->ID
] & DepCVer
) == DepCVer
)
1110 // Right, find the best version to install..
1111 Version
**Cur
= List
;
1112 PkgIterator P
= Start
.TargetPkg();
1113 PkgIterator
InstPkg(*Cache
,0);
1115 // See if there are direct matches (at the start of the list)
1116 for (; *Cur
!= 0 && (*Cur
)->ParentPkg
== P
.Index(); Cur
++)
1118 PkgIterator
Pkg(*Cache
,Cache
->PkgP
+ (*Cur
)->ParentPkg
);
1119 if (PkgState
[Pkg
->ID
].CandidateVer
!= *Cur
)
1125 // Select the highest priority providing package
1126 if (InstPkg
.end() == true)
1128 pkgPrioSortList(*Cache
,Cur
);
1129 for (; *Cur
!= 0; Cur
++)
1131 PkgIterator
Pkg(*Cache
,Cache
->PkgP
+ (*Cur
)->ParentPkg
);
1132 if (PkgState
[Pkg
->ID
].CandidateVer
!= *Cur
)
1139 if (InstPkg
.end() == false)
1141 if(DebugAutoInstall
== true)
1142 std::clog
<< OutputInDepth(Depth
) << "Installing " << InstPkg
.Name()
1143 << " as " << Start
.DepType() << " of " << Pkg
.Name()
1145 // now check if we should consider it a automatic dependency or not
1146 if(Pkg
.Section() && ConfigValueInSubTree("APT::Never-MarkAuto-Sections", Pkg
.Section()))
1148 if(DebugAutoInstall
== true)
1149 std::clog
<< OutputInDepth(Depth
) << "Setting NOT as auto-installed (direct "
1150 << Start
.DepType() << " of pkg in APT::Never-MarkAuto-Sections)" << std::endl
;
1151 MarkInstall(InstPkg
,true,Depth
+ 1, true);
1155 // mark automatic dependency
1156 MarkInstall(InstPkg
,true,Depth
+ 1, false, ForceImportantDeps
);
1157 // Set the autoflag, after MarkInstall because MarkInstall unsets it
1158 if (P
->CurrentVer
== 0)
1159 PkgState
[InstPkg
->ID
].Flags
|= Flag::Auto
;
1165 /* For conflicts we just de-install the package and mark as auto,
1166 Conflicts may not have or groups. For dpkg's Breaks we try to
1167 upgrade the package. */
1168 if (Start
.IsNegative() == true)
1170 for (Version
**I
= List
; *I
!= 0; I
++)
1172 VerIterator
Ver(*this,*I
);
1173 PkgIterator Pkg
= Ver
.ParentPkg();
1175 /* The List includes all packages providing this dependency,
1176 even providers which are not installed, so skip them. */
1177 if (PkgState
[Pkg
->ID
].InstallVer
== 0)
1180 if (PkgState
[Pkg
->ID
].CandidateVer
!= *I
&&
1181 Start
->Type
== Dep::DpkgBreaks
&&
1182 MarkInstall(Pkg
,true,Depth
+ 1, false, ForceImportantDeps
) == true)
1184 else if (MarkDelete(Pkg
,false,Depth
+ 1, false) == false)
1191 return Dep
.end() == true;
1194 // DepCache::IsInstallOk - check if it is ok to install this package /*{{{*/
1195 // ---------------------------------------------------------------------
1196 /* The default implementation does nothing.
1197 dpkg holds are enforced by the private IsModeChangeOk */
1198 bool pkgDepCache::IsInstallOk(PkgIterator
const &Pkg
,bool AutoInst
,
1199 unsigned long Depth
, bool FromUser
)
1204 // DepCache::SetReInstall - Set the reinstallation flag /*{{{*/
1205 // ---------------------------------------------------------------------
1207 void pkgDepCache::SetReInstall(PkgIterator
const &Pkg
,bool To
)
1209 if (unlikely(Pkg
.end() == true))
1212 ActionGroup
group(*this);
1217 StateCache
&P
= PkgState
[Pkg
->ID
];
1219 P
.iFlags
|= ReInstall
;
1221 P
.iFlags
&= ~ReInstall
;
1227 // DepCache::SetCandidateVersion - Change the candidate version /*{{{*/
1228 // ---------------------------------------------------------------------
1230 void pkgDepCache::SetCandidateVersion(VerIterator TargetVer
)
1232 pkgCache::PkgIterator Pkg
= TargetVer
.ParentPkg();
1233 StateCache
&P
= PkgState
[Pkg
->ID
];
1235 if (P
.CandidateVer
== TargetVer
)
1238 ActionGroup
group(*this);
1243 if (P
.CandidateVer
== P
.InstallVer
&& P
.Install() == true)
1244 P
.InstallVer
= (Version
*)TargetVer
;
1245 P
.CandidateVer
= (Version
*)TargetVer
;
1246 P
.Update(Pkg
,*this);
1254 // DepCache::SetCandidateRelease - Change the candidate version /*{{{*/
1255 // ---------------------------------------------------------------------
1256 /* changes the candidate of a package and walks over all its dependencies
1257 to check if it needs to change the candidate of the dependency, too,
1258 to reach a installable versionstate */
1259 bool pkgDepCache::SetCandidateRelease(pkgCache::VerIterator TargetVer
,
1260 std::string
const &TargetRel
)
1262 std::list
<std::pair
<pkgCache::VerIterator
, pkgCache::VerIterator
> > Changed
;
1263 return SetCandidateRelease(TargetVer
, TargetRel
, Changed
);
1265 bool pkgDepCache::SetCandidateRelease(pkgCache::VerIterator TargetVer
,
1266 std::string
const &TargetRel
,
1267 std::list
<std::pair
<pkgCache::VerIterator
, pkgCache::VerIterator
> > &Changed
)
1269 ActionGroup
group(*this);
1270 SetCandidateVersion(TargetVer
);
1272 if (TargetRel
== "installed" || TargetRel
== "candidate") // both doesn't make sense in this context
1275 pkgVersionMatch
Match(TargetRel
, pkgVersionMatch::Release
);
1276 // save the position of the last element we will not undo - if we have to
1277 std::list
<std::pair
<pkgCache::VerIterator
, pkgCache::VerIterator
> >::iterator newChanged
= --(Changed
.end());
1279 for (pkgCache::DepIterator D
= TargetVer
.DependsList(); D
.end() == false; ++D
)
1281 if (D
->Type
!= pkgCache::Dep::PreDepends
&& D
->Type
!= pkgCache::Dep::Depends
&&
1282 ((D
->Type
!= pkgCache::Dep::Recommends
&& D
->Type
!= pkgCache::Dep::Suggests
) ||
1283 IsImportantDep(D
) == false))
1286 // walk over an or-group and check if we need to do anything
1287 // for simpilicity no or-group is handled as a or-group including one dependency
1288 pkgCache::DepIterator Start
= D
;
1289 bool itsFine
= false;
1290 for (bool stillOr
= true; stillOr
== true; ++Start
)
1292 stillOr
= (Start
->CompareOp
& Dep::Or
) == Dep::Or
;
1293 pkgCache::PkgIterator
const P
= Start
.TargetPkg();
1294 // virtual packages can't be a solution
1295 if (P
.end() == true || (P
->ProvidesList
== 0 && P
->VersionList
== 0))
1297 pkgCache::VerIterator
const Cand
= PkgState
[P
->ID
].CandidateVerIter(*this);
1298 // no versioned dependency - but is it installable?
1299 if (Start
.TargetVer() == 0 || Start
.TargetVer()[0] == '\0')
1301 // Check if one of the providers is installable
1302 if (P
->ProvidesList
!= 0)
1304 pkgCache::PrvIterator Prv
= P
.ProvidesList();
1305 for (; Prv
.end() == false; ++Prv
)
1307 pkgCache::VerIterator
const C
= PkgState
[Prv
.OwnerPkg()->ID
].CandidateVerIter(*this);
1308 if (C
.end() == true || C
!= Prv
.OwnerVer() ||
1309 (VersionState(C
.DependsList(), DepInstall
, DepCandMin
, DepCandPolicy
) & DepCandMin
) != DepCandMin
)
1313 if (Prv
.end() == true)
1316 // no providers, so check if we have an installable candidate version
1317 else if (Cand
.end() == true ||
1318 (VersionState(Cand
.DependsList(), DepInstall
, DepCandMin
, DepCandPolicy
) & DepCandMin
) != DepCandMin
)
1323 if (Cand
.end() == true)
1325 // check if the current candidate is enough for the versioned dependency - and installable?
1326 if (VS().CheckDep(P
.CandVersion(), Start
->CompareOp
, Start
.TargetVer()) == true &&
1327 (VersionState(Cand
.DependsList(), DepInstall
, DepCandMin
, DepCandPolicy
) & DepCandMin
) == DepCandMin
)
1334 if (itsFine
== true) {
1335 // something in the or-group was fine, skip all other members
1336 for (; (D
->CompareOp
& Dep::Or
) == Dep::Or
; ++D
);
1340 // walk again over the or-group and check each if a candidate switch would help
1342 for (bool stillOr
= true; stillOr
== true; ++D
)
1344 stillOr
= (D
->CompareOp
& Dep::Or
) == Dep::Or
;
1345 // changing candidate will not help if the dependency is not versioned
1346 if (D
.TargetVer() == 0 || D
.TargetVer()[0] == '\0')
1348 if (stillOr
== true)
1353 pkgCache::VerIterator V
;
1354 if (TargetRel
== "newest")
1355 V
= D
.TargetPkg().VersionList();
1357 V
= Match
.Find(D
.TargetPkg());
1359 // check if the version from this release could satisfy the dependency
1360 if (V
.end() == true || VS().CheckDep(V
.VerStr(), D
->CompareOp
, D
.TargetVer()) == false)
1362 if (stillOr
== true)
1367 pkgCache::VerIterator oldCand
= PkgState
[D
.TargetPkg()->ID
].CandidateVerIter(*this);
1370 // Do we already touched this Version? If so, their versioned dependencies are okay, no need to check again
1371 for (std::list
<std::pair
<pkgCache::VerIterator
, pkgCache::VerIterator
> >::const_iterator c
= Changed
.begin();
1372 c
!= Changed
.end(); ++c
)
1374 if (c
->first
->ParentPkg
!= V
->ParentPkg
)
1381 if (itsFine
== false)
1383 // change the candidate
1384 Changed
.push_back(make_pair(oldCand
, TargetVer
));
1385 if (SetCandidateRelease(V
, TargetRel
, Changed
) == false)
1387 if (stillOr
== false)
1389 // undo the candidate changing
1390 SetCandidateVersion(oldCand
);
1397 // something in the or-group was fine, skip all other members
1398 for (; (D
->CompareOp
& Dep::Or
) == Dep::Or
; ++D
);
1402 if (itsFine
== false && (D
->Type
== pkgCache::Dep::PreDepends
|| D
->Type
== pkgCache::Dep::Depends
))
1404 // undo all changes which aren't lead to a solution
1405 for (std::list
<std::pair
<pkgCache::VerIterator
, pkgCache::VerIterator
> >::const_iterator c
= ++newChanged
;
1406 c
!= Changed
.end(); ++c
)
1407 SetCandidateVersion(c
->first
);
1408 Changed
.erase(newChanged
, Changed
.end());
1415 // DepCache::MarkAuto - set the Auto flag for a package /*{{{*/
1416 // ---------------------------------------------------------------------
1418 void pkgDepCache::MarkAuto(const PkgIterator
&Pkg
, bool Auto
)
1420 StateCache
&state
= PkgState
[Pkg
->ID
];
1422 ActionGroup
group(*this);
1425 state
.Flags
|= Flag::Auto
;
1427 state
.Flags
&= ~Flag::Auto
;
1430 // StateCache::Update - Compute the various static display things /*{{{*/
1431 // ---------------------------------------------------------------------
1432 /* This is called whenever the Candidate version changes. */
1433 void pkgDepCache::StateCache::Update(PkgIterator Pkg
,pkgCache
&Cache
)
1436 VerIterator Ver
= CandidateVerIter(Cache
);
1438 // Use a null string or the version string
1439 if (Ver
.end() == true)
1442 CandVersion
= Ver
.VerStr();
1444 // Find the current version
1446 if (Pkg
->CurrentVer
!= 0)
1447 CurVersion
= Pkg
.CurrentVer().VerStr();
1449 // Strip off the epochs for display
1450 CurVersion
= StripEpoch(CurVersion
);
1451 CandVersion
= StripEpoch(CandVersion
);
1453 // Figure out if its up or down or equal
1454 Status
= Ver
.CompareVer(Pkg
.CurrentVer());
1455 if (Pkg
->CurrentVer
== 0 || Pkg
->VersionList
== 0 || CandidateVer
== 0)
1459 // StateCache::StripEpoch - Remove the epoch specifier from the version /*{{{*/
1460 // ---------------------------------------------------------------------
1462 const char *pkgDepCache::StateCache::StripEpoch(const char *Ver
)
1468 for (const char *I
= Ver
; *I
!= 0; I
++)
1474 // Policy::GetCandidateVer - Returns the Candidate install version /*{{{*/
1475 // ---------------------------------------------------------------------
1476 /* The default just returns the highest available version that is not
1477 a source and automatic. */
1478 pkgCache::VerIterator
pkgDepCache::Policy::GetCandidateVer(PkgIterator
const &Pkg
)
1480 /* Not source/not automatic versions cannot be a candidate version
1481 unless they are already installed */
1482 VerIterator
Last(*(pkgCache
*)this,0);
1484 for (VerIterator I
= Pkg
.VersionList(); I
.end() == false; ++I
)
1486 if (Pkg
.CurrentVer() == I
)
1489 for (VerFileIterator J
= I
.FileList(); J
.end() == false; ++J
)
1491 if ((J
.File()->Flags
& Flag::NotSource
) != 0)
1494 /* Stash the highest version of a not-automatic source, we use it
1495 if there is nothing better */
1496 if ((J
.File()->Flags
& Flag::NotAutomatic
) != 0 ||
1497 (J
.File()->Flags
& Flag::ButAutomaticUpgrades
) != 0)
1499 if (Last
.end() == true)
1511 // Policy::IsImportantDep - True if the dependency is important /*{{{*/
1512 // ---------------------------------------------------------------------
1514 bool pkgDepCache::Policy::IsImportantDep(DepIterator
const &Dep
)
1516 if(Dep
.IsCritical())
1518 else if(Dep
->Type
== pkgCache::Dep::Recommends
)
1520 if (InstallRecommends
)
1522 // we suport a special mode to only install-recommends for certain
1524 // FIXME: this is a meant as a temporarly solution until the
1525 // recommends are cleaned up
1526 const char *sec
= Dep
.ParentVer().Section();
1527 if (sec
&& ConfigValueInSubTree("APT::Install-Recommends-Sections", sec
))
1530 else if(Dep
->Type
== pkgCache::Dep::Suggests
)
1531 return InstallSuggests
;
1536 // Policy::GetPriority - Get the priority of the package pin /*{{{*/
1537 signed short pkgDepCache::Policy::GetPriority(pkgCache::PkgIterator
const &Pkg
)
1539 signed short pkgDepCache::Policy::GetPriority(pkgCache::PkgFileIterator
const &File
)
1542 pkgDepCache::InRootSetFunc
*pkgDepCache::GetRootSetFunc() /*{{{*/
1544 DefaultRootSetFunc
*f
= new DefaultRootSetFunc
;
1545 if(f
->wasConstructedSuccessfully())
1554 bool pkgDepCache::MarkFollowsRecommends()
1556 return _config
->FindB("APT::AutoRemove::RecommendsImportant", true);
1559 bool pkgDepCache::MarkFollowsSuggests()
1561 return _config
->FindB("APT::AutoRemove::SuggestsImportant", true);
1564 // pkgDepCache::MarkRequired - the main mark algorithm /*{{{*/
1565 bool pkgDepCache::MarkRequired(InRootSetFunc
&userFunc
)
1567 if (_config
->Find("APT::Solver", "internal") != "internal")
1570 bool follow_recommends
;
1571 bool follow_suggests
;
1572 bool debug_autoremove
= _config
->FindB("Debug::pkgAutoRemove",false);
1575 for(PkgIterator p
= PkgBegin(); !p
.end(); ++p
)
1577 PkgState
[p
->ID
].Marked
= false;
1578 PkgState
[p
->ID
].Garbage
= false;
1581 if(debug_autoremove
&& PkgState
[p
->ID
].Flags
& Flag::Auto
)
1582 std::clog
<< "AutoDep: " << p
.FullName() << std::endl
;
1586 follow_recommends
= MarkFollowsRecommends();
1587 follow_suggests
= MarkFollowsSuggests();
1591 // do the mark part, this is the core bit of the algorithm
1592 for(PkgIterator p
= PkgBegin(); !p
.end(); ++p
)
1594 if(!(PkgState
[p
->ID
].Flags
& Flag::Auto
) ||
1595 (p
->Flags
& Flag::Essential
) ||
1596 userFunc
.InRootSet(p
) ||
1597 // be nice even then a required package violates the policy (#583517)
1598 // and do the full mark process also for required packages
1599 (p
.CurrentVer().end() != true &&
1600 p
.CurrentVer()->Priority
== pkgCache::State::Required
))
1602 // the package is installed (and set to keep)
1603 if(PkgState
[p
->ID
].Keep() && !p
.CurrentVer().end())
1604 MarkPackage(p
, p
.CurrentVer(),
1605 follow_recommends
, follow_suggests
);
1606 // the package is to be installed
1607 else if(PkgState
[p
->ID
].Install())
1608 MarkPackage(p
, PkgState
[p
->ID
].InstVerIter(*this),
1609 follow_recommends
, follow_suggests
);
1616 // MarkPackage - mark a single package in Mark-and-Sweep /*{{{*/
1617 void pkgDepCache::MarkPackage(const pkgCache::PkgIterator
&pkg
,
1618 const pkgCache::VerIterator
&ver
,
1619 bool const &follow_recommends
,
1620 bool const &follow_suggests
)
1622 pkgDepCache::StateCache
&state
= PkgState
[pkg
->ID
];
1624 // if we are marked already we are done
1628 VerIterator
const currver
= pkg
.CurrentVer();
1629 VerIterator
const instver
= state
.InstVerIter(*this);
1632 VerIterator
const candver
= state
.CandidateVerIter(*this);
1634 // If a package was garbage-collected but is now being marked, we
1635 // should re-select it
1636 // For cases when a pkg is set to upgrade and this trigger the
1637 // removal of a no-longer used dependency. if the pkg is set to
1638 // keep again later it will result in broken deps
1639 if(state
.Delete() && state
.RemoveReason
= Unused
)
1642 mark_install(pkg
, false, false, NULL
);
1643 else if(ver
==pkg
.CurrentVer())
1644 MarkKeep(pkg
, false, false);
1646 instver
=state
.InstVerIter(*this);
1650 // For packages that are not going to be removed, ignore versions
1651 // other than the InstVer. For packages that are going to be
1652 // removed, ignore versions other than the current version.
1653 if(!(ver
== instver
&& !instver
.end()) &&
1654 !(ver
== currver
&& instver
.end() && !ver
.end()))
1657 bool const debug_autoremove
= _config
->FindB("Debug::pkgAutoRemove", false);
1659 if(debug_autoremove
)
1661 std::clog
<< "Marking: " << pkg
.FullName();
1663 std::clog
<< " " << ver
.VerStr();
1665 std::clog
<< ", Curr=" << currver
.VerStr();
1667 std::clog
<< ", Inst=" << instver
.VerStr();
1668 std::clog
<< std::endl
;
1673 if(ver
.end() == true)
1676 for(DepIterator d
= ver
.DependsList(); !d
.end(); ++d
)
1678 if(d
->Type
== Dep::Depends
||
1679 d
->Type
== Dep::PreDepends
||
1680 (follow_recommends
&&
1681 d
->Type
== Dep::Recommends
) ||
1683 d
->Type
== Dep::Suggests
))
1685 // Try all versions of this package.
1686 for(VerIterator V
= d
.TargetPkg().VersionList();
1689 if(_system
->VS
->CheckDep(V
.VerStr(), d
->CompareOp
, d
.TargetVer()))
1691 if(debug_autoremove
)
1693 std::clog
<< "Following dep: " << d
.ParentPkg().FullName()
1694 << " " << d
.ParentVer().VerStr() << " "
1695 << d
.DepType() << " " << d
.TargetPkg().FullName();
1696 if((d
->CompareOp
& ~pkgCache::Dep::Or
) != pkgCache::Dep::NoOp
)
1698 std::clog
<< " (" << d
.CompType() << " "
1699 << d
.TargetVer() << ")";
1701 std::clog
<< std::endl
;
1703 MarkPackage(V
.ParentPkg(), V
,
1704 follow_recommends
, follow_suggests
);
1707 // Now try virtual packages
1708 for(PrvIterator prv
=d
.TargetPkg().ProvidesList();
1711 if(_system
->VS
->CheckDep(prv
.ProvideVersion(), d
->CompareOp
,
1714 if(debug_autoremove
)
1716 std::clog
<< "Following dep: " << d
.ParentPkg().FullName() << " "
1717 << d
.ParentVer().VerStr() << " "
1718 << d
.DepType() << " " << d
.TargetPkg().FullName() << " ";
1719 if((d
->CompareOp
& ~pkgCache::Dep::Or
) != pkgCache::Dep::NoOp
)
1721 std::clog
<< " (" << d
.CompType() << " "
1722 << d
.TargetVer() << ")";
1724 std::clog
<< ", provided by "
1725 << prv
.OwnerPkg().FullName() << " "
1726 << prv
.OwnerVer().VerStr()
1730 MarkPackage(prv
.OwnerPkg(), prv
.OwnerVer(),
1731 follow_recommends
, follow_suggests
);
1738 bool pkgDepCache::Sweep() /*{{{*/
1740 bool debug_autoremove
= _config
->FindB("Debug::pkgAutoRemove",false);
1743 for(PkgIterator p
=PkgBegin(); !p
.end(); ++p
)
1745 StateCache
&state
=PkgState
[p
->ID
];
1747 // skip required packages
1748 if (!p
.CurrentVer().end() &&
1749 (p
.CurrentVer()->Priority
== pkgCache::State::Required
))
1752 // if it is not marked and it is installed, it's garbage
1753 if(!state
.Marked
&& (!p
.CurrentVer().end() || state
.Install()))
1756 if(debug_autoremove
)
1757 std::clog
<< "Garbage: " << p
.FullName() << std::endl
;