]> git.saurik.com Git - apt.git/blame - apt-pkg/packagemanager.cc
merged from lp:~mvo/apt/mvo
[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 {
146 if(!List->IsFlag(D.TargetPkg(), pkgOrderList::Immediate))
147 {
148 if(Debug)
d183f850 149 clog << OutputInDepth(Depth) << "ImmediateAdd(): Adding Immediate flag to " << D.TargetPkg() << " cause of " << D.DepType() << " " << I.Name() << endl;
3a6d37fd 150 List->Flag(D.TargetPkg(),pkgOrderList::Immediate);
d183f850 151 ImmediateAdd(D.TargetPkg(), UseInstallVer, Depth + 1);
3a6d37fd
MV
152 }
153 }
154 return;
155}
156 /*}}}*/
7a1b1f8b
AL
157// PM::CreateOrderList - Create the ordering class /*{{{*/
158// ---------------------------------------------------------------------
159/* This populates the ordering list with all the packages that are
160 going to change. */
161bool pkgPackageManager::CreateOrderList()
162{
281daf46
AL
163 if (List != 0)
164 return true;
165
7a1b1f8b 166 delete List;
b2e465d6 167 List = new pkgOrderList(&Cache);
7a1b1f8b 168
5e312de7 169 static bool const NoImmConfigure = !_config->FindB("APT::Immediate-Configure",true);
079cc404 170
7a1b1f8b
AL
171 // Generate the list of affected packages and sort it
172 for (PkgIterator I = Cache.PkgBegin(); I.end() == false; I++)
173 {
e7b470ee
AL
174 // Ignore no-version packages
175 if (I->VersionList == 0)
176 continue;
177
138d4b3d
AL
178 // Mark the package and its dependends for immediate configuration
179 if (((I->Flags & pkgCache::Flag::Essential) == pkgCache::Flag::Essential ||
180 (I->Flags & pkgCache::Flag::Important) == pkgCache::Flag::Important) &&
079cc404 181 NoImmConfigure == false)
7a1b1f8b 182 {
3a6d37fd
MV
183 if(Debug)
184 clog << "CreateOrderList(): Adding Immediate flag for " << I.Name() << endl;
7a1b1f8b 185 List->Flag(I,pkgOrderList::Immediate);
3a6d37fd
MV
186
187 // Look for other install packages to make immediate configurea
188 ImmediateAdd(I, true);
d38b7b3d
AL
189
190 // And again with the current version.
3a6d37fd 191 ImmediateAdd(I, false);
7a1b1f8b
AL
192 }
193
194 // Not interesting
195 if ((Cache[I].Keep() == true ||
196 Cache[I].InstVerIter(Cache) == I.CurrentVer()) &&
d556d1a1 197 I.State() == pkgCache::PkgIterator::NeedsNothing &&
d0c59649 198 (Cache[I].iFlags & pkgDepCache::ReInstall) != pkgDepCache::ReInstall &&
d556d1a1
AL
199 (I.Purge() != false || Cache[I].Mode != pkgDepCache::ModeDelete ||
200 (Cache[I].iFlags & pkgDepCache::Purge) != pkgDepCache::Purge))
7a1b1f8b
AL
201 continue;
202
203 // Append it to the list
138d4b3d 204 List->push_back(I);
7a1b1f8b
AL
205 }
206
207 return true;
208}
209 /*}}}*/
6c139d6e
AL
210// PM::DepAlwaysTrue - Returns true if this dep is irrelevent /*{{{*/
211// ---------------------------------------------------------------------
212/* The restriction on provides is to eliminate the case when provides
213 are transitioning between valid states [ie exim to smail] */
214bool pkgPackageManager::DepAlwaysTrue(DepIterator D)
215{
216 if (D.TargetPkg()->ProvidesList != 0)
217 return false;
218
219 if ((Cache[D] & pkgDepCache::DepInstall) != 0 &&
220 (Cache[D] & pkgDepCache::DepNow) != 0)
221 return true;
222 return false;
223}
224 /*}}}*/
225// PM::CheckRConflicts - Look for reverse conflicts /*{{{*/
226// ---------------------------------------------------------------------
227/* This looks over the reverses for a conflicts line that needs early
228 removal. */
229bool pkgPackageManager::CheckRConflicts(PkgIterator Pkg,DepIterator D,
230 const char *Ver)
231{
232 for (;D.end() == false; D++)
233 {
b2e465d6
AL
234 if (D->Type != pkgCache::Dep::Conflicts &&
235 D->Type != pkgCache::Dep::Obsoletes)
6c139d6e 236 continue;
5af32db6
AL
237
238 // The package hasnt been changed
239 if (List->IsNow(Pkg) == false)
240 continue;
6c139d6e 241
5af32db6
AL
242 // Ignore self conflicts, ignore conflicts from irrelevent versions
243 if (D.ParentPkg() == Pkg || D.ParentVer() != D.ParentPkg().CurrentVer())
6c139d6e
AL
244 continue;
245
b2e465d6 246 if (Cache.VS().CheckDep(Ver,D->CompareOp,D.TargetVer()) == false)
6c139d6e 247 continue;
b2e465d6 248
6c139d6e 249 if (EarlyRemove(D.ParentPkg()) == false)
5af32db6
AL
250 return _error->Error("Reverse conflicts early remove for package '%s' failed",
251 Pkg.Name());
252 }
6c139d6e
AL
253 return true;
254}
255 /*}}}*/
256// PM::ConfigureAll - Run the all out configuration /*{{{*/
257// ---------------------------------------------------------------------
258/* This configures every package. It is assumed they are all unpacked and
259 that the final configuration is valid. */
260bool pkgPackageManager::ConfigureAll()
261{
b2e465d6 262 pkgOrderList OList(&Cache);
6c139d6e
AL
263
264 // Populate the order list
265 for (pkgOrderList::iterator I = List->begin(); I != List->end(); I++)
266 if (List->IsFlag(pkgCache::PkgIterator(Cache,*I),
267 pkgOrderList::UnPacked) == true)
268 OList.push_back(*I);
269
270 if (OList.OrderConfigure() == false)
271 return false;
5e312de7
DK
272
273 std::string const conf = _config->Find("PackageManager::Configure","all");
274 bool const ConfigurePkgs = (conf == "all");
275
6c139d6e
AL
276 // Perform the configuring
277 for (pkgOrderList::iterator I = OList.begin(); I != OList.end(); I++)
278 {
279 PkgIterator Pkg(Cache,*I);
280
5e312de7 281 if (ConfigurePkgs == true && Configure(Pkg) == false)
6c139d6e
AL
282 return false;
283
284 List->Flag(Pkg,pkgOrderList::Configured,pkgOrderList::States);
285 }
286
287 return true;
288}
289 /*}}}*/
290// PM::SmartConfigure - Perform immediate configuration of the pkg /*{{{*/
291// ---------------------------------------------------------------------
292/* This routine scheduals the configuration of the given package and all
293 of it's dependents. */
294bool pkgPackageManager::SmartConfigure(PkgIterator Pkg)
295{
0eacf067
MV
296 if (Debug == true)
297 clog << "SmartConfigure " << Pkg.Name() << endl;
298
b2e465d6 299 pkgOrderList OList(&Cache);
6c139d6e
AL
300
301 if (DepAdd(OList,Pkg) == false)
302 return false;
5e312de7
DK
303
304 static std::string const conf = _config->Find("PackageManager::Configure","all");
305 static bool const ConfigurePkgs = (conf == "all" || conf == "smart");
306
307 if (ConfigurePkgs == true)
308 if (OList.OrderConfigure() == false)
309 return false;
310
6c139d6e
AL
311 // Perform the configuring
312 for (pkgOrderList::iterator I = OList.begin(); I != OList.end(); I++)
313 {
314 PkgIterator Pkg(Cache,*I);
315
5e312de7 316 if (ConfigurePkgs == true && Configure(Pkg) == false)
6c139d6e
AL
317 return false;
318
319 List->Flag(Pkg,pkgOrderList::Configured,pkgOrderList::States);
320 }
321
322 // Sanity Check
323 if (List->IsFlag(Pkg,pkgOrderList::Configured) == false)
20382bad
DK
324 return _error->Error(_("Could not perform immediate configuration on '%s'."
325 "Please see man 5 apt.conf under APT::Immediate-Configure for details. (%d)"),Pkg.Name(),1);
326
6c139d6e
AL
327 return true;
328}
329 /*}}}*/
330// PM::DepAdd - Add all dependents to the oder list /*{{{*/
331// ---------------------------------------------------------------------
332/* This recursively adds all dependents to the order list */
333bool pkgPackageManager::DepAdd(pkgOrderList &OList,PkgIterator Pkg,int Depth)
334{
335 if (OList.IsFlag(Pkg,pkgOrderList::Added) == true)
336 return true;
337 if (List->IsFlag(Pkg,pkgOrderList::Configured) == true)
338 return true;
339 if (List->IsFlag(Pkg,pkgOrderList::UnPacked) == false)
340 return false;
131418cf
MV
341
342 if (Debug)
343 std::clog << OutputInDepth(Depth) << "DepAdd: " << Pkg.Name() << std::endl;
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 {
131418cf
MV
397 if (Debug)
398 std::clog << OutputInDepth(Depth) << "DepAdd FAILS on: " << Pkg.Name() << std::endl;
6c139d6e
AL
399 OList.Flag(Pkg,0,pkgOrderList::Added);
400 OList.pop_back();
401 Depth--;
402 return false;
403 }
404 }
405
406 Depth--;
407 return true;
408}
409 /*}}}*/
410// PM::EarlyRemove - Perform removal of packages before their time /*{{{*/
411// ---------------------------------------------------------------------
412/* This is called to deal with conflicts arising from unpacking */
413bool pkgPackageManager::EarlyRemove(PkgIterator Pkg)
414{
415 if (List->IsNow(Pkg) == false)
416 return true;
417
418 // Already removed it
419 if (List->IsFlag(Pkg,pkgOrderList::Removed) == true)
420 return true;
421
422 // Woops, it will not be re-installed!
423 if (List->IsFlag(Pkg,pkgOrderList::InList) == false)
424 return false;
9d4c8f67
AL
425
426 // Essential packages get special treatment
5af32db6 427 bool IsEssential = false;
9d4c8f67 428 if ((Pkg->Flags & pkgCache::Flag::Essential) != 0)
5af32db6
AL
429 IsEssential = true;
430
431 /* Check for packages that are the dependents of essential packages and
432 promote them too */
433 if (Pkg->CurrentVer != 0)
434 {
435 for (DepIterator D = Pkg.RevDependsList(); D.end() == false &&
436 IsEssential == false; D++)
437 if (D->Type == pkgCache::Dep::Depends || D->Type == pkgCache::Dep::PreDepends)
438 if ((D.ParentPkg()->Flags & pkgCache::Flag::Essential) != 0)
439 IsEssential = true;
440 }
441
442 if (IsEssential == true)
9d4c8f67
AL
443 {
444 if (_config->FindB("APT::Force-LoopBreak",false) == false)
b2e465d6
AL
445 return _error->Error(_("This installation run will require temporarily "
446 "removing the essential package %s due to a "
447 "Conflicts/Pre-Depends loop. This is often bad, "
448 "but if you really want to do it, activate the "
449 "APT::Force-LoopBreak option."),Pkg.Name());
9d4c8f67 450 }
6c139d6e
AL
451
452 bool Res = SmartRemove(Pkg);
453 if (Cache[Pkg].Delete() == false)
454 List->Flag(Pkg,pkgOrderList::Removed,pkgOrderList::States);
455
456 return Res;
457}
458 /*}}}*/
459// PM::SmartRemove - Removal Helper /*{{{*/
460// ---------------------------------------------------------------------
461/* */
462bool pkgPackageManager::SmartRemove(PkgIterator Pkg)
463{
464 if (List->IsNow(Pkg) == false)
465 return true;
466
467 List->Flag(Pkg,pkgOrderList::Configured,pkgOrderList::States);
fc4b5c9f 468 return Remove(Pkg,(Cache[Pkg].iFlags & pkgDepCache::Purge) == pkgDepCache::Purge);
6c139d6e
AL
469}
470 /*}}}*/
471// PM::SmartUnPack - Install helper /*{{{*/
472// ---------------------------------------------------------------------
473/* This performs the task of handling pre-depends. */
474bool pkgPackageManager::SmartUnPack(PkgIterator Pkg)
475{
476 // Check if it is already unpacked
477 if (Pkg.State() == pkgCache::PkgIterator::NeedsConfigure &&
478 Cache[Pkg].Keep() == true)
479 {
480 List->Flag(Pkg,pkgOrderList::UnPacked,pkgOrderList::States);
481 if (List->IsFlag(Pkg,pkgOrderList::Immediate) == true)
482 if (SmartConfigure(Pkg) == false)
20382bad 483 return _error->Error(_("Could not perform immediate configuration on already unpacked '%s'."
f66a64c2 484 "Please see man 5 apt.conf under APT::Immediate-Configure for details."),Pkg.Name());
6c139d6e
AL
485 return true;
486 }
981d20eb 487
6c139d6e
AL
488 /* See if this packages install version has any predependencies
489 that are not met by 'now' packages. */
490 for (DepIterator D = Cache[Pkg].InstVerIter(Cache).DependsList();
421c8d10 491 D.end() == false; )
6c139d6e 492 {
421c8d10
AL
493 // Compute a single dependency element (glob or)
494 pkgCache::DepIterator Start;
495 pkgCache::DepIterator End;
496 D.GlobOr(Start,End);
497
498 while (End->Type == pkgCache::Dep::PreDepends)
6c139d6e 499 {
f4945db3
MV
500 if (Debug == true)
501 clog << "PreDepends order for " << Pkg.Name() << std::endl;
502
6c139d6e 503 // Look for possible ok targets.
b2e465d6 504 SPtrArray<Version *> VList = Start.AllTargets();
6c139d6e
AL
505 bool Bad = true;
506 for (Version **I = VList; *I != 0 && Bad == true; I++)
507 {
508 VerIterator Ver(Cache,*I);
509 PkgIterator Pkg = Ver.ParentPkg();
510
511 // See if the current version is ok
512 if (Pkg.CurrentVer() == Ver && List->IsNow(Pkg) == true &&
513 Pkg.State() == PkgIterator::NeedsNothing)
514 {
515 Bad = false;
f4945db3
MV
516 if (Debug == true)
517 clog << "Found ok package " << Pkg.Name() << endl;
6c139d6e
AL
518 continue;
519 }
520 }
521
522 // Look for something that could be configured.
523 for (Version **I = VList; *I != 0 && Bad == true; I++)
524 {
525 VerIterator Ver(Cache,*I);
526 PkgIterator Pkg = Ver.ParentPkg();
527
528 // Not the install version
529 if (Cache[Pkg].InstallVer != *I ||
530 (Cache[Pkg].Keep() == true && Pkg.State() == PkgIterator::NeedsNothing))
531 continue;
532
f4945db3
MV
533 if (Debug == true)
534 clog << "Trying to SmartConfigure " << Pkg.Name() << endl;
6c139d6e
AL
535 Bad = !SmartConfigure(Pkg);
536 }
1006601e 537
421c8d10 538 /* If this or element did not match then continue on to the
1006601e 539 next or element until a matching element is found */
421c8d10 540 if (Bad == true)
1006601e
AL
541 {
542 // This triggers if someone make a pre-depends/depend loop.
421c8d10 543 if (Start == End)
1006601e
AL
544 return _error->Error("Couldn't configure pre-depend %s for %s, "
545 "probably a dependency cycle.",
546 End.TargetPkg().Name(),Pkg.Name());
421c8d10
AL
547 Start++;
548 }
549 else
550 break;
6c139d6e
AL
551 }
552
b2e465d6
AL
553 if (End->Type == pkgCache::Dep::Conflicts ||
554 End->Type == pkgCache::Dep::Obsoletes)
6c139d6e
AL
555 {
556 /* Look for conflicts. Two packages that are both in the install
557 state cannot conflict so we don't check.. */
b2e465d6 558 SPtrArray<Version *> VList = End.AllTargets();
6c139d6e
AL
559 for (Version **I = VList; *I != 0; I++)
560 {
561 VerIterator Ver(Cache,*I);
562 PkgIterator Pkg = Ver.ParentPkg();
563
564 // See if the current version is conflicting
565 if (Pkg.CurrentVer() == Ver && List->IsNow(Pkg) == true)
566 {
567 if (EarlyRemove(Pkg) == false)
568 return _error->Error("Internal Error, Could not early remove %s",Pkg.Name());
569 }
570 }
6c139d6e
AL
571 }
572 }
573
574 // Check for reverse conflicts.
5af32db6
AL
575 if (CheckRConflicts(Pkg,Pkg.RevDependsList(),
576 Cache[Pkg].InstVerIter(Cache).VerStr()) == false)
577 return false;
578
6c139d6e
AL
579 for (PrvIterator P = Cache[Pkg].InstVerIter(Cache).ProvidesList();
580 P.end() == false; P++)
581 CheckRConflicts(Pkg,P.ParentPkg().RevDependsList(),P.ProvideVersion());
582
583 if (Install(Pkg,FileNames[Pkg->ID]) == false)
584 return false;
585
586 List->Flag(Pkg,pkgOrderList::UnPacked,pkgOrderList::States);
587
588 // Perform immedate configuration of the package.
589 if (List->IsFlag(Pkg,pkgOrderList::Immediate) == true)
590 if (SmartConfigure(Pkg) == false)
20382bad
DK
591 return _error->Error(_("Could not perform immediate configuration on '%s'."
592 "Please see man 5 apt.conf under APT::Immediate-Configure for details. (%d)"),Pkg.Name(),2);
6c139d6e
AL
593
594 return true;
595}
596 /*}}}*/
597// PM::OrderInstall - Installation ordering routine /*{{{*/
598// ---------------------------------------------------------------------
599/* */
281daf46 600pkgPackageManager::OrderResult pkgPackageManager::OrderInstall()
6c139d6e 601{
7a1b1f8b 602 if (CreateOrderList() == false)
281daf46
AL
603 return Failed;
604
605 Reset();
6c139d6e 606
30e1eab5 607 if (Debug == true)
5e312de7 608 clog << "Beginning to order" << endl;
6c139d6e 609
5e312de7
DK
610 bool const ordering =
611 _config->FindB("PackageManager::UnpackAll",true) ?
612 List->OrderUnpack(FileNames) : List->OrderCritical();
613 if (ordering == false)
281daf46
AL
614 {
615 _error->Error("Internal ordering error");
616 return Failed;
617 }
618
30e1eab5
AL
619 if (Debug == true)
620 clog << "Done ordering" << endl;
621
281daf46 622 bool DoneSomething = false;
6c139d6e
AL
623 for (pkgOrderList::iterator I = List->begin(); I != List->end(); I++)
624 {
625 PkgIterator Pkg(Cache,*I);
281daf46
AL
626
627 if (List->IsNow(Pkg) == false)
628 {
629 if (Debug == true)
630 clog << "Skipping already done " << Pkg.Name() << endl;
631 continue;
632 }
633
2fd65468 634 if (List->IsMissing(Pkg) == true)
281daf46
AL
635 {
636 if (Debug == true)
a3eaf954 637 clog << "Sequence completed at " << Pkg.Name() << endl;
281daf46
AL
638 if (DoneSomething == false)
639 {
640 _error->Error("Internal Error, ordering was unable to handle the media swap");
641 return Failed;
642 }
643 return Incomplete;
644 }
6c139d6e
AL
645
646 // Sanity check
d0c59649
AL
647 if (Cache[Pkg].Keep() == true &&
648 Pkg.State() == pkgCache::PkgIterator::NeedsNothing &&
649 (Cache[Pkg].iFlags & pkgDepCache::ReInstall) != pkgDepCache::ReInstall)
281daf46 650 {
71a174ee 651 _error->Error("Internal Error, trying to manipulate a kept package (%s)",Pkg.Name());
281daf46
AL
652 return Failed;
653 }
6c139d6e
AL
654
655 // Perform a delete or an install
656 if (Cache[Pkg].Delete() == true)
657 {
658 if (SmartRemove(Pkg) == false)
281daf46 659 return Failed;
6c139d6e
AL
660 }
661 else
662 if (SmartUnPack(Pkg) == false)
281daf46
AL
663 return Failed;
664 DoneSomething = true;
6c139d6e 665 }
5e312de7 666
6c139d6e
AL
667 // Final run through the configure phase
668 if (ConfigureAll() == false)
281daf46 669 return Failed;
6c139d6e
AL
670
671 // Sanity check
672 for (pkgOrderList::iterator I = List->begin(); I != List->end(); I++)
281daf46 673 {
6c139d6e 674 if (List->IsFlag(*I,pkgOrderList::Configured) == false)
281daf46
AL
675 {
676 _error->Error("Internal error, packages left unconfigured. %s",
677 PkgIterator(Cache,*I).Name());
678 return Failed;
679 }
680 }
681
682 return Completed;
6c139d6e
AL
683}
684 /*}}}*/
1d6386f3
MV
685// PM::DoInstallPostFork - Does install part that happens after the fork /*{{{*/
686// ---------------------------------------------------------------------
687pkgPackageManager::OrderResult
688pkgPackageManager::DoInstallPostFork(int statusFd)
689{
690 if(statusFd > 0)
691 // FIXME: use SetCloseExec here once it taught about throwing
692 // exceptions instead of doing _exit(100) on failure
693 fcntl(statusFd,F_SETFD,FD_CLOEXEC);
694 bool goResult = Go(statusFd);
695 if(goResult == false)
696 return Failed;
697
1d6386f3
MV
698 return Res;
699};
700
2a7e07c7
MV
701// PM::DoInstall - Does the installation /*{{{*/
702// ---------------------------------------------------------------------
703/* This uses the filenames in FileNames and the information in the
704 DepCache to perform the installation of packages.*/
705pkgPackageManager::OrderResult pkgPackageManager::DoInstall(int statusFd)
706{
707 if(DoInstallPreFork() == Failed)
708 return Failed;
709
7230ad48 710 return DoInstallPostFork(statusFd);
2a7e07c7
MV
711}
712 /*}}}*/