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