]> git.saurik.com Git - apt.git/blob - apt-pkg/packagemanager.cc
Small fix for loop handeling.
[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 <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 /*}}}*/
30 using namespace std;
31
32 bool pkgPackageManager::SigINTStop = false;
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 NoImmConfigure = !_config->FindB("APT::Immediate-Configure",true);
172 ImmConfigureAll = _config->FindB("APT::Immediate-Configure-All",false);
173
174 if (Debug && ImmConfigureAll)
175 clog << "CreateOrderList(): Adding Immediate flag for all packages because of APT::Immediate-Configure-All" << endl;
176
177 // Generate the list of affected packages and sort it
178 for (PkgIterator I = Cache.PkgBegin(); I.end() == false; I++)
179 {
180 // Ignore no-version packages
181 if (I->VersionList == 0)
182 continue;
183
184 // Mark the package and its dependends for immediate configuration
185 if ((((I->Flags & pkgCache::Flag::Essential) == pkgCache::Flag::Essential ||
186 (I->Flags & pkgCache::Flag::Important) == pkgCache::Flag::Important) &&
187 NoImmConfigure == false) || ImmConfigureAll)
188 {
189 if(Debug && !ImmConfigureAll)
190 clog << "CreateOrderList(): Adding Immediate flag for " << I.Name() << endl;
191 List->Flag(I,pkgOrderList::Immediate);
192
193 if (!ImmConfigureAll) {
194 // Look for other install packages to make immediate configurea
195 ImmediateAdd(I, true);
196
197 // And again with the current version.
198 ImmediateAdd(I, false);
199 }
200 }
201
202 // Not interesting
203 if ((Cache[I].Keep() == true ||
204 Cache[I].InstVerIter(Cache) == I.CurrentVer()) &&
205 I.State() == pkgCache::PkgIterator::NeedsNothing &&
206 (Cache[I].iFlags & pkgDepCache::ReInstall) != pkgDepCache::ReInstall &&
207 (I.Purge() != false || Cache[I].Mode != pkgDepCache::ModeDelete ||
208 (Cache[I].iFlags & pkgDepCache::Purge) != pkgDepCache::Purge))
209 continue;
210
211 // Append it to the list
212 List->push_back(I);
213 }
214
215 return true;
216 }
217 /*}}}*/
218 // PM::DepAlwaysTrue - Returns true if this dep is irrelevent /*{{{*/
219 // ---------------------------------------------------------------------
220 /* The restriction on provides is to eliminate the case when provides
221 are transitioning between valid states [ie exim to smail] */
222 bool pkgPackageManager::DepAlwaysTrue(DepIterator D)
223 {
224 if (D.TargetPkg()->ProvidesList != 0)
225 return false;
226
227 if ((Cache[D] & pkgDepCache::DepInstall) != 0 &&
228 (Cache[D] & pkgDepCache::DepNow) != 0)
229 return true;
230 return false;
231 }
232 /*}}}*/
233 // PM::CheckRConflicts - Look for reverse conflicts /*{{{*/
234 // ---------------------------------------------------------------------
235 /* This looks over the reverses for a conflicts line that needs early
236 removal. */
237 bool pkgPackageManager::CheckRConflicts(PkgIterator Pkg,DepIterator D,
238 const char *Ver)
239 {
240 for (;D.end() == false; D++)
241 {
242 if (D->Type != pkgCache::Dep::Conflicts &&
243 D->Type != pkgCache::Dep::Obsoletes)
244 continue;
245
246 // The package hasnt been changed
247 if (List->IsNow(Pkg) == false)
248 continue;
249
250 // Ignore self conflicts, ignore conflicts from irrelevent versions
251 if (D.ParentPkg() == Pkg || D.ParentVer() != D.ParentPkg().CurrentVer())
252 continue;
253
254 if (Cache.VS().CheckDep(Ver,D->CompareOp,D.TargetVer()) == false)
255 continue;
256
257 if (EarlyRemove(D.ParentPkg()) == false)
258 return _error->Error("Reverse conflicts early remove for package '%s' failed",
259 Pkg.Name());
260 }
261 return true;
262 }
263 /*}}}*/
264 // PM::ConfigureAll - Run the all out configuration /*{{{*/
265 // ---------------------------------------------------------------------
266 /* This configures every package. It is assumed they are all unpacked and
267 that the final configuration is valid. This is also used to catch packages
268 that have not been configured when using ImmConfigureAll */
269 bool pkgPackageManager::ConfigureAll()
270 {
271 pkgOrderList OList(&Cache);
272
273 // Populate the order list
274 for (pkgOrderList::iterator I = List->begin(); I != List->end(); I++)
275 if (List->IsFlag(pkgCache::PkgIterator(Cache,*I),
276 pkgOrderList::UnPacked) == true)
277 OList.push_back(*I);
278
279 if (OList.OrderConfigure() == false)
280 return false;
281
282 std::string const conf = _config->Find("PackageManager::Configure","all");
283 bool const ConfigurePkgs = (conf == "all");
284
285 // Perform the configuring
286 for (pkgOrderList::iterator I = OList.begin(); I != OList.end(); I++)
287 {
288 PkgIterator Pkg(Cache,*I);
289
290 /* Check if the package has been configured, this can happen if SmartConfigure
291 calls its self */
292 if (List->IsFlag(Pkg,pkgOrderList::Configured)) continue;
293
294 if (ConfigurePkgs == true && SmartConfigure(Pkg) == false) {
295 if (ImmConfigureAll)
296 _error->Error(_("Could not perform immediate configuration on '%s'. "
297 "Please see man 5 apt.conf under APT::Immediate-Configure for details. (%d)"),Pkg.Name(),1);
298 else
299 _error->Error("Internal error, packages left unconfigured. %s",Pkg.Name());
300 return false;
301 }
302
303 List->Flag(Pkg,pkgOrderList::Configured,pkgOrderList::States);
304 }
305
306 return true;
307 }
308 /*}}}*/
309 // PM::SmartConfigure - Perform immediate configuration of the pkg /*{{{*/
310 // ---------------------------------------------------------------------
311 /* This function tries to put the system in a state where Pkg can be configured.
312 This involves checking each of Pkg's dependanies and unpacking and
313 configuring packages where needed.
314
315 Note on failure: This method can fail, without causing any problems.
316 This can happen when using Immediate-Configure-All, SmartUnPack may call
317 SmartConfigure, it may fail because of a complex dependancy situation, but
318 a error will only be reported if ConfigureAll fails. This is why some of the
319 messages this function reports on failure (return false;) as just warnings
320 only shown when debuging*/
321 bool pkgPackageManager::SmartConfigure(PkgIterator Pkg)
322 {
323 if (Debug)
324 clog << "SmartConfigure " << Pkg.Name() << endl;
325
326 VerIterator const instVer = Cache[Pkg].InstVerIter(Cache);
327
328 /* Because of the ordered list, most dependancies should be unpacked,
329 however if there is a loop (A depends on B, B depends on A) this will not
330 be the case, so check for dependancies before configuring. */
331 bool Bad = false;
332 for (DepIterator D = instVer.DependsList();
333 D.end() == false; )
334 {
335 // Compute a single dependency element (glob or)
336 pkgCache::DepIterator Start;
337 pkgCache::DepIterator End;
338 D.GlobOr(Start,End);
339
340 if (End->Type == pkgCache::Dep::Depends)
341 Bad = true;
342
343 // Check for dependanices that have not been unpacked, probably due to loops.
344 while (End->Type == pkgCache::Dep::Depends) {
345 PkgIterator DepPkg;
346 VerIterator InstallVer;
347 SPtrArray<Version *> VList = Start.AllTargets();
348
349 // Check through each version of each package that could satisfy this dependancy
350 for (Version **I = VList; *I != 0; I++) {
351 VerIterator Ver(Cache,*I);
352 DepPkg = Ver.ParentPkg();
353 InstallVer = VerIterator(Cache,Cache[DepPkg].InstallVer);
354
355 // Check if the current version of the package is avalible and will satisfy this dependancy
356 if (DepPkg.CurrentVer() == Ver && List->IsNow(DepPkg) == true &&
357 !List->IsFlag(DepPkg,pkgOrderList::Removed) && DepPkg.State() == PkgIterator::NeedsNothing)
358 {
359 Bad = false;
360 break;
361 }
362
363 // Check if the version that is going to be installed will satisfy the dependancy
364 if (Cache[DepPkg].InstallVer == *I) {
365 if (List->IsFlag(DepPkg,pkgOrderList::UnPacked)) {
366 /* Check for a loop to prevent one forming
367 If A depends on B and B depends on A, SmartConfigure will
368 just hop between them if this is not checked */
369 if (!List->IsFlag(DepPkg,pkgOrderList::Loop)) {
370 List->Flag(Pkg,pkgOrderList::Loop);
371 // If SmartConfigure was succesfull, Bad is false, so break
372 Bad = !SmartConfigure(DepPkg);
373 List->RmFlag(Pkg,pkgOrderList::Loop);
374 if (!Bad) break;
375 }
376 } else if (List->IsFlag(DepPkg,pkgOrderList::Configured)) {
377 Bad = false;
378 break;
379 }
380 }
381 }
382
383 /* If the dependany is still not satisfied, try, if possible, unpacking a package to satisfy it */
384 if (InstallVer != 0 && Bad) {
385 Bad = false;
386 if (!List->IsFlag(DepPkg,pkgOrderList::Loop)) {
387 List->Flag(Pkg,pkgOrderList::Loop);
388 if (Debug)
389 cout << " Unpacking " << DepPkg.Name() << " to avoid loop" << endl;
390 SmartUnPack(DepPkg, true);
391 List->RmFlag(Pkg,pkgOrderList::Loop);
392 }
393 }
394
395 if (Start==End) {
396 if (Bad && Debug) {
397 if (!List->IsFlag(DepPkg,pkgOrderList::Loop)) {
398 _error->Warning("Could not satisfy dependancies for %s",Pkg.Name());
399 }
400 }
401 break;
402 } else {
403 Start++;
404 }
405 }
406 }
407
408 if (Bad) {
409 if (Debug)
410 _error->Warning(_("Could not configure '%s'. "),Pkg.Name());
411 return false;
412 }
413
414 static std::string const conf = _config->Find("PackageManager::Configure","all");
415 static bool const ConfigurePkgs = (conf == "all" || conf == "smart");
416
417 if (List->IsFlag(Pkg,pkgOrderList::Configured))
418 return _error->Error("Internal configure error on '%s'. ",Pkg.Name(),1);
419
420 if (ConfigurePkgs == true && Configure(Pkg) == false)
421 return false;
422
423 List->Flag(Pkg,pkgOrderList::Configured,pkgOrderList::States);
424
425 if (Cache[Pkg].InstVerIter(Cache)->MultiArch == pkgCache::Version::Same)
426 for (PkgIterator P = Pkg.Group().PackageList();
427 P.end() == false; P = Pkg.Group().NextPkg(P))
428 {
429 if (Pkg == P || List->IsFlag(P,pkgOrderList::Configured) == true ||
430 Cache[P].InstallVer == 0 || (P.CurrentVer() == Cache[P].InstallVer &&
431 (Cache[Pkg].iFlags & pkgDepCache::ReInstall) != pkgDepCache::ReInstall))
432 continue;
433 SmartConfigure(P);
434 }
435
436 // Sanity Check
437 if (List->IsFlag(Pkg,pkgOrderList::Configured) == false)
438 return _error->Error(_("Could not configure '%s'. "),Pkg.Name());
439
440 return true;
441 }
442 /*}}}*/
443 // PM::EarlyRemove - Perform removal of packages before their time /*{{{*/
444 // ---------------------------------------------------------------------
445 /* This is called to deal with conflicts arising from unpacking */
446 bool pkgPackageManager::EarlyRemove(PkgIterator Pkg)
447 {
448 if (List->IsNow(Pkg) == false)
449 return true;
450
451 // Already removed it
452 if (List->IsFlag(Pkg,pkgOrderList::Removed) == true)
453 return true;
454
455 // Woops, it will not be re-installed!
456 if (List->IsFlag(Pkg,pkgOrderList::InList) == false)
457 return false;
458
459 // Essential packages get special treatment
460 bool IsEssential = false;
461 if ((Pkg->Flags & pkgCache::Flag::Essential) != 0)
462 IsEssential = true;
463
464 /* Check for packages that are the dependents of essential packages and
465 promote them too */
466 if (Pkg->CurrentVer != 0)
467 {
468 for (DepIterator D = Pkg.RevDependsList(); D.end() == false &&
469 IsEssential == false; D++)
470 if (D->Type == pkgCache::Dep::Depends || D->Type == pkgCache::Dep::PreDepends)
471 if ((D.ParentPkg()->Flags & pkgCache::Flag::Essential) != 0)
472 IsEssential = true;
473 }
474
475 if (IsEssential == true)
476 {
477 if (_config->FindB("APT::Force-LoopBreak",false) == false)
478 return _error->Error(_("This installation run will require temporarily "
479 "removing the essential package %s due to a "
480 "Conflicts/Pre-Depends loop. This is often bad, "
481 "but if you really want to do it, activate the "
482 "APT::Force-LoopBreak option."),Pkg.Name());
483 }
484
485 bool Res = SmartRemove(Pkg);
486 if (Cache[Pkg].Delete() == false)
487 List->Flag(Pkg,pkgOrderList::Removed,pkgOrderList::States);
488
489 return Res;
490 }
491 /*}}}*/
492 // PM::SmartRemove - Removal Helper /*{{{*/
493 // ---------------------------------------------------------------------
494 /* */
495 bool pkgPackageManager::SmartRemove(PkgIterator Pkg)
496 {
497 if (List->IsNow(Pkg) == false)
498 return true;
499
500 List->Flag(Pkg,pkgOrderList::Configured,pkgOrderList::States);
501
502 return Remove(Pkg,(Cache[Pkg].iFlags & pkgDepCache::Purge) == pkgDepCache::Purge);
503 return true;
504 }
505 /*}}}*/
506 // PM::SmartUnPack - Install helper /*{{{*/
507 // ---------------------------------------------------------------------
508 /* This puts the system in a state where it can Unpack Pkg, if Pkg is allready
509 unpacked, or when it has been unpacked, if Immediate==true it configures it. */
510 bool pkgPackageManager::SmartUnPack(PkgIterator Pkg)
511 {
512 return SmartUnPack(Pkg, true);
513 }
514 bool pkgPackageManager::SmartUnPack(PkgIterator Pkg, bool const Immediate)
515 {
516 if (Debug)
517 clog << "SmartUnPack " << Pkg.Name() << endl;
518
519 // Check if it is already unpacked
520 if (Pkg.State() == pkgCache::PkgIterator::NeedsConfigure &&
521 Cache[Pkg].Keep() == true)
522 {
523 List->Flag(Pkg,pkgOrderList::UnPacked,pkgOrderList::States);
524 if (Immediate == true &&
525 List->IsFlag(Pkg,pkgOrderList::Immediate) == true)
526 if (SmartConfigure(Pkg) == false)
527 _error->Warning(_("Could not perform immediate configuration on already unpacked '%s'. "
528 "Please see man 5 apt.conf under APT::Immediate-Configure for details."),Pkg.Name());
529 return true;
530 }
531
532 VerIterator const instVer = Cache[Pkg].InstVerIter(Cache);
533
534 /* PreUnpack Checks: This loop checks and attempts to rectify and problems that would prevent the package being unpacked.
535 It addresses: PreDepends, Conflicts, Obsoletes and Breaks (DpkgBreaks). Any resolutions that do not require it should
536 avoid configuration (calling SmartUnpack with Immediate=true), this is because when unpacking some packages with
537 complex dependancy structures, trying to configure some packages while breaking the loops can complicate things .
538 This will be either dealt with if the package is configured as a dependency of Pkg (if and when Pkg is configured),
539 or by the ConfigureAll call at the end of the for loop in OrderInstall. */
540 for (DepIterator D = instVer.DependsList();
541 D.end() == false; )
542 {
543 // Compute a single dependency element (glob or)
544 pkgCache::DepIterator Start;
545 pkgCache::DepIterator End;
546 D.GlobOr(Start,End);
547
548 while (End->Type == pkgCache::Dep::PreDepends)
549 {
550 if (Debug)
551 clog << "PreDepends order for " << Pkg.Name() << std::endl;
552
553 // Look for possible ok targets.
554 SPtrArray<Version *> VList = Start.AllTargets();
555 bool Bad = true;
556 for (Version **I = VList; *I != 0 && Bad == true; I++)
557 {
558 VerIterator Ver(Cache,*I);
559 PkgIterator Pkg = Ver.ParentPkg();
560
561 // See if the current version is ok
562 if (Pkg.CurrentVer() == Ver && List->IsNow(Pkg) == true &&
563 Pkg.State() == PkgIterator::NeedsNothing)
564 {
565 Bad = false;
566 if (Debug)
567 clog << "Found ok package " << Pkg.Name() << endl;
568 continue;
569 }
570 }
571
572 // Look for something that could be configured.
573 for (Version **I = VList; *I != 0 && Bad == true; I++)
574 {
575 VerIterator Ver(Cache,*I);
576 PkgIterator Pkg = Ver.ParentPkg();
577
578 // Not the install version
579 if (Cache[Pkg].InstallVer != *I ||
580 (Cache[Pkg].Keep() == true && Pkg.State() == PkgIterator::NeedsNothing))
581 continue;
582
583 if (List->IsFlag(Pkg,pkgOrderList::Configured)) {
584 Bad = false;
585 continue;
586 }
587
588 if (Debug)
589 clog << "Trying to SmartConfigure " << Pkg.Name() << endl;
590 Bad = !SmartConfigure(Pkg);
591 }
592
593 /* If this or element did not match then continue on to the
594 next or element until a matching element is found */
595 if (Bad == true)
596 {
597 // This triggers if someone make a pre-depends/depend loop.
598 if (Start == End)
599 return _error->Error("Couldn't configure pre-depend %s for %s, "
600 "probably a dependency cycle.",
601 End.TargetPkg().Name(),Pkg.Name());
602 Start++;
603 }
604 else
605 break;
606 }
607
608 if (End->Type == pkgCache::Dep::Conflicts ||
609 End->Type == pkgCache::Dep::Obsoletes)
610 {
611 /* Look for conflicts. Two packages that are both in the install
612 state cannot conflict so we don't check.. */
613 SPtrArray<Version *> VList = End.AllTargets();
614 for (Version **I = VList; *I != 0; I++)
615 {
616 VerIterator Ver(Cache,*I);
617 PkgIterator ConflictPkg = Ver.ParentPkg();
618 VerIterator InstallVer(Cache,Cache[ConflictPkg].InstallVer);
619
620 // See if the current version is conflicting
621 if (ConflictPkg.CurrentVer() == Ver && List->IsNow(ConflictPkg))
622 {
623 cout << Pkg.Name() << " conflicts with " << ConflictPkg.Name() << endl;
624 /* If a loop is not present or has not yet been detected, attempt to unpack packages
625 to resolve this conflict. If there is a loop present, remove packages to resolve this conflict */
626 if (!List->IsFlag(ConflictPkg,pkgOrderList::Loop)) {
627 if (Cache[ConflictPkg].Keep() == 0 && Cache[ConflictPkg].InstallVer != 0) {
628 if (Debug)
629 cout << "Unpacking " << ConflictPkg.Name() << " to prevent conflict" << endl;
630 List->Flag(Pkg,pkgOrderList::Loop);
631 SmartUnPack(ConflictPkg,false);
632 // Remove loop to allow it to be used later if needed
633 List->RmFlag(Pkg,pkgOrderList::Loop);
634 } else {
635 if (EarlyRemove(ConflictPkg) == false)
636 return _error->Error("Internal Error, Could not early remove %s",ConflictPkg.Name());
637 }
638 } else {
639 if (!List->IsFlag(ConflictPkg,pkgOrderList::Removed)) {
640 if (Debug)
641 cout << "Because of conficts knot, removing " << ConflictPkg.Name() << " to conflict violation" << endl;
642 if (EarlyRemove(ConflictPkg) == false)
643 return _error->Error("Internal Error, Could not early remove %s",ConflictPkg.Name());
644 }
645 }
646 }
647 }
648 }
649
650 // Check for breaks
651 if (End->Type == pkgCache::Dep::DpkgBreaks) {
652 SPtrArray<Version *> VList = End.AllTargets();
653 for (Version **I = VList; *I != 0; I++)
654 {
655 VerIterator Ver(Cache,*I);
656 PkgIterator BrokenPkg = Ver.ParentPkg();
657 VerIterator InstallVer(Cache,Cache[BrokenPkg].InstallVer);
658
659 // Check if it needs to be unpacked
660 if (List->IsFlag(BrokenPkg,pkgOrderList::InList) && Cache[BrokenPkg].Delete() == false &&
661 !List->IsFlag(BrokenPkg,pkgOrderList::Loop) && List->IsNow(BrokenPkg)) {
662 List->Flag(Pkg,pkgOrderList::Loop);
663 // Found a break, so unpack the package
664 if (Debug)
665 cout << " Unpacking " << BrokenPkg.Name() << " to avoid break" << endl;
666
667 SmartUnPack(BrokenPkg, false);
668 List->RmFlag(Pkg,pkgOrderList::Loop);
669 }
670 // Check if a package needs to be removed
671 if (Cache[BrokenPkg].Delete() == true && !List->IsFlag(BrokenPkg,pkgOrderList::Configured)) {
672 if (Debug)
673 cout << " Removing " << BrokenPkg.Name() << " to avoid break" << endl;
674 SmartRemove(BrokenPkg);
675 }
676 }
677 }
678 }
679
680 // Check for reverse conflicts.
681 if (CheckRConflicts(Pkg,Pkg.RevDependsList(),
682 instVer.VerStr()) == false)
683 return false;
684
685 for (PrvIterator P = instVer.ProvidesList();
686 P.end() == false; P++)
687 CheckRConflicts(Pkg,P.ParentPkg().RevDependsList(),P.ProvideVersion());
688
689 List->Flag(Pkg,pkgOrderList::UnPacked,pkgOrderList::States);
690
691 if (instVer->MultiArch == pkgCache::Version::Same)
692 for (PkgIterator P = Pkg.Group().PackageList();
693 P.end() == false; P = Pkg.Group().NextPkg(P))
694 {
695 if (Pkg == P || List->IsFlag(P,pkgOrderList::UnPacked) == true ||
696 Cache[P].InstallVer == 0 || (P.CurrentVer() == Cache[P].InstallVer &&
697 (Cache[Pkg].iFlags & pkgDepCache::ReInstall) != pkgDepCache::ReInstall))
698 continue;
699 SmartUnPack(P, false);
700 }
701
702 if(Install(Pkg,FileNames[Pkg->ID]) == false)
703 return false;
704
705 if (Immediate == true && List->IsFlag(Pkg,pkgOrderList::Immediate) == true) {
706
707 // Perform immedate configuration of the package.
708 if (SmartConfigure(Pkg) == false)
709 _error->Warning(_("Could not perform immediate configuration on '%s'. "
710 "Please see man 5 apt.conf under APT::Immediate-Configure for details. (%d)"),Pkg.Name(),2);
711 }
712
713 return true;
714 }
715 /*}}}*/
716 // PM::OrderInstall - Installation ordering routine /*{{{*/
717 // ---------------------------------------------------------------------
718 /* */
719 pkgPackageManager::OrderResult pkgPackageManager::OrderInstall()
720 {
721 if (CreateOrderList() == false)
722 return Failed;
723
724 Reset();
725
726 if (Debug == true)
727 clog << "Beginning to order" << endl;
728
729 bool const ordering =
730 _config->FindB("PackageManager::UnpackAll",true) ?
731 List->OrderUnpack(FileNames) : List->OrderCritical();
732 if (ordering == false)
733 {
734 _error->Error("Internal ordering error");
735 return Failed;
736 }
737
738 if (Debug == true)
739 clog << "Done ordering" << endl;
740
741 bool DoneSomething = false;
742 for (pkgOrderList::iterator I = List->begin(); I != List->end(); I++)
743 {
744 PkgIterator Pkg(Cache,*I);
745
746 if (List->IsNow(Pkg) == false)
747 {
748 if (!List->IsFlag(Pkg,pkgOrderList::Configured) && !NoImmConfigure) {
749 if (SmartConfigure(Pkg) == false && Debug)
750 _error->Warning("Internal Error, Could not configure %s",Pkg.Name());
751 // FIXME: The above warning message might need changing
752 } else {
753 if (Debug == true)
754 clog << "Skipping already done " << Pkg.Name() << endl;
755 }
756 continue;
757
758 }
759
760 if (List->IsMissing(Pkg) == true)
761 {
762 if (Debug == true)
763 clog << "Sequence completed at " << Pkg.Name() << endl;
764 if (DoneSomething == false)
765 {
766 _error->Error("Internal Error, ordering was unable to handle the media swap");
767 return Failed;
768 }
769 return Incomplete;
770 }
771
772 // Sanity check
773 if (Cache[Pkg].Keep() == true &&
774 Pkg.State() == pkgCache::PkgIterator::NeedsNothing &&
775 (Cache[Pkg].iFlags & pkgDepCache::ReInstall) != pkgDepCache::ReInstall)
776 {
777 _error->Error("Internal Error, trying to manipulate a kept package (%s)",Pkg.Name());
778 return Failed;
779 }
780
781 // Perform a delete or an install
782 if (Cache[Pkg].Delete() == true)
783 {
784 if (SmartRemove(Pkg) == false)
785 return Failed;
786 }
787 else
788 if (SmartUnPack(Pkg) == false)
789 return Failed;
790 DoneSomething = true;
791
792 if (ImmConfigureAll) {
793 /* ConfigureAll here to pick up and packages left unconfigured becuase they were unpacked in the
794 "PreUnpack Checks" section */
795 if (!ConfigureAll())
796 return Failed;
797 }
798 }
799
800 // Final run through the configure phase
801 if (ConfigureAll() == false)
802 return Failed;
803
804 // Sanity check
805 for (pkgOrderList::iterator I = List->begin(); I != List->end(); I++)
806 {
807 if (List->IsFlag(*I,pkgOrderList::Configured) == false)
808 {
809 _error->Error("Internal error, packages left unconfigured. %s",
810 PkgIterator(Cache,*I).Name());
811 return Failed;
812 }
813 }
814
815 return Completed;
816 }
817 /*}}}*/
818 // PM::DoInstallPostFork - Does install part that happens after the fork /*{{{*/
819 // ---------------------------------------------------------------------
820 pkgPackageManager::OrderResult
821 pkgPackageManager::DoInstallPostFork(int statusFd)
822 {
823 if(statusFd > 0)
824 // FIXME: use SetCloseExec here once it taught about throwing
825 // exceptions instead of doing _exit(100) on failure
826 fcntl(statusFd,F_SETFD,FD_CLOEXEC);
827 bool goResult = Go(statusFd);
828 if(goResult == false)
829 return Failed;
830
831 return Res;
832 };
833
834 // PM::DoInstall - Does the installation /*{{{*/
835 // ---------------------------------------------------------------------
836 /* This uses the filenames in FileNames and the information in the
837 DepCache to perform the installation of packages.*/
838 pkgPackageManager::OrderResult pkgPackageManager::DoInstall(int statusFd)
839 {
840 if(DoInstallPreFork() == Failed)
841 return Failed;
842
843 return DoInstallPostFork(statusFd);
844 }
845 /*}}}*/