]> git.saurik.com Git - apt.git/blob - apt-pkg/packagemanager.cc
53bb507b6e520318e3544b640d1bd3fe8a99b748
[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, 0) == 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, int const Depth)
322 {
323 // If this is true, only check and correct and dependancies without the Loop flag
324 bool PkgLoop = List->IsFlag(Pkg,pkgOrderList::Loop);
325
326 if (Debug) {
327 VerIterator InstallVer = VerIterator(Cache,Cache[Pkg].InstallVer);
328 clog << OutputInDepth(Depth) << "SmartConfigure " << Pkg.Name() << " (" << InstallVer.VerStr() << ")";
329 if (PkgLoop)
330 clog << " (Only Correct Dependancies)";
331 clog << endl;
332 }
333
334 VerIterator const instVer = Cache[Pkg].InstVerIter(Cache);
335
336 /* Because of the ordered list, most dependancies should be unpacked,
337 however if there is a loop (A depends on B, B depends on A) this will not
338 be the case, so check for dependancies before configuring. */
339 bool Bad = false;
340 for (DepIterator D = instVer.DependsList();
341 D.end() == false; )
342 {
343 // Compute a single dependency element (glob or)
344 pkgCache::DepIterator Start;
345 pkgCache::DepIterator End;
346 D.GlobOr(Start,End);
347
348 if (End->Type == pkgCache::Dep::Depends)
349 Bad = true;
350
351 // Check for dependanices that have not been unpacked, probably due to loops.
352 while (End->Type == pkgCache::Dep::Depends) {
353 PkgIterator DepPkg;
354 VerIterator InstallVer;
355 SPtrArray<Version *> VList = Start.AllTargets();
356
357 // Check through each version of each package that could satisfy this dependancy
358 for (Version **I = VList; *I != 0; I++) {
359 VerIterator Ver(Cache,*I);
360 DepPkg = Ver.ParentPkg();
361 InstallVer = VerIterator(Cache,Cache[DepPkg].InstallVer);
362
363 // Check if the current version of the package is avalible and will satisfy this dependancy
364 if (DepPkg.CurrentVer() == Ver && List->IsNow(DepPkg) == true &&
365 !List->IsFlag(DepPkg,pkgOrderList::Removed) && DepPkg.State() == PkgIterator::NeedsNothing)
366 {
367 Bad = false;
368 break;
369 }
370
371 // Check if the version that is going to be installed will satisfy the dependancy
372 if (Cache[DepPkg].InstallVer == *I) {
373 if (List->IsFlag(DepPkg,pkgOrderList::UnPacked)) {
374 if (PkgLoop && List->IsFlag(DepPkg,pkgOrderList::Loop)) {
375 // This dependancy has already been dealt with by another SmartConfigure on Pkg
376 Bad = false;
377 break;
378 }
379 /* Check for a loop to prevent one forming
380 If A depends on B and B depends on A, SmartConfigure will
381 just hop between them if this is not checked */
382 List->Flag(Pkg,pkgOrderList::Loop);
383 // If SmartConfigure was succesfull, Bad is false, so break
384 Bad = !SmartConfigure(DepPkg, Depth + 1);
385 List->RmFlag(Pkg,pkgOrderList::Loop);
386 if (!Bad) break;
387 } else if (List->IsFlag(DepPkg,pkgOrderList::Configured)) {
388 Bad = false;
389 break;
390 }
391 }
392 }
393
394 /* If the dependany is still not satisfied, try, if possible, unpacking a package to satisfy it */
395 if (InstallVer != 0 && Bad) {
396 Bad = false;
397 if (List->IsNow(DepPkg) && !List->IsFlag(DepPkg,pkgOrderList::Loop)) {
398 List->Flag(Pkg,pkgOrderList::Loop);
399 if (Debug)
400 cout << OutputInDepth(Depth) << "Unpacking " << DepPkg.Name() << " to avoid loop" << endl;
401 SmartUnPack(DepPkg, true, Depth + 1);
402 List->RmFlag(Pkg,pkgOrderList::Loop);
403 }
404 }
405
406 if (Start==End) {
407 if (Bad && Debug) {
408 if (!List->IsFlag(DepPkg,pkgOrderList::Loop)) {
409 _error->Warning("Could not satisfy dependancies for %s",Pkg.Name());
410 }
411 }
412 break;
413 } else {
414 Start++;
415 }
416 }
417 }
418
419 if (Bad) {
420 if (Debug)
421 _error->Warning(_("Could not configure '%s'. "),Pkg.Name());
422 return false;
423 }
424
425 if (PkgLoop) return true;
426
427 static std::string const conf = _config->Find("PackageManager::Configure","all");
428 static bool const ConfigurePkgs = (conf == "all" || conf == "smart");
429
430 if (List->IsFlag(Pkg,pkgOrderList::Configured))
431 return _error->Error("Internal configure error on '%s'. ",Pkg.Name(),1);
432
433 if (ConfigurePkgs == true && Configure(Pkg) == false)
434 return false;
435
436 List->Flag(Pkg,pkgOrderList::Configured,pkgOrderList::States);
437
438 if (Cache[Pkg].InstVerIter(Cache)->MultiArch == pkgCache::Version::Same)
439 for (PkgIterator P = Pkg.Group().PackageList();
440 P.end() == false; P = Pkg.Group().NextPkg(P))
441 {
442 if (Pkg == P || List->IsFlag(P,pkgOrderList::Configured) == true ||
443 Cache[P].InstallVer == 0 || (P.CurrentVer() == Cache[P].InstallVer &&
444 (Cache[Pkg].iFlags & pkgDepCache::ReInstall) != pkgDepCache::ReInstall))
445 continue;
446 SmartConfigure(P, (Depth +1));
447 }
448
449 // Sanity Check
450 if (List->IsFlag(Pkg,pkgOrderList::Configured) == false)
451 return _error->Error(_("Could not configure '%s'. "),Pkg.Name());
452
453 return true;
454 }
455 /*}}}*/
456 // PM::EarlyRemove - Perform removal of packages before their time /*{{{*/
457 // ---------------------------------------------------------------------
458 /* This is called to deal with conflicts arising from unpacking */
459 bool pkgPackageManager::EarlyRemove(PkgIterator Pkg)
460 {
461 if (List->IsNow(Pkg) == false)
462 return true;
463
464 // Already removed it
465 if (List->IsFlag(Pkg,pkgOrderList::Removed) == true)
466 return true;
467
468 // Woops, it will not be re-installed!
469 if (List->IsFlag(Pkg,pkgOrderList::InList) == false)
470 return false;
471
472 // Essential packages get special treatment
473 bool IsEssential = false;
474 if ((Pkg->Flags & pkgCache::Flag::Essential) != 0)
475 IsEssential = true;
476
477 /* Check for packages that are the dependents of essential packages and
478 promote them too */
479 if (Pkg->CurrentVer != 0)
480 {
481 for (DepIterator D = Pkg.RevDependsList(); D.end() == false &&
482 IsEssential == false; D++)
483 if (D->Type == pkgCache::Dep::Depends || D->Type == pkgCache::Dep::PreDepends)
484 if ((D.ParentPkg()->Flags & pkgCache::Flag::Essential) != 0)
485 IsEssential = true;
486 }
487
488 if (IsEssential == true)
489 {
490 if (_config->FindB("APT::Force-LoopBreak",false) == false)
491 return _error->Error(_("This installation run will require temporarily "
492 "removing the essential package %s due to a "
493 "Conflicts/Pre-Depends loop. This is often bad, "
494 "but if you really want to do it, activate the "
495 "APT::Force-LoopBreak option."),Pkg.Name());
496 }
497
498 bool Res = SmartRemove(Pkg);
499 if (Cache[Pkg].Delete() == false)
500 List->Flag(Pkg,pkgOrderList::Removed,pkgOrderList::States);
501
502 return Res;
503 }
504 /*}}}*/
505 // PM::SmartRemove - Removal Helper /*{{{*/
506 // ---------------------------------------------------------------------
507 /* */
508 bool pkgPackageManager::SmartRemove(PkgIterator Pkg)
509 {
510 if (List->IsNow(Pkg) == false)
511 return true;
512
513 List->Flag(Pkg,pkgOrderList::Configured,pkgOrderList::States);
514
515 return Remove(Pkg,(Cache[Pkg].iFlags & pkgDepCache::Purge) == pkgDepCache::Purge);
516 return true;
517 }
518 /*}}}*/
519 // PM::SmartUnPack - Install helper /*{{{*/
520 // ---------------------------------------------------------------------
521 /* This puts the system in a state where it can Unpack Pkg, if Pkg is allready
522 unpacked, or when it has been unpacked, if Immediate==true it configures it. */
523 bool pkgPackageManager::SmartUnPack(PkgIterator Pkg)
524 {
525 return SmartUnPack(Pkg, true, 0);
526 }
527 bool pkgPackageManager::SmartUnPack(PkgIterator Pkg, bool const Immediate, int const Depth)
528 {
529 bool PkgLoop = List->IsFlag(Pkg,pkgOrderList::Loop);
530
531 if (Debug) {
532 clog << OutputInDepth(Depth) << "SmartUnPack " << Pkg.Name();
533 VerIterator InstallVer = VerIterator(Cache,Cache[Pkg].InstallVer);
534 if (Pkg.CurrentVer() == 0)
535 cout << " (install version " << InstallVer.VerStr() << ")";
536 else
537 cout << " (replace version " << Pkg.CurrentVer().VerStr() << " with " << InstallVer.VerStr() << ")";
538 if (PkgLoop)
539 cout << " (Only Perform PreUnpack Checks)";
540 cout << endl;
541 }
542
543 // Check if it is already unpacked
544 if (Pkg.State() == pkgCache::PkgIterator::NeedsConfigure &&
545 Cache[Pkg].Keep() == true)
546 {
547 cout << OutputInDepth(Depth) << "SmartUnPack called on Package " << Pkg.Name() << " but its unpacked" << endl;
548 return false;
549 }
550
551 VerIterator const instVer = Cache[Pkg].InstVerIter(Cache);
552
553 /* PreUnpack Checks: This loop checks and attempts to rectify and problems that would prevent the package being unpacked.
554 It addresses: PreDepends, Conflicts, Obsoletes and Breaks (DpkgBreaks). Any resolutions that do not require it should
555 avoid configuration (calling SmartUnpack with Immediate=true), this is because when unpacking some packages with
556 complex dependancy structures, trying to configure some packages while breaking the loops can complicate things .
557 This will be either dealt with if the package is configured as a dependency of Pkg (if and when Pkg is configured),
558 or by the ConfigureAll call at the end of the for loop in OrderInstall. */
559 for (DepIterator D = instVer.DependsList();
560 D.end() == false; )
561 {
562 // Compute a single dependency element (glob or)
563 pkgCache::DepIterator Start;
564 pkgCache::DepIterator End;
565 D.GlobOr(Start,End);
566
567 while (End->Type == pkgCache::Dep::PreDepends)
568 {
569 if (Debug)
570 clog << OutputInDepth(Depth) << "PreDepends order for " << Pkg.Name() << std::endl;
571
572 // Look for possible ok targets.
573 SPtrArray<Version *> VList = Start.AllTargets();
574 bool Bad = true;
575 for (Version **I = VList; *I != 0 && Bad == true; I++)
576 {
577 VerIterator Ver(Cache,*I);
578 PkgIterator Pkg = Ver.ParentPkg();
579
580 // See if the current version is ok
581 if (Pkg.CurrentVer() == Ver && List->IsNow(Pkg) == true &&
582 Pkg.State() == PkgIterator::NeedsNothing)
583 {
584 Bad = false;
585 if (Debug)
586 clog << OutputInDepth(Depth) << "Found ok package " << Pkg.Name() << endl;
587 continue;
588 }
589 }
590
591 // Look for something that could be configured.
592 for (Version **I = VList; *I != 0 && Bad == true; I++)
593 {
594 VerIterator Ver(Cache,*I);
595 PkgIterator Pkg = Ver.ParentPkg();
596
597 // Not the install version
598 if (Cache[Pkg].InstallVer != *I ||
599 (Cache[Pkg].Keep() == true && Pkg.State() == PkgIterator::NeedsNothing))
600 continue;
601
602 if (List->IsFlag(Pkg,pkgOrderList::Configured)) {
603 Bad = false;
604 continue;
605 }
606
607 if (Debug)
608 clog << OutputInDepth(Depth) << "Trying to SmartConfigure " << Pkg.Name() << endl;
609 Bad = !SmartConfigure(Pkg, Depth + 1);
610 }
611
612 /* If this or element did not match then continue on to the
613 next or element until a matching element is found */
614 if (Bad == true)
615 {
616 // This triggers if someone make a pre-depends/depend loop.
617 if (Start == End)
618 return _error->Error("Couldn't configure pre-depend %s for %s, "
619 "probably a dependency cycle.",
620 End.TargetPkg().Name(),Pkg.Name());
621 Start++;
622 }
623 else
624 break;
625 }
626
627 if (End->Type == pkgCache::Dep::Conflicts ||
628 End->Type == pkgCache::Dep::Obsoletes)
629 {
630 /* Look for conflicts. Two packages that are both in the install
631 state cannot conflict so we don't check.. */
632 SPtrArray<Version *> VList = End.AllTargets();
633 for (Version **I = VList; *I != 0; I++)
634 {
635 VerIterator Ver(Cache,*I);
636 PkgIterator ConflictPkg = Ver.ParentPkg();
637 VerIterator InstallVer(Cache,Cache[ConflictPkg].InstallVer);
638
639 // See if the current version is conflicting
640 if (ConflictPkg.CurrentVer() == Ver && List->IsNow(ConflictPkg))
641 {
642 cout << OutputInDepth(Depth) << Pkg.Name() << " conflicts with " << ConflictPkg.Name() << endl;
643 /* If a loop is not present or has not yet been detected, attempt to unpack packages
644 to resolve this conflict. If there is a loop present, remove packages to resolve this conflict */
645 if (!List->IsFlag(ConflictPkg,pkgOrderList::Loop)) {
646 if (Cache[ConflictPkg].Keep() == 0 && Cache[ConflictPkg].InstallVer != 0) {
647 if (Debug)
648 cout << OutputInDepth(Depth) << OutputInDepth(Depth) << "Unpacking " << ConflictPkg.Name() << " to prevent conflict" << endl;
649 List->Flag(Pkg,pkgOrderList::Loop);
650 SmartUnPack(ConflictPkg,false, Depth + 1);
651 // Remove loop to allow it to be used later if needed
652 List->RmFlag(Pkg,pkgOrderList::Loop);
653 } else {
654 if (EarlyRemove(ConflictPkg) == false)
655 return _error->Error("Internal Error, Could not early remove %s",ConflictPkg.Name());
656 }
657 } else {
658 if (!List->IsFlag(ConflictPkg,pkgOrderList::Removed)) {
659 if (Debug)
660 cout << OutputInDepth(Depth) << "Because of conficts knot, removing " << ConflictPkg.Name() << " to conflict violation" << endl;
661 if (EarlyRemove(ConflictPkg) == false)
662 return _error->Error("Internal Error, Could not early remove %s",ConflictPkg.Name());
663 }
664 }
665 }
666 }
667 }
668
669 // Check for breaks
670 if (End->Type == pkgCache::Dep::DpkgBreaks) {
671 SPtrArray<Version *> VList = End.AllTargets();
672 for (Version **I = VList; *I != 0; I++)
673 {
674 VerIterator Ver(Cache,*I);
675 PkgIterator BrokenPkg = Ver.ParentPkg();
676 VerIterator InstallVer(Cache,Cache[BrokenPkg].InstallVer);
677
678 // Check if it needs to be unpacked
679 if (List->IsFlag(BrokenPkg,pkgOrderList::InList) && Cache[BrokenPkg].Delete() == false &&
680 List->IsNow(BrokenPkg)) {
681 if (PkgLoop && List->IsFlag(BrokenPkg,pkgOrderList::Loop)) {
682 // This dependancy has already been dealt with by another SmartUnPack on Pkg
683 break;
684 }
685 List->Flag(Pkg,pkgOrderList::Loop);
686 // Found a break, so unpack the package
687 if (Debug)
688 cout << OutputInDepth(Depth) << " Unpacking " << BrokenPkg.Name() << " to avoid break" << endl;
689
690 SmartUnPack(BrokenPkg, false, Depth + 1);
691 List->RmFlag(Pkg,pkgOrderList::Loop);
692 }
693 // Check if a package needs to be removed
694 if (Cache[BrokenPkg].Delete() == true && !List->IsFlag(BrokenPkg,pkgOrderList::Configured)) {
695 if (Debug)
696 cout << OutputInDepth(Depth) << " Removing " << BrokenPkg.Name() << " to avoid break" << endl;
697 SmartRemove(BrokenPkg);
698 }
699 }
700 }
701 }
702
703 // Check for reverse conflicts.
704 if (CheckRConflicts(Pkg,Pkg.RevDependsList(),
705 instVer.VerStr()) == false)
706 return false;
707
708 for (PrvIterator P = instVer.ProvidesList();
709 P.end() == false; P++)
710 CheckRConflicts(Pkg,P.ParentPkg().RevDependsList(),P.ProvideVersion());
711
712 if (PkgLoop) return true;
713
714 List->Flag(Pkg,pkgOrderList::UnPacked,pkgOrderList::States);
715
716 if (instVer->MultiArch == pkgCache::Version::Same)
717 for (PkgIterator P = Pkg.Group().PackageList();
718 P.end() == false; P = Pkg.Group().NextPkg(P))
719 {
720 if (Pkg == P || List->IsFlag(P,pkgOrderList::UnPacked) == true ||
721 Cache[P].InstallVer == 0 || (P.CurrentVer() == Cache[P].InstallVer &&
722 (Cache[Pkg].iFlags & pkgDepCache::ReInstall) != pkgDepCache::ReInstall))
723 continue;
724 SmartUnPack(P, false, Depth + 1);
725 }
726
727 if(Install(Pkg,FileNames[Pkg->ID]) == false)
728 return false;
729
730 if (Immediate == true) {
731 // Perform immedate configuration of the package.
732 if (SmartConfigure(Pkg, Depth + 1) == false)
733 _error->Warning(_("Could not perform immediate configuration on '%s'. "
734 "Please see man 5 apt.conf under APT::Immediate-Configure for details. (%d)"),Pkg.Name(),2);
735 }
736
737 return true;
738 }
739 /*}}}*/
740 // PM::OrderInstall - Installation ordering routine /*{{{*/
741 // ---------------------------------------------------------------------
742 /* */
743 pkgPackageManager::OrderResult pkgPackageManager::OrderInstall()
744 {
745 if (CreateOrderList() == false)
746 return Failed;
747
748 Reset();
749
750 if (Debug == true)
751 clog << "Beginning to order" << endl;
752
753 bool const ordering =
754 _config->FindB("PackageManager::UnpackAll",true) ?
755 List->OrderUnpack(FileNames) : List->OrderCritical();
756 if (ordering == false)
757 {
758 _error->Error("Internal ordering error");
759 return Failed;
760 }
761
762 if (Debug == true)
763 clog << "Done ordering" << endl;
764
765 bool DoneSomething = false;
766 for (pkgOrderList::iterator I = List->begin(); I != List->end(); I++)
767 {
768 PkgIterator Pkg(Cache,*I);
769
770 if (List->IsNow(Pkg) == false)
771 {
772 if (!List->IsFlag(Pkg,pkgOrderList::Configured) && !NoImmConfigure) {
773 if (SmartConfigure(Pkg, 0) == false && Debug)
774 _error->Warning("Internal Error, Could not configure %s",Pkg.Name());
775 // FIXME: The above warning message might need changing
776 } else {
777 if (Debug == true)
778 clog << "Skipping already done " << Pkg.Name() << endl;
779 }
780 continue;
781
782 }
783
784 if (List->IsMissing(Pkg) == true)
785 {
786 if (Debug == true)
787 clog << "Sequence completed at " << Pkg.Name() << endl;
788 if (DoneSomething == false)
789 {
790 _error->Error("Internal Error, ordering was unable to handle the media swap");
791 return Failed;
792 }
793 return Incomplete;
794 }
795
796 // Sanity check
797 if (Cache[Pkg].Keep() == true &&
798 Pkg.State() == pkgCache::PkgIterator::NeedsNothing &&
799 (Cache[Pkg].iFlags & pkgDepCache::ReInstall) != pkgDepCache::ReInstall)
800 {
801 _error->Error("Internal Error, trying to manipulate a kept package (%s)",Pkg.Name());
802 return Failed;
803 }
804
805 // Perform a delete or an install
806 if (Cache[Pkg].Delete() == true)
807 {
808 if (SmartRemove(Pkg) == false)
809 return Failed;
810 }
811 else
812 if (SmartUnPack(Pkg,List->IsFlag(Pkg,pkgOrderList::Immediate),0) == false)
813 return Failed;
814 DoneSomething = true;
815
816 if (ImmConfigureAll) {
817 /* ConfigureAll here to pick up and packages left unconfigured becuase they were unpacked in the
818 "PreUnpack Checks" section */
819 if (!ConfigureAll())
820 return Failed;
821 }
822 }
823
824 // Final run through the configure phase
825 if (ConfigureAll() == false)
826 return Failed;
827
828 // Sanity check
829 for (pkgOrderList::iterator I = List->begin(); I != List->end(); I++)
830 {
831 if (List->IsFlag(*I,pkgOrderList::Configured) == false)
832 {
833 _error->Error("Internal error, packages left unconfigured. %s",
834 PkgIterator(Cache,*I).Name());
835 return Failed;
836 }
837 }
838
839 return Completed;
840 }
841 /*}}}*/
842 // PM::DoInstallPostFork - Does install part that happens after the fork /*{{{*/
843 // ---------------------------------------------------------------------
844 pkgPackageManager::OrderResult
845 pkgPackageManager::DoInstallPostFork(int statusFd)
846 {
847 if(statusFd > 0)
848 // FIXME: use SetCloseExec here once it taught about throwing
849 // exceptions instead of doing _exit(100) on failure
850 fcntl(statusFd,F_SETFD,FD_CLOEXEC);
851 bool goResult = Go(statusFd);
852 if(goResult == false)
853 return Failed;
854
855 return Res;
856 };
857
858 // PM::DoInstall - Does the installation /*{{{*/
859 // ---------------------------------------------------------------------
860 /* This uses the filenames in FileNames and the information in the
861 DepCache to perform the installation of packages.*/
862 pkgPackageManager::OrderResult pkgPackageManager::DoInstall(int statusFd)
863 {
864 if(DoInstallPreFork() == Failed)
865 return Failed;
866
867 return DoInstallPostFork(statusFd);
868 }
869 /*}}}*/