merge with my debian-sid branch
[ntk/apt.git] / apt-pkg / depcache.cc
CommitLineData
6c139d6e
AL
1// -*- mode: cpp; mode: fold -*-
2// Description /*{{{*/
e7b470ee 3// $Id: depcache.cc,v 1.25 2001/05/27 05:36:04 jgg Exp $
6c139d6e
AL
4/* ######################################################################
5
6 Dependency Cache - Caches Dependency information.
7
8 ##################################################################### */
9 /*}}}*/
10// Include Files /*{{{*/
ea542140
DK
11#include<config.h>
12
094a497d 13#include <apt-pkg/depcache.h>
094a497d 14#include <apt-pkg/version.h>
2c085486 15#include <apt-pkg/versionmatch.h>
094a497d 16#include <apt-pkg/error.h>
b2e465d6
AL
17#include <apt-pkg/sptr.h>
18#include <apt-pkg/algorithms.h>
afb1e2e3 19#include <apt-pkg/fileutl.h>
fa3b0945 20#include <apt-pkg/strutl.h>
afb1e2e3 21#include <apt-pkg/configuration.h>
8b32e920 22#include <apt-pkg/aptconfiguration.h>
74a05226 23#include <apt-pkg/pkgsystem.h>
afb1e2e3 24#include <apt-pkg/tagfile.h>
472ff00e 25#include <apt-pkg/progress.h>
120365ce
MV
26
27#include <iostream>
ea542140 28#include <sstream>
b1a8717a 29#include <set>
d4c5f11f 30
8a3a2e99
MV
31#include <sys/stat.h>
32
ea542140 33#include <apti18n.h>
92fcbfc1 34 /*}}}*/
8f3ba4e8
DK
35
36using std::string;
37
92fcbfc1 38// helper for Install-Recommends-Sections and Never-MarkAuto-Sections /*{{{*/
cb1933df
MV
39static bool
40ConfigValueInSubTree(const char* SubTree, const char *needle)
41{
42 Configuration::Item const *Opts;
43 Opts = _config->Tree(SubTree);
44 if (Opts != 0 && Opts->Child != 0)
45 {
46 Opts = Opts->Child;
47 for (; Opts != 0; Opts = Opts->Next)
48 {
49 if (Opts->Value.empty() == true)
50 continue;
51 if (strcmp(needle, Opts->Value.c_str()) == 0)
52 return true;
53 }
54 }
55 return false;
56}
92fcbfc1
DK
57 /*}}}*/
58pkgDepCache::ActionGroup::ActionGroup(pkgDepCache &cache) : /*{{{*/
74a05226
MV
59 cache(cache), released(false)
60{
61 ++cache.group_level;
62}
63
64void pkgDepCache::ActionGroup::release()
65{
66 if(!released)
67 {
68 if(cache.group_level == 0)
69 std::cerr << "W: Unbalanced action groups, expect badness" << std::endl;
70 else
71 {
72 --cache.group_level;
73
74 if(cache.group_level == 0)
75 cache.MarkAndSweep();
76 }
77
ab60fb67 78 released = true;
74a05226
MV
79 }
80}
81
82pkgDepCache::ActionGroup::~ActionGroup()
83{
84 release();
85}
92fcbfc1 86 /*}}}*/
6c139d6e
AL
87// DepCache::pkgDepCache - Constructors /*{{{*/
88// ---------------------------------------------------------------------
89/* */
b2e465d6 90pkgDepCache::pkgDepCache(pkgCache *pCache,Policy *Plcy) :
74a05226 91 group_level(0), Cache(pCache), PkgState(0), DepState(0)
6c139d6e 92{
af29ffb4
MV
93 DebugMarker = _config->FindB("Debug::pkgDepCache::Marker", false);
94 DebugAutoInstall = _config->FindB("Debug::pkgDepCache::AutoInstall", false);
b2e465d6
AL
95 delLocalPolicy = 0;
96 LocalPolicy = Plcy;
97 if (LocalPolicy == 0)
98 delLocalPolicy = LocalPolicy = new Policy;
6c139d6e
AL
99}
100 /*}}}*/
101// DepCache::~pkgDepCache - Destructor /*{{{*/
102// ---------------------------------------------------------------------
103/* */
104pkgDepCache::~pkgDepCache()
105{
106 delete [] PkgState;
107 delete [] DepState;
b2e465d6 108 delete delLocalPolicy;
6c139d6e
AL
109}
110 /*}}}*/
6c139d6e
AL
111// DepCache::Init - Generate the initial extra structures. /*{{{*/
112// ---------------------------------------------------------------------
113/* This allocats the extension buffers and initializes them. */
a246f2dc 114bool pkgDepCache::Init(OpProgress *Prog)
6c139d6e 115{
74a05226
MV
116 // Suppress mark updates during this operation (just in case) and
117 // run a mark operation when Init terminates.
118 ActionGroup actions(*this);
119
6c139d6e
AL
120 delete [] PkgState;
121 delete [] DepState;
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);
b2e465d6 126
a246f2dc
AL
127 if (Prog != 0)
128 {
129 Prog->OverallProgress(0,2*Head().PackageCount,Head().PackageCount,
db0db9fe
CP
130 _("Building dependency tree"));
131 Prog->SubProgress(Head().PackageCount,_("Candidate versions"));
a246f2dc
AL
132 }
133
6c139d6e
AL
134 /* Set the current state of everything. In this state all of the
135 packages are kept exactly as is. See AllUpgrade */
a246f2dc 136 int Done = 0;
f7f0d6c7 137 for (PkgIterator I = PkgBegin(); I.end() != true; ++I, ++Done)
6c139d6e 138 {
2edcefd5 139 if (Prog != 0 && Done%20 == 0)
a246f2dc
AL
140 Prog->Progress(Done);
141
6c139d6e
AL
142 // Find the proper cache slot
143 StateCache &State = PkgState[I->ID];
144 State.iFlags = 0;
afb1e2e3 145
6c139d6e
AL
146 // Figure out the install version
147 State.CandidateVer = GetCandidateVer(I);
148 State.InstallVer = I.CurrentVer();
149 State.Mode = ModeKeep;
150
151 State.Update(I,*this);
152 }
153
a246f2dc
AL
154 if (Prog != 0)
155 {
156
157 Prog->OverallProgress(Head().PackageCount,2*Head().PackageCount,
158 Head().PackageCount,
db0db9fe
CP
159 _("Building dependency tree"));
160 Prog->SubProgress(Head().PackageCount,_("Dependency generation"));
a246f2dc
AL
161 }
162
163 Update(Prog);
e004867d
MV
164
165 if(Prog != 0)
166 Prog->Done();
74a05226 167
6c139d6e
AL
168 return true;
169}
170 /*}}}*/
92fcbfc1 171bool pkgDepCache::readStateFile(OpProgress *Prog) /*{{{*/
a83d884d
MV
172{
173 FileFd state_file;
d34690e1 174 string const state = _config->FindFile("Dir::State::extended_states");
36f1098a 175 if(RealFileExists(state)) {
a83d884d 176 state_file.Open(state, FileFd::ReadOnly);
650faab0 177 off_t const file_size = state_file.Size();
bc80031f
MV
178 if(Prog != NULL)
179 Prog->OverallProgress(0, file_size, 1,
180 _("Reading state information"));
a83d884d
MV
181
182 pkgTagFile tagfile(&state_file);
183 pkgTagSection section;
650faab0 184 off_t amt = 0;
e0b94b97 185 bool const debug_autoremove = _config->FindB("Debug::pkgAutoRemove",false);
a83d884d 186 while(tagfile.Step(section)) {
e0b94b97
DK
187 string const pkgname = section.FindS("Package");
188 string pkgarch = section.FindS("Architecture");
189 if (pkgarch.empty() == true)
190 pkgarch = "any";
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)
194 continue;
195
196 short const reason = section.FindI("Auto-Installed", 0);
197 if(reason > 0)
198 {
199 PkgState[pkg->ID].Flags |= Flag::Auto;
200 if (unlikely(debug_autoremove))
6ee2b0f8 201 std::clog << "Auto-Installed : " << pkg.FullName() << std::endl;
e0b94b97
DK
202 if (pkgarch == "any")
203 {
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;
208 }
a83d884d 209 }
e0b94b97
DK
210 amt += section.size();
211 if(Prog != NULL)
212 Prog->OverallProgress(amt, file_size, 1,
213 _("Reading state information"));
a83d884d 214 }
eef21b9f
DK
215 if(Prog != NULL)
216 Prog->OverallProgress(file_size, file_size, 1,
217 _("Reading state information"));
a83d884d
MV
218 }
219
220 return true;
221}
92fcbfc1
DK
222 /*}}}*/
223bool pkgDepCache::writeStateFile(OpProgress *prog, bool InstalledOnly) /*{{{*/
a83d884d 224{
e0b94b97 225 bool const debug_autoremove = _config->FindB("Debug::pkgAutoRemove",false);
95afdfd0
OS
226
227 if(debug_autoremove)
e23e6733
MV
228 std::clog << "pkgDepCache::writeStateFile()" << std::endl;
229
b1a8717a 230 FileFd StateFile;
d34690e1 231 string const state = _config->FindFile("Dir::State::extended_states");
9a9665f9
MV
232
233 // if it does not exist, create a empty one
36f1098a 234 if(!RealFileExists(state))
9a9665f9 235 {
22041bd2 236 StateFile.Open(state, FileFd::WriteAtomic);
9a9665f9
MV
237 StateFile.Close();
238 }
239
240 // open it
b1a8717a
MV
241 if(!StateFile.Open(state, FileFd::ReadOnly))
242 return _error->Error(_("Failed to open StateFile %s"),
a83d884d
MV
243 state.c_str());
244
b1a8717a 245 FILE *OutFile;
e0b94b97 246 string const outfile = state + ".tmp";
b1a8717a
MV
247 if((OutFile = fopen(outfile.c_str(),"w")) == NULL)
248 return _error->Error(_("Failed to write temporary StateFile %s"),
249 outfile.c_str());
80fa0d8a 250
b1a8717a
MV
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)) {
c176c4d0 257 string const pkgname = section.FindS("Package");
e0b94b97
DK
258 string pkgarch = section.FindS("Architecture");
259 if (pkgarch.empty() == true)
260 pkgarch = "native";
b1a8717a
MV
261 // Silently ignore unknown packages and packages with no actual
262 // version.
e0b94b97 263 pkgCache::PkgIterator pkg = Cache->FindPkg(pkgname, pkgarch);
b1a8717a
MV
264 if(pkg.end() || pkg.VersionList().end())
265 continue;
c176c4d0
DK
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)))
272 {
273 // The section is obsolete if it contains no other tag
274 unsigned int const count = section.Count();
275 if (count < 2 ||
c67dc114
DK
276 (count == 2 && section.Exists("Auto-Installed")) ||
277 (count == 3 && section.Exists("Auto-Installed") && section.Exists("Architecture")))
c176c4d0
DK
278 continue;
279 else
280 newAuto = false;
281 }
b1a8717a 282 if(_config->FindB("Debug::pkgAutoRemove",false))
a1e42d1f 283 std::clog << "Update existing AutoInstall info: "
e0b94b97
DK
284 << pkg.FullName() << std::endl;
285 TFRewriteData rewrite[3];
286 rewrite[0].Tag = "Architecture";
287 rewrite[0].Rewrite = pkg.Arch();
b1a8717a 288 rewrite[0].NewTag = 0;
e0b94b97
DK
289 rewrite[1].Tag = "Auto-Installed";
290 rewrite[1].Rewrite = newAuto ? "1" : "0";
291 rewrite[1].NewTag = 0;
292 rewrite[2].Tag = 0;
b1a8717a
MV
293 TFRewrite(OutFile, section, nullreorderlist, rewrite);
294 fprintf(OutFile,"\n");
e0b94b97 295 pkgs_seen.insert(pkg.FullName());
b1a8717a
MV
296 }
297
298 // then write the ones we have not seen yet
299 std::ostringstream ostr;
f7f0d6c7 300 for(pkgCache::PkgIterator pkg=Cache->PkgBegin(); !pkg.end(); ++pkg) {
c176c4d0
DK
301 StateCache const &P = PkgState[pkg->ID];
302 if(P.Flags & Flag::Auto) {
e0b94b97 303 if (pkgs_seen.find(pkg.FullName()) != pkgs_seen.end()) {
95afdfd0 304 if(debug_autoremove)
e0b94b97 305 std::clog << "Skipping already written " << pkg.FullName() << std::endl;
b1a8717a
MV
306 continue;
307 }
c176c4d0
DK
308 // skip not installed ones if requested
309 if (InstalledOnly && (
310 (pkg->CurrentVer == 0 && P.Mode != ModeInstall) ||
311 (pkg->CurrentVer != 0 && P.Mode == ModeDelete)))
312 continue;
e0b94b97
DK
313 const char* const pkgarch = pkg.Arch();
314 if (strcmp(pkgarch, "all") == 0)
315 continue;
95afdfd0 316 if(debug_autoremove)
e0b94b97 317 std::clog << "Writing new AutoInstall: " << pkg.FullName() << std::endl;
a83d884d 318 ostr.str(string(""));
e0b94b97
DK
319 ostr << "Package: " << pkg.Name()
320 << "\nArchitecture: " << pkgarch
fc5aece9 321 << "\nAuto-Installed: 1\n\n";
3c8cda8b 322 fprintf(OutFile,"%s",ostr.str().c_str());
a83d884d
MV
323 }
324 }
a4decc40 325 fclose(OutFile);
b1a8717a 326
8a3a2e99 327 // move the outfile over the real file and set permissions
b1a8717a 328 rename(outfile.c_str(), state.c_str());
8a3a2e99 329 chmod(state.c_str(), 0644);
b1a8717a 330
a83d884d
MV
331 return true;
332}
92fcbfc1 333 /*}}}*/
6c139d6e
AL
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. */
340bool pkgDepCache::CheckDep(DepIterator Dep,int Type,PkgIterator &Res)
341{
342 Res = Dep.TargetPkg();
343
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 */
359e46db 347 if (Dep.TargetPkg() != Dep.ParentPkg() || Dep.IsNegative() == false)
6c139d6e
AL
348 {
349 PkgIterator Pkg = Dep.TargetPkg();
350 // Check the base package
351 if (Type == NowVersion && Pkg->CurrentVer != 0)
b2e465d6
AL
352 if (VS().CheckDep(Pkg.CurrentVer().VerStr(),Dep->CompareOp,
353 Dep.TargetVer()) == true)
6c139d6e
AL
354 return true;
355
356 if (Type == InstallVersion && PkgState[Pkg->ID].InstallVer != 0)
b2e465d6
AL
357 if (VS().CheckDep(PkgState[Pkg->ID].InstVerIter(*this).VerStr(),
358 Dep->CompareOp,Dep.TargetVer()) == true)
6c139d6e
AL
359 return true;
360
361 if (Type == CandidateVersion && PkgState[Pkg->ID].CandidateVer != 0)
b2e465d6
AL
362 if (VS().CheckDep(PkgState[Pkg->ID].CandidateVerIter(*this).VerStr(),
363 Dep->CompareOp,Dep.TargetVer()) == true)
6c139d6e
AL
364 return true;
365 }
366
b2e465d6
AL
367 if (Dep->Type == Dep::Obsoletes)
368 return false;
369
6c139d6e
AL
370 // Check the providing packages
371 PrvIterator P = Dep.TargetPkg().ProvidesList();
372 PkgIterator Pkg = Dep.ParentPkg();
f7f0d6c7 373 for (; P.end() != true; ++P)
6c139d6e 374 {
d3814b27
DK
375 /* Provides may never be applied against the same package (or group)
376 if it is a conflicts. See the comment above. */
359e46db 377 if (P.OwnerPkg()->Group == Pkg->Group && Dep.IsNegative() == true)
6c139d6e
AL
378 continue;
379
380 // Check if the provides is a hit
381 if (Type == NowVersion)
382 {
383 if (P.OwnerPkg().CurrentVer() != P.OwnerVer())
384 continue;
385 }
386
387 if (Type == InstallVersion)
388 {
389 StateCache &State = PkgState[P.OwnerPkg()->ID];
390 if (State.InstallVer != (Version *)P.OwnerVer())
391 continue;
392 }
393
394 if (Type == CandidateVersion)
395 {
396 StateCache &State = PkgState[P.OwnerPkg()->ID];
397 if (State.CandidateVer != (Version *)P.OwnerVer())
398 continue;
399 }
400
401 // Compare the versions.
b2e465d6 402 if (VS().CheckDep(P.ProvideVersion(),Dep->CompareOp,Dep.TargetVer()) == true)
6c139d6e
AL
403 {
404 Res = P.OwnerPkg();
405 return true;
406 }
407 }
408
409 return false;
410}
411 /*}}}*/
412// DepCache::AddSizes - Add the packages sizes to the counters /*{{{*/
413// ---------------------------------------------------------------------
81305a0b 414/* Call with Inverse = true to preform the inverse opration */
6935cd05 415void pkgDepCache::AddSizes(const PkgIterator &Pkg, bool const Inverse)
81305a0b
DK
416{
417 StateCache &P = PkgState[Pkg->ID];
418
419 if (Pkg->VersionList == 0)
420 return;
421
422 if (Pkg.State() == pkgCache::PkgIterator::NeedsConfigure &&
423 P.Keep() == true)
424 return;
425
426 // Compute the size data
427 if (P.NewInstall() == true)
428 {
429 if (Inverse == false) {
430 iUsrSize += P.InstVerIter(*this)->InstalledSize;
431 iDownloadSize += P.InstVerIter(*this)->Size;
432 } else {
433 iUsrSize -= P.InstVerIter(*this)->InstalledSize;
434 iDownloadSize -= P.InstVerIter(*this)->Size;
435 }
436 return;
437 }
438
439 // Upgrading
440 if (Pkg->CurrentVer != 0 &&
441 (P.InstallVer != (Version *)Pkg.CurrentVer() ||
442 (P.iFlags & ReInstall) == ReInstall) && P.InstallVer != 0)
443 {
444 if (Inverse == false) {
445 iUsrSize -= Pkg.CurrentVer()->InstalledSize;
446 iUsrSize += P.InstVerIter(*this)->InstalledSize;
447 iDownloadSize += P.InstVerIter(*this)->Size;
448 } else {
449 iUsrSize -= P.InstVerIter(*this)->InstalledSize;
450 iUsrSize += Pkg.CurrentVer()->InstalledSize;
451 iDownloadSize -= P.InstVerIter(*this)->Size;
452 }
453 return;
454 }
455
456 // Reinstall
457 if (Pkg.State() == pkgCache::PkgIterator::NeedsUnpack &&
458 P.Delete() == false)
459 {
460 if (Inverse == false)
461 iDownloadSize += P.InstVerIter(*this)->Size;
462 else
463 iDownloadSize -= P.InstVerIter(*this)->Size;
464 return;
465 }
466
467 // Removing
468 if (Pkg->CurrentVer != 0 && P.InstallVer == 0)
469 {
470 if (Inverse == false)
471 iUsrSize -= Pkg.CurrentVer()->InstalledSize;
472 else
473 iUsrSize += Pkg.CurrentVer()->InstalledSize;
d38b7b3d
AL
474 return;
475 }
6c139d6e
AL
476}
477 /*}}}*/
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 */
6935cd05 486void pkgDepCache::AddStates(const PkgIterator &Pkg, bool const Invert)
6c139d6e 487{
6935cd05 488 signed char const Add = (Invert == false) ? 1 : -1;
6c139d6e
AL
489 StateCache &State = PkgState[Pkg->ID];
490
4ef9a929 491 // The Package is broken (either minimal dep or policy dep)
6c139d6e
AL
492 if ((State.DepState & DepInstMin) != DepInstMin)
493 iBrokenCount += Add;
4ef9a929
MV
494 if ((State.DepState & DepInstPolicy) != DepInstPolicy)
495 iPolicyBrokenCount += Add;
6c139d6e
AL
496
497 // Bad state
498 if (Pkg.State() != PkgIterator::NeedsNothing)
499 iBadCount += Add;
500
501 // Not installed
502 if (Pkg->CurrentVer == 0)
503 {
949e033c
DK
504 if (State.Mode == ModeDelete &&
505 (State.iFlags & Purge) == Purge && Pkg.Purge() == false)
d556d1a1
AL
506 iDelCount += Add;
507
6c139d6e
AL
508 if (State.Mode == ModeInstall)
509 iInstCount += Add;
510 return;
511 }
512
513 // Installed, no upgrade
6321777b 514 if (State.Status == 0)
d0c59649 515 {
6c139d6e
AL
516 if (State.Mode == ModeDelete)
517 iDelCount += Add;
d0c59649
AL
518 else
519 if ((State.iFlags & ReInstall) == ReInstall)
520 iInstCount += Add;
521
6c139d6e
AL
522 return;
523 }
524
525 // Alll 3 are possible
526 if (State.Mode == ModeDelete)
527 iDelCount += Add;
528 if (State.Mode == ModeKeep)
529 iKeepCount += Add;
530 if (State.Mode == ModeInstall)
531 iInstCount += Add;
532}
533 /*}}}*/
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. */
538void pkgDepCache::BuildGroupOrs(VerIterator const &V)
539{
540 unsigned char Group = 0;
541
f7f0d6c7 542 for (DepIterator D = V.DependsList(); D.end() != true; ++D)
6c139d6e
AL
543 {
544 // Build the dependency state.
545 unsigned char &State = DepState[D->ID];
546
547 /* Invert for Conflicts. We have to do this twice to get the
548 right sense for a conflicts group */
359e46db 549 if (D.IsNegative() == true)
6c139d6e
AL
550 State = ~State;
551
552 // Add to the group if we are within an or..
d2685fd6 553 State &= 0x7;
6c139d6e
AL
554 Group |= State;
555 State |= Group << 3;
556 if ((D->CompareOp & Dep::Or) != Dep::Or)
557 Group = 0;
558
559 // Invert for Conflicts
359e46db 560 if (D.IsNegative() == true)
6c139d6e
AL
561 State = ~State;
562 }
563}
564 /*}}}*/
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. */
571unsigned char pkgDepCache::VersionState(DepIterator D,unsigned char Check,
572 unsigned char SetMin,
573 unsigned char SetPolicy)
574{
575 unsigned char Dep = 0xFF;
576
577 while (D.end() != true)
578 {
579 // Compute a single dependency element (glob or)
580 DepIterator Start = D;
581 unsigned char State = 0;
f7f0d6c7 582 for (bool LastOR = true; D.end() == false && LastOR == true; ++D)
6c139d6e
AL
583 {
584 State |= DepState[D->ID];
585 LastOR = (D->CompareOp & Dep::Or) == Dep::Or;
586 }
587
588 // Minimum deps that must be satisfied to have a working package
589 if (Start.IsCritical() == true)
590 if ((State & Check) != Check)
591 Dep &= ~SetMin;
592
593 // Policy deps that must be satisfied to install the package
594 if (IsImportantDep(Start) == true &&
595 (State & Check) != Check)
596 Dep &= ~SetPolicy;
597 }
598
599 return Dep;
600}
601 /*}}}*/
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. */
607unsigned char pkgDepCache::DependencyState(DepIterator &D)
608{
609 unsigned char State = 0;
610
611 if (CheckDep(D,NowVersion) == true)
612 State |= DepNow;
613 if (CheckDep(D,InstallVersion) == true)
614 State |= DepInstall;
615 if (CheckDep(D,CandidateVersion) == true)
616 State |= DepCVer;
617
618 return State;
619}
620 /*}}}*/
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. */
626void pkgDepCache::UpdateVerState(PkgIterator Pkg)
627{
628 // Empty deps are always true
629 StateCache &State = PkgState[Pkg->ID];
630 State.DepState = 0xFF;
631
632 // Check the Current state
633 if (Pkg->CurrentVer != 0)
634 {
635 DepIterator D = Pkg.CurrentVer().DependsList();
636 State.DepState &= VersionState(D,DepNow,DepNowMin,DepNowPolicy);
637 }
638
639 /* Check the candidate state. We do not compare against the whole as
640 a candidate state but check the candidate version against the
641 install states */
642 if (State.CandidateVer != 0)
643 {
644 DepIterator D = State.CandidateVerIter(*this).DependsList();
645 State.DepState &= VersionState(D,DepInstall,DepCandMin,DepCandPolicy);
646 }
647
648 // Check target state which can only be current or installed
649 if (State.InstallVer != 0)
650 {
651 DepIterator D = State.InstVerIter(*this).DependsList();
652 State.DepState &= VersionState(D,DepInstall,DepInstMin,DepInstPolicy);
653 }
654}
655 /*}}}*/
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. */
a246f2dc 660void pkgDepCache::Update(OpProgress *Prog)
6c139d6e
AL
661{
662 iUsrSize = 0;
663 iDownloadSize = 0;
664 iDelCount = 0;
665 iInstCount = 0;
666 iKeepCount = 0;
667 iBrokenCount = 0;
668 iBadCount = 0;
8b32e920 669
6c139d6e 670 // Perform the depends pass
a246f2dc 671 int Done = 0;
f7f0d6c7 672 for (PkgIterator I = PkgBegin(); I.end() != true; ++I, ++Done)
6c139d6e 673 {
2edcefd5 674 if (Prog != 0 && Done%20 == 0)
a246f2dc 675 Prog->Progress(Done);
f7f0d6c7 676 for (VerIterator V = I.VersionList(); V.end() != true; ++V)
6c139d6e
AL
677 {
678 unsigned char Group = 0;
8b32e920 679
f7f0d6c7 680 for (DepIterator D = V.DependsList(); D.end() != true; ++D)
6c139d6e
AL
681 {
682 // Build the dependency state.
683 unsigned char &State = DepState[D->ID];
b2e465d6 684 State = DependencyState(D);
6c139d6e
AL
685
686 // Add to the group if we are within an or..
687 Group |= State;
688 State |= Group << 3;
689 if ((D->CompareOp & Dep::Or) != Dep::Or)
690 Group = 0;
691
692 // Invert for Conflicts
359e46db 693 if (D.IsNegative() == true)
6c139d6e 694 State = ~State;
8b32e920 695 }
6c139d6e
AL
696 }
697
8b32e920 698 // Compute the package dependency state and size additions
6c139d6e
AL
699 AddSizes(I);
700 UpdateVerState(I);
701 AddStates(I);
702 }
a246f2dc 703
8b32e920 704 if (Prog != 0)
a246f2dc 705 Prog->Progress(Done);
74a05226
MV
706
707 readStateFile(Prog);
6c139d6e
AL
708}
709 /*}}}*/
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.
74a05226 713 It is mainly meant to scan reverse dependencies. */
6c139d6e
AL
714void pkgDepCache::Update(DepIterator D)
715{
716 // Update the reverse deps
f7f0d6c7 717 for (;D.end() != true; ++D)
6c139d6e
AL
718 {
719 unsigned char &State = DepState[D->ID];
720 State = DependencyState(D);
721
722 // Invert for Conflicts
359e46db 723 if (D.IsNegative() == true)
6c139d6e 724 State = ~State;
b2e465d6 725
6c139d6e
AL
726 RemoveStates(D.ParentPkg());
727 BuildGroupOrs(D.ParentVer());
728 UpdateVerState(D.ParentPkg());
729 AddStates(D.ParentPkg());
730 }
731}
732 /*}}}*/
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. */
737void pkgDepCache::Update(PkgIterator const &Pkg)
b2e465d6 738{
6c139d6e
AL
739 // Recompute the dep of the package
740 RemoveStates(Pkg);
741 UpdateVerState(Pkg);
742 AddStates(Pkg);
743
744 // Update the reverse deps
745 Update(Pkg.RevDependsList());
746
747 // Update the provides map for the current ver
748 if (Pkg->CurrentVer != 0)
749 for (PrvIterator P = Pkg.CurrentVer().ProvidesList();
f7f0d6c7 750 P.end() != true; ++P)
6c139d6e
AL
751 Update(P.ParentPkg().RevDependsList());
752
753 // Update the provides map for the candidate ver
9972233d
AL
754 if (PkgState[Pkg->ID].CandidateVer != 0)
755 for (PrvIterator P = PkgState[Pkg->ID].CandidateVerIter(*this).ProvidesList();
f7f0d6c7 756 P.end() != true; ++P)
9972233d 757 Update(P.ParentPkg().RevDependsList());
6c139d6e 758}
6c139d6e 759 /*}}}*/
6c139d6e
AL
760// DepCache::MarkKeep - Put the package in the keep state /*{{{*/
761// ---------------------------------------------------------------------
762/* */
3d619a20 763bool pkgDepCache::MarkKeep(PkgIterator const &Pkg, bool Soft, bool FromUser,
af29ffb4 764 unsigned long Depth)
6c139d6e 765{
dde0c674 766 if (IsModeChangeOk(ModeKeep, Pkg, Depth, FromUser) == false)
3d619a20 767 return false;
813c8eea
AL
768
769 /* Reject an attempt to keep a non-source broken installed package, those
770 must be upgraded */
771 if (Pkg.State() == PkgIterator::NeedsUnpack &&
772 Pkg.CurrentVer().Downloadable() == false)
3d619a20 773 return false;
74a05226 774
6c139d6e
AL
775 /* We changed the soft state all the time so the UI is a bit nicer
776 to use */
777 StateCache &P = PkgState[Pkg->ID];
dde0c674
DK
778
779 // Check that it is not already kept
780 if (P.Mode == ModeKeep)
3d619a20 781 return true;
dde0c674 782
6c139d6e
AL
783 if (Soft == true)
784 P.iFlags |= AutoKept;
785 else
786 P.iFlags &= ~AutoKept;
6c139d6e 787
dde0c674
DK
788 ActionGroup group(*this);
789
32085498
MV
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
74a05226
MV
797 if(FromUser && !P.Marked)
798 P.Flags &= ~Flag::Auto;
32085498
MV
799#endif
800
af29ffb4 801 if (DebugMarker == true)
c3a85f49 802 std::clog << OutputInDepth(Depth) << "MarkKeep " << Pkg << " FU=" << FromUser << std::endl;
af29ffb4 803
6c139d6e
AL
804 RemoveSizes(Pkg);
805 RemoveStates(Pkg);
806
807 P.Mode = ModeKeep;
808 if (Pkg->CurrentVer == 0)
809 P.InstallVer = 0;
810 else
811 P.InstallVer = Pkg.CurrentVer();
812
813 AddStates(Pkg);
6c139d6e 814 Update(Pkg);
6c139d6e 815 AddSizes(Pkg);
3d619a20
DK
816
817 return true;
6c139d6e
AL
818}
819 /*}}}*/
820// DepCache::MarkDelete - Put the package in the delete state /*{{{*/
821// ---------------------------------------------------------------------
822/* */
3d619a20 823bool pkgDepCache::MarkDelete(PkgIterator const &Pkg, bool rPurge,
6910a2ac 824 unsigned long Depth, bool FromUser)
6c139d6e 825{
dde0c674 826 if (IsModeChangeOk(ModeDelete, Pkg, Depth, FromUser) == false)
3d619a20 827 return false;
6c139d6e 828
dde0c674 829 StateCache &P = PkgState[Pkg->ID];
74a05226 830
6c139d6e 831 // Check that it is not already marked for delete
d556d1a1
AL
832 if ((P.Mode == ModeDelete || P.InstallVer == 0) &&
833 (Pkg.Purge() == true || rPurge == false))
3d619a20 834 return true;
6c139d6e 835
dde0c674 836 // check if we are allowed to remove the package
6910a2ac 837 if (IsDeleteOk(Pkg,rPurge,Depth,FromUser) == false)
3d619a20 838 return false;
6910a2ac 839
dde0c674
DK
840 P.iFlags &= ~(AutoKept | Purge);
841 if (rPurge == true)
842 P.iFlags |= Purge;
843
844 ActionGroup group(*this);
845
af29ffb4 846 if (DebugMarker == true)
35db2f35 847 std::clog << OutputInDepth(Depth) << (rPurge ? "MarkPurge " : "MarkDelete ") << Pkg << " FU=" << FromUser << std::endl;
af29ffb4 848
6c139d6e
AL
849 RemoveSizes(Pkg);
850 RemoveStates(Pkg);
851
d556d1a1 852 if (Pkg->CurrentVer == 0 && (Pkg.Purge() == true || rPurge == false))
3d615484
AL
853 P.Mode = ModeKeep;
854 else
855 P.Mode = ModeDelete;
6c139d6e 856 P.InstallVer = 0;
6c139d6e
AL
857
858 AddStates(Pkg);
859 Update(Pkg);
860 AddSizes(Pkg);
803ea2a8 861
3d619a20 862 return true;
6c139d6e
AL
863}
864 /*}}}*/
6910a2ac
DK
865// DepCache::IsDeleteOk - check if it is ok to remove this package /*{{{*/
866// ---------------------------------------------------------------------
dde0c674
DK
867/* The default implementation tries to prevent deletion of install requests.
868 dpkg holds are enforced by the private IsModeChangeOk */
6910a2ac
DK
869bool pkgDepCache::IsDeleteOk(PkgIterator const &Pkg,bool rPurge,
870 unsigned long Depth, bool FromUser)
871{
dde0c674 872 if (FromUser == false && Pkg->CurrentVer == 0)
0c6aa02e
DK
873 {
874 StateCache &P = PkgState[Pkg->ID];
875 if (P.InstallVer != 0 && P.Status == 2 && (P.Flags & Flag::Auto) != Flag::Auto)
876 {
877 if (DebugMarker == true)
878 std::clog << OutputInDepth(Depth) << "Manual install request prevents MarkDelete of " << Pkg << std::endl;
879 return false;
880 }
881 }
dde0c674
DK
882 return true;
883}
884 /*}}}*/
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 */
891char const* PrintMode(char const mode)
892{
893 switch (mode)
894 {
895 case pkgDepCache::ModeInstall: return "Install";
896 case pkgDepCache::ModeKeep: return "Keep";
897 case pkgDepCache::ModeDelete: return "Delete";
898 default: return "UNKNOWN";
899 }
900}
901bool pkgDepCache::IsModeChangeOk(ModeList const mode, PkgIterator const &Pkg,
902 unsigned long const Depth, bool const FromUser)
903{
904 // we are not trying to hard…
905 if (unlikely(Depth > 100))
906 return false;
907
908 // general sanity
909 if (unlikely(Pkg.end() == true || Pkg->VersionList == 0))
910 return false;
911
cc26da01
DK
912 // the user is always right
913 if (FromUser == true)
914 return true;
915
916 StateCache &P = PkgState[Pkg->ID];
917
918 // if previous state was set by user only user can reset it
919 if ((P.iFlags & Protected) == Protected)
920 {
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;
925 return false;
926 }
dde0c674 927 // enforce dpkg holds
cc26da01 928 else if (mode != ModeKeep && Pkg->SelectedState == pkgCache::State::Hold &&
dde0c674
DK
929 _config->FindB("APT::Ignore-Hold",false) == false)
930 {
cc26da01 931 if (unlikely(DebugMarker == true) && P.Mode != mode)
dde0c674
DK
932 std::clog << OutputInDepth(Depth) << "Hold prevents Mark" << PrintMode(mode)
933 << " of " << Pkg << std::endl;
934 return false;
935 }
936
6910a2ac
DK
937 return true;
938}
939 /*}}}*/
6c139d6e
AL
940// DepCache::MarkInstall - Put the package in the install state /*{{{*/
941// ---------------------------------------------------------------------
942/* */
3d619a20 943bool pkgDepCache::MarkInstall(PkgIterator const &Pkg,bool AutoInst,
7610bb3d
MV
944 unsigned long Depth, bool FromUser,
945 bool ForceImportantDeps)
b2e465d6 946{
dde0c674 947 if (IsModeChangeOk(ModeInstall, Pkg, Depth, FromUser) == false)
3d619a20 948 return false;
dde0c674
DK
949
950 StateCache &P = PkgState[Pkg->ID];
951
952 // See if there is even any possible instalation candidate
953 if (P.CandidateVer == 0)
3d619a20 954 return false;
74a05226 955
6c139d6e
AL
956 /* Check that it is not already marked for install and that it can be
957 installed */
60681f93
MV
958 if ((P.InstPolicyBroken() == false && P.InstBroken() == false) &&
959 (P.Mode == ModeInstall ||
6c139d6e
AL
960 P.CandidateVer == (Version *)Pkg.CurrentVer()))
961 {
962 if (P.CandidateVer == (Version *)Pkg.CurrentVer() && P.InstallVer == 0)
3d619a20
DK
963 return MarkKeep(Pkg, false, FromUser, Depth+1);
964 return true;
6c139d6e 965 }
b2e465d6 966
6910a2ac
DK
967 // check if we are allowed to install the package
968 if (IsInstallOk(Pkg,AutoInst,Depth,FromUser) == false)
3d619a20 969 return false;
6910a2ac 970
dde0c674
DK
971 ActionGroup group(*this);
972 P.iFlags &= ~AutoKept;
973
6c139d6e
AL
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 */
977 RemoveSizes(Pkg);
978 RemoveStates(Pkg);
979
980 P.Mode = ModeInstall;
981 P.InstallVer = P.CandidateVer;
74a05226
MV
982
983 if(FromUser)
984 {
e26a777c
DK
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)))
74a05226
MV
989 P.Flags &= ~Flag::Auto;
990 }
991 else
992 {
993 // Set it to auto if this is a new install.
994 if(P.Status == 2)
995 P.Flags |= Flag::Auto;
996 }
6c139d6e
AL
997 if (P.CandidateVer == (Version *)Pkg.CurrentVer())
998 P.Mode = ModeKeep;
999
1000 AddStates(Pkg);
1001 Update(Pkg);
1002 AddSizes(Pkg);
6910a2ac 1003
98278a81 1004 if (AutoInst == false || _config->Find("APT::Solver", "internal") != "internal")
3d619a20 1005 return true;
6c139d6e 1006
af29ffb4 1007 if (DebugMarker == true)
c3a85f49 1008 std::clog << OutputInDepth(Depth) << "MarkInstall " << Pkg << " FU=" << FromUser << std::endl;
af29ffb4 1009
6c139d6e
AL
1010 DepIterator Dep = P.InstVerIter(*this).DependsList();
1011 for (; Dep.end() != true;)
1012 {
1013 // Grok or groups
1014 DepIterator Start = Dep;
1015 bool Result = true;
b2e465d6 1016 unsigned Ors = 0;
f7f0d6c7 1017 for (bool LastOR = true; Dep.end() == false && LastOR == true; ++Dep, ++Ors)
6c139d6e
AL
1018 {
1019 LastOR = (Dep->CompareOp & Dep::Or) == Dep::Or;
1020
1021 if ((DepState[Dep->ID] & DepInstall) == DepInstall)
1022 Result = false;
1023 }
1024
1025 // Dep is satisfied okay.
1026 if (Result == false)
1027 continue;
1028
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
4ef9a929
MV
1031 it will be installed. Otherwise we only check for important
1032 deps that have changed from the installed version
1033 */
6c139d6e
AL
1034 if (IsImportantDep(Start) == false)
1035 continue;
e92f6a18
DK
1036
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)
1040 ++Start;
1041 if (Ors == 1 && (DepState[Start->ID] &DepCVer) != DepCVer && Start.IsNegative() == false)
1042 {
1043 if(DebugAutoInstall == true)
1044 std::clog << OutputInDepth(Depth) << Start << " can't be satisfied!" << std::endl;
1045 if (Start.IsCritical() == false)
1046 continue;
1047 // if the dependency was critical, we can't install it, so remove it again
1048 MarkDelete(Pkg,false,Depth + 1, false);
3d619a20 1049 return false;
e92f6a18
DK
1050 }
1051
0526822a
DB
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)
1b1c2224 1058 */
6ed08516 1059 if (Pkg->CurrentVer != 0 && ForceImportantDeps == false && Start.IsCritical() == false)
1b1c2224 1060 {
6ed08516
DK
1061 bool isNewImportantDep = true;
1062 bool isPreviouslySatisfiedImportantDep = false;
1063 for (DepIterator D = Pkg.CurrentVer().DependsList(); D.end() != true; ++D)
1d722933 1064 {
6ed08516
DK
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())
1070 continue;
1071
1072 isNewImportantDep = false;
1073
1074 while ((D->CompareOp & Dep::Or) != 0)
1075 ++D;
1076
1077 isPreviouslySatisfiedImportantDep = (((*this)[D] & DepGNow) != 0);
1078 if (isPreviouslySatisfiedImportantDep == true)
1079 break;
1080 }
1081
1082 if(isNewImportantDep == true)
1083 {
1084 if (DebugAutoInstall == true)
1085 std::clog << OutputInDepth(Depth) << "new important dependency: "
1086 << Start.TargetPkg().FullName() << std::endl;
1087 }
1088 else if(isPreviouslySatisfiedImportantDep == true)
1089 {
1090 if (DebugAutoInstall == true)
1091 std::clog << OutputInDepth(Depth) << "previously satisfied important dependency on "
1092 << Start.TargetPkg().FullName() << std::endl;
1093 }
1094 else
1095 {
1096 if (DebugAutoInstall == true)
1097 std::clog << OutputInDepth(Depth) << "ignore old unsatisfied important dependency on "
1098 << Start.TargetPkg().FullName() << std::endl;
1099 continue;
1d722933 1100 }
1b1c2224 1101 }
6ed08516 1102
b2e465d6
AL
1103 /* This bit is for processing the possibilty of an install/upgrade
1104 fixing the problem */
1105 SPtrArray<Version *> List = Start.AllTargets();
308c7d30
IJ
1106 if (Start->Type != Dep::DpkgBreaks &&
1107 (DepState[Start->ID] & DepCVer) == DepCVer)
6c139d6e 1108 {
b2e465d6
AL
1109 // Right, find the best version to install..
1110 Version **Cur = List;
1111 PkgIterator P = Start.TargetPkg();
1112 PkgIterator InstPkg(*Cache,0);
6c139d6e 1113
b2e465d6
AL
1114 // See if there are direct matches (at the start of the list)
1115 for (; *Cur != 0 && (*Cur)->ParentPkg == P.Index(); Cur++)
1116 {
1117 PkgIterator Pkg(*Cache,Cache->PkgP + (*Cur)->ParentPkg);
1118 if (PkgState[Pkg->ID].CandidateVer != *Cur)
1119 continue;
1120 InstPkg = Pkg;
1121 break;
1122 }
1123
1124 // Select the highest priority providing package
2ed9b455 1125 if (InstPkg.end() == true)
b2e465d6
AL
1126 {
1127 pkgPrioSortList(*Cache,Cur);
1128 for (; *Cur != 0; Cur++)
1129 {
1130 PkgIterator Pkg(*Cache,Cache->PkgP + (*Cur)->ParentPkg);
1131 if (PkgState[Pkg->ID].CandidateVer != *Cur)
1132 continue;
1133 InstPkg = Pkg;
1134 break;
1135 }
1136 }
1137
6910a2ac 1138 if (InstPkg.end() == false)
b2e465d6 1139 {
af29ffb4
MV
1140 if(DebugAutoInstall == true)
1141 std::clog << OutputInDepth(Depth) << "Installing " << InstPkg.Name()
1142 << " as " << Start.DepType() << " of " << Pkg.Name()
d4c5f11f 1143 << std::endl;
92b9551f 1144 // now check if we should consider it a automatic dependency or not
cb1933df 1145 if(Pkg.Section() && ConfigValueInSubTree("APT::Never-MarkAuto-Sections", Pkg.Section()))
92b9551f 1146 {
af29ffb4
MV
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;
92b9551f
MV
1150 MarkInstall(InstPkg,true,Depth + 1, true);
1151 }
1152 else
1153 {
1154 // mark automatic dependency
b51ff02a 1155 MarkInstall(InstPkg,true,Depth + 1, false, ForceImportantDeps);
92b9551f
MV
1156 // Set the autoflag, after MarkInstall because MarkInstall unsets it
1157 if (P->CurrentVer == 0)
1158 PkgState[InstPkg->ID].Flags |= Flag::Auto;
1159 }
b2e465d6 1160 }
6c139d6e
AL
1161 continue;
1162 }
308c7d30 1163
b2e465d6 1164 /* For conflicts we just de-install the package and mark as auto,
308c7d30
IJ
1165 Conflicts may not have or groups. For dpkg's Breaks we try to
1166 upgrade the package. */
359e46db 1167 if (Start.IsNegative() == true)
6c139d6e 1168 {
6c139d6e
AL
1169 for (Version **I = List; *I != 0; I++)
1170 {
1171 VerIterator Ver(*this,*I);
1172 PkgIterator Pkg = Ver.ParentPkg();
308c7d30 1173
edbda33b
DK
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)
1177 continue;
1178
736f6751 1179 if (PkgState[Pkg->ID].CandidateVer != *I &&
a16dec4d
DK
1180 Start->Type == Dep::DpkgBreaks &&
1181 MarkInstall(Pkg,true,Depth + 1, false, ForceImportantDeps) == true)
1182 continue;
1183 else if (MarkDelete(Pkg,false,Depth + 1, false) == false)
1184 break;
6c139d6e 1185 }
6c139d6e
AL
1186 continue;
1187 }
1188 }
3d619a20 1189
a16dec4d 1190 return Dep.end() == true;
6c139d6e 1191}
92fcbfc1 1192 /*}}}*/
6910a2ac 1193// DepCache::IsInstallOk - check if it is ok to install this package /*{{{*/
2d403b92 1194// ---------------------------------------------------------------------
dde0c674
DK
1195/* The default implementation does nothing.
1196 dpkg holds are enforced by the private IsModeChangeOk */
6910a2ac
DK
1197bool pkgDepCache::IsInstallOk(PkgIterator const &Pkg,bool AutoInst,
1198 unsigned long Depth, bool FromUser)
2d403b92 1199{
6910a2ac 1200 return true;
2d403b92
MV
1201}
1202 /*}}}*/
d0c59649
AL
1203// DepCache::SetReInstall - Set the reinstallation flag /*{{{*/
1204// ---------------------------------------------------------------------
1205/* */
1206void pkgDepCache::SetReInstall(PkgIterator const &Pkg,bool To)
1207{
1019948c
DK
1208 if (unlikely(Pkg.end() == true))
1209 return;
1210
74a05226
MV
1211 ActionGroup group(*this);
1212
d0c59649
AL
1213 RemoveSizes(Pkg);
1214 RemoveStates(Pkg);
1215
1216 StateCache &P = PkgState[Pkg->ID];
1217 if (To == true)
1218 P.iFlags |= ReInstall;
1219 else
1220 P.iFlags &= ~ReInstall;
1221
1222 AddStates(Pkg);
1223 AddSizes(Pkg);
1224}
1225 /*}}}*/
b2e465d6
AL
1226// DepCache::SetCandidateVersion - Change the candidate version /*{{{*/
1227// ---------------------------------------------------------------------
1228/* */
27e8981a 1229void pkgDepCache::SetCandidateVersion(VerIterator TargetVer)
b2e465d6
AL
1230{
1231 pkgCache::PkgIterator Pkg = TargetVer.ParentPkg();
1232 StateCache &P = PkgState[Pkg->ID];
74a05226 1233
08fa1cab
DK
1234 if (P.CandidateVer == TargetVer)
1235 return;
1236
1237 ActionGroup group(*this);
1238
b2e465d6
AL
1239 RemoveSizes(Pkg);
1240 RemoveStates(Pkg);
1241
758729c8 1242 if (P.CandidateVer == P.InstallVer && P.Install() == true)
b2e465d6
AL
1243 P.InstallVer = (Version *)TargetVer;
1244 P.CandidateVer = (Version *)TargetVer;
1245 P.Update(Pkg,*this);
1246
1247 AddStates(Pkg);
1248 Update(Pkg);
1249 AddSizes(Pkg);
1019948c 1250
b2e465d6 1251}
08fa1cab 1252 /*}}}*/
2c085486
DK
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 */
1258bool pkgDepCache::SetCandidateRelease(pkgCache::VerIterator TargetVer,
1259 std::string const &TargetRel)
1260{
1261 std::list<std::pair<pkgCache::VerIterator, pkgCache::VerIterator> > Changed;
1262 return SetCandidateRelease(TargetVer, TargetRel, Changed);
1263}
1264bool pkgDepCache::SetCandidateRelease(pkgCache::VerIterator TargetVer,
1265 std::string const &TargetRel,
1266 std::list<std::pair<pkgCache::VerIterator, pkgCache::VerIterator> > &Changed)
1267{
758729c8 1268 ActionGroup group(*this);
2c085486
DK
1269 SetCandidateVersion(TargetVer);
1270
1271 if (TargetRel == "installed" || TargetRel == "candidate") // both doesn't make sense in this context
1272 return true;
1273
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());
1277
1278 for (pkgCache::DepIterator D = TargetVer.DependsList(); D.end() == false; ++D)
1279 {
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))
1283 continue;
1284
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)
1290 {
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))
1295 continue;
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')
1299 {
1300 // Check if one of the providers is installable
1301 if (P->ProvidesList != 0)
1302 {
1303 pkgCache::PrvIterator Prv = P.ProvidesList();
1304 for (; Prv.end() == false; ++Prv)
1305 {
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)
1309 continue;
1310 break;
1311 }
1312 if (Prv.end() == true)
1313 continue;
1314 }
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)
1318 continue;
1319 itsFine = true;
1320 break;
1321 }
1322 if (Cand.end() == true)
1323 continue;
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)
1327 {
1328 itsFine = true;
1329 break;
1330 }
1331 }
1332
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);
1336 continue;
1337 }
1338
1339 // walk again over the or-group and check each if a candidate switch would help
1340 itsFine = false;
1341 for (bool stillOr = true; stillOr == true; ++D)
1342 {
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')
1346 {
1347 if (stillOr == true)
1348 continue;
1349 break;
1350 }
1351
1352 pkgCache::VerIterator V;
1353 if (TargetRel == "newest")
1354 V = D.TargetPkg().VersionList();
1355 else
1356 V = Match.Find(D.TargetPkg());
1357
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)
1360 {
1361 if (stillOr == true)
1362 continue;
1363 break;
1364 }
1365
1366 pkgCache::VerIterator oldCand = PkgState[D.TargetPkg()->ID].CandidateVerIter(*this);
1367 if (V == oldCand)
1368 {
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)
1372 {
1373 if (c->first->ParentPkg != V->ParentPkg)
1374 continue;
1375 itsFine = true;
1376 break;
1377 }
1378 }
1379
1380 if (itsFine == false)
1381 {
1382 // change the candidate
1383 Changed.push_back(make_pair(oldCand, TargetVer));
1384 if (SetCandidateRelease(V, TargetRel, Changed) == false)
1385 {
1386 if (stillOr == false)
1387 break;
1388 // undo the candidate changing
1389 SetCandidateVersion(oldCand);
1390 Changed.pop_back();
1391 continue;
1392 }
1393 itsFine = true;
1394 }
1395
1396 // something in the or-group was fine, skip all other members
1397 for (; (D->CompareOp & Dep::Or) == Dep::Or; ++D);
1398 break;
1399 }
1400
1401 if (itsFine == false && (D->Type == pkgCache::Dep::PreDepends || D->Type == pkgCache::Dep::Depends))
1402 {
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());
1408 return false;
1409 }
1410 }
1411 return true;
1412}
1413 /*}}}*/
08fa1cab
DK
1414// DepCache::MarkAuto - set the Auto flag for a package /*{{{*/
1415// ---------------------------------------------------------------------
1416/* */
74a05226
MV
1417void pkgDepCache::MarkAuto(const PkgIterator &Pkg, bool Auto)
1418{
1419 StateCache &state = PkgState[Pkg->ID];
1420
1421 ActionGroup group(*this);
1422
1423 if(Auto)
1424 state.Flags |= Flag::Auto;
1425 else
1426 state.Flags &= ~Flag::Auto;
1427}
b2e465d6 1428 /*}}}*/
6c139d6e
AL
1429// StateCache::Update - Compute the various static display things /*{{{*/
1430// ---------------------------------------------------------------------
1431/* This is called whenever the Candidate version changes. */
1432void pkgDepCache::StateCache::Update(PkgIterator Pkg,pkgCache &Cache)
1433{
1434 // Some info
1435 VerIterator Ver = CandidateVerIter(Cache);
1436
1437 // Use a null string or the version string
1438 if (Ver.end() == true)
1439 CandVersion = "";
1440 else
1441 CandVersion = Ver.VerStr();
1442
1443 // Find the current version
1444 CurVersion = "";
1445 if (Pkg->CurrentVer != 0)
1446 CurVersion = Pkg.CurrentVer().VerStr();
1447
1448 // Strip off the epochs for display
1449 CurVersion = StripEpoch(CurVersion);
1450 CandVersion = StripEpoch(CandVersion);
1451
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)
1455 Status = 2;
1456}
1457 /*}}}*/
1458// StateCache::StripEpoch - Remove the epoch specifier from the version /*{{{*/
1459// ---------------------------------------------------------------------
1460/* */
1461const char *pkgDepCache::StateCache::StripEpoch(const char *Ver)
1462{
1463 if (Ver == 0)
1464 return 0;
1465
1466 // Strip any epoch
1467 for (const char *I = Ver; *I != 0; I++)
1468 if (*I == ':')
1469 return I + 1;
1470 return Ver;
1471}
1472 /*}}}*/
b2e465d6 1473// Policy::GetCandidateVer - Returns the Candidate install version /*{{{*/
6321777b 1474// ---------------------------------------------------------------------
b2e465d6
AL
1475/* The default just returns the highest available version that is not
1476 a source and automatic. */
e841200b 1477pkgCache::VerIterator pkgDepCache::Policy::GetCandidateVer(PkgIterator const &Pkg)
6321777b 1478{
b2e465d6
AL
1479 /* Not source/not automatic versions cannot be a candidate version
1480 unless they are already installed */
1481 VerIterator Last(*(pkgCache *)this,0);
6321777b 1482
f7f0d6c7 1483 for (VerIterator I = Pkg.VersionList(); I.end() == false; ++I)
b2e465d6
AL
1484 {
1485 if (Pkg.CurrentVer() == I)
1486 return I;
1487
f7f0d6c7 1488 for (VerFileIterator J = I.FileList(); J.end() == false; ++J)
b2e465d6
AL
1489 {
1490 if ((J.File()->Flags & Flag::NotSource) != 0)
1491 continue;
1492
1493 /* Stash the highest version of a not-automatic source, we use it
1494 if there is nothing better */
5ed56f93
DK
1495 if ((J.File()->Flags & Flag::NotAutomatic) != 0 ||
1496 (J.File()->Flags & Flag::ButAutomaticUpgrades) != 0)
b2e465d6
AL
1497 {
1498 if (Last.end() == true)
1499 Last = I;
1500 continue;
1501 }
1502
1503 return I;
1504 }
1505 }
6321777b 1506
b2e465d6
AL
1507 return Last;
1508}
1509 /*}}}*/
1510// Policy::IsImportantDep - True if the dependency is important /*{{{*/
1511// ---------------------------------------------------------------------
1512/* */
e841200b 1513bool pkgDepCache::Policy::IsImportantDep(DepIterator const &Dep)
b2e465d6 1514{
60681f93
MV
1515 if(Dep.IsCritical())
1516 return true;
1d722933
MV
1517 else if(Dep->Type == pkgCache::Dep::Recommends)
1518 {
b20c1683 1519 if (InstallRecommends)
1d722933
MV
1520 return true;
1521 // we suport a special mode to only install-recommends for certain
1522 // sections
1523 // FIXME: this is a meant as a temporarly solution until the
1524 // recommends are cleaned up
cb1933df
MV
1525 const char *sec = Dep.ParentVer().Section();
1526 if (sec && ConfigValueInSubTree("APT::Install-Recommends-Sections", sec))
1527 return true;
1d722933 1528 }
60681f93 1529 else if(Dep->Type == pkgCache::Dep::Suggests)
b20c1683 1530 return InstallSuggests;
60681f93 1531
74a05226
MV
1532 return false;
1533}
92fcbfc1 1534 /*}}}*/
6d38011b
DK
1535// Policy::GetPriority - Get the priority of the package pin /*{{{*/
1536signed short pkgDepCache::Policy::GetPriority(pkgCache::PkgIterator const &Pkg)
1537{ return 0; };
1538signed short pkgDepCache::Policy::GetPriority(pkgCache::PkgFileIterator const &File)
1539{ return 0; };
1540 /*}}}*/
92fcbfc1 1541pkgDepCache::InRootSetFunc *pkgDepCache::GetRootSetFunc() /*{{{*/
74a05226
MV
1542{
1543 DefaultRootSetFunc *f = new DefaultRootSetFunc;
1544 if(f->wasConstructedSuccessfully())
1545 return f;
1546 else
1547 {
1548 delete f;
1549 return NULL;
1550 }
1551}
92fcbfc1 1552 /*}}}*/
74a05226
MV
1553bool pkgDepCache::MarkFollowsRecommends()
1554{
1555 return _config->FindB("APT::AutoRemove::RecommendsImportant", true);
1556}
1557
1558bool pkgDepCache::MarkFollowsSuggests()
1559{
db4351be 1560 return _config->FindB("APT::AutoRemove::SuggestsImportant", true);
74a05226
MV
1561}
1562
92fcbfc1 1563// pkgDepCache::MarkRequired - the main mark algorithm /*{{{*/
74a05226
MV
1564bool pkgDepCache::MarkRequired(InRootSetFunc &userFunc)
1565{
98278a81 1566 if (_config->Find("APT::Solver", "internal") != "internal")
76d4aab0
DK
1567 return true;
1568
74a05226
MV
1569 bool follow_recommends;
1570 bool follow_suggests;
95afdfd0 1571 bool debug_autoremove = _config->FindB("Debug::pkgAutoRemove",false);
74a05226
MV
1572
1573 // init the states
1574 for(PkgIterator p = PkgBegin(); !p.end(); ++p)
1575 {
1576 PkgState[p->ID].Marked = false;
1577 PkgState[p->ID].Garbage = false;
1578
1579 // debug output
95afdfd0 1580 if(debug_autoremove && PkgState[p->ID].Flags & Flag::Auto)
e0b94b97 1581 std::clog << "AutoDep: " << p.FullName() << std::endl;
74a05226
MV
1582 }
1583
1584 // init vars
1585 follow_recommends = MarkFollowsRecommends();
1586 follow_suggests = MarkFollowsSuggests();
1587
1588
1589
1590 // do the mark part, this is the core bit of the algorithm
1591 for(PkgIterator p = PkgBegin(); !p.end(); ++p)
1592 {
1593 if(!(PkgState[p->ID].Flags & Flag::Auto) ||
1594 (p->Flags & Flag::Essential) ||
83789130
DK
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))
74a05226
MV
1600 {
1601 // the package is installed (and set to keep)
1602 if(PkgState[p->ID].Keep() && !p.CurrentVer().end())
83860e37 1603 MarkPackage(p, p.CurrentVer(),
74a05226
MV
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);
1609 }
1610 }
1611
1612 return true;
1613}
92fcbfc1
DK
1614 /*}}}*/
1615// MarkPackage - mark a single package in Mark-and-Sweep /*{{{*/
74a05226
MV
1616void pkgDepCache::MarkPackage(const pkgCache::PkgIterator &pkg,
1617 const pkgCache::VerIterator &ver,
e0b94b97
DK
1618 bool const &follow_recommends,
1619 bool const &follow_suggests)
74a05226
MV
1620{
1621 pkgDepCache::StateCache &state = PkgState[pkg->ID];
e0b94b97
DK
1622
1623 // if we are marked already we are done
1624 if(state.Marked)
1625 return;
1626
1627 VerIterator const currver = pkg.CurrentVer();
e0b94b97 1628 VerIterator const instver = state.InstVerIter(*this);
74a05226
MV
1629
1630#if 0
cda456d7
DK
1631 VerIterator const candver = state.CandidateVerIter(*this);
1632
74a05226
MV
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)
1639 {
1640 if(ver==candver)
1641 mark_install(pkg, false, false, NULL);
1642 else if(ver==pkg.CurrentVer())
1643 MarkKeep(pkg, false, false);
1644
1645 instver=state.InstVerIter(*this);
1646 }
1647#endif
1648
36baa77a
MV
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()))
74a05226
MV
1654 return;
1655
e0b94b97 1656 bool const debug_autoremove = _config->FindB("Debug::pkgAutoRemove", false);
74a05226 1657
95afdfd0 1658 if(debug_autoremove)
83860e37 1659 {
e0b94b97 1660 std::clog << "Marking: " << pkg.FullName();
83860e37
DB
1661 if(!ver.end())
1662 std::clog << " " << ver.VerStr();
1663 if(!currver.end())
1664 std::clog << ", Curr=" << currver.VerStr();
1665 if(!instver.end())
1666 std::clog << ", Inst=" << instver.VerStr();
1667 std::clog << std::endl;
1668 }
1669
74a05226
MV
1670 state.Marked=true;
1671
e0b94b97
DK
1672 if(ver.end() == true)
1673 return;
1674
74a05226
MV
1675 for(DepIterator d = ver.DependsList(); !d.end(); ++d)
1676 {
1677 if(d->Type == Dep::Depends ||
1678 d->Type == Dep::PreDepends ||
1679 (follow_recommends &&
1680 d->Type == Dep::Recommends) ||
1681 (follow_suggests &&
1682 d->Type == Dep::Suggests))
1683 {
1684 // Try all versions of this package.
1685 for(VerIterator V = d.TargetPkg().VersionList();
1686 !V.end(); ++V)
1687 {
1688 if(_system->VS->CheckDep(V.VerStr(), d->CompareOp, d.TargetVer()))
1689 {
95afdfd0 1690 if(debug_autoremove)
83860e37 1691 {
e0b94b97 1692 std::clog << "Following dep: " << d.ParentPkg().FullName()
83860e37 1693 << " " << d.ParentVer().VerStr() << " "
e0b94b97 1694 << d.DepType() << " " << d.TargetPkg().FullName();
83860e37
DB
1695 if((d->CompareOp & ~pkgCache::Dep::Or) != pkgCache::Dep::NoOp)
1696 {
1697 std::clog << " (" << d.CompType() << " "
1698 << d.TargetVer() << ")";
1699 }
1700 std::clog << std::endl;
1701 }
e0b94b97 1702 MarkPackage(V.ParentPkg(), V,
74a05226
MV
1703 follow_recommends, follow_suggests);
1704 }
1705 }
1706 // Now try virtual packages
1707 for(PrvIterator prv=d.TargetPkg().ProvidesList();
1708 !prv.end(); ++prv)
1709 {
1710 if(_system->VS->CheckDep(prv.ProvideVersion(), d->CompareOp,
1711 d.TargetVer()))
1712 {
95afdfd0 1713 if(debug_autoremove)
83860e37 1714 {
e0b94b97
DK
1715 std::clog << "Following dep: " << d.ParentPkg().FullName() << " "
1716 << d.ParentVer().VerStr() << " "
1717 << d.DepType() << " " << d.TargetPkg().FullName() << " ";
83860e37
DB
1718 if((d->CompareOp & ~pkgCache::Dep::Or) != pkgCache::Dep::NoOp)
1719 {
1720 std::clog << " (" << d.CompType() << " "
1721 << d.TargetVer() << ")";
1722 }
1723 std::clog << ", provided by "
e0b94b97 1724 << prv.OwnerPkg().FullName() << " "
83860e37
DB
1725 << prv.OwnerVer().VerStr()
1726 << std::endl;
1727 }
1728
74a05226
MV
1729 MarkPackage(prv.OwnerPkg(), prv.OwnerVer(),
1730 follow_recommends, follow_suggests);
1731 }
1732 }
1733 }
1734 }
74a05226 1735}
92fcbfc1
DK
1736 /*}}}*/
1737bool pkgDepCache::Sweep() /*{{{*/
74a05226 1738{
95afdfd0
OS
1739 bool debug_autoremove = _config->FindB("Debug::pkgAutoRemove",false);
1740
74a05226
MV
1741 // do the sweep
1742 for(PkgIterator p=PkgBegin(); !p.end(); ++p)
95afdfd0 1743 {
74a05226
MV
1744 StateCache &state=PkgState[p->ID];
1745
c9b320e8
MV
1746 // skip required packages
1747 if (!p.CurrentVer().end() &&
1748 (p.CurrentVer()->Priority == pkgCache::State::Required))
1749 continue;
1750
74a05226 1751 // if it is not marked and it is installed, it's garbage
32085498 1752 if(!state.Marked && (!p.CurrentVer().end() || state.Install()))
74a05226
MV
1753 {
1754 state.Garbage=true;
95afdfd0 1755 if(debug_autoremove)
6ee2b0f8 1756 std::clog << "Garbage: " << p.FullName() << std::endl;
74a05226
MV
1757 }
1758 }
1759
1760 return true;
1761}
92fcbfc1 1762 /*}}}*/