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