]> git.saurik.com Git - apt.git/blob - apt-pkg/packagemanager.cc
More changes to make imediate configuration work for all packages,
[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 // PM::PackageManager - Constructor /*{{{*/
33 // ---------------------------------------------------------------------
34 /* */
35 pkgPackageManager::pkgPackageManager(pkgDepCache *pCache) : Cache(*pCache)
36 {
37 FileNames = new string[Cache.Head().PackageCount];
38 List = 0;
39 Debug = _config->FindB("Debug::pkgPackageManager",false);
40 }
41 /*}}}*/
42 // PM::PackageManager - Destructor /*{{{*/
43 // ---------------------------------------------------------------------
44 /* */
45 pkgPackageManager::~pkgPackageManager()
46 {
47 delete List;
48 delete [] FileNames;
49 }
50 /*}}}*/
51 // PM::GetArchives - Queue the archives for download /*{{{*/
52 // ---------------------------------------------------------------------
53 /* */
54 bool pkgPackageManager::GetArchives(pkgAcquire *Owner,pkgSourceList *Sources,
55 pkgRecords *Recs)
56 {
57 if (CreateOrderList() == false)
58 return false;
59
60 bool const ordering =
61 _config->FindB("PackageManager::UnpackAll",true) ?
62 List->OrderUnpack() : List->OrderCritical();
63 if (ordering == false)
64 return _error->Error("Internal ordering error");
65
66 for (pkgOrderList::iterator I = List->begin(); I != List->end(); I++)
67 {
68 PkgIterator Pkg(Cache,*I);
69 FileNames[Pkg->ID] = string();
70
71 // Skip packages to erase
72 if (Cache[Pkg].Delete() == true)
73 continue;
74
75 // Skip Packages that need configure only.
76 if (Pkg.State() == pkgCache::PkgIterator::NeedsConfigure &&
77 Cache[Pkg].Keep() == true)
78 continue;
79
80 // Skip already processed packages
81 if (List->IsNow(Pkg) == false)
82 continue;
83
84 new pkgAcqArchive(Owner,Sources,Recs,Cache[Pkg].InstVerIter(Cache),
85 FileNames[Pkg->ID]);
86 }
87
88 return true;
89 }
90 /*}}}*/
91 // PM::FixMissing - Keep all missing packages /*{{{*/
92 // ---------------------------------------------------------------------
93 /* This is called to correct the installation when packages could not
94 be downloaded. */
95 bool pkgPackageManager::FixMissing()
96 {
97 pkgDepCache::ActionGroup group(Cache);
98 pkgProblemResolver Resolve(&Cache);
99 List->SetFileList(FileNames);
100
101 bool Bad = false;
102 for (PkgIterator I = Cache.PkgBegin(); I.end() == false; I++)
103 {
104 if (List->IsMissing(I) == false)
105 continue;
106
107 // Okay, this file is missing and we need it. Mark it for keep
108 Bad = true;
109 Cache.MarkKeep(I, false, false);
110 }
111
112 // We have to empty the list otherwise it will not have the new changes
113 delete List;
114 List = 0;
115
116 if (Bad == false)
117 return true;
118
119 // Now downgrade everything that is broken
120 return Resolve.ResolveByKeep() == true && Cache.BrokenCount() == 0;
121 }
122 /*}}}*/
123 // PM::ImmediateAdd - Add the immediate flag recursivly /*{{{*/
124 // ---------------------------------------------------------------------
125 /* This adds the immediate flag to the pkg and recursively to the
126 dependendies
127 */
128 void pkgPackageManager::ImmediateAdd(PkgIterator I, bool UseInstallVer, unsigned const int &Depth)
129 {
130 DepIterator D;
131
132 if(UseInstallVer)
133 {
134 if(Cache[I].InstallVer == 0)
135 return;
136 D = Cache[I].InstVerIter(Cache).DependsList();
137 } else {
138 if (I->CurrentVer == 0)
139 return;
140 D = I.CurrentVer().DependsList();
141 }
142
143 for ( /* nothing */ ; D.end() == false; D++)
144 if (D->Type == pkgCache::Dep::Depends || D->Type == pkgCache::Dep::PreDepends)
145 {
146 if(!List->IsFlag(D.TargetPkg(), pkgOrderList::Immediate))
147 {
148 if(Debug)
149 clog << OutputInDepth(Depth) << "ImmediateAdd(): Adding Immediate flag to " << D.TargetPkg() << " cause of " << D.DepType() << " " << I.Name() << endl;
150 List->Flag(D.TargetPkg(),pkgOrderList::Immediate);
151 ImmediateAdd(D.TargetPkg(), UseInstallVer, Depth + 1);
152 }
153 }
154 return;
155 }
156 /*}}}*/
157 // PM::CreateOrderList - Create the ordering class /*{{{*/
158 // ---------------------------------------------------------------------
159 /* This populates the ordering list with all the packages that are
160 going to change. */
161 bool pkgPackageManager::CreateOrderList()
162 {
163 if (List != 0)
164 return true;
165
166 delete List;
167 List = new pkgOrderList(&Cache);
168
169 static bool const NoImmConfigure = !_config->FindB("APT::Immediate-Configure",true);
170 ImmConfigureAll = _config->FindB("APT::Immediate-Configure-All",false);
171
172 if (Debug && ImmConfigureAll)
173 clog << "CreateOrderList(): Adding Immediate flag for all packages because of APT::Immediate-Configure-All" << endl;
174
175 // Generate the list of affected packages and sort it
176 for (PkgIterator I = Cache.PkgBegin(); I.end() == false; I++)
177 {
178 // Ignore no-version packages
179 if (I->VersionList == 0)
180 continue;
181
182 // Mark the package and its dependends for immediate configuration
183 if ((((I->Flags & pkgCache::Flag::Essential) == pkgCache::Flag::Essential ||
184 (I->Flags & pkgCache::Flag::Important) == pkgCache::Flag::Important) &&
185 NoImmConfigure == false) || ImmConfigureAll)
186 {
187 if(Debug && !ImmConfigureAll)
188 clog << "CreateOrderList(): Adding Immediate flag for " << I.Name() << endl;
189 List->Flag(I,pkgOrderList::Immediate);
190
191 if (!ImmConfigureAll) {
192 // Look for other install packages to make immediate configurea
193 ImmediateAdd(I, true);
194
195 // And again with the current version.
196 ImmediateAdd(I, false);
197 }
198 }
199
200 // Not interesting
201 if ((Cache[I].Keep() == true ||
202 Cache[I].InstVerIter(Cache) == I.CurrentVer()) &&
203 I.State() == pkgCache::PkgIterator::NeedsNothing &&
204 (Cache[I].iFlags & pkgDepCache::ReInstall) != pkgDepCache::ReInstall &&
205 (I.Purge() != false || Cache[I].Mode != pkgDepCache::ModeDelete ||
206 (Cache[I].iFlags & pkgDepCache::Purge) != pkgDepCache::Purge))
207 continue;
208
209 // Append it to the list
210 List->push_back(I);
211 }
212
213 return true;
214 }
215 /*}}}*/
216 // PM::DepAlwaysTrue - Returns true if this dep is irrelevent /*{{{*/
217 // ---------------------------------------------------------------------
218 /* The restriction on provides is to eliminate the case when provides
219 are transitioning between valid states [ie exim to smail] */
220 bool pkgPackageManager::DepAlwaysTrue(DepIterator D)
221 {
222 if (D.TargetPkg()->ProvidesList != 0)
223 return false;
224
225 if ((Cache[D] & pkgDepCache::DepInstall) != 0 &&
226 (Cache[D] & pkgDepCache::DepNow) != 0)
227 return true;
228 return false;
229 }
230 /*}}}*/
231 // PM::CheckRConflicts - Look for reverse conflicts /*{{{*/
232 // ---------------------------------------------------------------------
233 /* This looks over the reverses for a conflicts line that needs early
234 removal. */
235 bool pkgPackageManager::CheckRConflicts(PkgIterator Pkg,DepIterator D,
236 const char *Ver)
237 {
238 for (;D.end() == false; D++)
239 {
240 if (D->Type != pkgCache::Dep::Conflicts &&
241 D->Type != pkgCache::Dep::Obsoletes)
242 continue;
243
244 // The package hasnt been changed
245 if (List->IsNow(Pkg) == false)
246 continue;
247
248 // Ignore self conflicts, ignore conflicts from irrelevent versions
249 if (D.ParentPkg() == Pkg || D.ParentVer() != D.ParentPkg().CurrentVer())
250 continue;
251
252 if (Cache.VS().CheckDep(Ver,D->CompareOp,D.TargetVer()) == false)
253 continue;
254
255 if (EarlyRemove(D.ParentPkg()) == false)
256 return _error->Error("Reverse conflicts early remove for package '%s' failed",
257 Pkg.Name());
258 }
259 return true;
260 }
261 /*}}}*/
262 // PM::ConfigureAll - Run the all out configuration /*{{{*/
263 // ---------------------------------------------------------------------
264 /* This configures every package. It is assumed they are all unpacked and
265 that the final configuration is valid. */
266 bool pkgPackageManager::ConfigureAll()
267 {
268 pkgOrderList OList(&Cache);
269
270 // Populate the order list
271 for (pkgOrderList::iterator I = List->begin(); I != List->end(); I++)
272 if (List->IsFlag(pkgCache::PkgIterator(Cache,*I),
273 pkgOrderList::UnPacked) == true)
274 OList.push_back(*I);
275
276 if (OList.OrderConfigure() == false)
277 return false;
278
279 std::string const conf = _config->Find("PackageManager::Configure","all");
280 bool const ConfigurePkgs = (conf == "all");
281
282 // Perform the configuring
283 for (pkgOrderList::iterator I = OList.begin(); I != OList.end(); I++)
284 {
285 PkgIterator Pkg(Cache,*I);
286
287 if (ConfigurePkgs == true && VerifyAndConfigure(Pkg,OList) == false)
288 return false;
289
290 List->Flag(Pkg,pkgOrderList::Configured,pkgOrderList::States);
291 }
292
293 return true;
294 }
295 /*}}}*/
296 // PM::SmartConfigure - Perform immediate configuration of the pkg /*{{{*/
297 // ---------------------------------------------------------------------
298 /* This routine scheduals the configuration of the given package and all
299 of it's dependents. */
300 bool pkgPackageManager::SmartConfigure(PkgIterator Pkg)
301 {
302 if (Debug == true)
303 clog << "SmartConfigure " << Pkg.Name() << endl;
304
305 pkgOrderList OList(&Cache);
306
307 if (DepAdd(OList,Pkg) == false)
308 return false;
309
310 static std::string const conf = _config->Find("PackageManager::Configure","all");
311 static bool const ConfigurePkgs = (conf == "all" || conf == "smart");
312
313 if (ConfigurePkgs == true)
314 if (OList.OrderConfigure() == false)
315 return false;
316
317 // Perform the configuring
318 for (pkgOrderList::iterator I = OList.begin(); I != OList.end(); I++)
319 {
320 PkgIterator Pkg(Cache,*I);
321
322 if (ConfigurePkgs == true && VerifyAndConfigure(Pkg,OList) == false)
323 return false;
324
325 List->Flag(Pkg,pkgOrderList::Configured,pkgOrderList::States);
326 }
327
328 if (Cache[Pkg].InstVerIter(Cache)->MultiArch == pkgCache::Version::Same)
329 for (PkgIterator P = Pkg.Group().PackageList();
330 P.end() == false; P = Pkg.Group().NextPkg(P))
331 {
332 if (Pkg == P || List->IsFlag(P,pkgOrderList::Configured) == true ||
333 Cache[P].InstallVer == 0 || (P.CurrentVer() == Cache[P].InstallVer &&
334 (Cache[Pkg].iFlags & pkgDepCache::ReInstall) != pkgDepCache::ReInstall))
335 continue;
336 SmartConfigure(P);
337 }
338
339 // Sanity Check
340 if (List->IsFlag(Pkg,pkgOrderList::Configured) == false)
341 return _error->Error(_("Could not perform immediate configuration on '%s'. "
342 "Please see man 5 apt.conf under APT::Immediate-Configure for details. (%d)"),Pkg.Name(),1);
343
344 return true;
345 }
346
347 // PM::VerifyConfigure - Check configuration of dependancies /*{{{*/
348 // ---------------------------------------------------------------------
349 /* This routine checks that all a packages dependancies have been
350 configured, before it is going to be configured. If this gives a warning
351 on a virtual package, it means that the package thats providing it is not
352 configured*/
353 bool pkgPackageManager::VerifyConfigure(PkgIterator Pkg, pkgOrderList &OList)
354 {
355 // If this is true at the end, then the package should not be configured
356 bool error=true;
357 // This holds the the OR status of the previous dependancy
358 bool previousOr=false;
359
360 // First iterate through the dependancies of Pkg
361 for (DepIterator D = Cache[Pkg].InstVerIter(Cache).DependsList(); D.end() == false; D++)
362 {
363
364 /* If the dependancy is of type Depends or PreDepends, we need to check it, but only if it is going to be
365 configured at some point */
366 if (D->Type == pkgCache::Dep::Depends || D->Type == pkgCache::Dep::PreDepends) {
367
368 /* If the previous package and this package are OR dependancies, and the previous package satisfied the dependancy
369 then skip this dependancy as it is not relevent, this will repeat for the next package if the situation is the
370 same */
371 if (previousOr && !error) { // As error has not been reset, this refers to the previous dependancy
372 previousOr = (D->CompareOp & pkgCache::Dep::Or) == pkgCache::Dep::Or;
373 continue;
374 }
375
376 // Reset error
377 error = true;
378
379 // Check thorugh all possible versions of this dependancy (D)
380 SPtrArray<Version *> VList = D.AllTargets();
381 for (Version **I = VList; *I != 0; I++)
382 {
383 VerIterator DepVer(Cache,*I);
384 PkgIterator DepPkg = DepVer.ParentPkg();
385 VerIterator DepInstallVer(Cache,Cache[DepPkg].InstallVer);
386
387 if (DepPkg.CurrentVer() == DepVer && !List->IsFlag(DepPkg,pkgOrderList::UnPacked)) {
388 error=false;
389 break;
390 }
391
392 if (Cache[DepPkg].InstallVer == DepVer &&
393 (List->IsFlag(DepPkg,pkgOrderList::Configured) || OList.IsFlag(DepPkg,pkgOrderList::InList))) {
394 error=false;
395 break;
396 }
397 }
398
399 /* Only worry here if this package is a OR with the next, as even though this package does not satisfy the OR
400 the next one might */
401 if (error && !((D->CompareOp & pkgCache::Dep::Or) == pkgCache::Dep::Or)) {
402 _error->Error("Package %s should not be configured because package %s is not configured",Pkg.Name(),D.TargetPkg().Name());
403 return false;
404 /* If the previous package is a OR but not this package, but there is still an error then fail as it will not
405 be satisfied */
406 } else if (error && previousOr && !((D->CompareOp & pkgCache::Dep::Or) == pkgCache::Dep::Or)) {
407 _error->Error("Package %s should not be configured because package %s (or any alternatives) are not configured",Pkg.Name(),D.TargetPkg().Name());
408 return false;
409 }
410
411 previousOr = (D->CompareOp & pkgCache::Dep::Or) == pkgCache::Dep::Or;
412 } else {
413 previousOr=false;
414 }
415 }
416 return true;
417 }
418
419 // PM::VerifyAndConfigure - Check configuration of dependancies /*{{{*/
420 // ---------------------------------------------------------------------
421 /* This routine verifies if a package can be configured and if so
422 configures it */
423 bool pkgPackageManager::VerifyAndConfigure(PkgIterator Pkg, pkgOrderList &OList)
424 {
425 if (VerifyConfigure(Pkg, OList))
426 return Configure(Pkg);
427 else
428 return false;
429
430 }
431 /*}}}*/
432 // PM::DepAdd - Add all dependents to the oder list /*{{{*/
433 // ---------------------------------------------------------------------
434 /* This recursively adds all dependents to the order list */
435 bool pkgPackageManager::DepAdd(pkgOrderList &OList,PkgIterator Pkg,int Depth)
436 {
437 if (OList.IsFlag(Pkg,pkgOrderList::Added) == true)
438 return true;
439 if (List->IsFlag(Pkg,pkgOrderList::Configured) == true)
440 return true;
441 if (List->IsFlag(Pkg,pkgOrderList::UnPacked) == false)
442 return false;
443
444 if (Debug)
445 std::clog << OutputInDepth(Depth) << "DepAdd: " << Pkg.Name() << std::endl;
446
447 // Put the package on the list
448 OList.push_back(Pkg);
449 OList.Flag(Pkg,pkgOrderList::Added);
450 Depth++;
451
452 // Check the dependencies to see if they are all satisfied.
453 bool Bad = false;
454 for (DepIterator D = Cache[Pkg].InstVerIter(Cache).DependsList(); D.end() == false;)
455 {
456 if (D->Type != pkgCache::Dep::Depends && D->Type != pkgCache::Dep::PreDepends)
457 {
458 D++;
459 continue;
460 }
461
462 // Grok or groups
463 Bad = true;
464 for (bool LastOR = true; D.end() == false && LastOR == true; D++)
465 {
466 LastOR = (D->CompareOp & pkgCache::Dep::Or) == pkgCache::Dep::Or;
467
468 if (Bad == false)
469 continue;
470
471 SPtrArray<Version *> VList = D.AllTargets();
472 for (Version **I = VList; *I != 0 && Bad == true; I++)
473 {
474 VerIterator Ver(Cache,*I);
475 PkgIterator Pkg = Ver.ParentPkg();
476 VerIterator InstallVer(Cache,Cache[Pkg].InstallVer);
477 VerIterator CandVer(Cache,Cache[Pkg].CandidateVer);
478
479 if (Debug && false) {
480 if (Ver==0) {
481 cout << OutputInDepth(Depth) << "Checking if " << Ver << " of " << Pkg.Name() << " satisfies this dependancy" << endl;
482 } else {
483 cout << OutputInDepth(Depth) << "Checking if " << Ver.VerStr() << " of " << Pkg.Name() << " satisfies this dependancy" << endl;
484 }
485
486 if (Pkg.CurrentVer()==0) {
487 cout << OutputInDepth(Depth) << " CurrentVer " << Pkg.CurrentVer() << " IsNow " << List->IsNow(Pkg) << " NeedsNothing " << (Pkg.State() == PkgIterator::NeedsNothing) << endl;
488 } else {
489 cout << OutputInDepth(Depth) << " CurrentVer " << Pkg.CurrentVer().VerStr() << " IsNow " << List->IsNow(Pkg) << " NeedsNothing " << (Pkg.State() == PkgIterator::NeedsNothing) << endl;
490 }
491
492 if (InstallVer==0) {
493 cout << OutputInDepth(Depth )<< " InstallVer " << InstallVer << endl;
494 } else {
495 cout << OutputInDepth(Depth )<< " InstallVer " << InstallVer.VerStr() << endl;
496 }
497 if (CandVer != 0)
498 cout << " CandVer " << CandVer.VerStr() << endl;
499
500 cout << OutputInDepth(Depth) << " Keep " << Cache[Pkg].Keep() << " Unpacked " << List->IsFlag(Pkg,pkgOrderList::UnPacked) << " Configured " << List->IsFlag(Pkg,pkgOrderList::Configured) << endl;
501
502 }
503 // See if the current version is ok
504 if (Pkg.CurrentVer() == Ver && List->IsNow(Pkg) == true &&
505 Pkg.State() == PkgIterator::NeedsNothing)
506 {
507 Bad = false;
508 continue;
509 }
510
511 // Not the install version
512 if ((Cache[Pkg].InstallVer != *I && Cache[Pkg].CandidateVer != *I) ||
513 (Cache[Pkg].Keep() == true && Pkg.State() == PkgIterator::NeedsNothing &&
514 (Cache[Pkg].iFlags & pkgDepCache::ReInstall) != pkgDepCache::ReInstall))
515 continue;
516
517 if (List->IsFlag(Pkg,pkgOrderList::UnPacked) == true)
518 Bad = !DepAdd(OList,Pkg,Depth);
519 if (List->IsFlag(Pkg,pkgOrderList::Configured) == true)
520 Bad = false;
521 }
522 }
523
524 if (Bad == true)
525 {
526 if (Debug)
527 std::clog << OutputInDepth(Depth) << "DepAdd FAILS on: " << Pkg.Name() << std::endl;
528 OList.Flag(Pkg,0,pkgOrderList::Added);
529 OList.pop_back();
530 Depth--;
531 return false;
532 }
533 }
534
535 Depth--;
536 return true;
537 }
538 /*}}}*/
539 // PM::EarlyRemove - Perform removal of packages before their time /*{{{*/
540 // ---------------------------------------------------------------------
541 /* This is called to deal with conflicts arising from unpacking */
542 bool pkgPackageManager::EarlyRemove(PkgIterator Pkg)
543 {
544 if (List->IsNow(Pkg) == false)
545 return true;
546
547 // Already removed it
548 if (List->IsFlag(Pkg,pkgOrderList::Removed) == true)
549 return true;
550
551 // Woops, it will not be re-installed!
552 if (List->IsFlag(Pkg,pkgOrderList::InList) == false)
553 return false;
554
555 // Essential packages get special treatment
556 bool IsEssential = false;
557 if ((Pkg->Flags & pkgCache::Flag::Essential) != 0)
558 IsEssential = true;
559
560 /* Check for packages that are the dependents of essential packages and
561 promote them too */
562 if (Pkg->CurrentVer != 0)
563 {
564 for (DepIterator D = Pkg.RevDependsList(); D.end() == false &&
565 IsEssential == false; D++)
566 if (D->Type == pkgCache::Dep::Depends || D->Type == pkgCache::Dep::PreDepends)
567 if ((D.ParentPkg()->Flags & pkgCache::Flag::Essential) != 0)
568 IsEssential = true;
569 }
570
571 if (IsEssential == true)
572 {
573 if (_config->FindB("APT::Force-LoopBreak",false) == false)
574 return _error->Error(_("This installation run will require temporarily "
575 "removing the essential package %s due to a "
576 "Conflicts/Pre-Depends loop. This is often bad, "
577 "but if you really want to do it, activate the "
578 "APT::Force-LoopBreak option."),Pkg.Name());
579 }
580
581 bool Res = SmartRemove(Pkg);
582 if (Cache[Pkg].Delete() == false)
583 List->Flag(Pkg,pkgOrderList::Removed,pkgOrderList::States);
584
585 return Res;
586 }
587 /*}}}*/
588 // PM::SmartRemove - Removal Helper /*{{{*/
589 // ---------------------------------------------------------------------
590 /* */
591 bool pkgPackageManager::SmartRemove(PkgIterator Pkg)
592 {
593 if (List->IsNow(Pkg) == false)
594 return true;
595
596 List->Flag(Pkg,pkgOrderList::Configured,pkgOrderList::States);
597
598 return Remove(Pkg,(Cache[Pkg].iFlags & pkgDepCache::Purge) == pkgDepCache::Purge);
599 return true;
600 }
601 /*}}}*/
602 // PM::SmartUnPack - Install helper /*{{{*/
603 // ---------------------------------------------------------------------
604 /* This performs the task of handling pre-depends. */
605 bool pkgPackageManager::SmartUnPack(PkgIterator Pkg)
606 {
607 return SmartUnPack(Pkg, true);
608 }
609 bool pkgPackageManager::SmartUnPack(PkgIterator Pkg, bool const Immediate)
610 {
611 if (Debug == true)
612 clog << "SmartUnPack " << Pkg.Name() << endl;
613
614 // Check if it is already unpacked
615 if (Pkg.State() == pkgCache::PkgIterator::NeedsConfigure &&
616 Cache[Pkg].Keep() == true)
617 {
618 List->Flag(Pkg,pkgOrderList::UnPacked,pkgOrderList::States);
619 if (Immediate == true &&
620 List->IsFlag(Pkg,pkgOrderList::Immediate) == true)
621 if (SmartConfigure(Pkg) == false)
622 return _error->Error(_("Could not perform immediate configuration on already unpacked '%s'. "
623 "Please see man 5 apt.conf under APT::Immediate-Configure for details."),Pkg.Name());
624 return true;
625 }
626
627 VerIterator const instVer = Cache[Pkg].InstVerIter(Cache);
628
629 /* See if this packages install version has any predependencies
630 that are not met by 'now' packages. */
631 for (DepIterator D = instVer.DependsList();
632 D.end() == false; )
633 {
634 // Compute a single dependency element (glob or)
635 pkgCache::DepIterator Start;
636 pkgCache::DepIterator End;
637 D.GlobOr(Start,End);
638
639 while (End->Type == pkgCache::Dep::PreDepends)
640 {
641 if (Debug)
642 clog << "PreDepends order for " << Pkg.Name() << std::endl;
643
644 // Look for possible ok targets.
645 SPtrArray<Version *> VList = Start.AllTargets();
646 bool Bad = true;
647 for (Version **I = VList; *I != 0 && Bad == true; I++)
648 {
649 VerIterator Ver(Cache,*I);
650 PkgIterator Pkg = Ver.ParentPkg();
651
652 // See if the current version is ok
653 if (Pkg.CurrentVer() == Ver && List->IsNow(Pkg) == true &&
654 Pkg.State() == PkgIterator::NeedsNothing)
655 {
656 Bad = false;
657 if (Debug)
658 clog << "Found ok package " << Pkg.Name() << endl;
659 continue;
660 }
661 }
662
663 // Look for something that could be configured.
664 for (Version **I = VList; *I != 0 && Bad == true; I++)
665 {
666 VerIterator Ver(Cache,*I);
667 PkgIterator Pkg = Ver.ParentPkg();
668
669 // Not the install version
670 if (Cache[Pkg].InstallVer != *I ||
671 (Cache[Pkg].Keep() == true && Pkg.State() == PkgIterator::NeedsNothing))
672 continue;
673
674 if (Debug)
675 clog << "Trying to SmartConfigure " << Pkg.Name() << endl;
676 Bad = !SmartConfigure(Pkg);
677 }
678
679 /* If this or element did not match then continue on to the
680 next or element until a matching element is found */
681 if (Bad == true)
682 {
683 // This triggers if someone make a pre-depends/depend loop.
684 if (Start == End)
685 return _error->Error("Couldn't configure pre-depend %s for %s, "
686 "probably a dependency cycle.",
687 End.TargetPkg().Name(),Pkg.Name());
688 Start++;
689 }
690 else
691 break;
692 }
693
694 if (End->Type == pkgCache::Dep::Conflicts ||
695 End->Type == pkgCache::Dep::Obsoletes)
696 {
697 /* Look for conflicts. Two packages that are both in the install
698 state cannot conflict so we don't check.. */
699 SPtrArray<Version *> VList = End.AllTargets();
700 for (Version **I = VList; *I != 0; I++)
701 {
702 VerIterator Ver(Cache,*I);
703 PkgIterator ConflictPkg = Ver.ParentPkg();
704 VerIterator InstallVer(Cache,Cache[ConflictPkg].InstallVer);
705
706 // See if the current version is conflicting
707 if (ConflictPkg.CurrentVer() == Ver && !List->IsFlag(ConflictPkg,pkgOrderList::UnPacked))
708 {
709 if (Debug && false)
710 cout << " " << Pkg.Name() << " conflicts with " << ConflictPkg.Name() << endl;
711
712 if (Debug && false) {
713 if (Ver==0) {
714 cout << " Checking if " << Ver << " of " << ConflictPkg.Name() << " satisfies this dependancy" << endl;
715 } else {
716 cout << " Checking if " << Ver.VerStr() << " of " << ConflictPkg.Name() << " satisfies this dependancy" << endl;
717 }
718
719 if (ConflictPkg.CurrentVer()==0) {
720 cout << " CurrentVer " << ConflictPkg.CurrentVer() << " IsNow " << List->IsNow(ConflictPkg) << " NeedsNothing " << (ConflictPkg.State() == PkgIterator::NeedsNothing) << endl;
721 } else {
722 cout << " CurrentVer " << ConflictPkg.CurrentVer().VerStr() << " IsNow " << List->IsNow(ConflictPkg) << " NeedsNothing " << (ConflictPkg.State() == PkgIterator::NeedsNothing) << endl;
723 }
724
725 if (InstallVer==0) {
726 cout << " InstallVer " << InstallVer << endl;
727 } else {
728 cout << " InstallVer " << InstallVer.VerStr() << endl;
729 }
730
731 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;
732 cout << " Delete " << Cache[ConflictPkg].Delete() << endl;
733 }
734
735 if (!List->IsFlag(ConflictPkg,pkgOrderList::Loop)) {
736 if (Cache[ConflictPkg].Keep() == 0 && Cache[ConflictPkg].InstallVer != 0) {
737 cout << "Unpacking " << ConflictPkg.Name() << " to prevent conflict" << endl;
738 List->Flag(Pkg,pkgOrderList::Loop);
739 SmartUnPack(ConflictPkg,false);
740 } else {
741 if (EarlyRemove(ConflictPkg) == false)
742 return _error->Error("Internal Error, Could not early remove %s",ConflictPkg.Name());
743 }
744 } else {
745 if (!List->IsFlag(ConflictPkg,pkgOrderList::Removed)) {
746 cout << "Because of conficts knot, removing " << ConflictPkg.Name() << " to conflict violation" << endl;
747 if (EarlyRemove(ConflictPkg) == false)
748 return _error->Error("Internal Error, Could not early remove %s",ConflictPkg.Name());
749 }
750 }
751 }
752 }
753 }
754
755 // Check for breaks
756 if (End->Type == pkgCache::Dep::DpkgBreaks) {
757 SPtrArray<Version *> VList = End.AllTargets();
758 for (Version **I = VList; *I != 0; I++)
759 {
760 VerIterator Ver(Cache,*I);
761 PkgIterator BrokenPkg = Ver.ParentPkg();
762 VerIterator InstallVer(Cache,Cache[BrokenPkg].InstallVer);
763
764 cout << " " << Pkg.Name() << " breaks " << BrokenPkg.Name() << endl;
765 if (Debug && false) {
766 if (Ver==0) {
767 cout << " Checking if " << Ver << " of " << BrokenPkg.Name() << " satisfies this dependancy" << endl;
768 } else {
769 cout << " Checking if " << Ver.VerStr() << " of " << BrokenPkg.Name() << " satisfies this dependancy" << endl;
770 }
771
772 if (BrokenPkg.CurrentVer()==0) {
773 cout << " CurrentVer " << BrokenPkg.CurrentVer() << " IsNow " << List->IsNow(BrokenPkg) << " NeedsNothing " << (BrokenPkg.State() == PkgIterator::NeedsNothing) << endl;
774 } else {
775 cout << " CurrentVer " << BrokenPkg.CurrentVer().VerStr() << " IsNow " << List->IsNow(BrokenPkg) << " NeedsNothing " << (BrokenPkg.State() == PkgIterator::NeedsNothing) << endl;
776 }
777
778 if (InstallVer==0) {
779 cout << " InstallVer " << InstallVer << endl;
780 } else {
781 cout << " InstallVer " << InstallVer.VerStr() << endl;
782 }
783
784 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;
785 cout << " Delete " << Cache[BrokenPkg].Delete() << endl;
786 }
787 // Check if it needs to be unpacked
788 if (List->IsFlag(BrokenPkg,pkgOrderList::InList) && Cache[BrokenPkg].Delete() == false &&
789 !List->IsFlag(BrokenPkg,pkgOrderList::Loop) && List->IsNow(BrokenPkg)) {
790 List->Flag(Pkg,pkgOrderList::Loop);
791 // Found a break, so unpack the package
792 if (Debug)
793 cout << " Unpacking " << BrokenPkg.Name() << " to avoid break" << endl;
794 SmartUnPack(BrokenPkg, false);
795 }
796 // Check if a package needs to be removed
797 if (Cache[BrokenPkg].Delete() == true && !List->IsFlag(BrokenPkg,pkgOrderList::Configured)) {
798 if (Debug)
799 cout << " Removing " << BrokenPkg.Name() << " to avoid break" << endl;
800 SmartRemove(BrokenPkg);
801 }
802 }
803 }
804 }
805
806 // FIXME: Crude but effective fix, allows the SmartUnPack method to be used for packages that new to the system
807 if (instVer != 0) {
808 //cout << "Check for reverse conflicts on " << Pkg.Name() << " " << instVer.VerStr() << endl;
809
810 // Check for reverse conflicts.
811 if (CheckRConflicts(Pkg,Pkg.RevDependsList(),
812 instVer.VerStr()) == false)
813 return false;
814
815 for (PrvIterator P = instVer.ProvidesList();
816 P.end() == false; P++)
817 CheckRConflicts(Pkg,P.ParentPkg().RevDependsList(),P.ProvideVersion());
818
819 List->Flag(Pkg,pkgOrderList::UnPacked,pkgOrderList::States);
820
821 if (instVer->MultiArch == pkgCache::Version::Same)
822 for (PkgIterator P = Pkg.Group().PackageList();
823 P.end() == false; P = Pkg.Group().NextPkg(P))
824 {
825 if (Pkg == P || List->IsFlag(P,pkgOrderList::UnPacked) == true ||
826 Cache[P].InstallVer == 0 || (P.CurrentVer() == Cache[P].InstallVer &&
827 (Cache[Pkg].iFlags & pkgDepCache::ReInstall) != pkgDepCache::ReInstall))
828 continue;
829 SmartUnPack(P, false);
830 }
831
832 } else {
833 VerIterator InstallVer(Cache,Cache[Pkg].InstallVer);
834 //cout << "Check for reverse conflicts on " << Pkg.Name() << " " << InstallVer.VerStr() << endl;
835
836 // Check for reverse conflicts.
837 if (CheckRConflicts(Pkg,Pkg.RevDependsList(),
838 InstallVer.VerStr()) == false)
839 return false;
840
841 List->Flag(Pkg,pkgOrderList::UnPacked,pkgOrderList::States);
842 }
843
844 if(Install(Pkg,FileNames[Pkg->ID]) == false)
845 return false;
846
847 /* Because of the ordered list, most dependancies should be unpacked,
848 however if there is a loop this is not the case, so check for dependancies before configuring.
849 This is done after the package installation as it makes it easier to deal with conflicts problems */
850 for (DepIterator D = instVer.DependsList();
851 D.end() == false; )
852 {
853 // Compute a single dependency element (glob or)
854 pkgCache::DepIterator Start;
855 pkgCache::DepIterator End;
856 D.GlobOr(Start,End);
857
858 // Check for dependanices that have not been unpacked, probably due to loops.
859 bool Bad = true;
860 while (End->Type == pkgCache::Dep::Depends) {
861 PkgIterator DepPkg;
862 VerIterator InstallVer;
863 SPtrArray<Version *> VList = Start.AllTargets();
864
865 for (Version **I = VList; *I != 0; I++) {
866 VerIterator Ver(Cache,*I);
867 DepPkg = Ver.ParentPkg();
868
869 if (!Bad) continue;
870
871 InstallVer = VerIterator(Cache,Cache[DepPkg].InstallVer);
872 VerIterator CandVer(Cache,Cache[DepPkg].CandidateVer);
873
874 if (Debug && false) {
875 if (Ver==0) {
876 cout << " Checking if " << Ver << " of " << DepPkg.Name() << " satisfies this dependancy" << endl;
877 } else {
878 cout << " Checking if " << Ver.VerStr() << " of " << DepPkg.Name() << " satisfies this dependancy" << endl;
879 }
880
881 if (DepPkg.CurrentVer()==0) {
882 cout << " CurrentVer " << DepPkg.CurrentVer() << " IsNow " << List->IsNow(DepPkg) << " NeedsNothing " << (DepPkg.State() == PkgIterator::NeedsNothing) << endl;
883 } else {
884 cout << " CurrentVer " << DepPkg.CurrentVer().VerStr() << " IsNow " << List->IsNow(DepPkg) << " NeedsNothing " << (DepPkg.State() == PkgIterator::NeedsNothing) << endl;
885 }
886
887 if (InstallVer==0) {
888 cout << " InstallVer " << InstallVer << endl;
889 } else {
890 cout << " InstallVer " << InstallVer.VerStr() << endl;
891 }
892 if (CandVer != 0)
893 cout << " CandVer " << CandVer.VerStr() << endl;
894
895 cout << " Keep " << Cache[DepPkg].Keep() << " Unpacked " << List->IsFlag(DepPkg,pkgOrderList::UnPacked) << " Configured " << List->IsFlag(DepPkg,pkgOrderList::Configured) << endl;
896
897 }
898
899 // Check if it satisfies this dependancy
900 if (DepPkg.CurrentVer() == Ver && List->IsNow(DepPkg) == true &&
901 DepPkg.State() == PkgIterator::NeedsNothing)
902 {
903 Bad = false;
904 continue;
905 }
906
907 if (Cache[DepPkg].InstallVer == *I && !List->IsNow(DepPkg)) {
908 Bad = false;
909 continue;
910 }
911 }
912
913 if (InstallVer != 0 && Bad) {
914 Bad = false;
915 // Found a break, so unpack the package
916 List->Flag(Pkg,pkgOrderList::Loop);
917 if (!List->IsFlag(DepPkg,pkgOrderList::Loop)) {
918 if (Debug)
919 cout << " Unpacking " << DepPkg.Name() << " to avoid loop" << endl;
920 SmartUnPack(DepPkg, false);
921 }
922 }
923
924 if (Start==End) {
925 if (Bad) {
926 //return
927 _error->Error("Could not satisfy dependancies for %s",Pkg.Name());
928 }
929 break;
930
931 } else {
932 Start++;
933 }
934 }
935 }
936
937 // Perform immedate configuration of the package.
938 if (Immediate == true &&
939 List->IsFlag(Pkg,pkgOrderList::Immediate) == true)
940 if (SmartConfigure(Pkg) == false)
941 //return
942 _error->Error(_("Could not perform immediate configuration on '%s'. "
943 "Please see man 5 apt.conf under APT::Immediate-Configure for details. (%d)"),Pkg.Name(),2);
944
945 return true;
946 }
947 /*}}}*/
948 // PM::OrderInstall - Installation ordering routine /*{{{*/
949 // ---------------------------------------------------------------------
950 /* */
951 pkgPackageManager::OrderResult pkgPackageManager::OrderInstall()
952 {
953 if (CreateOrderList() == false)
954 return Failed;
955
956 Reset();
957
958 if (Debug == true)
959 clog << "Beginning to order" << endl;
960
961 bool const ordering =
962 _config->FindB("PackageManager::UnpackAll",true) ?
963 List->OrderUnpack(FileNames) : List->OrderCritical();
964 if (ordering == false)
965 {
966 _error->Error("Internal ordering error");
967 return Failed;
968 }
969
970 if (Debug == true)
971 clog << "Done ordering" << endl;
972
973 bool DoneSomething = false;
974 for (pkgOrderList::iterator I = List->begin(); I != List->end(); I++)
975 {
976 PkgIterator Pkg(Cache,*I);
977
978 if (List->IsNow(Pkg) == false)
979 {
980 if (Debug == true)
981 clog << "Skipping already done " << Pkg.Name() << endl;
982 continue;
983 }
984
985 if (List->IsMissing(Pkg) == true)
986 {
987 if (Debug == true)
988 clog << "Sequence completed at " << Pkg.Name() << endl;
989 if (DoneSomething == false)
990 {
991 _error->Error("Internal Error, ordering was unable to handle the media swap");
992 return Failed;
993 }
994 return Incomplete;
995 }
996
997 // Sanity check
998 if (Cache[Pkg].Keep() == true &&
999 Pkg.State() == pkgCache::PkgIterator::NeedsNothing &&
1000 (Cache[Pkg].iFlags & pkgDepCache::ReInstall) != pkgDepCache::ReInstall)
1001 {
1002 _error->Error("Internal Error, trying to manipulate a kept package (%s)",Pkg.Name());
1003 return Failed;
1004 }
1005
1006 // Perform a delete or an install
1007 if (Cache[Pkg].Delete() == true)
1008 {
1009 if (SmartRemove(Pkg) == false)
1010 return Failed;
1011 }
1012 else
1013 if (SmartUnPack(Pkg) == false)
1014 return Failed;
1015 DoneSomething = true;
1016 }
1017
1018 // Final run through the configure phase
1019 if (ConfigureAll() == false)
1020 return Failed;
1021
1022 // Sanity check
1023 for (pkgOrderList::iterator I = List->begin(); I != List->end(); I++)
1024 {
1025 if (List->IsFlag(*I,pkgOrderList::Configured) == false)
1026 {
1027 _error->Error("Internal error, packages left unconfigured. %s",
1028 PkgIterator(Cache,*I).Name());
1029 return Failed;
1030 }
1031 }
1032
1033 return Completed;
1034 }
1035 /*}}}*/
1036 // PM::DoInstallPostFork - Does install part that happens after the fork /*{{{*/
1037 // ---------------------------------------------------------------------
1038 pkgPackageManager::OrderResult
1039 pkgPackageManager::DoInstallPostFork(int statusFd)
1040 {
1041 if(statusFd > 0)
1042 // FIXME: use SetCloseExec here once it taught about throwing
1043 // exceptions instead of doing _exit(100) on failure
1044 fcntl(statusFd,F_SETFD,FD_CLOEXEC);
1045 bool goResult = Go(statusFd);
1046 if(goResult == false)
1047 return Failed;
1048
1049 return Res;
1050 };
1051
1052 // PM::DoInstall - Does the installation /*{{{*/
1053 // ---------------------------------------------------------------------
1054 /* This uses the filenames in FileNames and the information in the
1055 DepCache to perform the installation of packages.*/
1056 pkgPackageManager::OrderResult pkgPackageManager::DoInstall(int statusFd)
1057 {
1058 if(DoInstallPreFork() == Failed)
1059 return Failed;
1060
1061 return DoInstallPostFork(statusFd);
1062 }
1063 /*}}}*/