]> git.saurik.com Git - apt.git/blame - apt-pkg/packagemanager.cc
Cleanup includes after running iwyu
[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 /*{{{*/
453b82a3 16#include <config.h>
ea542140 17
094a497d
AL
18#include <apt-pkg/packagemanager.h>
19#include <apt-pkg/orderlist.h>
20#include <apt-pkg/depcache.h>
21#include <apt-pkg/error.h>
22#include <apt-pkg/version.h>
03e39e59 23#include <apt-pkg/acquire-item.h>
30e1eab5
AL
24#include <apt-pkg/algorithms.h>
25#include <apt-pkg/configuration.h>
453b82a3
DK
26#include <apt-pkg/macros.h>
27#include <apt-pkg/pkgcache.h>
28#include <apt-pkg/cacheiterators.h>
29#include <apt-pkg/strutl.h>
b58f28d4 30#include <apt-pkg/install-progress.h>
453b82a3
DK
31
32#include <stddef.h>
33#include <list>
34#include <string>
5819a761 35#include <iostream>
a00a9b44
DK
36
37#include <apti18n.h>
92fcbfc1 38 /*}}}*/
5819a761
AL
39using namespace std;
40
590f1923
CB
41bool pkgPackageManager::SigINTStop = false;
42
6c139d6e
AL
43// PM::PackageManager - Constructor /*{{{*/
44// ---------------------------------------------------------------------
45/* */
dcaa1185 46pkgPackageManager::pkgPackageManager(pkgDepCache *pCache) : Cache(*pCache),
6c55f07a 47 List(NULL), Res(Incomplete), d(NULL)
6c139d6e
AL
48{
49 FileNames = new string[Cache.Head().PackageCount];
30e1eab5 50 Debug = _config->FindB("Debug::pkgPackageManager",false);
dcaa1185
DK
51 NoImmConfigure = !_config->FindB("APT::Immediate-Configure",true);
52 ImmConfigureAll = _config->FindB("APT::Immediate-Configure-All",false);
6c139d6e
AL
53}
54 /*}}}*/
55// PM::PackageManager - Destructor /*{{{*/
56// ---------------------------------------------------------------------
57/* */
58pkgPackageManager::~pkgPackageManager()
59{
60 delete List;
61 delete [] FileNames;
62}
63 /*}}}*/
03e39e59
AL
64// PM::GetArchives - Queue the archives for download /*{{{*/
65// ---------------------------------------------------------------------
66/* */
67bool pkgPackageManager::GetArchives(pkgAcquire *Owner,pkgSourceList *Sources,
68 pkgRecords *Recs)
69{
7a1b1f8b
AL
70 if (CreateOrderList() == false)
71 return false;
72
5e312de7
DK
73 bool const ordering =
74 _config->FindB("PackageManager::UnpackAll",true) ?
75 List->OrderUnpack() : List->OrderCritical();
76 if (ordering == false)
7a1b1f8b
AL
77 return _error->Error("Internal ordering error");
78
91c03d37 79 for (pkgOrderList::iterator I = List->begin(); I != List->end(); ++I)
7a1b1f8b
AL
80 {
81 PkgIterator Pkg(Cache,*I);
281daf46
AL
82 FileNames[Pkg->ID] = string();
83
7a1b1f8b
AL
84 // Skip packages to erase
85 if (Cache[Pkg].Delete() == true)
03e39e59 86 continue;
d38b7b3d
AL
87
88 // Skip Packages that need configure only.
9dbb421f
AL
89 if (Pkg.State() == pkgCache::PkgIterator::NeedsConfigure &&
90 Cache[Pkg].Keep() == true)
d38b7b3d 91 continue;
281daf46
AL
92
93 // Skip already processed packages
94 if (List->IsNow(Pkg) == false)
95 continue;
803ea2a8 96
7a1b1f8b
AL
97 new pkgAcqArchive(Owner,Sources,Recs,Cache[Pkg].InstVerIter(Cache),
98 FileNames[Pkg->ID]);
03e39e59 99 }
7a1b1f8b 100
03e39e59
AL
101 return true;
102}
103 /*}}}*/
6c139d6e
AL
104// PM::FixMissing - Keep all missing packages /*{{{*/
105// ---------------------------------------------------------------------
106/* This is called to correct the installation when packages could not
107 be downloaded. */
108bool pkgPackageManager::FixMissing()
bdae53f1 109{
e6756cde 110 pkgDepCache::ActionGroup group(Cache);
b2e465d6 111 pkgProblemResolver Resolve(&Cache);
2fd65468 112 List->SetFileList(FileNames);
e6756cde 113
9dbb421f 114 bool Bad = false;
f7f0d6c7 115 for (PkgIterator I = Cache.PkgBegin(); I.end() == false; ++I)
6c139d6e 116 {
2fd65468 117 if (List->IsMissing(I) == false)
9dbb421f 118 continue;
2fd65468 119
9dbb421f
AL
120 // Okay, this file is missing and we need it. Mark it for keep
121 Bad = true;
74a05226 122 Cache.MarkKeep(I, false, false);
6c139d6e 123 }
bdae53f1
AL
124
125 // We have to empty the list otherwise it will not have the new changes
126 delete List;
127 List = 0;
6c139d6e 128
9dbb421f
AL
129 if (Bad == false)
130 return true;
131
6c139d6e 132 // Now downgrade everything that is broken
30e1eab5 133 return Resolve.ResolveByKeep() == true && Cache.BrokenCount() == 0;
6c139d6e
AL
134}
135 /*}}}*/
3a6d37fd
MV
136// PM::ImmediateAdd - Add the immediate flag recursivly /*{{{*/
137// ---------------------------------------------------------------------
138/* This adds the immediate flag to the pkg and recursively to the
139 dependendies
140 */
d183f850 141void pkgPackageManager::ImmediateAdd(PkgIterator I, bool UseInstallVer, unsigned const int &Depth)
3a6d37fd
MV
142{
143 DepIterator D;
144
145 if(UseInstallVer)
146 {
147 if(Cache[I].InstallVer == 0)
148 return;
149 D = Cache[I].InstVerIter(Cache).DependsList();
150 } else {
151 if (I->CurrentVer == 0)
152 return;
153 D = I.CurrentVer().DependsList();
154 }
155
f7f0d6c7 156 for ( /* nothing */ ; D.end() == false; ++D)
3a6d37fd
MV
157 if (D->Type == pkgCache::Dep::Depends || D->Type == pkgCache::Dep::PreDepends)
158 {
159 if(!List->IsFlag(D.TargetPkg(), pkgOrderList::Immediate))
160 {
161 if(Debug)
90436124 162 clog << OutputInDepth(Depth) << "ImmediateAdd(): Adding Immediate flag to " << D.TargetPkg() << " cause of " << D.DepType() << " " << I.FullName() << endl;
3a6d37fd 163 List->Flag(D.TargetPkg(),pkgOrderList::Immediate);
d183f850 164 ImmediateAdd(D.TargetPkg(), UseInstallVer, Depth + 1);
3a6d37fd
MV
165 }
166 }
167 return;
168}
169 /*}}}*/
7a1b1f8b
AL
170// PM::CreateOrderList - Create the ordering class /*{{{*/
171// ---------------------------------------------------------------------
172/* This populates the ordering list with all the packages that are
173 going to change. */
174bool pkgPackageManager::CreateOrderList()
175{
281daf46
AL
176 if (List != 0)
177 return true;
178
7a1b1f8b 179 delete List;
b2e465d6 180 List = new pkgOrderList(&Cache);
dcaa1185 181
a6c8798a
CB
182 if (Debug && ImmConfigureAll)
183 clog << "CreateOrderList(): Adding Immediate flag for all packages because of APT::Immediate-Configure-All" << endl;
079cc404 184
7a1b1f8b 185 // Generate the list of affected packages and sort it
f7f0d6c7 186 for (PkgIterator I = Cache.PkgBegin(); I.end() == false; ++I)
7a1b1f8b 187 {
e7b470ee
AL
188 // Ignore no-version packages
189 if (I->VersionList == 0)
190 continue;
191
138d4b3d 192 // Mark the package and its dependends for immediate configuration
fb805d80 193 if ((((I->Flags & pkgCache::Flag::Essential) == pkgCache::Flag::Essential) &&
a6c8798a 194 NoImmConfigure == false) || ImmConfigureAll)
7a1b1f8b 195 {
a6c8798a 196 if(Debug && !ImmConfigureAll)
90436124 197 clog << "CreateOrderList(): Adding Immediate flag for " << I.FullName() << endl;
7a1b1f8b 198 List->Flag(I,pkgOrderList::Immediate);
d38b7b3d 199
a6c8798a 200 if (!ImmConfigureAll) {
a6c8798a
CB
201 // Look for other install packages to make immediate configurea
202 ImmediateAdd(I, true);
e2a5ff0c 203
a6c8798a
CB
204 // And again with the current version.
205 ImmediateAdd(I, false);
206 }
7a1b1f8b
AL
207 }
208
209 // Not interesting
210 if ((Cache[I].Keep() == true ||
211 Cache[I].InstVerIter(Cache) == I.CurrentVer()) &&
d556d1a1 212 I.State() == pkgCache::PkgIterator::NeedsNothing &&
d0c59649 213 (Cache[I].iFlags & pkgDepCache::ReInstall) != pkgDepCache::ReInstall &&
d556d1a1
AL
214 (I.Purge() != false || Cache[I].Mode != pkgDepCache::ModeDelete ||
215 (Cache[I].iFlags & pkgDepCache::Purge) != pkgDepCache::Purge))
7a1b1f8b
AL
216 continue;
217
218 // Append it to the list
138d4b3d 219 List->push_back(I);
7a1b1f8b
AL
220 }
221
222 return true;
223}
224 /*}}}*/
1e3f4083 225// PM::DepAlwaysTrue - Returns true if this dep is irrelevant /*{{{*/
6c139d6e
AL
226// ---------------------------------------------------------------------
227/* The restriction on provides is to eliminate the case when provides
228 are transitioning between valid states [ie exim to smail] */
229bool pkgPackageManager::DepAlwaysTrue(DepIterator D)
230{
231 if (D.TargetPkg()->ProvidesList != 0)
232 return false;
233
234 if ((Cache[D] & pkgDepCache::DepInstall) != 0 &&
235 (Cache[D] & pkgDepCache::DepNow) != 0)
236 return true;
237 return false;
238}
239 /*}}}*/
240// PM::CheckRConflicts - Look for reverse conflicts /*{{{*/
241// ---------------------------------------------------------------------
242/* This looks over the reverses for a conflicts line that needs early
243 removal. */
244bool pkgPackageManager::CheckRConflicts(PkgIterator Pkg,DepIterator D,
245 const char *Ver)
246{
f7f0d6c7 247 for (;D.end() == false; ++D)
6c139d6e 248 {
b2e465d6
AL
249 if (D->Type != pkgCache::Dep::Conflicts &&
250 D->Type != pkgCache::Dep::Obsoletes)
6c139d6e 251 continue;
5af32db6 252
1e3f4083 253 // The package hasn't been changed
5af32db6
AL
254 if (List->IsNow(Pkg) == false)
255 continue;
6c139d6e 256
1e3f4083 257 // Ignore self conflicts, ignore conflicts from irrelevant versions
85434114 258 if (D.IsIgnorable(Pkg) || D.ParentVer() != D.ParentPkg().CurrentVer())
6c139d6e
AL
259 continue;
260
b2e465d6 261 if (Cache.VS().CheckDep(Ver,D->CompareOp,D.TargetVer()) == false)
6c139d6e 262 continue;
b2e465d6 263
0eb4af9d 264 if (EarlyRemove(D.ParentPkg(), &D) == false)
5af32db6 265 return _error->Error("Reverse conflicts early remove for package '%s' failed",
90436124 266 Pkg.FullName().c_str());
5af32db6 267 }
6c139d6e
AL
268 return true;
269}
270 /*}}}*/
271// PM::ConfigureAll - Run the all out configuration /*{{{*/
272// ---------------------------------------------------------------------
273/* This configures every package. It is assumed they are all unpacked and
590f1923
CB
274 that the final configuration is valid. This is also used to catch packages
275 that have not been configured when using ImmConfigureAll */
6c139d6e
AL
276bool pkgPackageManager::ConfigureAll()
277{
b2e465d6 278 pkgOrderList OList(&Cache);
6c139d6e
AL
279
280 // Populate the order list
91c03d37 281 for (pkgOrderList::iterator I = List->begin(); I != List->end(); ++I)
6c139d6e
AL
282 if (List->IsFlag(pkgCache::PkgIterator(Cache,*I),
283 pkgOrderList::UnPacked) == true)
284 OList.push_back(*I);
285
286 if (OList.OrderConfigure() == false)
287 return false;
5e312de7
DK
288
289 std::string const conf = _config->Find("PackageManager::Configure","all");
290 bool const ConfigurePkgs = (conf == "all");
291
6c139d6e 292 // Perform the configuring
91c03d37 293 for (pkgOrderList::iterator I = OList.begin(); I != OList.end(); ++I)
6c139d6e
AL
294 {
295 PkgIterator Pkg(Cache,*I);
17182c0c
CB
296
297 /* Check if the package has been configured, this can happen if SmartConfigure
298 calls its self */
299 if (List->IsFlag(Pkg,pkgOrderList::Configured)) continue;
803ea2a8 300
d41d0e01 301 if (ConfigurePkgs == true && SmartConfigure(Pkg, 0) == false) {
c7c7d3e8
CB
302 if (ImmConfigureAll)
303 _error->Error(_("Could not perform immediate configuration on '%s'. "
90436124 304 "Please see man 5 apt.conf under APT::Immediate-Configure for details. (%d)"),Pkg.FullName().c_str(),1);
c7c7d3e8 305 else
90436124 306 _error->Error("Internal error, packages left unconfigured. %s",Pkg.FullName().c_str());
6c139d6e 307 return false;
634985f8 308 }
6c139d6e
AL
309
310 List->Flag(Pkg,pkgOrderList::Configured,pkgOrderList::States);
311 }
312
313 return true;
314}
315 /*}}}*/
0eb4af9d
DK
316// PM::NonLoopingSmart - helper to avoid loops while calling Smart methods /*{{{*/
317// -----------------------------------------------------------------------
318/* ensures that a loop of the form A depends B, B depends A (and similar)
319 is not leading us down into infinite recursion segfault land */
320bool pkgPackageManager::NonLoopingSmart(SmartAction const action, pkgCache::PkgIterator &Pkg,
321 pkgCache::PkgIterator DepPkg, int const Depth, bool const PkgLoop,
322 bool * const Bad, bool * const Changed)
323{
324 if (PkgLoop == false)
325 List->Flag(Pkg,pkgOrderList::Loop);
326 bool success = false;
327 switch(action)
328 {
329 case UNPACK_IMMEDIATE: success = SmartUnPack(DepPkg, true, Depth + 1); break;
330 case UNPACK: success = SmartUnPack(DepPkg, false, Depth + 1); break;
331 case CONFIGURE: success = SmartConfigure(DepPkg, Depth + 1); break;
332 }
333 if (PkgLoop == false)
334 List->RmFlag(Pkg,pkgOrderList::Loop);
335
336 if (success == false)
337 return false;
338
339 if (Bad != NULL)
340 *Bad = false;
341 if (Changed != NULL && List->IsFlag(DepPkg,pkgOrderList::Loop) == false)
342 *Changed = true;
343 return true;
344}
345 /*}}}*/
6c139d6e
AL
346// PM::SmartConfigure - Perform immediate configuration of the pkg /*{{{*/
347// ---------------------------------------------------------------------
c7c7d3e8 348/* This function tries to put the system in a state where Pkg can be configured.
0eb4af9d
DK
349 This involves checking each of Pkg's dependencies and unpacking and
350 configuring packages where needed. */
d41d0e01 351bool pkgPackageManager::SmartConfigure(PkgIterator Pkg, int const Depth)
6c139d6e 352{
38ff3de6 353 // If this is true, only check and correct and dependencies without the Loop flag
2dd2c801 354 bool const PkgLoop = List->IsFlag(Pkg,pkgOrderList::Loop);
d41d0e01 355
987d8d03
CB
356 if (Debug) {
357 VerIterator InstallVer = VerIterator(Cache,Cache[Pkg].InstallVer);
90436124 358 clog << OutputInDepth(Depth) << "SmartConfigure " << Pkg.FullName() << " (" << InstallVer.VerStr() << ")";
d41d0e01 359 if (PkgLoop)
38ff3de6 360 clog << " (Only Correct Dependencies)";
d41d0e01 361 clog << endl;
987d8d03 362 }
0eacf067 363
590f1923 364 VerIterator const instVer = Cache[Pkg].InstVerIter(Cache);
0eb4af9d
DK
365
366 /* Because of the ordered list, most dependencies should be unpacked,
367 however if there is a loop (A depends on B, B depends on A) this will not
38ff3de6 368 be the case, so check for dependencies before configuring. */
2dd2c801 369 bool Bad = false, Changed = false;
9c5104cf 370 const unsigned int max_loops = _config->FindI("APT::pkgPackageManager::MaxLoopCount", 5000);
bce4caa3 371 unsigned int i=0;
42d51f33 372 std::list<DepIterator> needConfigure;
bce4caa3
MV
373 do
374 {
2f589691
MV
375 // Check each dependency and see if anything needs to be done
376 // so that it can be configured
2dd2c801
DK
377 Changed = false;
378 for (DepIterator D = instVer.DependsList(); D.end() == false; )
379 {
380 // Compute a single dependency element (glob or)
381 pkgCache::DepIterator Start, End;
382 D.GlobOr(Start,End);
383
384 if (End->Type != pkgCache::Dep::Depends)
385 continue;
386 Bad = true;
387
2f589691
MV
388 // the first pass checks if we its all good, i.e. if we have
389 // to do anything at all
2dd2c801
DK
390 for (DepIterator Cur = Start; true; ++Cur)
391 {
98cc7fd2 392 std::unique_ptr<Version *> VList(Cur.AllTargets());
2dd2c801 393
98cc7fd2 394 for (Version **I = VList.get(); *I != 0; ++I)
6c139d6e 395 {
2dd2c801
DK
396 VerIterator Ver(Cache,*I);
397 PkgIterator DepPkg = Ver.ParentPkg();
398
399 // Check if the current version of the package is available and will satisfy this dependency
400 if (DepPkg.CurrentVer() == Ver && List->IsNow(DepPkg) == true &&
401 List->IsFlag(DepPkg,pkgOrderList::Removed) == false &&
4e6a7e26
DK
402 DepPkg.State() == PkgIterator::NeedsNothing &&
403 (Cache[DepPkg].iFlags & pkgDepCache::ReInstall) != pkgDepCache::ReInstall)
2dd2c801
DK
404 {
405 Bad = false;
406 break;
407 }
408
2f589691
MV
409 // Check if the version that is going to be installed will satisfy the dependency
410 if (Cache[DepPkg].InstallVer != *I || List->IsNow(DepPkg) == false)
411 continue;
412
413 if (PkgLoop == true)
414 {
415 if (Debug)
4e6a7e26
DK
416 std::clog << OutputInDepth(Depth) << "Package " << Pkg << " loops in SmartConfigure";
417 if (List->IsFlag(DepPkg,pkgOrderList::UnPacked))
418 Bad = false;
419 else if (Debug)
420 std::clog << ", but it isn't unpacked yet";
421 if (Debug)
422 std::clog << std::endl;
2f589691
MV
423 }
424 }
425
426 if (Cur == End || Bad == false)
427 break;
428 }
429
430 // this dependency is in a good state, so we can stop
431 if (Bad == false)
432 {
433 if (Debug)
4e6a7e26 434 std::clog << OutputInDepth(Depth) << "Found ok dep " << Start.TargetPkg() << std::endl;
2f589691
MV
435 continue;
436 }
437
438 // Check for dependencies that have not been unpacked,
439 // probably due to loops.
440 for (DepIterator Cur = Start; true; ++Cur)
441 {
98cc7fd2 442 std::unique_ptr<Version *> VList(Cur.AllTargets());
2f589691 443
98cc7fd2 444 for (Version **I = VList.get(); *I != 0; ++I)
2f589691
MV
445 {
446 VerIterator Ver(Cache,*I);
447 PkgIterator DepPkg = Ver.ParentPkg();
448
449 // Check if the current version of the package is available and will satisfy this dependency
450 if (DepPkg.CurrentVer() == Ver && List->IsNow(DepPkg) == true &&
451 List->IsFlag(DepPkg,pkgOrderList::Removed) == false &&
4e6a7e26
DK
452 DepPkg.State() == PkgIterator::NeedsNothing &&
453 (Cache[DepPkg].iFlags & pkgDepCache::ReInstall) != pkgDepCache::ReInstall)
2f589691
MV
454 continue;
455
2dd2c801 456 // Check if the version that is going to be installed will satisfy the dependency
42d51f33 457 if (Cache[DepPkg].InstallVer != *I || List->IsNow(DepPkg) == false)
2dd2c801
DK
458 continue;
459
42d51f33 460 if (PkgLoop == true)
2dd2c801 461 {
42d51f33 462 if (Debug)
4e6a7e26
DK
463 std::clog << OutputInDepth(Depth) << "Package " << Pkg << " loops in SmartConfigure";
464 if (List->IsFlag(DepPkg,pkgOrderList::UnPacked))
465 Bad = false;
466 else if (Debug)
467 std::clog << ", but it isn't unpacked yet";
468 if (Debug)
469 std::clog << std::endl;
42d51f33
DK
470 }
471 else
472 {
473 if (Debug)
474 clog << OutputInDepth(Depth) << "Unpacking " << DepPkg.FullName() << " to avoid loop " << Cur << endl;
0eb4af9d 475 if (NonLoopingSmart(UNPACK_IMMEDIATE, Pkg, DepPkg, Depth, PkgLoop, &Bad, &Changed) == false)
71e7a0f3 476 return false;
2dd2c801 477 }
2f589691
MV
478 // at this point we either unpacked a Dep or we are in a loop,
479 // no need to unpack a second one
0eb4af9d 480 break;
590f1923 481 }
42d51f33
DK
482
483 if (Cur == End || Bad == false)
2dd2c801 484 break;
42d51f33 485 }
2dd2c801
DK
486
487 if (Bad == false)
488 continue;
489
42d51f33
DK
490 needConfigure.push_back(Start);
491 }
492 if (i++ > max_loops)
493 return _error->Error("Internal error: MaxLoopCount reached in SmartUnPack (1) for %s, aborting", Pkg.FullName().c_str());
494 } while (Changed == true);
495
2f589691 496 // now go over anything that needs configuring
42d51f33
DK
497 Bad = false, Changed = false, i = 0;
498 do
499 {
500 Changed = false;
6420c00e 501 for (std::list<DepIterator>::const_iterator D = needConfigure.begin(); D != needConfigure.end(); ++D)
42d51f33 502 {
6420c00e 503 // Compute a single dependency element (glob or) without modifying D
42d51f33 504 pkgCache::DepIterator Start, End;
6420c00e
DK
505 {
506 pkgCache::DepIterator Discard = *D;
507 Discard.GlobOr(Start,End);
508 }
42d51f33
DK
509
510 if (End->Type != pkgCache::Dep::Depends)
511 continue;
512 Bad = true;
513
514 // Search for dependencies which are unpacked but aren't configured yet (maybe loops)
2dd2c801
DK
515 for (DepIterator Cur = Start; true; ++Cur)
516 {
98cc7fd2 517 std::unique_ptr<Version *> VList(Cur.AllTargets());
2dd2c801 518
98cc7fd2 519 for (Version **I = VList.get(); *I != 0; ++I)
2dd2c801
DK
520 {
521 VerIterator Ver(Cache,*I);
522 PkgIterator DepPkg = Ver.ParentPkg();
523
524 // Check if the version that is going to be installed will satisfy the dependency
42d51f33 525 if (Cache[DepPkg].InstallVer != *I)
2dd2c801
DK
526 continue;
527
42d51f33 528 if (List->IsFlag(DepPkg,pkgOrderList::UnPacked))
d9f6c795 529 {
42d51f33
DK
530 if (List->IsFlag(DepPkg,pkgOrderList::Loop) && PkgLoop)
531 {
532 // This dependency has already been dealt with by another SmartConfigure on Pkg
533 Bad = false;
534 break;
535 }
0eb4af9d
DK
536 if (Debug)
537 std::clog << OutputInDepth(Depth) << "Configure already unpacked " << DepPkg << std::endl;
538 if (NonLoopingSmart(CONFIGURE, Pkg, DepPkg, Depth, PkgLoop, &Bad, &Changed) == false)
71e7a0f3 539 return false;
71e7a0f3 540 break;
0eb4af9d 541
d9f6c795 542 }
42d51f33
DK
543 else if (List->IsFlag(DepPkg,pkgOrderList::Configured))
544 {
545 Bad = false;
546 break;
547 }
590f1923 548 }
42d51f33 549 if (Cur == End || Bad == false)
2dd2c801 550 break;
42d51f33
DK
551 }
552
553
2dd2c801 554 if (Bad == true && Changed == false && Debug == true)
6420c00e 555 std::clog << OutputInDepth(Depth) << "Could not satisfy " << *D << std::endl;
6c139d6e 556 }
bce4caa3 557 if (i++ > max_loops)
42d51f33 558 return _error->Error("Internal error: MaxLoopCount reached in SmartUnPack (2) for %s, aborting", Pkg.FullName().c_str());
2dd2c801 559 } while (Changed == true);
0eb4af9d 560
71e7a0f3
DK
561 if (Bad == true)
562 return _error->Error(_("Could not configure '%s'. "),Pkg.FullName().c_str());
0eb4af9d 563
a99d02a8 564 if (PkgLoop) return true;
5e312de7
DK
565
566 static std::string const conf = _config->Find("PackageManager::Configure","all");
567 static bool const ConfigurePkgs = (conf == "all" || conf == "smart");
568
0eb4af9d 569 if (List->IsFlag(Pkg,pkgOrderList::Configured))
90436124 570 return _error->Error("Internal configure error on '%s'.", Pkg.FullName().c_str());
5e312de7 571
590f1923
CB
572 if (ConfigurePkgs == true && Configure(Pkg) == false)
573 return false;
75a90b93 574
590f1923 575 List->Flag(Pkg,pkgOrderList::Configured,pkgOrderList::States);
6c139d6e 576
894d672e 577 if ((Cache[Pkg].InstVerIter(Cache)->MultiArch & pkgCache::Version::Same) == pkgCache::Version::Same)
d77b985a
DK
578 for (PkgIterator P = Pkg.Group().PackageList();
579 P.end() == false; P = Pkg.Group().NextPkg(P))
580 {
581 if (Pkg == P || List->IsFlag(P,pkgOrderList::Configured) == true ||
2b8b1e7a 582 List->IsFlag(P,pkgOrderList::UnPacked) == false ||
d77b985a
DK
583 Cache[P].InstallVer == 0 || (P.CurrentVer() == Cache[P].InstallVer &&
584 (Cache[Pkg].iFlags & pkgDepCache::ReInstall) != pkgDepCache::ReInstall))
585 continue;
71e7a0f3
DK
586 if (SmartConfigure(P, (Depth +1)) == false)
587 return false;
d77b985a
DK
588 }
589
6c139d6e
AL
590 // Sanity Check
591 if (List->IsFlag(Pkg,pkgOrderList::Configured) == false)
90436124 592 return _error->Error(_("Could not configure '%s'. "),Pkg.FullName().c_str());
20382bad 593
6c139d6e
AL
594 return true;
595}
596 /*}}}*/
6c139d6e
AL
597// PM::EarlyRemove - Perform removal of packages before their time /*{{{*/
598// ---------------------------------------------------------------------
599/* This is called to deal with conflicts arising from unpacking */
600bool pkgPackageManager::EarlyRemove(PkgIterator Pkg)
0eb4af9d
DK
601{
602 return EarlyRemove(Pkg, NULL);
603}
604bool pkgPackageManager::EarlyRemove(PkgIterator Pkg, DepIterator const * const Dep)
6c139d6e
AL
605{
606 if (List->IsNow(Pkg) == false)
607 return true;
0eb4af9d 608
6c139d6e
AL
609 // Already removed it
610 if (List->IsFlag(Pkg,pkgOrderList::Removed) == true)
611 return true;
0eb4af9d 612
6c139d6e
AL
613 // Woops, it will not be re-installed!
614 if (List->IsFlag(Pkg,pkgOrderList::InList) == false)
615 return false;
9d4c8f67 616
0eb4af9d
DK
617 // these breaks on M-A:same packages can be dealt with. They 'loop' by design
618 if (Dep != NULL && (*Dep)->Type == pkgCache::Dep::DpkgBreaks && Dep->IsMultiArchImplicit() == true)
619 return true;
620
9d4c8f67 621 // Essential packages get special treatment
5af32db6 622 bool IsEssential = false;
c5200869
JAK
623 if ((Pkg->Flags & pkgCache::Flag::Essential) != 0 ||
624 (Pkg->Flags & pkgCache::Flag::Important) != 0)
5af32db6
AL
625 IsEssential = true;
626
0eb4af9d 627 /* Check for packages that are the dependents of essential packages and
5af32db6
AL
628 promote them too */
629 if (Pkg->CurrentVer != 0)
630 {
0eb4af9d 631 for (pkgCache::DepIterator D = Pkg.RevDependsList(); D.end() == false &&
f7f0d6c7 632 IsEssential == false; ++D)
5af32db6 633 if (D->Type == pkgCache::Dep::Depends || D->Type == pkgCache::Dep::PreDepends)
c5200869
JAK
634 if ((D.ParentPkg()->Flags & pkgCache::Flag::Essential) != 0 ||
635 (D.ParentPkg()->Flags & pkgCache::Flag::Important) != 0)
5af32db6
AL
636 IsEssential = true;
637 }
638
639 if (IsEssential == true)
9d4c8f67
AL
640 {
641 if (_config->FindB("APT::Force-LoopBreak",false) == false)
b2e465d6
AL
642 return _error->Error(_("This installation run will require temporarily "
643 "removing the essential package %s due to a "
644 "Conflicts/Pre-Depends loop. This is often bad, "
645 "but if you really want to do it, activate the "
90436124 646 "APT::Force-LoopBreak option."),Pkg.FullName().c_str());
9d4c8f67 647 }
0eb4af9d
DK
648 // dpkg will auto-deconfigure it, no need for the big remove hammer
649 else if (Dep != NULL && (*Dep)->Type == pkgCache::Dep::DpkgBreaks)
650 return true;
651
6c139d6e
AL
652 bool Res = SmartRemove(Pkg);
653 if (Cache[Pkg].Delete() == false)
654 List->Flag(Pkg,pkgOrderList::Removed,pkgOrderList::States);
0eb4af9d 655
6c139d6e
AL
656 return Res;
657}
658 /*}}}*/
659// PM::SmartRemove - Removal Helper /*{{{*/
660// ---------------------------------------------------------------------
661/* */
662bool pkgPackageManager::SmartRemove(PkgIterator Pkg)
663{
664 if (List->IsNow(Pkg) == false)
665 return true;
666
667 List->Flag(Pkg,pkgOrderList::Configured,pkgOrderList::States);
803ea2a8 668
28166356 669 return Remove(Pkg,(Cache[Pkg].iFlags & pkgDepCache::Purge) == pkgDepCache::Purge);
6c139d6e
AL
670}
671 /*}}}*/
672// PM::SmartUnPack - Install helper /*{{{*/
673// ---------------------------------------------------------------------
1e3f4083 674/* This puts the system in a state where it can Unpack Pkg, if Pkg is already
590f1923 675 unpacked, or when it has been unpacked, if Immediate==true it configures it. */
6c139d6e 676bool pkgPackageManager::SmartUnPack(PkgIterator Pkg)
d77b985a 677{
d41d0e01 678 return SmartUnPack(Pkg, true, 0);
d77b985a 679}
d41d0e01 680bool pkgPackageManager::SmartUnPack(PkgIterator Pkg, bool const Immediate, int const Depth)
6c139d6e 681{
d41d0e01
CB
682 bool PkgLoop = List->IsFlag(Pkg,pkgOrderList::Loop);
683
987d8d03 684 if (Debug) {
90436124 685 clog << OutputInDepth(Depth) << "SmartUnPack " << Pkg.FullName();
987d8d03
CB
686 VerIterator InstallVer = VerIterator(Cache,Cache[Pkg].InstallVer);
687 if (Pkg.CurrentVer() == 0)
c4f931f8 688 clog << " (install version " << InstallVer.VerStr() << ")";
987d8d03 689 else
c4f931f8 690 clog << " (replace version " << Pkg.CurrentVer().VerStr() << " with " << InstallVer.VerStr() << ")";
d41d0e01 691 if (PkgLoop)
c4f931f8 692 clog << " (Only Perform PreUnpack Checks)";
0caa5a4c
DK
693 if (Immediate)
694 clog << " immediately";
c4f931f8 695 clog << endl;
987d8d03 696 }
cfcdf7fe 697
d77b985a
DK
698 VerIterator const instVer = Cache[Pkg].InstVerIter(Cache);
699
0eb4af9d 700 /* PreUnpack Checks: This loop checks and attempts to rectify any problems that would prevent the package being unpacked.
98ee4922 701 It addresses: PreDepends, Conflicts, Obsoletes and Breaks (DpkgBreaks). Any resolutions that do not require it should
c7c7d3e8 702 avoid configuration (calling SmartUnpack with Immediate=true), this is because when unpacking some packages with
0eb4af9d 703 complex dependency structures, trying to configure some packages while breaking the loops can complicate things.
98ee4922 704 This will be either dealt with if the package is configured as a dependency of Pkg (if and when Pkg is configured),
c7c7d3e8 705 or by the ConfigureAll call at the end of the for loop in OrderInstall. */
0eb4af9d
DK
706 bool SomethingBad = false, Changed = false;
707 bool couldBeTemporaryRemoved = Depth != 0 && List->IsFlag(Pkg,pkgOrderList::Removed) == false;
9c5104cf 708 const unsigned int max_loops = _config->FindI("APT::pkgPackageManager::MaxLoopCount", 5000);
5ab7b53b 709 unsigned int i = 0;
bce4caa3
MV
710 do
711 {
98ee4922
DK
712 Changed = false;
713 for (DepIterator D = instVer.DependsList(); D.end() == false; )
6c139d6e 714 {
98ee4922
DK
715 // Compute a single dependency element (glob or)
716 pkgCache::DepIterator Start, End;
717 D.GlobOr(Start,End);
f4945db3 718
98ee4922
DK
719 if (End->Type == pkgCache::Dep::PreDepends)
720 {
721 bool Bad = true;
722 if (Debug)
723 clog << OutputInDepth(Depth) << "PreDepends order for " << Pkg.FullName() << std::endl;
724
725 // Look for easy targets: packages that are already okay
726 for (DepIterator Cur = Start; Bad == true; ++Cur)
6c139d6e 727 {
98cc7fd2
JAK
728 std::unique_ptr<Version *> VList(Cur.AllTargets());
729 for (Version **I = VList.get(); *I != 0; ++I)
98ee4922
DK
730 {
731 VerIterator Ver(Cache,*I);
732 PkgIterator Pkg = Ver.ParentPkg();
733
734 // See if the current version is ok
735 if (Pkg.CurrentVer() == Ver && List->IsNow(Pkg) == true &&
4e6a7e26
DK
736 Pkg.State() == PkgIterator::NeedsNothing &&
737 (Cache[Pkg].iFlags & pkgDepCache::ReInstall) != pkgDepCache::ReInstall)
98ee4922
DK
738 {
739 Bad = false;
740 if (Debug)
741 clog << OutputInDepth(Depth) << "Found ok package " << Pkg.FullName() << endl;
742 break;
743 }
744 }
745 if (Cur == End)
746 break;
17182c0c 747 }
6c139d6e 748
98ee4922 749 // Look for something that could be configured.
275024e9 750 for (DepIterator Cur = Start; Bad == true && Cur.end() == false; ++Cur)
98ee4922 751 {
98cc7fd2
JAK
752 std::unique_ptr<Version *[]> VList(Cur.AllTargets());
753 for (Version **I = VList.get(); *I != 0; ++I)
98ee4922
DK
754 {
755 VerIterator Ver(Cache,*I);
0eb4af9d 756 PkgIterator DepPkg = Ver.ParentPkg();
1006601e 757
98ee4922 758 // Not the install version
4e6a7e26
DK
759 if (Cache[DepPkg].InstallVer != *I)
760 continue;
761
762 if (Cache[DepPkg].Keep() == true && DepPkg.State() == PkgIterator::NeedsNothing &&
763 (Cache[DepPkg].iFlags & pkgDepCache::ReInstall) != pkgDepCache::ReInstall)
98ee4922
DK
764 continue;
765
0eb4af9d 766 if (List->IsFlag(DepPkg,pkgOrderList::Configured))
98ee4922
DK
767 {
768 Bad = false;
769 break;
770 }
771
772 // check if it needs unpack or if if configure is enough
0eb4af9d 773 if (List->IsFlag(DepPkg,pkgOrderList::UnPacked) == false)
98ee4922 774 {
4e6a7e26
DK
775 // two packages pre-depending on each other can't be handled sanely
776 if (List->IsFlag(DepPkg,pkgOrderList::Loop) && PkgLoop)
777 {
778 // this isn't an error as there is potential for something else to satisfy it
779 // (like a provides or an or-group member)
780 if (Debug)
781 clog << OutputInDepth(Depth) << "Unpack loop detected between " << DepPkg.FullName() << " and " << Pkg.FullName() << endl;
782 continue;
783 }
784
98ee4922 785 if (Debug)
0eb4af9d
DK
786 clog << OutputInDepth(Depth) << "Trying to SmartUnpack " << DepPkg.FullName() << endl;
787 if (NonLoopingSmart(UNPACK_IMMEDIATE, Pkg, DepPkg, Depth, PkgLoop, &Bad, &Changed) == false)
71e7a0f3 788 return false;
98ee4922
DK
789 }
790 else
791 {
792 if (Debug)
0eb4af9d
DK
793 clog << OutputInDepth(Depth) << "Trying to SmartConfigure " << DepPkg.FullName() << endl;
794 if (NonLoopingSmart(CONFIGURE, Pkg, DepPkg, Depth, PkgLoop, &Bad, &Changed) == false)
71e7a0f3 795 return false;
98ee4922 796 }
0eb4af9d 797 break;
e2a5ff0c 798 }
6c139d6e 799 }
98ee4922
DK
800
801 if (Bad == true)
0eb4af9d 802 SomethingBad = true;
6c139d6e 803 }
98ee4922 804 else if (End->Type == pkgCache::Dep::Conflicts ||
0eb4af9d
DK
805 End->Type == pkgCache::Dep::Obsoletes ||
806 End->Type == pkgCache::Dep::DpkgBreaks)
cfcdf7fe 807 {
98cc7fd2
JAK
808 std::unique_ptr<Version *[]> VList(End.AllTargets());
809 for (Version **I = VList.get(); *I != 0; ++I)
3e9ab9f0 810 {
98ee4922
DK
811 VerIterator Ver(Cache,*I);
812 PkgIterator ConflictPkg = Ver.ParentPkg();
0eb4af9d
DK
813 if (ConflictPkg.CurrentVer() != Ver)
814 {
815 if (Debug)
816 std::clog << OutputInDepth(Depth) << "Ignore not-installed version " << Ver.VerStr() << " of " << ConflictPkg.FullName() << " for " << End << std::endl;
817 continue;
818 }
3e9ab9f0 819
0eb4af9d 820 if (List->IsNow(ConflictPkg) == false)
98ee4922 821 {
2252183c 822 if (Debug)
0eb4af9d
DK
823 std::clog << OutputInDepth(Depth) << "Ignore already dealt-with version " << Ver.VerStr() << " of " << ConflictPkg.FullName() << " for " << End << std::endl;
824 continue;
825 }
3e9ab9f0 826
0eb4af9d 827 if (List->IsFlag(ConflictPkg,pkgOrderList::Removed) == true)
98ee4922 828 {
2252183c 829 if (Debug)
0eb4af9d
DK
830 clog << OutputInDepth(Depth) << "Ignoring " << End << " as " << ConflictPkg.FullName() << "was temporarily removed" << endl;
831 continue;
832 }
833
834 if (List->IsFlag(ConflictPkg,pkgOrderList::Loop) && PkgLoop)
835 {
836 if (End->Type == pkgCache::Dep::DpkgBreaks && End.IsMultiArchImplicit() == true)
440d3d65
DK
837 {
838 if (Debug)
0eb4af9d
DK
839 clog << OutputInDepth(Depth) << "Because dependency is MultiArchImplicit we ignored looping on: " << ConflictPkg << endl;
840 continue;
98ee4922 841 }
98ee4922 842 if (Debug)
440d3d65 843 {
0eb4af9d
DK
844 if (End->Type == pkgCache::Dep::DpkgBreaks)
845 clog << OutputInDepth(Depth) << "Because of breaks knot, deconfigure " << ConflictPkg.FullName() << " temporarily" << endl;
846 else
71e7a0f3 847 clog << OutputInDepth(Depth) << "Because of conflict knot, removing " << ConflictPkg.FullName() << " temporarily" << endl;
98ee4922 848 }
0eb4af9d
DK
849 if (EarlyRemove(ConflictPkg, &End) == false)
850 return _error->Error("Internal Error, Could not early remove %s (2)",ConflictPkg.FullName().c_str());
851 SomethingBad = true;
98ee4922
DK
852 continue;
853 }
854
0eb4af9d 855 if (Cache[ConflictPkg].Delete() == false)
98ee4922 856 {
0eb4af9d 857 if (Debug)
98ee4922 858 {
0eb4af9d
DK
859 clog << OutputInDepth(Depth) << "Unpacking " << ConflictPkg.FullName() << " to avoid " << End;
860 if (PkgLoop == true)
861 clog << " (Looping)";
862 clog << std::endl;
440d3d65 863 }
0eb4af9d
DK
864 // we would like to avoid temporary removals and all that at best via a simple unpack
865 _error->PushToStack();
866 if (NonLoopingSmart(UNPACK, Pkg, ConflictPkg, Depth, PkgLoop, NULL, &Changed) == false)
2264548f 867 {
0eb4af9d
DK
868 // but if it fails ignore this failure and look for alternative ways of solving
869 if (Debug)
440d3d65 870 {
1df24acf 871 clog << OutputInDepth(Depth) << "Avoidance unpack of " << ConflictPkg.FullName() << " failed for " << End << " ignoring:" << std::endl;
0eb4af9d
DK
872 _error->DumpErrors(std::clog);
873 }
874 _error->RevertToStack();
875 // ignorance can only happen if a) one of the offenders is already gone
876 if (List->IsFlag(ConflictPkg,pkgOrderList::Removed) == true)
440d3d65 877 {
0eb4af9d
DK
878 if (Debug)
879 clog << OutputInDepth(Depth) << "But " << ConflictPkg.FullName() << " was temporarily removed in the meantime to satisfy " << End << endl;
98ee4922 880 }
0eb4af9d 881 else if (List->IsFlag(Pkg,pkgOrderList::Removed) == true)
98ee4922
DK
882 {
883 if (Debug)
0eb4af9d 884 clog << OutputInDepth(Depth) << "But " << Pkg.FullName() << " was temporarily removed in the meantime to satisfy " << End << endl;
98ee4922 885 }
0eb4af9d 886 // or b) we can make one go (removal or dpkg auto-deconfigure)
98ee4922
DK
887 else
888 {
889 if (Debug)
0eb4af9d
DK
890 clog << OutputInDepth(Depth) << "So temprorary remove/deconfigure " << ConflictPkg.FullName() << " to satisfy " << End << endl;
891 if (EarlyRemove(ConflictPkg, &End) == false)
892 return _error->Error("Internal Error, Could not early remove %s (2)",ConflictPkg.FullName().c_str());
440d3d65 893 }
2264548f 894 }
0eb4af9d
DK
895 else
896 _error->MergeWithStack();
6b92f60c 897 }
0eb4af9d 898 else
6b92f60c
DK
899 {
900 if (Debug)
0eb4af9d
DK
901 clog << OutputInDepth(Depth) << "Removing " << ConflictPkg.FullName() << " now to avoid " << End << endl;
902 // no earlyremove() here as user has already agreed to the permanent removal
903 if (SmartRemove(Pkg) == false)
904 return _error->Error("Internal Error, Could not early remove %s (1)",ConflictPkg.FullName().c_str());
6b92f60c 905 }
6c139d6e
AL
906 }
907 }
6c139d6e 908 }
bce4caa3 909 if (i++ > max_loops)
91ea3def 910 return _error->Error("Internal error: APT::pkgPackageManager::MaxLoopCount reached in SmartConfigure for %s, aborting", Pkg.FullName().c_str());
98ee4922 911 } while (Changed == true);
0eb4af9d
DK
912
913 if (SomethingBad == true)
914 return _error->Error("Couldn't configure %s, probably a dependency cycle.", Pkg.FullName().c_str());
915
916 if (couldBeTemporaryRemoved == true && List->IsFlag(Pkg,pkgOrderList::Removed) == true)
917 {
918 if (Debug)
919 std::clog << OutputInDepth(Depth) << "Prevent unpack as " << Pkg << " is currently temporarily removed" << std::endl;
920 return true;
921 }
922
6c139d6e 923 // Check for reverse conflicts.
5af32db6 924 if (CheckRConflicts(Pkg,Pkg.RevDependsList(),
d77b985a 925 instVer.VerStr()) == false)
c7c7d3e8 926 return false;
5af32db6 927
d77b985a 928 for (PrvIterator P = instVer.ProvidesList();
f7f0d6c7 929 P.end() == false; ++P)
32d9baea
DK
930 if (Pkg->Group != P.OwnerPkg()->Group)
931 CheckRConflicts(Pkg,P.ParentPkg().RevDependsList(),P.ProvideVersion());
70ae2409 932
75a90b93
DK
933 if (PkgLoop)
934 return true;
940f2160 935
d77b985a
DK
936 List->Flag(Pkg,pkgOrderList::UnPacked,pkgOrderList::States);
937
2a2a7ef4 938 if (Immediate == true && (instVer->MultiArch & pkgCache::Version::Same) == pkgCache::Version::Same)
30426f48
DK
939 {
940 /* Do lockstep M-A:same unpacking in two phases:
941 First unpack all installed architectures, then the not installed.
942 This way we avoid that M-A: enabled packages are installed before
943 their older non-M-A enabled packages are replaced by newer versions */
944 bool const installed = Pkg->CurrentVer != 0;
36635720
DK
945 if (installed == true &&
946 (instVer != Pkg.CurrentVer() ||
947 ((Cache[Pkg].iFlags & pkgDepCache::ReInstall) == pkgDepCache::ReInstall)) &&
948 Install(Pkg,FileNames[Pkg->ID]) == false)
30426f48 949 return false;
d77b985a
DK
950 for (PkgIterator P = Pkg.Group().PackageList();
951 P.end() == false; P = Pkg.Group().NextPkg(P))
952 {
30426f48 953 if (P->CurrentVer == 0 || P == Pkg || List->IsFlag(P,pkgOrderList::UnPacked) == true ||
d77b985a
DK
954 Cache[P].InstallVer == 0 || (P.CurrentVer() == Cache[P].InstallVer &&
955 (Cache[Pkg].iFlags & pkgDepCache::ReInstall) != pkgDepCache::ReInstall))
956 continue;
75a90b93 957 if (SmartUnPack(P, false, Depth + 1) == false)
30426f48 958 return false;
d77b985a 959 }
30426f48
DK
960 if (installed == false && Install(Pkg,FileNames[Pkg->ID]) == false)
961 return false;
962 for (PkgIterator P = Pkg.Group().PackageList();
963 P.end() == false; P = Pkg.Group().NextPkg(P))
964 {
965 if (P->CurrentVer != 0 || P == Pkg || List->IsFlag(P,pkgOrderList::UnPacked) == true ||
2b8b1e7a 966 List->IsFlag(P,pkgOrderList::Configured) == true ||
30426f48
DK
967 Cache[P].InstallVer == 0 || (P.CurrentVer() == Cache[P].InstallVer &&
968 (Cache[Pkg].iFlags & pkgDepCache::ReInstall) != pkgDepCache::ReInstall))
969 continue;
75a90b93 970 if (SmartUnPack(P, false, Depth + 1) == false)
30426f48
DK
971 return false;
972 }
973 }
cd5e8444 974 // packages which are already unpacked don't need to be unpacked again
d4b4e5ea
DK
975 else if ((instVer != Pkg.CurrentVer() ||
976 ((Cache[Pkg].iFlags & pkgDepCache::ReInstall) == pkgDepCache::ReInstall)) &&
977 Install(Pkg,FileNames[Pkg->ID]) == false)
28166356
DK
978 return false;
979
d41d0e01 980 if (Immediate == true) {
590f1923 981 // Perform immedate configuration of the package.
d41d0e01 982 if (SmartConfigure(Pkg, Depth + 1) == false)
0eb4af9d 983 _error->Error(_("Could not perform immediate configuration on '%s'. "
90436124 984 "Please see man 5 apt.conf under APT::Immediate-Configure for details. (%d)"),Pkg.FullName().c_str(),2);
590f1923 985 }
6c139d6e
AL
986
987 return true;
988}
989 /*}}}*/
990// PM::OrderInstall - Installation ordering routine /*{{{*/
991// ---------------------------------------------------------------------
992/* */
281daf46 993pkgPackageManager::OrderResult pkgPackageManager::OrderInstall()
6c139d6e 994{
7a1b1f8b 995 if (CreateOrderList() == false)
281daf46
AL
996 return Failed;
997
998 Reset();
6c139d6e 999
30e1eab5 1000 if (Debug == true)
5e312de7 1001 clog << "Beginning to order" << endl;
6c139d6e 1002
5e312de7
DK
1003 bool const ordering =
1004 _config->FindB("PackageManager::UnpackAll",true) ?
1005 List->OrderUnpack(FileNames) : List->OrderCritical();
1006 if (ordering == false)
281daf46
AL
1007 {
1008 _error->Error("Internal ordering error");
1009 return Failed;
1010 }
1011
30e1eab5
AL
1012 if (Debug == true)
1013 clog << "Done ordering" << endl;
1014
281daf46 1015 bool DoneSomething = false;
91c03d37 1016 for (pkgOrderList::iterator I = List->begin(); I != List->end(); ++I)
6c139d6e
AL
1017 {
1018 PkgIterator Pkg(Cache,*I);
0caa5a4c 1019
281daf46
AL
1020 if (List->IsNow(Pkg) == false)
1021 {
0caa5a4c
DK
1022 if (Debug == true)
1023 clog << "Skipping already done " << Pkg.FullName() << endl;
281daf46
AL
1024 continue;
1025 }
0caa5a4c 1026
2fd65468 1027 if (List->IsMissing(Pkg) == true)
281daf46
AL
1028 {
1029 if (Debug == true)
90436124 1030 clog << "Sequence completed at " << Pkg.FullName() << endl;
281daf46
AL
1031 if (DoneSomething == false)
1032 {
1033 _error->Error("Internal Error, ordering was unable to handle the media swap");
1034 return Failed;
1035 }
1036 return Incomplete;
1037 }
6c139d6e
AL
1038
1039 // Sanity check
d0c59649
AL
1040 if (Cache[Pkg].Keep() == true &&
1041 Pkg.State() == pkgCache::PkgIterator::NeedsNothing &&
1042 (Cache[Pkg].iFlags & pkgDepCache::ReInstall) != pkgDepCache::ReInstall)
281daf46 1043 {
90436124 1044 _error->Error("Internal Error, trying to manipulate a kept package (%s)",Pkg.FullName().c_str());
281daf46
AL
1045 return Failed;
1046 }
6c139d6e
AL
1047
1048 // Perform a delete or an install
1049 if (Cache[Pkg].Delete() == true)
1050 {
1051 if (SmartRemove(Pkg) == false)
281daf46 1052 return Failed;
6c139d6e
AL
1053 }
1054 else
d41d0e01 1055 if (SmartUnPack(Pkg,List->IsFlag(Pkg,pkgOrderList::Immediate),0) == false)
281daf46
AL
1056 return Failed;
1057 DoneSomething = true;
590f1923
CB
1058
1059 if (ImmConfigureAll) {
1e3f4083 1060 /* ConfigureAll here to pick up and packages left unconfigured because they were unpacked in the
590f1923 1061 "PreUnpack Checks" section */
c7c7d3e8
CB
1062 if (!ConfigureAll())
1063 return Failed;
590f1923 1064 }
6c139d6e 1065 }
5e312de7 1066
6c139d6e
AL
1067 // Final run through the configure phase
1068 if (ConfigureAll() == false)
281daf46 1069 return Failed;
6c139d6e
AL
1070
1071 // Sanity check
91c03d37 1072 for (pkgOrderList::iterator I = List->begin(); I != List->end(); ++I)
281daf46 1073 {
6c139d6e 1074 if (List->IsFlag(*I,pkgOrderList::Configured) == false)
281daf46
AL
1075 {
1076 _error->Error("Internal error, packages left unconfigured. %s",
90436124 1077 PkgIterator(Cache,*I).FullName().c_str());
281daf46
AL
1078 return Failed;
1079 }
9fc57a59 1080 }
281daf46
AL
1081
1082 return Completed;
6c139d6e 1083}
3b1b0f29
MV
1084// PM::DoInstallPostFork - compat /*{{{*/
1085// ---------------------------------------------------------------------
1086 /*}}}*/
1087pkgPackageManager::OrderResult
1088pkgPackageManager::DoInstallPostFork(int statusFd)
1089{
bd5f39b3
MV
1090 APT::Progress::PackageManager *progress = new
1091 APT::Progress::PackageManagerProgressFd(statusFd);
1092 pkgPackageManager::OrderResult res = DoInstallPostFork(progress);
1093 delete progress;
1094 return res;
1095}
6c139d6e 1096 /*}}}*/
1d6386f3
MV
1097// PM::DoInstallPostFork - Does install part that happens after the fork /*{{{*/
1098// ---------------------------------------------------------------------
1099pkgPackageManager::OrderResult
e6ad8031 1100pkgPackageManager::DoInstallPostFork(APT::Progress::PackageManager *progress)
1d6386f3 1101{
5e9458e2
MV
1102 bool goResult = Go(progress);
1103 if(goResult == false)
1104 return Failed;
1105
1106 return Res;
bf3ad91f 1107}
e6ad8031 1108 /*}}}*/
2a7e07c7
MV
1109// PM::DoInstall - Does the installation /*{{{*/
1110// ---------------------------------------------------------------------
3b1b0f29
MV
1111/* compat */
1112pkgPackageManager::OrderResult
1113pkgPackageManager::DoInstall(int statusFd)
1114{
1115 APT::Progress::PackageManager *progress = new
1116 APT::Progress::PackageManagerProgressFd(statusFd);
1117 OrderResult res = DoInstall(progress);
1118 delete progress;
1119 return res;
1120 }
1121 /*}}}*/
1122// PM::DoInstall - Does the installation /*{{{*/
1123// ---------------------------------------------------------------------
2a7e07c7
MV
1124/* This uses the filenames in FileNames and the information in the
1125 DepCache to perform the installation of packages.*/
e6ad8031
MV
1126pkgPackageManager::OrderResult
1127pkgPackageManager::DoInstall(APT::Progress::PackageManager *progress)
2a7e07c7
MV
1128{
1129 if(DoInstallPreFork() == Failed)
1130 return Failed;
1131
e6ad8031 1132 return DoInstallPostFork(progress);
2a7e07c7 1133}
eef71338 1134 /*}}}*/