]>
Commit | Line | Data |
---|---|---|
6c139d6e AL |
1 | // -*- mode: cpp; mode: fold -*- |
2 | // Description /*{{{*/ | |
b9c0654c | 3 | // $Id: packagemanager.cc,v 1.30 2003/04/27 03:04:15 doogie Exp $ |
6c139d6e AL |
4 | /* ###################################################################### |
5 | ||
6 | Package Manager - Abstacts the package manager | |
7 | ||
8 | More work is needed in the area of transitioning provides, ie exim | |
9 | replacing smail. This can cause interesing side effects. | |
10 | ||
11 | Other cases involving conflicts+replaces should be tested. | |
12 | ||
13 | ##################################################################### */ | |
14 | /*}}}*/ | |
15 | // Include Files /*{{{*/ | |
16 | #ifdef __GNUG__ | |
094a497d | 17 | #pragma implementation "apt-pkg/packagemanager.h" |
6c139d6e | 18 | #endif |
b2e465d6 | 19 | |
094a497d AL |
20 | #include <apt-pkg/packagemanager.h> |
21 | #include <apt-pkg/orderlist.h> | |
22 | #include <apt-pkg/depcache.h> | |
23 | #include <apt-pkg/error.h> | |
24 | #include <apt-pkg/version.h> | |
03e39e59 | 25 | #include <apt-pkg/acquire-item.h> |
30e1eab5 AL |
26 | #include <apt-pkg/algorithms.h> |
27 | #include <apt-pkg/configuration.h> | |
b2e465d6 AL |
28 | #include <apt-pkg/sptr.h> |
29 | ||
30 | #include <apti18n.h> | |
5819a761 | 31 | #include <iostream> |
6c139d6e AL |
32 | /*}}}*/ |
33 | ||
5819a761 AL |
34 | using namespace std; |
35 | ||
6c139d6e AL |
36 | // PM::PackageManager - Constructor /*{{{*/ |
37 | // --------------------------------------------------------------------- | |
38 | /* */ | |
b2e465d6 | 39 | pkgPackageManager::pkgPackageManager(pkgDepCache *pCache) : Cache(*pCache) |
6c139d6e AL |
40 | { |
41 | FileNames = new string[Cache.Head().PackageCount]; | |
42 | List = 0; | |
30e1eab5 | 43 | Debug = _config->FindB("Debug::pkgPackageManager",false); |
6c139d6e AL |
44 | } |
45 | /*}}}*/ | |
46 | // PM::PackageManager - Destructor /*{{{*/ | |
47 | // --------------------------------------------------------------------- | |
48 | /* */ | |
49 | pkgPackageManager::~pkgPackageManager() | |
50 | { | |
51 | delete List; | |
52 | delete [] FileNames; | |
53 | } | |
54 | /*}}}*/ | |
03e39e59 AL |
55 | // PM::GetArchives - Queue the archives for download /*{{{*/ |
56 | // --------------------------------------------------------------------- | |
57 | /* */ | |
58 | bool pkgPackageManager::GetArchives(pkgAcquire *Owner,pkgSourceList *Sources, | |
59 | pkgRecords *Recs) | |
60 | { | |
7a1b1f8b AL |
61 | if (CreateOrderList() == false) |
62 | return false; | |
63 | ||
64 | if (List->OrderUnpack() == false) | |
65 | return _error->Error("Internal ordering error"); | |
66 | ||
67 | for (pkgOrderList::iterator I = List->begin(); I != List->end(); I++) | |
68 | { | |
69 | PkgIterator Pkg(Cache,*I); | |
281daf46 AL |
70 | FileNames[Pkg->ID] = string(); |
71 | ||
7a1b1f8b AL |
72 | // Skip packages to erase |
73 | if (Cache[Pkg].Delete() == true) | |
03e39e59 | 74 | continue; |
d38b7b3d AL |
75 | |
76 | // Skip Packages that need configure only. | |
9dbb421f AL |
77 | if (Pkg.State() == pkgCache::PkgIterator::NeedsConfigure && |
78 | Cache[Pkg].Keep() == true) | |
d38b7b3d | 79 | continue; |
281daf46 AL |
80 | |
81 | // Skip already processed packages | |
82 | if (List->IsNow(Pkg) == false) | |
83 | continue; | |
84 | ||
7a1b1f8b AL |
85 | new pkgAcqArchive(Owner,Sources,Recs,Cache[Pkg].InstVerIter(Cache), |
86 | FileNames[Pkg->ID]); | |
03e39e59 | 87 | } |
7a1b1f8b | 88 | |
03e39e59 AL |
89 | return true; |
90 | } | |
91 | /*}}}*/ | |
6c139d6e AL |
92 | // PM::FixMissing - Keep all missing packages /*{{{*/ |
93 | // --------------------------------------------------------------------- | |
94 | /* This is called to correct the installation when packages could not | |
95 | be downloaded. */ | |
96 | bool pkgPackageManager::FixMissing() | |
bdae53f1 | 97 | { |
e6756cde | 98 | pkgDepCache::ActionGroup group(Cache); |
b2e465d6 | 99 | pkgProblemResolver Resolve(&Cache); |
2fd65468 | 100 | List->SetFileList(FileNames); |
e6756cde | 101 | |
9dbb421f | 102 | bool Bad = false; |
6c139d6e AL |
103 | for (PkgIterator I = Cache.PkgBegin(); I.end() == false; I++) |
104 | { | |
2fd65468 | 105 | if (List->IsMissing(I) == false) |
9dbb421f | 106 | continue; |
2fd65468 | 107 | |
9dbb421f AL |
108 | // Okay, this file is missing and we need it. Mark it for keep |
109 | Bad = true; | |
74a05226 | 110 | Cache.MarkKeep(I, false, false); |
6c139d6e | 111 | } |
bdae53f1 AL |
112 | |
113 | // We have to empty the list otherwise it will not have the new changes | |
114 | delete List; | |
115 | List = 0; | |
6c139d6e | 116 | |
9dbb421f AL |
117 | if (Bad == false) |
118 | return true; | |
119 | ||
6c139d6e | 120 | // Now downgrade everything that is broken |
30e1eab5 | 121 | return Resolve.ResolveByKeep() == true && Cache.BrokenCount() == 0; |
6c139d6e AL |
122 | } |
123 | /*}}}*/ | |
124 | ||
7a1b1f8b AL |
125 | // PM::CreateOrderList - Create the ordering class /*{{{*/ |
126 | // --------------------------------------------------------------------- | |
127 | /* This populates the ordering list with all the packages that are | |
128 | going to change. */ | |
129 | bool pkgPackageManager::CreateOrderList() | |
130 | { | |
281daf46 AL |
131 | if (List != 0) |
132 | return true; | |
133 | ||
7a1b1f8b | 134 | delete List; |
b2e465d6 | 135 | List = new pkgOrderList(&Cache); |
7a1b1f8b | 136 | |
b9c0654c | 137 | bool NoImmConfigure = !_config->FindB("APT::Immediate-Configure",true); |
079cc404 | 138 | |
7a1b1f8b AL |
139 | // Generate the list of affected packages and sort it |
140 | for (PkgIterator I = Cache.PkgBegin(); I.end() == false; I++) | |
141 | { | |
e7b470ee AL |
142 | // Ignore no-version packages |
143 | if (I->VersionList == 0) | |
144 | continue; | |
145 | ||
138d4b3d AL |
146 | // Mark the package and its dependends for immediate configuration |
147 | if (((I->Flags & pkgCache::Flag::Essential) == pkgCache::Flag::Essential || | |
148 | (I->Flags & pkgCache::Flag::Important) == pkgCache::Flag::Important) && | |
079cc404 | 149 | NoImmConfigure == false) |
7a1b1f8b AL |
150 | { |
151 | List->Flag(I,pkgOrderList::Immediate); | |
d38b7b3d AL |
152 | |
153 | // Look for other packages to make immediate configurea | |
7a1b1f8b AL |
154 | if (Cache[I].InstallVer != 0) |
155 | for (DepIterator D = Cache[I].InstVerIter(Cache).DependsList(); | |
156 | D.end() == false; D++) | |
157 | if (D->Type == pkgCache::Dep::Depends || D->Type == pkgCache::Dep::PreDepends) | |
158 | List->Flag(D.TargetPkg(),pkgOrderList::Immediate); | |
d38b7b3d AL |
159 | |
160 | // And again with the current version. | |
7a1b1f8b AL |
161 | if (I->CurrentVer != 0) |
162 | for (DepIterator D = I.CurrentVer().DependsList(); | |
163 | D.end() == false; D++) | |
164 | if (D->Type == pkgCache::Dep::Depends || D->Type == pkgCache::Dep::PreDepends) | |
165 | List->Flag(D.TargetPkg(),pkgOrderList::Immediate); | |
166 | } | |
167 | ||
168 | // Not interesting | |
169 | if ((Cache[I].Keep() == true || | |
170 | Cache[I].InstVerIter(Cache) == I.CurrentVer()) && | |
d556d1a1 | 171 | I.State() == pkgCache::PkgIterator::NeedsNothing && |
d0c59649 | 172 | (Cache[I].iFlags & pkgDepCache::ReInstall) != pkgDepCache::ReInstall && |
d556d1a1 AL |
173 | (I.Purge() != false || Cache[I].Mode != pkgDepCache::ModeDelete || |
174 | (Cache[I].iFlags & pkgDepCache::Purge) != pkgDepCache::Purge)) | |
7a1b1f8b AL |
175 | continue; |
176 | ||
177 | // Append it to the list | |
138d4b3d | 178 | List->push_back(I); |
7a1b1f8b AL |
179 | } |
180 | ||
181 | return true; | |
182 | } | |
183 | /*}}}*/ | |
6c139d6e AL |
184 | // PM::DepAlwaysTrue - Returns true if this dep is irrelevent /*{{{*/ |
185 | // --------------------------------------------------------------------- | |
186 | /* The restriction on provides is to eliminate the case when provides | |
187 | are transitioning between valid states [ie exim to smail] */ | |
188 | bool pkgPackageManager::DepAlwaysTrue(DepIterator D) | |
189 | { | |
190 | if (D.TargetPkg()->ProvidesList != 0) | |
191 | return false; | |
192 | ||
193 | if ((Cache[D] & pkgDepCache::DepInstall) != 0 && | |
194 | (Cache[D] & pkgDepCache::DepNow) != 0) | |
195 | return true; | |
196 | return false; | |
197 | } | |
198 | /*}}}*/ | |
199 | // PM::CheckRConflicts - Look for reverse conflicts /*{{{*/ | |
200 | // --------------------------------------------------------------------- | |
201 | /* This looks over the reverses for a conflicts line that needs early | |
202 | removal. */ | |
203 | bool pkgPackageManager::CheckRConflicts(PkgIterator Pkg,DepIterator D, | |
204 | const char *Ver) | |
205 | { | |
206 | for (;D.end() == false; D++) | |
207 | { | |
b2e465d6 AL |
208 | if (D->Type != pkgCache::Dep::Conflicts && |
209 | D->Type != pkgCache::Dep::Obsoletes) | |
6c139d6e | 210 | continue; |
5af32db6 AL |
211 | |
212 | // The package hasnt been changed | |
213 | if (List->IsNow(Pkg) == false) | |
214 | continue; | |
6c139d6e | 215 | |
5af32db6 AL |
216 | // Ignore self conflicts, ignore conflicts from irrelevent versions |
217 | if (D.ParentPkg() == Pkg || D.ParentVer() != D.ParentPkg().CurrentVer()) | |
6c139d6e AL |
218 | continue; |
219 | ||
b2e465d6 | 220 | if (Cache.VS().CheckDep(Ver,D->CompareOp,D.TargetVer()) == false) |
6c139d6e | 221 | continue; |
b2e465d6 | 222 | |
6c139d6e | 223 | if (EarlyRemove(D.ParentPkg()) == false) |
5af32db6 AL |
224 | return _error->Error("Reverse conflicts early remove for package '%s' failed", |
225 | Pkg.Name()); | |
226 | } | |
6c139d6e AL |
227 | return true; |
228 | } | |
229 | /*}}}*/ | |
230 | // PM::ConfigureAll - Run the all out configuration /*{{{*/ | |
231 | // --------------------------------------------------------------------- | |
232 | /* This configures every package. It is assumed they are all unpacked and | |
233 | that the final configuration is valid. */ | |
234 | bool pkgPackageManager::ConfigureAll() | |
235 | { | |
b2e465d6 | 236 | pkgOrderList OList(&Cache); |
6c139d6e AL |
237 | |
238 | // Populate the order list | |
239 | for (pkgOrderList::iterator I = List->begin(); I != List->end(); I++) | |
240 | if (List->IsFlag(pkgCache::PkgIterator(Cache,*I), | |
241 | pkgOrderList::UnPacked) == true) | |
242 | OList.push_back(*I); | |
243 | ||
244 | if (OList.OrderConfigure() == false) | |
245 | return false; | |
246 | ||
247 | // Perform the configuring | |
248 | for (pkgOrderList::iterator I = OList.begin(); I != OList.end(); I++) | |
249 | { | |
250 | PkgIterator Pkg(Cache,*I); | |
251 | ||
252 | if (Configure(Pkg) == false) | |
253 | return false; | |
254 | ||
255 | List->Flag(Pkg,pkgOrderList::Configured,pkgOrderList::States); | |
256 | } | |
257 | ||
258 | return true; | |
259 | } | |
260 | /*}}}*/ | |
261 | // PM::SmartConfigure - Perform immediate configuration of the pkg /*{{{*/ | |
262 | // --------------------------------------------------------------------- | |
263 | /* This routine scheduals the configuration of the given package and all | |
264 | of it's dependents. */ | |
265 | bool pkgPackageManager::SmartConfigure(PkgIterator Pkg) | |
266 | { | |
b2e465d6 | 267 | pkgOrderList OList(&Cache); |
6c139d6e AL |
268 | |
269 | if (DepAdd(OList,Pkg) == false) | |
270 | return false; | |
271 | ||
272 | if (OList.OrderConfigure() == false) | |
273 | return false; | |
b2e465d6 | 274 | |
6c139d6e AL |
275 | // Perform the configuring |
276 | for (pkgOrderList::iterator I = OList.begin(); I != OList.end(); I++) | |
277 | { | |
278 | PkgIterator Pkg(Cache,*I); | |
279 | ||
280 | if (Configure(Pkg) == false) | |
281 | return false; | |
282 | ||
283 | List->Flag(Pkg,pkgOrderList::Configured,pkgOrderList::States); | |
284 | } | |
285 | ||
286 | // Sanity Check | |
287 | if (List->IsFlag(Pkg,pkgOrderList::Configured) == false) | |
288 | return _error->Error("Internal error, could not immediate configure %s",Pkg.Name()); | |
289 | ||
290 | return true; | |
291 | } | |
292 | /*}}}*/ | |
293 | // PM::DepAdd - Add all dependents to the oder list /*{{{*/ | |
294 | // --------------------------------------------------------------------- | |
295 | /* This recursively adds all dependents to the order list */ | |
296 | bool pkgPackageManager::DepAdd(pkgOrderList &OList,PkgIterator Pkg,int Depth) | |
297 | { | |
298 | if (OList.IsFlag(Pkg,pkgOrderList::Added) == true) | |
299 | return true; | |
300 | if (List->IsFlag(Pkg,pkgOrderList::Configured) == true) | |
301 | return true; | |
302 | if (List->IsFlag(Pkg,pkgOrderList::UnPacked) == false) | |
303 | return false; | |
b2e465d6 | 304 | |
6c139d6e AL |
305 | // Put the package on the list |
306 | OList.push_back(Pkg); | |
307 | OList.Flag(Pkg,pkgOrderList::Added); | |
308 | Depth++; | |
309 | ||
310 | // Check the dependencies to see if they are all satisfied. | |
311 | bool Bad = false; | |
312 | for (DepIterator D = Cache[Pkg].InstVerIter(Cache).DependsList(); D.end() == false;) | |
313 | { | |
b50b2c97 | 314 | if (D->Type != pkgCache::Dep::Depends && D->Type != pkgCache::Dep::PreDepends) |
6c139d6e AL |
315 | { |
316 | D++; | |
317 | continue; | |
318 | } | |
319 | ||
320 | // Grok or groups | |
321 | Bad = true; | |
322 | for (bool LastOR = true; D.end() == false && LastOR == true; D++) | |
323 | { | |
b50b2c97 | 324 | LastOR = (D->CompareOp & pkgCache::Dep::Or) == pkgCache::Dep::Or; |
6c139d6e AL |
325 | |
326 | if (Bad == false) | |
327 | continue; | |
328 | ||
b2e465d6 | 329 | SPtrArray<Version *> VList = D.AllTargets(); |
6c139d6e AL |
330 | for (Version **I = VList; *I != 0 && Bad == true; I++) |
331 | { | |
332 | VerIterator Ver(Cache,*I); | |
333 | PkgIterator Pkg = Ver.ParentPkg(); | |
334 | ||
335 | // See if the current version is ok | |
336 | if (Pkg.CurrentVer() == Ver && List->IsNow(Pkg) == true && | |
337 | Pkg.State() == PkgIterator::NeedsNothing) | |
338 | { | |
339 | Bad = false; | |
340 | continue; | |
341 | } | |
342 | ||
343 | // Not the install version | |
344 | if (Cache[Pkg].InstallVer != *I || | |
345 | (Cache[Pkg].Keep() == true && Pkg.State() == PkgIterator::NeedsNothing)) | |
346 | continue; | |
b2e465d6 | 347 | |
6c139d6e AL |
348 | if (List->IsFlag(Pkg,pkgOrderList::UnPacked) == true) |
349 | Bad = !DepAdd(OList,Pkg,Depth); | |
350 | if (List->IsFlag(Pkg,pkgOrderList::Configured) == true) | |
351 | Bad = false; | |
352 | } | |
6c139d6e AL |
353 | } |
354 | ||
355 | if (Bad == true) | |
356 | { | |
357 | OList.Flag(Pkg,0,pkgOrderList::Added); | |
358 | OList.pop_back(); | |
359 | Depth--; | |
360 | return false; | |
361 | } | |
362 | } | |
363 | ||
364 | Depth--; | |
365 | return true; | |
366 | } | |
367 | /*}}}*/ | |
368 | // PM::EarlyRemove - Perform removal of packages before their time /*{{{*/ | |
369 | // --------------------------------------------------------------------- | |
370 | /* This is called to deal with conflicts arising from unpacking */ | |
371 | bool pkgPackageManager::EarlyRemove(PkgIterator Pkg) | |
372 | { | |
373 | if (List->IsNow(Pkg) == false) | |
374 | return true; | |
375 | ||
376 | // Already removed it | |
377 | if (List->IsFlag(Pkg,pkgOrderList::Removed) == true) | |
378 | return true; | |
379 | ||
380 | // Woops, it will not be re-installed! | |
381 | if (List->IsFlag(Pkg,pkgOrderList::InList) == false) | |
382 | return false; | |
9d4c8f67 AL |
383 | |
384 | // Essential packages get special treatment | |
5af32db6 | 385 | bool IsEssential = false; |
9d4c8f67 | 386 | if ((Pkg->Flags & pkgCache::Flag::Essential) != 0) |
5af32db6 AL |
387 | IsEssential = true; |
388 | ||
389 | /* Check for packages that are the dependents of essential packages and | |
390 | promote them too */ | |
391 | if (Pkg->CurrentVer != 0) | |
392 | { | |
393 | for (DepIterator D = Pkg.RevDependsList(); D.end() == false && | |
394 | IsEssential == false; D++) | |
395 | if (D->Type == pkgCache::Dep::Depends || D->Type == pkgCache::Dep::PreDepends) | |
396 | if ((D.ParentPkg()->Flags & pkgCache::Flag::Essential) != 0) | |
397 | IsEssential = true; | |
398 | } | |
399 | ||
400 | if (IsEssential == true) | |
9d4c8f67 AL |
401 | { |
402 | if (_config->FindB("APT::Force-LoopBreak",false) == false) | |
b2e465d6 AL |
403 | return _error->Error(_("This installation run will require temporarily " |
404 | "removing the essential package %s due to a " | |
405 | "Conflicts/Pre-Depends loop. This is often bad, " | |
406 | "but if you really want to do it, activate the " | |
407 | "APT::Force-LoopBreak option."),Pkg.Name()); | |
9d4c8f67 | 408 | } |
6c139d6e AL |
409 | |
410 | bool Res = SmartRemove(Pkg); | |
411 | if (Cache[Pkg].Delete() == false) | |
412 | List->Flag(Pkg,pkgOrderList::Removed,pkgOrderList::States); | |
413 | ||
414 | return Res; | |
415 | } | |
416 | /*}}}*/ | |
417 | // PM::SmartRemove - Removal Helper /*{{{*/ | |
418 | // --------------------------------------------------------------------- | |
419 | /* */ | |
420 | bool pkgPackageManager::SmartRemove(PkgIterator Pkg) | |
421 | { | |
422 | if (List->IsNow(Pkg) == false) | |
423 | return true; | |
424 | ||
425 | List->Flag(Pkg,pkgOrderList::Configured,pkgOrderList::States); | |
fc4b5c9f | 426 | return Remove(Pkg,(Cache[Pkg].iFlags & pkgDepCache::Purge) == pkgDepCache::Purge); |
6c139d6e AL |
427 | } |
428 | /*}}}*/ | |
429 | // PM::SmartUnPack - Install helper /*{{{*/ | |
430 | // --------------------------------------------------------------------- | |
431 | /* This performs the task of handling pre-depends. */ | |
432 | bool pkgPackageManager::SmartUnPack(PkgIterator Pkg) | |
433 | { | |
434 | // Check if it is already unpacked | |
435 | if (Pkg.State() == pkgCache::PkgIterator::NeedsConfigure && | |
436 | Cache[Pkg].Keep() == true) | |
437 | { | |
438 | List->Flag(Pkg,pkgOrderList::UnPacked,pkgOrderList::States); | |
439 | if (List->IsFlag(Pkg,pkgOrderList::Immediate) == true) | |
440 | if (SmartConfigure(Pkg) == false) | |
b2e465d6 | 441 | return _error->Error("Internal Error, Could not perform immediate configuration (1) on %s",Pkg.Name()); |
6c139d6e AL |
442 | return true; |
443 | } | |
981d20eb | 444 | |
6c139d6e AL |
445 | /* See if this packages install version has any predependencies |
446 | that are not met by 'now' packages. */ | |
447 | for (DepIterator D = Cache[Pkg].InstVerIter(Cache).DependsList(); | |
421c8d10 | 448 | D.end() == false; ) |
6c139d6e | 449 | { |
421c8d10 AL |
450 | // Compute a single dependency element (glob or) |
451 | pkgCache::DepIterator Start; | |
452 | pkgCache::DepIterator End; | |
453 | D.GlobOr(Start,End); | |
454 | ||
455 | while (End->Type == pkgCache::Dep::PreDepends) | |
6c139d6e AL |
456 | { |
457 | // Look for possible ok targets. | |
b2e465d6 | 458 | SPtrArray<Version *> VList = Start.AllTargets(); |
6c139d6e AL |
459 | bool Bad = true; |
460 | for (Version **I = VList; *I != 0 && Bad == true; I++) | |
461 | { | |
462 | VerIterator Ver(Cache,*I); | |
463 | PkgIterator Pkg = Ver.ParentPkg(); | |
464 | ||
465 | // See if the current version is ok | |
466 | if (Pkg.CurrentVer() == Ver && List->IsNow(Pkg) == true && | |
467 | Pkg.State() == PkgIterator::NeedsNothing) | |
468 | { | |
469 | Bad = false; | |
470 | continue; | |
471 | } | |
472 | } | |
473 | ||
474 | // Look for something that could be configured. | |
475 | for (Version **I = VList; *I != 0 && Bad == true; I++) | |
476 | { | |
477 | VerIterator Ver(Cache,*I); | |
478 | PkgIterator Pkg = Ver.ParentPkg(); | |
479 | ||
480 | // Not the install version | |
481 | if (Cache[Pkg].InstallVer != *I || | |
482 | (Cache[Pkg].Keep() == true && Pkg.State() == PkgIterator::NeedsNothing)) | |
483 | continue; | |
484 | ||
485 | Bad = !SmartConfigure(Pkg); | |
486 | } | |
1006601e | 487 | |
421c8d10 | 488 | /* If this or element did not match then continue on to the |
1006601e | 489 | next or element until a matching element is found */ |
421c8d10 | 490 | if (Bad == true) |
1006601e AL |
491 | { |
492 | // This triggers if someone make a pre-depends/depend loop. | |
421c8d10 | 493 | if (Start == End) |
1006601e AL |
494 | return _error->Error("Couldn't configure pre-depend %s for %s, " |
495 | "probably a dependency cycle.", | |
496 | End.TargetPkg().Name(),Pkg.Name()); | |
421c8d10 AL |
497 | Start++; |
498 | } | |
499 | else | |
500 | break; | |
6c139d6e AL |
501 | } |
502 | ||
b2e465d6 AL |
503 | if (End->Type == pkgCache::Dep::Conflicts || |
504 | End->Type == pkgCache::Dep::Obsoletes) | |
6c139d6e AL |
505 | { |
506 | /* Look for conflicts. Two packages that are both in the install | |
507 | state cannot conflict so we don't check.. */ | |
b2e465d6 | 508 | SPtrArray<Version *> VList = End.AllTargets(); |
6c139d6e AL |
509 | for (Version **I = VList; *I != 0; I++) |
510 | { | |
511 | VerIterator Ver(Cache,*I); | |
512 | PkgIterator Pkg = Ver.ParentPkg(); | |
513 | ||
514 | // See if the current version is conflicting | |
515 | if (Pkg.CurrentVer() == Ver && List->IsNow(Pkg) == true) | |
516 | { | |
517 | if (EarlyRemove(Pkg) == false) | |
518 | return _error->Error("Internal Error, Could not early remove %s",Pkg.Name()); | |
519 | } | |
520 | } | |
6c139d6e AL |
521 | } |
522 | } | |
523 | ||
524 | // Check for reverse conflicts. | |
5af32db6 AL |
525 | if (CheckRConflicts(Pkg,Pkg.RevDependsList(), |
526 | Cache[Pkg].InstVerIter(Cache).VerStr()) == false) | |
527 | return false; | |
528 | ||
6c139d6e AL |
529 | for (PrvIterator P = Cache[Pkg].InstVerIter(Cache).ProvidesList(); |
530 | P.end() == false; P++) | |
531 | CheckRConflicts(Pkg,P.ParentPkg().RevDependsList(),P.ProvideVersion()); | |
532 | ||
533 | if (Install(Pkg,FileNames[Pkg->ID]) == false) | |
534 | return false; | |
535 | ||
536 | List->Flag(Pkg,pkgOrderList::UnPacked,pkgOrderList::States); | |
537 | ||
538 | // Perform immedate configuration of the package. | |
539 | if (List->IsFlag(Pkg,pkgOrderList::Immediate) == true) | |
540 | if (SmartConfigure(Pkg) == false) | |
b2e465d6 | 541 | return _error->Error("Internal Error, Could not perform immediate configuration (2) on %s",Pkg.Name()); |
6c139d6e AL |
542 | |
543 | return true; | |
544 | } | |
545 | /*}}}*/ | |
546 | // PM::OrderInstall - Installation ordering routine /*{{{*/ | |
547 | // --------------------------------------------------------------------- | |
548 | /* */ | |
281daf46 | 549 | pkgPackageManager::OrderResult pkgPackageManager::OrderInstall() |
6c139d6e | 550 | { |
7a1b1f8b | 551 | if (CreateOrderList() == false) |
281daf46 AL |
552 | return Failed; |
553 | ||
554 | Reset(); | |
6c139d6e | 555 | |
30e1eab5 AL |
556 | if (Debug == true) |
557 | clog << "Begining to order" << endl; | |
6c139d6e | 558 | |
281daf46 AL |
559 | if (List->OrderUnpack(FileNames) == false) |
560 | { | |
561 | _error->Error("Internal ordering error"); | |
562 | return Failed; | |
563 | } | |
564 | ||
30e1eab5 AL |
565 | if (Debug == true) |
566 | clog << "Done ordering" << endl; | |
567 | ||
281daf46 | 568 | bool DoneSomething = false; |
6c139d6e AL |
569 | for (pkgOrderList::iterator I = List->begin(); I != List->end(); I++) |
570 | { | |
571 | PkgIterator Pkg(Cache,*I); | |
281daf46 AL |
572 | |
573 | if (List->IsNow(Pkg) == false) | |
574 | { | |
575 | if (Debug == true) | |
576 | clog << "Skipping already done " << Pkg.Name() << endl; | |
577 | continue; | |
578 | } | |
579 | ||
2fd65468 | 580 | if (List->IsMissing(Pkg) == true) |
281daf46 AL |
581 | { |
582 | if (Debug == true) | |
a3eaf954 | 583 | clog << "Sequence completed at " << Pkg.Name() << endl; |
281daf46 AL |
584 | if (DoneSomething == false) |
585 | { | |
586 | _error->Error("Internal Error, ordering was unable to handle the media swap"); | |
587 | return Failed; | |
588 | } | |
589 | return Incomplete; | |
590 | } | |
6c139d6e AL |
591 | |
592 | // Sanity check | |
d0c59649 AL |
593 | if (Cache[Pkg].Keep() == true && |
594 | Pkg.State() == pkgCache::PkgIterator::NeedsNothing && | |
595 | (Cache[Pkg].iFlags & pkgDepCache::ReInstall) != pkgDepCache::ReInstall) | |
281daf46 | 596 | { |
71a174ee | 597 | _error->Error("Internal Error, trying to manipulate a kept package (%s)",Pkg.Name()); |
281daf46 AL |
598 | return Failed; |
599 | } | |
6c139d6e AL |
600 | |
601 | // Perform a delete or an install | |
602 | if (Cache[Pkg].Delete() == true) | |
603 | { | |
604 | if (SmartRemove(Pkg) == false) | |
281daf46 | 605 | return Failed; |
6c139d6e AL |
606 | } |
607 | else | |
608 | if (SmartUnPack(Pkg) == false) | |
281daf46 AL |
609 | return Failed; |
610 | DoneSomething = true; | |
6c139d6e AL |
611 | } |
612 | ||
613 | // Final run through the configure phase | |
614 | if (ConfigureAll() == false) | |
281daf46 | 615 | return Failed; |
6c139d6e AL |
616 | |
617 | // Sanity check | |
618 | for (pkgOrderList::iterator I = List->begin(); I != List->end(); I++) | |
281daf46 | 619 | { |
6c139d6e | 620 | if (List->IsFlag(*I,pkgOrderList::Configured) == false) |
281daf46 AL |
621 | { |
622 | _error->Error("Internal error, packages left unconfigured. %s", | |
623 | PkgIterator(Cache,*I).Name()); | |
624 | return Failed; | |
625 | } | |
626 | } | |
627 | ||
628 | return Completed; | |
6c139d6e AL |
629 | } |
630 | /*}}}*/ | |
2a7e07c7 MV |
631 | // PM::DoInstall - Does the installation /*{{{*/ |
632 | // --------------------------------------------------------------------- | |
633 | /* This uses the filenames in FileNames and the information in the | |
634 | DepCache to perform the installation of packages.*/ | |
635 | pkgPackageManager::OrderResult pkgPackageManager::DoInstall(int statusFd) | |
636 | { | |
637 | if(DoInstallPreFork() == Failed) | |
638 | return Failed; | |
639 | ||
7230ad48 | 640 | return DoInstallPostFork(statusFd); |
2a7e07c7 MV |
641 | } |
642 | /*}}}*/ |