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