]>
Commit | Line | Data |
---|---|---|
6c139d6e AL |
1 | // -*- mode: cpp; mode: fold -*- |
2 | // Description /*{{{*/ | |
3 | // $Id: depcache.cc,v 1.1 1998/07/07 04:17:01 jgg Exp $ | |
4 | /* ###################################################################### | |
5 | ||
6 | Dependency Cache - Caches Dependency information. | |
7 | ||
8 | ##################################################################### */ | |
9 | /*}}}*/ | |
10 | // Include Files /*{{{*/ | |
11 | #ifdef __GNUG__ | |
12 | #pragma implementation "pkglib/depcache.h" | |
13 | #endif | |
14 | #include <pkglib/depcache.h> | |
15 | ||
16 | #include <pkglib/version.h> | |
17 | #include <pkglib/error.h> | |
18 | /*}}}*/ | |
19 | ||
20 | // DepCache::pkgDepCache - Constructors /*{{{*/ | |
21 | // --------------------------------------------------------------------- | |
22 | /* */ | |
23 | pkgDepCache::pkgDepCache(MMap &Map) : | |
24 | pkgCache(Map), PkgState(0), DepState(0) | |
25 | { | |
26 | if (_error->PendingError() == false) | |
27 | Init(); | |
28 | } | |
29 | /*}}}*/ | |
30 | // DepCache::~pkgDepCache - Destructor /*{{{*/ | |
31 | // --------------------------------------------------------------------- | |
32 | /* */ | |
33 | pkgDepCache::~pkgDepCache() | |
34 | { | |
35 | delete [] PkgState; | |
36 | delete [] DepState; | |
37 | } | |
38 | /*}}}*/ | |
39 | // DepCache::ReMap - Regenerate the extra data for the new cache /*{{{*/ | |
40 | // --------------------------------------------------------------------- | |
41 | /* pkgCache's constructors call this function, but because the object is not | |
42 | fully constructed at that point it will not result in this function being | |
43 | called but pkgCache::ReMap will be instead.*/ | |
44 | bool pkgDepCache::ReMap() | |
45 | { | |
46 | if (pkgCache::ReMap() == false) | |
47 | return false; | |
48 | ||
49 | return Init(); | |
50 | } | |
51 | /*}}}*/ | |
52 | // DepCache::Init - Generate the initial extra structures. /*{{{*/ | |
53 | // --------------------------------------------------------------------- | |
54 | /* This allocats the extension buffers and initializes them. */ | |
55 | bool pkgDepCache::Init() | |
56 | { | |
57 | delete [] PkgState; | |
58 | delete [] DepState; | |
59 | PkgState = new StateCache[Head().PackageCount]; | |
60 | DepState = new unsigned char[Head().DependsCount]; | |
61 | memset(PkgState,0,sizeof(*PkgState)*Head().PackageCount); | |
62 | memset(DepState,0,sizeof(*DepState)*Head().DependsCount); | |
63 | ||
64 | /* Set the current state of everything. In this state all of the | |
65 | packages are kept exactly as is. See AllUpgrade */ | |
66 | for (PkgIterator I = PkgBegin(); I.end() != true; I++) | |
67 | { | |
68 | // Find the proper cache slot | |
69 | StateCache &State = PkgState[I->ID]; | |
70 | State.iFlags = 0; | |
71 | ||
72 | // Figure out the install version | |
73 | State.CandidateVer = GetCandidateVer(I); | |
74 | State.InstallVer = I.CurrentVer(); | |
75 | State.Mode = ModeKeep; | |
76 | ||
77 | State.Update(I,*this); | |
78 | } | |
79 | ||
80 | Update(); | |
81 | ||
82 | return true; | |
83 | } | |
84 | /*}}}*/ | |
85 | // DepCache::GetCandidateVer - Returns the Candidate install version /*{{{*/ | |
86 | // --------------------------------------------------------------------- | |
87 | /* The default just returns the target version if it exists or the | |
88 | highest version. */ | |
89 | pkgDepCache::VerIterator pkgDepCache::GetCandidateVer(PkgIterator Pkg) | |
90 | { | |
91 | // Try to use an explicit target | |
92 | if (Pkg->TargetVer == 0) | |
93 | { | |
94 | /* Not source versions cannot be a candidate version unless they | |
95 | are already installed */ | |
96 | for (VerIterator I = Pkg.VersionList(); I.end() == false; I++) | |
97 | { | |
98 | if (Pkg.CurrentVer() == I) | |
99 | return I; | |
100 | for (VerFileIterator J = I.FileList(); J.end() == false; J++) | |
101 | if ((J.File()->Flags & Flag::NotSource) == 0) | |
102 | return I; | |
103 | } | |
104 | ||
105 | return VerIterator(*this,0); | |
106 | } | |
107 | else | |
108 | return Pkg.TargetVer(); | |
109 | } | |
110 | /*}}}*/ | |
111 | // DepCache::IsImportantDep - True if the dependency is important /*{{{*/ | |
112 | // --------------------------------------------------------------------- | |
113 | /* */ | |
114 | bool pkgDepCache::IsImportantDep(DepIterator Dep) | |
115 | { | |
116 | return Dep.IsCritical(); | |
117 | } | |
118 | /*}}}*/ | |
119 | ||
120 | // DepCache::CheckDep - Checks a single dependency /*{{{*/ | |
121 | // --------------------------------------------------------------------- | |
122 | /* This first checks the dependency against the main target package and | |
123 | then walks along the package provides list and checks if each provides | |
124 | will be installed then checks the provides against the dep. Res will be | |
125 | set to the package which was used to satisfy the dep. */ | |
126 | bool pkgDepCache::CheckDep(DepIterator Dep,int Type,PkgIterator &Res) | |
127 | { | |
128 | Res = Dep.TargetPkg(); | |
129 | ||
130 | /* Check simple depends. A depends -should- never self match but | |
131 | we allow it anyhow because dpkg does. Technically it is a packaging | |
132 | bug. Conflicts may never self match */ | |
133 | if (Dep.TargetPkg() != Dep.ParentPkg() || Dep->Type != Dep::Conflicts) | |
134 | { | |
135 | PkgIterator Pkg = Dep.TargetPkg(); | |
136 | // Check the base package | |
137 | if (Type == NowVersion && Pkg->CurrentVer != 0) | |
138 | if (pkgCheckDep(Dep.TargetVer(), | |
139 | Pkg.CurrentVer().VerStr(),Dep->CompareOp) == true) | |
140 | return true; | |
141 | ||
142 | if (Type == InstallVersion && PkgState[Pkg->ID].InstallVer != 0) | |
143 | if (pkgCheckDep(Dep.TargetVer(), | |
144 | PkgState[Pkg->ID].InstVerIter(*this).VerStr(), | |
145 | Dep->CompareOp) == true) | |
146 | return true; | |
147 | ||
148 | if (Type == CandidateVersion && PkgState[Pkg->ID].CandidateVer != 0) | |
149 | if (pkgCheckDep(Dep.TargetVer(), | |
150 | PkgState[Pkg->ID].CandidateVerIter(*this).VerStr(), | |
151 | Dep->CompareOp) == true) | |
152 | return true; | |
153 | } | |
154 | ||
155 | // Check the providing packages | |
156 | PrvIterator P = Dep.TargetPkg().ProvidesList(); | |
157 | PkgIterator Pkg = Dep.ParentPkg(); | |
158 | for (; P.end() != true; P++) | |
159 | { | |
160 | /* Provides may never be applied against the same package if it is | |
161 | a conflicts. See the comment above. */ | |
162 | if (P.OwnerPkg() == Pkg && Dep->Type == Dep::Conflicts) | |
163 | continue; | |
164 | ||
165 | // Check if the provides is a hit | |
166 | if (Type == NowVersion) | |
167 | { | |
168 | if (P.OwnerPkg().CurrentVer() != P.OwnerVer()) | |
169 | continue; | |
170 | } | |
171 | ||
172 | if (Type == InstallVersion) | |
173 | { | |
174 | StateCache &State = PkgState[P.OwnerPkg()->ID]; | |
175 | if (State.InstallVer != (Version *)P.OwnerVer()) | |
176 | continue; | |
177 | } | |
178 | ||
179 | if (Type == CandidateVersion) | |
180 | { | |
181 | StateCache &State = PkgState[P.OwnerPkg()->ID]; | |
182 | if (State.CandidateVer != (Version *)P.OwnerVer()) | |
183 | continue; | |
184 | } | |
185 | ||
186 | // Compare the versions. | |
187 | if (pkgCheckDep(Dep.TargetVer(),P.ProvideVersion(),Dep->CompareOp) == true) | |
188 | { | |
189 | Res = P.OwnerPkg(); | |
190 | return true; | |
191 | } | |
192 | } | |
193 | ||
194 | return false; | |
195 | } | |
196 | /*}}}*/ | |
197 | // DepCache::AddSizes - Add the packages sizes to the counters /*{{{*/ | |
198 | // --------------------------------------------------------------------- | |
199 | /* Call with Mult = -1 to preform the inverse opration */ | |
200 | void pkgDepCache::AddSizes(const PkgIterator &Pkg,long Mult) | |
201 | { | |
202 | StateCache &P = PkgState[Pkg->ID]; | |
203 | ||
204 | // Compute the size data | |
205 | if (P.NewInstall() == true) | |
206 | { | |
207 | iUsrSize += Mult*P.InstVerIter(*this)->InstalledSize; | |
208 | iDownloadSize += Mult*P.InstVerIter(*this)->Size; | |
209 | } | |
210 | ||
211 | // Upgrading | |
212 | if (Pkg->CurrentVer != 0 && P.InstallVer != (Version *)Pkg.CurrentVer() && | |
213 | P.InstallVer != 0) | |
214 | { | |
215 | iUsrSize += Mult*(P.InstVerIter(*this)->InstalledSize - | |
216 | Pkg.CurrentVer()->InstalledSize); | |
217 | iDownloadSize += Mult*P.InstVerIter(*this)->Size; | |
218 | } | |
219 | ||
220 | // Removing | |
221 | if (Pkg->CurrentVer != 0 && P.InstallVer == 0) | |
222 | iUsrSize -= Mult*Pkg.CurrentVer()->InstalledSize; | |
223 | } | |
224 | /*}}}*/ | |
225 | // DepCache::AddStates - Add the package to the state counter /*{{{*/ | |
226 | // --------------------------------------------------------------------- | |
227 | /* This routine is tricky to use, you must make sure that it is never | |
228 | called twice for the same package. This means the Remove/Add section | |
229 | should be as short as possible and not encompass any code that will | |
230 | calld Remove/Add itself. Remember, dependencies can be circular so | |
231 | while processing a dep for Pkg it is possible that Add/Remove | |
232 | will be called on Pkg */ | |
233 | void pkgDepCache::AddStates(const PkgIterator &Pkg,int Add) | |
234 | { | |
235 | StateCache &State = PkgState[Pkg->ID]; | |
236 | ||
237 | // The Package is broken | |
238 | if ((State.DepState & DepInstMin) != DepInstMin) | |
239 | iBrokenCount += Add; | |
240 | ||
241 | // Bad state | |
242 | if (Pkg.State() != PkgIterator::NeedsNothing) | |
243 | iBadCount += Add; | |
244 | ||
245 | // Not installed | |
246 | if (Pkg->CurrentVer == 0) | |
247 | { | |
248 | if (State.Mode == ModeInstall) | |
249 | iInstCount += Add; | |
250 | return; | |
251 | } | |
252 | ||
253 | // Installed, no upgrade | |
254 | if (State.Upgradable() == false) | |
255 | { | |
256 | if (State.Mode == ModeDelete) | |
257 | iDelCount += Add; | |
258 | return; | |
259 | } | |
260 | ||
261 | // Alll 3 are possible | |
262 | if (State.Mode == ModeDelete) | |
263 | iDelCount += Add; | |
264 | if (State.Mode == ModeKeep) | |
265 | iKeepCount += Add; | |
266 | if (State.Mode == ModeInstall) | |
267 | iInstCount += Add; | |
268 | } | |
269 | /*}}}*/ | |
270 | // DepCache::BuildGroupOrs - Generate the Or group dep data /*{{{*/ | |
271 | // --------------------------------------------------------------------- | |
272 | /* The or group results are stored in the last item of the or group. This | |
273 | allows easy detection of the state of a whole or'd group. */ | |
274 | void pkgDepCache::BuildGroupOrs(VerIterator const &V) | |
275 | { | |
276 | unsigned char Group = 0; | |
277 | ||
278 | for (DepIterator D = V.DependsList(); D.end() != true; D++) | |
279 | { | |
280 | // Build the dependency state. | |
281 | unsigned char &State = DepState[D->ID]; | |
282 | ||
283 | /* Invert for Conflicts. We have to do this twice to get the | |
284 | right sense for a conflicts group */ | |
285 | if (D->Type == Dep::Conflicts) | |
286 | State = ~State; | |
287 | ||
288 | // Add to the group if we are within an or.. | |
289 | Group |= State; | |
290 | State |= Group << 3; | |
291 | if ((D->CompareOp & Dep::Or) != Dep::Or) | |
292 | Group = 0; | |
293 | ||
294 | // Invert for Conflicts | |
295 | if (D->Type == Dep::Conflicts) | |
296 | State = ~State; | |
297 | } | |
298 | } | |
299 | /*}}}*/ | |
300 | // DepCache::VersionState - Perform a pass over a dependency list /*{{{*/ | |
301 | // --------------------------------------------------------------------- | |
302 | /* This is used to run over a dependency list and determine the dep | |
303 | state of the list, filtering it through both a Min check and a Policy | |
304 | check. The return result will have SetMin/SetPolicy low if a check | |
305 | fails. It uses the DepState cache for it's computations. */ | |
306 | unsigned char pkgDepCache::VersionState(DepIterator D,unsigned char Check, | |
307 | unsigned char SetMin, | |
308 | unsigned char SetPolicy) | |
309 | { | |
310 | unsigned char Dep = 0xFF; | |
311 | ||
312 | while (D.end() != true) | |
313 | { | |
314 | // Compute a single dependency element (glob or) | |
315 | DepIterator Start = D; | |
316 | unsigned char State = 0; | |
317 | for (bool LastOR = true; D.end() == false && LastOR == true; D++) | |
318 | { | |
319 | State |= DepState[D->ID]; | |
320 | LastOR = (D->CompareOp & Dep::Or) == Dep::Or; | |
321 | } | |
322 | ||
323 | // Minimum deps that must be satisfied to have a working package | |
324 | if (Start.IsCritical() == true) | |
325 | if ((State & Check) != Check) | |
326 | Dep &= ~SetMin; | |
327 | ||
328 | // Policy deps that must be satisfied to install the package | |
329 | if (IsImportantDep(Start) == true && | |
330 | (State & Check) != Check) | |
331 | Dep &= ~SetPolicy; | |
332 | } | |
333 | ||
334 | return Dep; | |
335 | } | |
336 | /*}}}*/ | |
337 | // DepCache::DependencyState - Compute the 3 results for a dep /*{{{*/ | |
338 | // --------------------------------------------------------------------- | |
339 | /* This is the main dependency computation bit. It computes the 3 main | |
340 | results for a dependencys, Now, Install and Candidate. Callers must | |
341 | invert the result if dealing with conflicts. */ | |
342 | unsigned char pkgDepCache::DependencyState(DepIterator &D) | |
343 | { | |
344 | unsigned char State = 0; | |
345 | ||
346 | if (CheckDep(D,NowVersion) == true) | |
347 | State |= DepNow; | |
348 | if (CheckDep(D,InstallVersion) == true) | |
349 | State |= DepInstall; | |
350 | if (CheckDep(D,CandidateVersion) == true) | |
351 | State |= DepCVer; | |
352 | ||
353 | return State; | |
354 | } | |
355 | /*}}}*/ | |
356 | // DepCache::UpdateVerState - Compute the Dep member of the state /*{{{*/ | |
357 | // --------------------------------------------------------------------- | |
358 | /* This determines the combined dependency representation of a package | |
359 | for its two states now and install. This is done by using the pre-generated | |
360 | dependency information. */ | |
361 | void pkgDepCache::UpdateVerState(PkgIterator Pkg) | |
362 | { | |
363 | // Empty deps are always true | |
364 | StateCache &State = PkgState[Pkg->ID]; | |
365 | State.DepState = 0xFF; | |
366 | ||
367 | // Check the Current state | |
368 | if (Pkg->CurrentVer != 0) | |
369 | { | |
370 | DepIterator D = Pkg.CurrentVer().DependsList(); | |
371 | State.DepState &= VersionState(D,DepNow,DepNowMin,DepNowPolicy); | |
372 | } | |
373 | ||
374 | /* Check the candidate state. We do not compare against the whole as | |
375 | a candidate state but check the candidate version against the | |
376 | install states */ | |
377 | if (State.CandidateVer != 0) | |
378 | { | |
379 | DepIterator D = State.CandidateVerIter(*this).DependsList(); | |
380 | State.DepState &= VersionState(D,DepInstall,DepCandMin,DepCandPolicy); | |
381 | } | |
382 | ||
383 | // Check target state which can only be current or installed | |
384 | if (State.InstallVer != 0) | |
385 | { | |
386 | DepIterator D = State.InstVerIter(*this).DependsList(); | |
387 | State.DepState &= VersionState(D,DepInstall,DepInstMin,DepInstPolicy); | |
388 | } | |
389 | } | |
390 | /*}}}*/ | |
391 | // DepCache::Update - Figure out all the state information /*{{{*/ | |
392 | // --------------------------------------------------------------------- | |
393 | /* This will figure out the state of all the packages and all the | |
394 | dependencies based on the current policy. */ | |
395 | void pkgDepCache::Update() | |
396 | { | |
397 | iUsrSize = 0; | |
398 | iDownloadSize = 0; | |
399 | iDelCount = 0; | |
400 | iInstCount = 0; | |
401 | iKeepCount = 0; | |
402 | iBrokenCount = 0; | |
403 | iBadCount = 0; | |
404 | ||
405 | // Perform the depends pass | |
406 | for (PkgIterator I = PkgBegin(); I.end() != true; I++) | |
407 | { | |
408 | for (VerIterator V = I.VersionList(); V.end() != true; V++) | |
409 | { | |
410 | unsigned char Group = 0; | |
411 | ||
412 | for (DepIterator D = V.DependsList(); D.end() != true; D++) | |
413 | { | |
414 | // Build the dependency state. | |
415 | unsigned char &State = DepState[D->ID]; | |
416 | State = DependencyState(D);; | |
417 | ||
418 | // Add to the group if we are within an or.. | |
419 | Group |= State; | |
420 | State |= Group << 3; | |
421 | if ((D->CompareOp & Dep::Or) != Dep::Or) | |
422 | Group = 0; | |
423 | ||
424 | // Invert for Conflicts | |
425 | if (D->Type == Dep::Conflicts) | |
426 | State = ~State; | |
427 | } | |
428 | } | |
429 | ||
430 | // Compute the pacakge dependency state and size additions | |
431 | AddSizes(I); | |
432 | UpdateVerState(I); | |
433 | AddStates(I); | |
434 | } | |
435 | } | |
436 | /*}}}*/ | |
437 | // DepCache::Update - Update the deps list of a package /*{{{*/ | |
438 | // --------------------------------------------------------------------- | |
439 | /* This is a helper for update that only does the dep portion of the scan. | |
440 | It is mainly ment to scan reverse dependencies. */ | |
441 | void pkgDepCache::Update(DepIterator D) | |
442 | { | |
443 | // Update the reverse deps | |
444 | for (;D.end() != true; D++) | |
445 | { | |
446 | unsigned char &State = DepState[D->ID]; | |
447 | State = DependencyState(D); | |
448 | ||
449 | // Invert for Conflicts | |
450 | if (D->Type == Dep::Conflicts) | |
451 | State = ~State; | |
452 | ||
453 | RemoveStates(D.ParentPkg()); | |
454 | BuildGroupOrs(D.ParentVer()); | |
455 | UpdateVerState(D.ParentPkg()); | |
456 | AddStates(D.ParentPkg()); | |
457 | } | |
458 | } | |
459 | /*}}}*/ | |
460 | // DepCache::Update - Update the related deps of a package /*{{{*/ | |
461 | // --------------------------------------------------------------------- | |
462 | /* This is called whenever the state of a package changes. It updates | |
463 | all cached dependencies related to this package. */ | |
464 | void pkgDepCache::Update(PkgIterator const &Pkg) | |
465 | { | |
466 | // Recompute the dep of the package | |
467 | RemoveStates(Pkg); | |
468 | UpdateVerState(Pkg); | |
469 | AddStates(Pkg); | |
470 | ||
471 | // Update the reverse deps | |
472 | Update(Pkg.RevDependsList()); | |
473 | ||
474 | // Update the provides map for the current ver | |
475 | if (Pkg->CurrentVer != 0) | |
476 | for (PrvIterator P = Pkg.CurrentVer().ProvidesList(); | |
477 | P.end() != true; P++) | |
478 | Update(P.ParentPkg().RevDependsList()); | |
479 | ||
480 | // Update the provides map for the candidate ver | |
481 | for (PrvIterator P = PkgState[Pkg->ID].CandidateVerIter(*this).ProvidesList(); | |
482 | P.end() != true; P++) | |
483 | Update(P.ParentPkg().RevDependsList()); | |
484 | } | |
485 | ||
486 | /*}}}*/ | |
487 | ||
488 | // DepCache::MarkKeep - Put the package in the keep state /*{{{*/ | |
489 | // --------------------------------------------------------------------- | |
490 | /* */ | |
491 | void pkgDepCache::MarkKeep(PkgIterator const &Pkg,bool Soft) | |
492 | { | |
493 | // Simplifies other routines. | |
494 | if (Pkg.end() == true) | |
495 | return; | |
496 | ||
497 | /* We changed the soft state all the time so the UI is a bit nicer | |
498 | to use */ | |
499 | StateCache &P = PkgState[Pkg->ID]; | |
500 | if (Soft == true) | |
501 | P.iFlags |= AutoKept; | |
502 | else | |
503 | P.iFlags &= ~AutoKept; | |
504 | ||
505 | // Check that it is not already kept | |
506 | if (P.Mode == ModeKeep) | |
507 | return; | |
508 | ||
509 | // We dont even try to keep virtual packages.. | |
510 | if (Pkg->VersionList == 0) | |
511 | return; | |
512 | ||
513 | P.Flags &= ~Flag::Auto; | |
514 | RemoveSizes(Pkg); | |
515 | RemoveStates(Pkg); | |
516 | ||
517 | P.Mode = ModeKeep; | |
518 | if (Pkg->CurrentVer == 0) | |
519 | P.InstallVer = 0; | |
520 | else | |
521 | P.InstallVer = Pkg.CurrentVer(); | |
522 | ||
523 | AddStates(Pkg); | |
524 | ||
525 | Update(Pkg); | |
526 | ||
527 | AddSizes(Pkg); | |
528 | } | |
529 | /*}}}*/ | |
530 | // DepCache::MarkDelete - Put the package in the delete state /*{{{*/ | |
531 | // --------------------------------------------------------------------- | |
532 | /* */ | |
533 | void pkgDepCache::MarkDelete(PkgIterator const &Pkg) | |
534 | { | |
535 | // Simplifies other routines. | |
536 | if (Pkg.end() == true) | |
537 | return; | |
538 | ||
539 | // Check that it is not already marked for delete | |
540 | StateCache &P = PkgState[Pkg->ID]; | |
541 | P.iFlags &= ~AutoKept; | |
542 | if (P.Mode == ModeDelete || P.InstallVer == 0) | |
543 | return; | |
544 | ||
545 | // We dont even try to delete virtual packages.. | |
546 | if (Pkg->VersionList == 0) | |
547 | return; | |
548 | ||
549 | RemoveSizes(Pkg); | |
550 | RemoveStates(Pkg); | |
551 | ||
552 | P.Mode = ModeDelete; | |
553 | P.InstallVer = 0; | |
554 | P.Flags &= Flag::Auto; | |
555 | ||
556 | AddStates(Pkg); | |
557 | Update(Pkg); | |
558 | AddSizes(Pkg); | |
559 | } | |
560 | /*}}}*/ | |
561 | // DepCache::MarkInstall - Put the package in the install state /*{{{*/ | |
562 | // --------------------------------------------------------------------- | |
563 | /* */ | |
564 | void pkgDepCache::MarkInstall(PkgIterator const &Pkg,bool AutoInst) | |
565 | { | |
566 | // Simplifies other routines. | |
567 | if (Pkg.end() == true) | |
568 | return; | |
569 | ||
570 | /* Check that it is not already marked for install and that it can be | |
571 | installed */ | |
572 | StateCache &P = PkgState[Pkg->ID]; | |
573 | P.iFlags &= ~AutoKept; | |
574 | if (P.InstBroken() == false && (P.Mode == ModeInstall || | |
575 | P.CandidateVer == (Version *)Pkg.CurrentVer())) | |
576 | { | |
577 | if (P.CandidateVer == (Version *)Pkg.CurrentVer() && P.InstallVer == 0) | |
578 | MarkKeep(Pkg); | |
579 | return; | |
580 | } | |
581 | ||
582 | // We dont even try to install virtual packages.. | |
583 | if (Pkg->VersionList == 0) | |
584 | return; | |
585 | ||
586 | /* Target the candidate version and remove the autoflag. We reset the | |
587 | autoflag below if this was called recursively. Otherwise the user | |
588 | should have the ability to de-auto a package by changing its state */ | |
589 | RemoveSizes(Pkg); | |
590 | RemoveStates(Pkg); | |
591 | ||
592 | P.Mode = ModeInstall; | |
593 | P.InstallVer = P.CandidateVer; | |
594 | P.Flags &= ~Flag::Auto; | |
595 | if (P.CandidateVer == (Version *)Pkg.CurrentVer()) | |
596 | P.Mode = ModeKeep; | |
597 | ||
598 | AddStates(Pkg); | |
599 | Update(Pkg); | |
600 | AddSizes(Pkg); | |
601 | ||
602 | if (AutoInst == false) | |
603 | return; | |
604 | ||
605 | DepIterator Dep = P.InstVerIter(*this).DependsList(); | |
606 | for (; Dep.end() != true;) | |
607 | { | |
608 | // Grok or groups | |
609 | DepIterator Start = Dep; | |
610 | bool Result = true; | |
611 | for (bool LastOR = true; Dep.end() == false && LastOR == true; Dep++) | |
612 | { | |
613 | LastOR = (Dep->CompareOp & Dep::Or) == Dep::Or; | |
614 | ||
615 | if ((DepState[Dep->ID] & DepInstall) == DepInstall) | |
616 | Result = false; | |
617 | } | |
618 | ||
619 | // Dep is satisfied okay. | |
620 | if (Result == false) | |
621 | continue; | |
622 | ||
623 | /* Check if this dep should be consider for install. If it is a user | |
624 | defined important dep and we are installed a new package then | |
625 | it will be installed. Otherwise we only worry about critical deps */ | |
626 | if (IsImportantDep(Start) == false) | |
627 | continue; | |
628 | if (Pkg->CurrentVer != 0 && Start.IsCritical() == false) | |
629 | continue; | |
630 | ||
631 | // Now we have to take action... | |
632 | PkgIterator P = Start.SmartTargetPkg(); | |
633 | if ((DepState[Start->ID] & DepCVer) == DepCVer) | |
634 | { | |
635 | MarkInstall(P,true); | |
636 | ||
637 | // Set the autoflag, after MarkInstall because MarkInstall unsets it | |
638 | if (P->CurrentVer == 0) | |
639 | PkgState[P->ID].Flags |= Flag::Auto; | |
640 | ||
641 | continue; | |
642 | } | |
643 | ||
644 | // For conflicts we just de-install the package and mark as auto | |
645 | if (Start->Type == Dep::Conflicts) | |
646 | { | |
647 | Version **List = Start.AllTargets(); | |
648 | for (Version **I = List; *I != 0; I++) | |
649 | { | |
650 | VerIterator Ver(*this,*I); | |
651 | PkgIterator Pkg = Ver.ParentPkg(); | |
652 | ||
653 | MarkDelete(Pkg); | |
654 | PkgState[Pkg->ID].Flags |= Flag::Auto; | |
655 | } | |
656 | delete [] List; | |
657 | continue; | |
658 | } | |
659 | } | |
660 | } | |
661 | /*}}}*/ | |
662 | ||
663 | #if 0 | |
664 | // DepCache::ResolveConflicts - Figure the auto upgrades /*{{{*/ | |
665 | // --------------------------------------------------------------------- | |
666 | /* This routine attempts to resolve conflicts generated by automatic | |
667 | upgrading. It is known as 'Stage 1' but that name isn't as proper anymore. | |
668 | ||
669 | It's most important function is during the initial load of APT. The | |
670 | loading code will mark every package for upgrade to it's candidate version | |
671 | and then call this routine. This routine will then 'soft keep' every | |
672 | package that causes conflict, is conflicted, or so on. It is a bit | |
673 | agressive in that it may unselect more packages in some odd cases | |
674 | than are strictly necessary but in the case where no packages were | |
675 | conflicting before it will always produce a system with no packages | |
676 | conflicting after. | |
677 | ||
678 | This routine is also used during state changes that require autoupgrade | |
679 | scanning. That is, if a new package is marked for install then all packages | |
680 | that have been soft kept are reconsidered for upgrade. | |
681 | ||
682 | It is called with state information about what can be un-upgraded and | |
683 | what the pre-upgrade install state was. It is expected that the caller | |
684 | has already marked the desired packages to the install state. Bit 0 is | |
685 | the original install state and Bit 1 is controls whether the package | |
686 | should be touched. | |
687 | */ | |
688 | void pkgDepCache::ResolveConflicts(unsigned char *Touched) | |
689 | { | |
690 | bool Again = false; | |
691 | do | |
692 | { | |
693 | Again = false; | |
694 | for (PkgIterator I = PkgBegin(); I.end() != true; I++) | |
695 | { | |
696 | // The package will install OK | |
697 | if ((PkgState[I->ID].DepState & DepInstMin) == DepInstMin) | |
698 | continue; | |
699 | ||
700 | /* The package was broken before and this upgrade will not | |
701 | make things better. We simply mark the package for keep | |
702 | and assume an upgrade attempt will be hopeless. This might | |
703 | not be ideal. */ | |
704 | if ((Touched[I->ID] & (1 << 0)) != (1 << 0)) | |
705 | { | |
706 | // The package isnt to be touched | |
707 | if ((Touched[I->ID] & (1 << 1)) == (1 << 1)) | |
708 | MarkKeep(I,true); | |
709 | ||
710 | continue; | |
711 | } | |
712 | ||
713 | // Check to see if not upgrading it will solve the problem | |
714 | if (I->CurrentVer != 0) | |
715 | { | |
716 | // The package isnt to be touched | |
717 | if ((Touched[I->ID] & (1 << 1)) == (1 << 1)) | |
718 | { | |
719 | if (PkgState[I->ID].Mode != ModeKeep) | |
720 | Again = true; | |
721 | ||
722 | MarkKeep(I,true); | |
723 | } | |
724 | ||
725 | /* Check if the package is sill broken. If so then we cant leave | |
726 | it as is and get a working system. Lets try marking some | |
727 | depends for 'keep'. This is brutal, it keeps everything in | |
728 | sight to fix the problem. */ | |
729 | DepIterator D = I.CurrentVer().DependsList(); | |
730 | for (;(PkgState[I->ID].DepState & DepInstMin) != DepInstMin && | |
731 | D.end() != true; D++) | |
732 | { | |
733 | // We only worry about critical deps. | |
734 | if (D.IsCritical() != true) | |
735 | continue; | |
736 | ||
737 | unsigned char State = DepState[D->ID]; | |
738 | ||
739 | // This dep never was set before so we dont need to set it now | |
740 | if ((State & DepNow) != DepNow) | |
741 | continue; | |
742 | ||
743 | // The dep is okay now no worries. | |
744 | if ((State & DepInstall) == DepInstall) | |
745 | continue; | |
746 | ||
747 | // Locate a target to keep | |
748 | PkgIterator P(*this); | |
749 | if (CheckDep(D,NowVersion,P) == true) | |
750 | { | |
751 | // We cant touch this package | |
752 | if ((Touched[P->ID] & (1 << 1)) == (1 << 1)) | |
753 | MarkKeep(P,true); | |
754 | } | |
755 | } | |
756 | } | |
757 | } | |
758 | } | |
759 | while (Again == true); | |
760 | } | |
761 | /*}}}*/ | |
762 | // DepCache::PromoteAutoKeep - Gentler version of the above /*{{{*/ | |
763 | // --------------------------------------------------------------------- | |
764 | /* This is used when installing packages, all it does is attempt to promote | |
765 | everything that has been auto-kept. It simply promotes everything | |
766 | irregardless of it having a chance to work and then runs ResolveConflicts | |
767 | on the result. This allows circular depends loops to work but isn't | |
768 | terribly fast. */ | |
769 | void pkgDepCache::PromoteAutoKeep() | |
770 | { | |
771 | /* Initialize the touchd array. Bit 0 is the old install state bit 1 | |
772 | is the touch value */ | |
773 | unsigned char *Touch = new unsigned char[Head().PackageCount]; | |
774 | for (unsigned int I = 0; I != Head().PackageCount; I++) | |
775 | { | |
776 | if ((PkgState[I].DepState & DepInstMin) == DepInstMin) | |
777 | Touch[I] = 1 << 0; | |
778 | else | |
779 | Touch[I] = 0; | |
780 | } | |
781 | ||
782 | // This allows circular depends to work | |
783 | for (PkgIterator I = PkgBegin(); I.end() != true; I++) | |
784 | { | |
785 | /* It wasnt installed before or it is not autokept or it is not | |
786 | upgradeable */ | |
787 | StateCache &P = PkgState[I->ID]; | |
788 | if (I->CurrentVer == 0 || P.Mode != ModeKeep || I->VersionList == 0 || | |
789 | P.CandidateVer == (Version *)I.CurrentVer() || | |
790 | (P.iFlags & AutoKept) != AutoKept) | |
791 | continue; | |
792 | ||
793 | P.Mode = ModeInstall; | |
794 | P.InstallVer = P.CandidateVer; | |
795 | if (P.CandidateVer == (Version *)I.CurrentVer()) | |
796 | P.Mode = ModeKeep; | |
797 | ||
798 | // Okay autoupgrade it. | |
799 | Touch[I->ID] |= 1 << 1; | |
800 | } | |
801 | ||
802 | Update(); | |
803 | ResolveConflicts(Touch); | |
804 | ||
805 | delete [] Touch; | |
806 | } | |
807 | /*}}}*/ | |
808 | // DepCache::AllUpgrade - Try to upgrade everything /*{{{*/ | |
809 | // --------------------------------------------------------------------- | |
810 | /* */ | |
811 | void pkgDepCache::AllUpgrade() | |
812 | { | |
813 | // Set everything to an upgrade mode | |
814 | for (PkgIterator I = PkgBegin(); I.end() != true; I++) | |
815 | { | |
816 | StateCache &State = PkgState[I->ID]; | |
817 | ||
818 | /* We dont upgrade packages marked for deletion or that are | |
819 | not installed or that don't have an upgrade */ | |
820 | if (State.Mode == ModeDelete || I->CurrentVer == 0 || | |
821 | (Version *)I.CurrentVer() == State.CandidateVer) | |
822 | continue; | |
823 | ||
824 | // Set the state to upgrade | |
825 | State.iFlags = 0; | |
826 | State.Mode = ModeInstall; | |
827 | State.InstallVer = State.CandidateVer; | |
828 | if (State.CandidateVer == (Version *)I.CurrentVer()) | |
829 | State.Mode = ModeKeep; | |
830 | ||
831 | // Do not upgrade things that have the hold flag set. | |
832 | if (I->SelectedState == State::Hold) | |
833 | { | |
834 | State.InstallVer = I.CurrentVer(); | |
835 | State.Mode = ModeKeep; | |
836 | } | |
837 | State.Update(I,*this); | |
838 | } | |
839 | ||
840 | Update(); | |
841 | ||
842 | /* Initialize the touchd array. Bit 0 is the old install state bit 1 | |
843 | is the touch value */ | |
844 | unsigned char *Touch = new unsigned char[Head().PackageCount]; | |
845 | for (unsigned int I = 0; I != Head().PackageCount; I++) | |
846 | { | |
847 | if ((PkgState[I].DepState & DepNowMin) == DepNowMin) | |
848 | Touch[I] = (1 << 0) | (1 << 1); | |
849 | else | |
850 | Touch[I] = 1 << 1; | |
851 | } | |
852 | ||
853 | // Now downgrade everything that is broken | |
854 | ResolveConflicts(Touch); | |
855 | delete [] Touch; | |
856 | } | |
857 | /*}}}*/ | |
858 | #endif | |
859 | ||
860 | // StateCache::Update - Compute the various static display things /*{{{*/ | |
861 | // --------------------------------------------------------------------- | |
862 | /* This is called whenever the Candidate version changes. */ | |
863 | void pkgDepCache::StateCache::Update(PkgIterator Pkg,pkgCache &Cache) | |
864 | { | |
865 | // Some info | |
866 | VerIterator Ver = CandidateVerIter(Cache); | |
867 | ||
868 | // Use a null string or the version string | |
869 | if (Ver.end() == true) | |
870 | CandVersion = ""; | |
871 | else | |
872 | CandVersion = Ver.VerStr(); | |
873 | ||
874 | // Find the current version | |
875 | CurVersion = ""; | |
876 | if (Pkg->CurrentVer != 0) | |
877 | CurVersion = Pkg.CurrentVer().VerStr(); | |
878 | ||
879 | // Strip off the epochs for display | |
880 | CurVersion = StripEpoch(CurVersion); | |
881 | CandVersion = StripEpoch(CandVersion); | |
882 | ||
883 | // Figure out if its up or down or equal | |
884 | Status = Ver.CompareVer(Pkg.CurrentVer()); | |
885 | if (Pkg->CurrentVer == 0 || Pkg->VersionList == 0 || CandidateVer == 0) | |
886 | Status = 2; | |
887 | } | |
888 | /*}}}*/ | |
889 | // StateCache::StripEpoch - Remove the epoch specifier from the version /*{{{*/ | |
890 | // --------------------------------------------------------------------- | |
891 | /* */ | |
892 | const char *pkgDepCache::StateCache::StripEpoch(const char *Ver) | |
893 | { | |
894 | if (Ver == 0) | |
895 | return 0; | |
896 | ||
897 | // Strip any epoch | |
898 | for (const char *I = Ver; *I != 0; I++) | |
899 | if (*I == ':') | |
900 | return I + 1; | |
901 | return Ver; | |
902 | } | |
903 | /*}}}*/ |