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