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