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