]> git.saurik.com Git - apt.git/blame - apt-pkg/packagemanager.cc
implement apt-get source msg 'Please use: $vcs' for git
[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 /*}}}*/
9106d7c9
DK
271// PM::CheckRBreaks - Look for reverse breaks /*{{{*/
272bool pkgPackageManager::CheckRBreaks(PkgIterator const &Pkg, DepIterator D,
273 const char * const Ver)
274{
275 for (;D.end() == false; ++D)
276 {
277 if (D->Type != pkgCache::Dep::DpkgBreaks)
278 continue;
279
280 PkgIterator const DP = D.ParentPkg();
281 if (Cache[DP].Delete() == false)
282 continue;
283
284 // Ignore self conflicts, ignore conflicts from irrelevant versions
285 if (D.IsIgnorable(Pkg) || D.ParentVer() != DP.CurrentVer())
286 continue;
287
288 if (Cache.VS().CheckDep(Ver, D->CompareOp, D.TargetVer()) == false)
289 continue;
290
291 // no earlyremove() here as user has already agreed to the permanent removal
292 if (SmartRemove(DP) == false)
293 return _error->Error("Internal Error, Could not early remove %s (%d)",DP.FullName().c_str(), 4);
294 }
295 return true;
296}
297 /*}}}*/
6c139d6e
AL
298// PM::ConfigureAll - Run the all out configuration /*{{{*/
299// ---------------------------------------------------------------------
300/* This configures every package. It is assumed they are all unpacked and
590f1923
CB
301 that the final configuration is valid. This is also used to catch packages
302 that have not been configured when using ImmConfigureAll */
6c139d6e
AL
303bool pkgPackageManager::ConfigureAll()
304{
b2e465d6 305 pkgOrderList OList(&Cache);
6c139d6e
AL
306
307 // Populate the order list
91c03d37 308 for (pkgOrderList::iterator I = List->begin(); I != List->end(); ++I)
6c139d6e
AL
309 if (List->IsFlag(pkgCache::PkgIterator(Cache,*I),
310 pkgOrderList::UnPacked) == true)
311 OList.push_back(*I);
312
313 if (OList.OrderConfigure() == false)
314 return false;
5e312de7
DK
315
316 std::string const conf = _config->Find("PackageManager::Configure","all");
317 bool const ConfigurePkgs = (conf == "all");
318
6c139d6e 319 // Perform the configuring
91c03d37 320 for (pkgOrderList::iterator I = OList.begin(); I != OList.end(); ++I)
6c139d6e
AL
321 {
322 PkgIterator Pkg(Cache,*I);
17182c0c
CB
323
324 /* Check if the package has been configured, this can happen if SmartConfigure
325 calls its self */
326 if (List->IsFlag(Pkg,pkgOrderList::Configured)) continue;
803ea2a8 327
d41d0e01 328 if (ConfigurePkgs == true && SmartConfigure(Pkg, 0) == false) {
c7c7d3e8
CB
329 if (ImmConfigureAll)
330 _error->Error(_("Could not perform immediate configuration on '%s'. "
90436124 331 "Please see man 5 apt.conf under APT::Immediate-Configure for details. (%d)"),Pkg.FullName().c_str(),1);
c7c7d3e8 332 else
90436124 333 _error->Error("Internal error, packages left unconfigured. %s",Pkg.FullName().c_str());
6c139d6e 334 return false;
634985f8 335 }
6c139d6e
AL
336
337 List->Flag(Pkg,pkgOrderList::Configured,pkgOrderList::States);
338 }
339
340 return true;
341}
342 /*}}}*/
0eb4af9d
DK
343// PM::NonLoopingSmart - helper to avoid loops while calling Smart methods /*{{{*/
344// -----------------------------------------------------------------------
345/* ensures that a loop of the form A depends B, B depends A (and similar)
346 is not leading us down into infinite recursion segfault land */
347bool pkgPackageManager::NonLoopingSmart(SmartAction const action, pkgCache::PkgIterator &Pkg,
348 pkgCache::PkgIterator DepPkg, int const Depth, bool const PkgLoop,
349 bool * const Bad, bool * const Changed)
350{
351 if (PkgLoop == false)
352 List->Flag(Pkg,pkgOrderList::Loop);
353 bool success = false;
354 switch(action)
355 {
356 case UNPACK_IMMEDIATE: success = SmartUnPack(DepPkg, true, Depth + 1); break;
357 case UNPACK: success = SmartUnPack(DepPkg, false, Depth + 1); break;
358 case CONFIGURE: success = SmartConfigure(DepPkg, Depth + 1); break;
359 }
360 if (PkgLoop == false)
361 List->RmFlag(Pkg,pkgOrderList::Loop);
362
363 if (success == false)
364 return false;
365
366 if (Bad != NULL)
367 *Bad = false;
368 if (Changed != NULL && List->IsFlag(DepPkg,pkgOrderList::Loop) == false)
369 *Changed = true;
370 return true;
371}
372 /*}}}*/
6c139d6e
AL
373// PM::SmartConfigure - Perform immediate configuration of the pkg /*{{{*/
374// ---------------------------------------------------------------------
c7c7d3e8 375/* This function tries to put the system in a state where Pkg can be configured.
0eb4af9d
DK
376 This involves checking each of Pkg's dependencies and unpacking and
377 configuring packages where needed. */
d41d0e01 378bool pkgPackageManager::SmartConfigure(PkgIterator Pkg, int const Depth)
6c139d6e 379{
38ff3de6 380 // If this is true, only check and correct and dependencies without the Loop flag
2dd2c801 381 bool const PkgLoop = List->IsFlag(Pkg,pkgOrderList::Loop);
d41d0e01 382
987d8d03
CB
383 if (Debug) {
384 VerIterator InstallVer = VerIterator(Cache,Cache[Pkg].InstallVer);
90436124 385 clog << OutputInDepth(Depth) << "SmartConfigure " << Pkg.FullName() << " (" << InstallVer.VerStr() << ")";
d41d0e01 386 if (PkgLoop)
38ff3de6 387 clog << " (Only Correct Dependencies)";
d41d0e01 388 clog << endl;
987d8d03 389 }
0eacf067 390
590f1923 391 VerIterator const instVer = Cache[Pkg].InstVerIter(Cache);
0eb4af9d
DK
392
393 /* Because of the ordered list, most dependencies should be unpacked,
394 however if there is a loop (A depends on B, B depends on A) this will not
38ff3de6 395 be the case, so check for dependencies before configuring. */
2dd2c801 396 bool Bad = false, Changed = false;
9c5104cf 397 const unsigned int max_loops = _config->FindI("APT::pkgPackageManager::MaxLoopCount", 5000);
bce4caa3 398 unsigned int i=0;
42d51f33 399 std::list<DepIterator> needConfigure;
bce4caa3
MV
400 do
401 {
2f589691
MV
402 // Check each dependency and see if anything needs to be done
403 // so that it can be configured
2dd2c801
DK
404 Changed = false;
405 for (DepIterator D = instVer.DependsList(); D.end() == false; )
406 {
407 // Compute a single dependency element (glob or)
408 pkgCache::DepIterator Start, End;
409 D.GlobOr(Start,End);
410
411 if (End->Type != pkgCache::Dep::Depends)
412 continue;
413 Bad = true;
414
2f589691
MV
415 // the first pass checks if we its all good, i.e. if we have
416 // to do anything at all
2dd2c801
DK
417 for (DepIterator Cur = Start; true; ++Cur)
418 {
93a0805b 419 std::unique_ptr<Version *[]> VList(Cur.AllTargets());
2dd2c801 420
98cc7fd2 421 for (Version **I = VList.get(); *I != 0; ++I)
6c139d6e 422 {
2dd2c801
DK
423 VerIterator Ver(Cache,*I);
424 PkgIterator DepPkg = Ver.ParentPkg();
425
426 // Check if the current version of the package is available and will satisfy this dependency
427 if (DepPkg.CurrentVer() == Ver && List->IsNow(DepPkg) == true &&
428 List->IsFlag(DepPkg,pkgOrderList::Removed) == false &&
4e6a7e26
DK
429 DepPkg.State() == PkgIterator::NeedsNothing &&
430 (Cache[DepPkg].iFlags & pkgDepCache::ReInstall) != pkgDepCache::ReInstall)
2dd2c801
DK
431 {
432 Bad = false;
433 break;
434 }
435
2f589691
MV
436 // Check if the version that is going to be installed will satisfy the dependency
437 if (Cache[DepPkg].InstallVer != *I || List->IsNow(DepPkg) == false)
438 continue;
439
440 if (PkgLoop == true)
441 {
442 if (Debug)
4e6a7e26
DK
443 std::clog << OutputInDepth(Depth) << "Package " << Pkg << " loops in SmartConfigure";
444 if (List->IsFlag(DepPkg,pkgOrderList::UnPacked))
445 Bad = false;
446 else if (Debug)
447 std::clog << ", but it isn't unpacked yet";
448 if (Debug)
449 std::clog << std::endl;
2f589691
MV
450 }
451 }
452
453 if (Cur == End || Bad == false)
454 break;
455 }
456
457 // this dependency is in a good state, so we can stop
458 if (Bad == false)
459 {
460 if (Debug)
4e6a7e26 461 std::clog << OutputInDepth(Depth) << "Found ok dep " << Start.TargetPkg() << std::endl;
2f589691
MV
462 continue;
463 }
464
465 // Check for dependencies that have not been unpacked,
466 // probably due to loops.
467 for (DepIterator Cur = Start; true; ++Cur)
468 {
93a0805b 469 std::unique_ptr<Version *[]> VList(Cur.AllTargets());
2f589691 470
98cc7fd2 471 for (Version **I = VList.get(); *I != 0; ++I)
2f589691
MV
472 {
473 VerIterator Ver(Cache,*I);
474 PkgIterator DepPkg = Ver.ParentPkg();
475
476 // Check if the current version of the package is available and will satisfy this dependency
477 if (DepPkg.CurrentVer() == Ver && List->IsNow(DepPkg) == true &&
478 List->IsFlag(DepPkg,pkgOrderList::Removed) == false &&
4e6a7e26
DK
479 DepPkg.State() == PkgIterator::NeedsNothing &&
480 (Cache[DepPkg].iFlags & pkgDepCache::ReInstall) != pkgDepCache::ReInstall)
2f589691
MV
481 continue;
482
2dd2c801 483 // Check if the version that is going to be installed will satisfy the dependency
42d51f33 484 if (Cache[DepPkg].InstallVer != *I || List->IsNow(DepPkg) == false)
2dd2c801
DK
485 continue;
486
42d51f33 487 if (PkgLoop == true)
2dd2c801 488 {
42d51f33 489 if (Debug)
4e6a7e26
DK
490 std::clog << OutputInDepth(Depth) << "Package " << Pkg << " loops in SmartConfigure";
491 if (List->IsFlag(DepPkg,pkgOrderList::UnPacked))
492 Bad = false;
493 else if (Debug)
494 std::clog << ", but it isn't unpacked yet";
495 if (Debug)
496 std::clog << std::endl;
42d51f33
DK
497 }
498 else
499 {
500 if (Debug)
501 clog << OutputInDepth(Depth) << "Unpacking " << DepPkg.FullName() << " to avoid loop " << Cur << endl;
0eb4af9d 502 if (NonLoopingSmart(UNPACK_IMMEDIATE, Pkg, DepPkg, Depth, PkgLoop, &Bad, &Changed) == false)
71e7a0f3 503 return false;
2dd2c801 504 }
2f589691
MV
505 // at this point we either unpacked a Dep or we are in a loop,
506 // no need to unpack a second one
0eb4af9d 507 break;
590f1923 508 }
42d51f33
DK
509
510 if (Cur == End || Bad == false)
2dd2c801 511 break;
42d51f33 512 }
2dd2c801
DK
513
514 if (Bad == false)
515 continue;
516
42d51f33
DK
517 needConfigure.push_back(Start);
518 }
519 if (i++ > max_loops)
520 return _error->Error("Internal error: MaxLoopCount reached in SmartUnPack (1) for %s, aborting", Pkg.FullName().c_str());
521 } while (Changed == true);
522
2f589691 523 // now go over anything that needs configuring
42d51f33
DK
524 Bad = false, Changed = false, i = 0;
525 do
526 {
527 Changed = false;
6420c00e 528 for (std::list<DepIterator>::const_iterator D = needConfigure.begin(); D != needConfigure.end(); ++D)
42d51f33 529 {
6420c00e 530 // Compute a single dependency element (glob or) without modifying D
42d51f33 531 pkgCache::DepIterator Start, End;
6420c00e
DK
532 {
533 pkgCache::DepIterator Discard = *D;
534 Discard.GlobOr(Start,End);
535 }
42d51f33
DK
536
537 if (End->Type != pkgCache::Dep::Depends)
538 continue;
539 Bad = true;
540
541 // Search for dependencies which are unpacked but aren't configured yet (maybe loops)
2dd2c801
DK
542 for (DepIterator Cur = Start; true; ++Cur)
543 {
93a0805b 544 std::unique_ptr<Version *[]> VList(Cur.AllTargets());
2dd2c801 545
98cc7fd2 546 for (Version **I = VList.get(); *I != 0; ++I)
2dd2c801
DK
547 {
548 VerIterator Ver(Cache,*I);
549 PkgIterator DepPkg = Ver.ParentPkg();
550
551 // Check if the version that is going to be installed will satisfy the dependency
42d51f33 552 if (Cache[DepPkg].InstallVer != *I)
2dd2c801
DK
553 continue;
554
42d51f33 555 if (List->IsFlag(DepPkg,pkgOrderList::UnPacked))
d9f6c795 556 {
42d51f33
DK
557 if (List->IsFlag(DepPkg,pkgOrderList::Loop) && PkgLoop)
558 {
559 // This dependency has already been dealt with by another SmartConfigure on Pkg
560 Bad = false;
561 break;
562 }
0eb4af9d
DK
563 if (Debug)
564 std::clog << OutputInDepth(Depth) << "Configure already unpacked " << DepPkg << std::endl;
565 if (NonLoopingSmart(CONFIGURE, Pkg, DepPkg, Depth, PkgLoop, &Bad, &Changed) == false)
71e7a0f3 566 return false;
71e7a0f3 567 break;
0eb4af9d 568
d9f6c795 569 }
42d51f33
DK
570 else if (List->IsFlag(DepPkg,pkgOrderList::Configured))
571 {
572 Bad = false;
573 break;
574 }
590f1923 575 }
42d51f33 576 if (Cur == End || Bad == false)
2dd2c801 577 break;
42d51f33
DK
578 }
579
580
2dd2c801 581 if (Bad == true && Changed == false && Debug == true)
6420c00e 582 std::clog << OutputInDepth(Depth) << "Could not satisfy " << *D << std::endl;
6c139d6e 583 }
bce4caa3 584 if (i++ > max_loops)
42d51f33 585 return _error->Error("Internal error: MaxLoopCount reached in SmartUnPack (2) for %s, aborting", Pkg.FullName().c_str());
2dd2c801 586 } while (Changed == true);
0eb4af9d 587
71e7a0f3
DK
588 if (Bad == true)
589 return _error->Error(_("Could not configure '%s'. "),Pkg.FullName().c_str());
0eb4af9d 590
9106d7c9
DK
591 // Check for reverse conflicts.
592 if (CheckRBreaks(Pkg,Pkg.RevDependsList(), instVer.VerStr()) == false)
593 return false;
594
595 for (PrvIterator P = instVer.ProvidesList(); P.end() == false; ++P)
596 if (Pkg->Group != P.OwnerPkg()->Group)
597 CheckRBreaks(Pkg,P.ParentPkg().RevDependsList(),P.ProvideVersion());
598
a99d02a8 599 if (PkgLoop) return true;
5e312de7
DK
600
601 static std::string const conf = _config->Find("PackageManager::Configure","all");
602 static bool const ConfigurePkgs = (conf == "all" || conf == "smart");
603
0eb4af9d 604 if (List->IsFlag(Pkg,pkgOrderList::Configured))
90436124 605 return _error->Error("Internal configure error on '%s'.", Pkg.FullName().c_str());
5e312de7 606
590f1923
CB
607 if (ConfigurePkgs == true && Configure(Pkg) == false)
608 return false;
75a90b93 609
590f1923 610 List->Flag(Pkg,pkgOrderList::Configured,pkgOrderList::States);
6c139d6e 611
894d672e 612 if ((Cache[Pkg].InstVerIter(Cache)->MultiArch & pkgCache::Version::Same) == pkgCache::Version::Same)
d77b985a
DK
613 for (PkgIterator P = Pkg.Group().PackageList();
614 P.end() == false; P = Pkg.Group().NextPkg(P))
615 {
616 if (Pkg == P || List->IsFlag(P,pkgOrderList::Configured) == true ||
2b8b1e7a 617 List->IsFlag(P,pkgOrderList::UnPacked) == false ||
d77b985a
DK
618 Cache[P].InstallVer == 0 || (P.CurrentVer() == Cache[P].InstallVer &&
619 (Cache[Pkg].iFlags & pkgDepCache::ReInstall) != pkgDepCache::ReInstall))
620 continue;
71e7a0f3
DK
621 if (SmartConfigure(P, (Depth +1)) == false)
622 return false;
d77b985a
DK
623 }
624
6c139d6e
AL
625 // Sanity Check
626 if (List->IsFlag(Pkg,pkgOrderList::Configured) == false)
90436124 627 return _error->Error(_("Could not configure '%s'. "),Pkg.FullName().c_str());
20382bad 628
6c139d6e
AL
629 return true;
630}
631 /*}}}*/
6c139d6e
AL
632// PM::EarlyRemove - Perform removal of packages before their time /*{{{*/
633// ---------------------------------------------------------------------
634/* This is called to deal with conflicts arising from unpacking */
635bool pkgPackageManager::EarlyRemove(PkgIterator Pkg)
0eb4af9d
DK
636{
637 return EarlyRemove(Pkg, NULL);
638}
639bool pkgPackageManager::EarlyRemove(PkgIterator Pkg, DepIterator const * const Dep)
6c139d6e
AL
640{
641 if (List->IsNow(Pkg) == false)
642 return true;
0eb4af9d 643
6c139d6e
AL
644 // Already removed it
645 if (List->IsFlag(Pkg,pkgOrderList::Removed) == true)
646 return true;
0eb4af9d 647
6c139d6e
AL
648 // Woops, it will not be re-installed!
649 if (List->IsFlag(Pkg,pkgOrderList::InList) == false)
650 return false;
9d4c8f67 651
0eb4af9d
DK
652 // these breaks on M-A:same packages can be dealt with. They 'loop' by design
653 if (Dep != NULL && (*Dep)->Type == pkgCache::Dep::DpkgBreaks && Dep->IsMultiArchImplicit() == true)
654 return true;
655
9d4c8f67 656 // Essential packages get special treatment
5af32db6 657 bool IsEssential = false;
c5200869
JAK
658 if ((Pkg->Flags & pkgCache::Flag::Essential) != 0 ||
659 (Pkg->Flags & pkgCache::Flag::Important) != 0)
5af32db6
AL
660 IsEssential = true;
661
0eb4af9d 662 /* Check for packages that are the dependents of essential packages and
5af32db6
AL
663 promote them too */
664 if (Pkg->CurrentVer != 0)
665 {
0eb4af9d 666 for (pkgCache::DepIterator D = Pkg.RevDependsList(); D.end() == false &&
f7f0d6c7 667 IsEssential == false; ++D)
5af32db6 668 if (D->Type == pkgCache::Dep::Depends || D->Type == pkgCache::Dep::PreDepends)
c5200869
JAK
669 if ((D.ParentPkg()->Flags & pkgCache::Flag::Essential) != 0 ||
670 (D.ParentPkg()->Flags & pkgCache::Flag::Important) != 0)
5af32db6
AL
671 IsEssential = true;
672 }
673
674 if (IsEssential == true)
9d4c8f67
AL
675 {
676 if (_config->FindB("APT::Force-LoopBreak",false) == false)
b2e465d6
AL
677 return _error->Error(_("This installation run will require temporarily "
678 "removing the essential package %s due to a "
679 "Conflicts/Pre-Depends loop. This is often bad, "
680 "but if you really want to do it, activate the "
90436124 681 "APT::Force-LoopBreak option."),Pkg.FullName().c_str());
9d4c8f67 682 }
0eb4af9d
DK
683 // dpkg will auto-deconfigure it, no need for the big remove hammer
684 else if (Dep != NULL && (*Dep)->Type == pkgCache::Dep::DpkgBreaks)
685 return true;
686
6c139d6e
AL
687 bool Res = SmartRemove(Pkg);
688 if (Cache[Pkg].Delete() == false)
689 List->Flag(Pkg,pkgOrderList::Removed,pkgOrderList::States);
0eb4af9d 690
6c139d6e
AL
691 return Res;
692}
693 /*}}}*/
694// PM::SmartRemove - Removal Helper /*{{{*/
695// ---------------------------------------------------------------------
696/* */
697bool pkgPackageManager::SmartRemove(PkgIterator Pkg)
698{
699 if (List->IsNow(Pkg) == false)
700 return true;
701
702 List->Flag(Pkg,pkgOrderList::Configured,pkgOrderList::States);
803ea2a8 703
28166356 704 return Remove(Pkg,(Cache[Pkg].iFlags & pkgDepCache::Purge) == pkgDepCache::Purge);
6c139d6e
AL
705}
706 /*}}}*/
707// PM::SmartUnPack - Install helper /*{{{*/
708// ---------------------------------------------------------------------
1e3f4083 709/* This puts the system in a state where it can Unpack Pkg, if Pkg is already
590f1923 710 unpacked, or when it has been unpacked, if Immediate==true it configures it. */
6c139d6e 711bool pkgPackageManager::SmartUnPack(PkgIterator Pkg)
d77b985a 712{
d41d0e01 713 return SmartUnPack(Pkg, true, 0);
d77b985a 714}
d41d0e01 715bool pkgPackageManager::SmartUnPack(PkgIterator Pkg, bool const Immediate, int const Depth)
6c139d6e 716{
d41d0e01
CB
717 bool PkgLoop = List->IsFlag(Pkg,pkgOrderList::Loop);
718
987d8d03 719 if (Debug) {
90436124 720 clog << OutputInDepth(Depth) << "SmartUnPack " << Pkg.FullName();
987d8d03
CB
721 VerIterator InstallVer = VerIterator(Cache,Cache[Pkg].InstallVer);
722 if (Pkg.CurrentVer() == 0)
c4f931f8 723 clog << " (install version " << InstallVer.VerStr() << ")";
987d8d03 724 else
c4f931f8 725 clog << " (replace version " << Pkg.CurrentVer().VerStr() << " with " << InstallVer.VerStr() << ")";
d41d0e01 726 if (PkgLoop)
c4f931f8 727 clog << " (Only Perform PreUnpack Checks)";
0caa5a4c
DK
728 if (Immediate)
729 clog << " immediately";
c4f931f8 730 clog << endl;
987d8d03 731 }
cfcdf7fe 732
d77b985a
DK
733 VerIterator const instVer = Cache[Pkg].InstVerIter(Cache);
734
0eb4af9d 735 /* PreUnpack Checks: This loop checks and attempts to rectify any problems that would prevent the package being unpacked.
98ee4922 736 It addresses: PreDepends, Conflicts, Obsoletes and Breaks (DpkgBreaks). Any resolutions that do not require it should
c7c7d3e8 737 avoid configuration (calling SmartUnpack with Immediate=true), this is because when unpacking some packages with
0eb4af9d 738 complex dependency structures, trying to configure some packages while breaking the loops can complicate things.
98ee4922 739 This will be either dealt with if the package is configured as a dependency of Pkg (if and when Pkg is configured),
c7c7d3e8 740 or by the ConfigureAll call at the end of the for loop in OrderInstall. */
0eb4af9d
DK
741 bool SomethingBad = false, Changed = false;
742 bool couldBeTemporaryRemoved = Depth != 0 && List->IsFlag(Pkg,pkgOrderList::Removed) == false;
9c5104cf 743 const unsigned int max_loops = _config->FindI("APT::pkgPackageManager::MaxLoopCount", 5000);
5ab7b53b 744 unsigned int i = 0;
bce4caa3
MV
745 do
746 {
98ee4922
DK
747 Changed = false;
748 for (DepIterator D = instVer.DependsList(); D.end() == false; )
6c139d6e 749 {
98ee4922
DK
750 // Compute a single dependency element (glob or)
751 pkgCache::DepIterator Start, End;
752 D.GlobOr(Start,End);
f4945db3 753
98ee4922
DK
754 if (End->Type == pkgCache::Dep::PreDepends)
755 {
756 bool Bad = true;
757 if (Debug)
758 clog << OutputInDepth(Depth) << "PreDepends order for " << Pkg.FullName() << std::endl;
759
760 // Look for easy targets: packages that are already okay
761 for (DepIterator Cur = Start; Bad == true; ++Cur)
6c139d6e 762 {
93a0805b 763 std::unique_ptr<Version *[]> VList(Cur.AllTargets());
98cc7fd2 764 for (Version **I = VList.get(); *I != 0; ++I)
98ee4922
DK
765 {
766 VerIterator Ver(Cache,*I);
767 PkgIterator Pkg = Ver.ParentPkg();
768
769 // See if the current version is ok
770 if (Pkg.CurrentVer() == Ver && List->IsNow(Pkg) == true &&
4e6a7e26
DK
771 Pkg.State() == PkgIterator::NeedsNothing &&
772 (Cache[Pkg].iFlags & pkgDepCache::ReInstall) != pkgDepCache::ReInstall)
98ee4922
DK
773 {
774 Bad = false;
775 if (Debug)
776 clog << OutputInDepth(Depth) << "Found ok package " << Pkg.FullName() << endl;
777 break;
778 }
779 }
780 if (Cur == End)
781 break;
17182c0c 782 }
6c139d6e 783
98ee4922 784 // Look for something that could be configured.
275024e9 785 for (DepIterator Cur = Start; Bad == true && Cur.end() == false; ++Cur)
98ee4922 786 {
98cc7fd2
JAK
787 std::unique_ptr<Version *[]> VList(Cur.AllTargets());
788 for (Version **I = VList.get(); *I != 0; ++I)
98ee4922
DK
789 {
790 VerIterator Ver(Cache,*I);
0eb4af9d 791 PkgIterator DepPkg = Ver.ParentPkg();
1006601e 792
98ee4922 793 // Not the install version
4e6a7e26
DK
794 if (Cache[DepPkg].InstallVer != *I)
795 continue;
796
797 if (Cache[DepPkg].Keep() == true && DepPkg.State() == PkgIterator::NeedsNothing &&
798 (Cache[DepPkg].iFlags & pkgDepCache::ReInstall) != pkgDepCache::ReInstall)
98ee4922
DK
799 continue;
800
0eb4af9d 801 if (List->IsFlag(DepPkg,pkgOrderList::Configured))
98ee4922
DK
802 {
803 Bad = false;
804 break;
805 }
806
807 // check if it needs unpack or if if configure is enough
0eb4af9d 808 if (List->IsFlag(DepPkg,pkgOrderList::UnPacked) == false)
98ee4922 809 {
4e6a7e26
DK
810 // two packages pre-depending on each other can't be handled sanely
811 if (List->IsFlag(DepPkg,pkgOrderList::Loop) && PkgLoop)
812 {
813 // this isn't an error as there is potential for something else to satisfy it
814 // (like a provides or an or-group member)
815 if (Debug)
816 clog << OutputInDepth(Depth) << "Unpack loop detected between " << DepPkg.FullName() << " and " << Pkg.FullName() << endl;
817 continue;
818 }
819
98ee4922 820 if (Debug)
0eb4af9d
DK
821 clog << OutputInDepth(Depth) << "Trying to SmartUnpack " << DepPkg.FullName() << endl;
822 if (NonLoopingSmart(UNPACK_IMMEDIATE, Pkg, DepPkg, Depth, PkgLoop, &Bad, &Changed) == false)
71e7a0f3 823 return false;
98ee4922
DK
824 }
825 else
826 {
827 if (Debug)
0eb4af9d
DK
828 clog << OutputInDepth(Depth) << "Trying to SmartConfigure " << DepPkg.FullName() << endl;
829 if (NonLoopingSmart(CONFIGURE, Pkg, DepPkg, Depth, PkgLoop, &Bad, &Changed) == false)
71e7a0f3 830 return false;
98ee4922 831 }
0eb4af9d 832 break;
e2a5ff0c 833 }
6c139d6e 834 }
98ee4922
DK
835
836 if (Bad == true)
0eb4af9d 837 SomethingBad = true;
6c139d6e 838 }
98ee4922 839 else if (End->Type == pkgCache::Dep::Conflicts ||
0eb4af9d
DK
840 End->Type == pkgCache::Dep::Obsoletes ||
841 End->Type == pkgCache::Dep::DpkgBreaks)
cfcdf7fe 842 {
98cc7fd2
JAK
843 std::unique_ptr<Version *[]> VList(End.AllTargets());
844 for (Version **I = VList.get(); *I != 0; ++I)
3e9ab9f0 845 {
98ee4922
DK
846 VerIterator Ver(Cache,*I);
847 PkgIterator ConflictPkg = Ver.ParentPkg();
0eb4af9d
DK
848 if (ConflictPkg.CurrentVer() != Ver)
849 {
850 if (Debug)
851 std::clog << OutputInDepth(Depth) << "Ignore not-installed version " << Ver.VerStr() << " of " << ConflictPkg.FullName() << " for " << End << std::endl;
852 continue;
853 }
3e9ab9f0 854
0eb4af9d 855 if (List->IsNow(ConflictPkg) == false)
98ee4922 856 {
2252183c 857 if (Debug)
0eb4af9d
DK
858 std::clog << OutputInDepth(Depth) << "Ignore already dealt-with version " << Ver.VerStr() << " of " << ConflictPkg.FullName() << " for " << End << std::endl;
859 continue;
860 }
3e9ab9f0 861
0eb4af9d 862 if (List->IsFlag(ConflictPkg,pkgOrderList::Removed) == true)
98ee4922 863 {
2252183c 864 if (Debug)
0eb4af9d
DK
865 clog << OutputInDepth(Depth) << "Ignoring " << End << " as " << ConflictPkg.FullName() << "was temporarily removed" << endl;
866 continue;
867 }
868
869 if (List->IsFlag(ConflictPkg,pkgOrderList::Loop) && PkgLoop)
870 {
871 if (End->Type == pkgCache::Dep::DpkgBreaks && End.IsMultiArchImplicit() == true)
440d3d65
DK
872 {
873 if (Debug)
0eb4af9d
DK
874 clog << OutputInDepth(Depth) << "Because dependency is MultiArchImplicit we ignored looping on: " << ConflictPkg << endl;
875 continue;
98ee4922 876 }
98ee4922 877 if (Debug)
440d3d65 878 {
0eb4af9d
DK
879 if (End->Type == pkgCache::Dep::DpkgBreaks)
880 clog << OutputInDepth(Depth) << "Because of breaks knot, deconfigure " << ConflictPkg.FullName() << " temporarily" << endl;
881 else
71e7a0f3 882 clog << OutputInDepth(Depth) << "Because of conflict knot, removing " << ConflictPkg.FullName() << " temporarily" << endl;
98ee4922 883 }
0eb4af9d 884 if (EarlyRemove(ConflictPkg, &End) == false)
9106d7c9 885 return _error->Error("Internal Error, Could not early remove %s (%d)",ConflictPkg.FullName().c_str(), 3);
0eb4af9d 886 SomethingBad = true;
98ee4922
DK
887 continue;
888 }
889
0eb4af9d 890 if (Cache[ConflictPkg].Delete() == false)
98ee4922 891 {
0eb4af9d 892 if (Debug)
98ee4922 893 {
0eb4af9d
DK
894 clog << OutputInDepth(Depth) << "Unpacking " << ConflictPkg.FullName() << " to avoid " << End;
895 if (PkgLoop == true)
896 clog << " (Looping)";
897 clog << std::endl;
440d3d65 898 }
0eb4af9d
DK
899 // we would like to avoid temporary removals and all that at best via a simple unpack
900 _error->PushToStack();
901 if (NonLoopingSmart(UNPACK, Pkg, ConflictPkg, Depth, PkgLoop, NULL, &Changed) == false)
2264548f 902 {
0eb4af9d
DK
903 // but if it fails ignore this failure and look for alternative ways of solving
904 if (Debug)
440d3d65 905 {
1df24acf 906 clog << OutputInDepth(Depth) << "Avoidance unpack of " << ConflictPkg.FullName() << " failed for " << End << " ignoring:" << std::endl;
95278287 907 _error->DumpErrors(std::clog, GlobalError::DEBUG, false);
0eb4af9d
DK
908 }
909 _error->RevertToStack();
910 // ignorance can only happen if a) one of the offenders is already gone
911 if (List->IsFlag(ConflictPkg,pkgOrderList::Removed) == true)
440d3d65 912 {
0eb4af9d
DK
913 if (Debug)
914 clog << OutputInDepth(Depth) << "But " << ConflictPkg.FullName() << " was temporarily removed in the meantime to satisfy " << End << endl;
98ee4922 915 }
0eb4af9d 916 else if (List->IsFlag(Pkg,pkgOrderList::Removed) == true)
98ee4922
DK
917 {
918 if (Debug)
0eb4af9d 919 clog << OutputInDepth(Depth) << "But " << Pkg.FullName() << " was temporarily removed in the meantime to satisfy " << End << endl;
98ee4922 920 }
0eb4af9d 921 // or b) we can make one go (removal or dpkg auto-deconfigure)
98ee4922
DK
922 else
923 {
924 if (Debug)
0eb4af9d
DK
925 clog << OutputInDepth(Depth) << "So temprorary remove/deconfigure " << ConflictPkg.FullName() << " to satisfy " << End << endl;
926 if (EarlyRemove(ConflictPkg, &End) == false)
9106d7c9 927 return _error->Error("Internal Error, Could not early remove %s (%d)",ConflictPkg.FullName().c_str(), 2);
440d3d65 928 }
2264548f 929 }
0eb4af9d
DK
930 else
931 _error->MergeWithStack();
6b92f60c 932 }
0eb4af9d 933 else
6b92f60c
DK
934 {
935 if (Debug)
0eb4af9d
DK
936 clog << OutputInDepth(Depth) << "Removing " << ConflictPkg.FullName() << " now to avoid " << End << endl;
937 // no earlyremove() here as user has already agreed to the permanent removal
938 if (SmartRemove(Pkg) == false)
9106d7c9 939 return _error->Error("Internal Error, Could not early remove %s (%d)",ConflictPkg.FullName().c_str(), 1);
6b92f60c 940 }
6c139d6e
AL
941 }
942 }
6c139d6e 943 }
bce4caa3 944 if (i++ > max_loops)
91ea3def 945 return _error->Error("Internal error: APT::pkgPackageManager::MaxLoopCount reached in SmartConfigure for %s, aborting", Pkg.FullName().c_str());
98ee4922 946 } while (Changed == true);
0eb4af9d
DK
947
948 if (SomethingBad == true)
949 return _error->Error("Couldn't configure %s, probably a dependency cycle.", Pkg.FullName().c_str());
950
951 if (couldBeTemporaryRemoved == true && List->IsFlag(Pkg,pkgOrderList::Removed) == true)
952 {
953 if (Debug)
954 std::clog << OutputInDepth(Depth) << "Prevent unpack as " << Pkg << " is currently temporarily removed" << std::endl;
955 return true;
956 }
957
6c139d6e 958 // Check for reverse conflicts.
5af32db6 959 if (CheckRConflicts(Pkg,Pkg.RevDependsList(),
d77b985a 960 instVer.VerStr()) == false)
c7c7d3e8 961 return false;
5af32db6 962
d77b985a 963 for (PrvIterator P = instVer.ProvidesList();
f7f0d6c7 964 P.end() == false; ++P)
32d9baea
DK
965 if (Pkg->Group != P.OwnerPkg()->Group)
966 CheckRConflicts(Pkg,P.ParentPkg().RevDependsList(),P.ProvideVersion());
70ae2409 967
75a90b93
DK
968 if (PkgLoop)
969 return true;
940f2160 970
d77b985a
DK
971 List->Flag(Pkg,pkgOrderList::UnPacked,pkgOrderList::States);
972
2a2a7ef4 973 if (Immediate == true && (instVer->MultiArch & pkgCache::Version::Same) == pkgCache::Version::Same)
30426f48
DK
974 {
975 /* Do lockstep M-A:same unpacking in two phases:
976 First unpack all installed architectures, then the not installed.
977 This way we avoid that M-A: enabled packages are installed before
978 their older non-M-A enabled packages are replaced by newer versions */
979 bool const installed = Pkg->CurrentVer != 0;
36635720
DK
980 if (installed == true &&
981 (instVer != Pkg.CurrentVer() ||
982 ((Cache[Pkg].iFlags & pkgDepCache::ReInstall) == pkgDepCache::ReInstall)) &&
983 Install(Pkg,FileNames[Pkg->ID]) == false)
30426f48 984 return false;
d77b985a
DK
985 for (PkgIterator P = Pkg.Group().PackageList();
986 P.end() == false; P = Pkg.Group().NextPkg(P))
987 {
30426f48 988 if (P->CurrentVer == 0 || P == Pkg || List->IsFlag(P,pkgOrderList::UnPacked) == true ||
d77b985a
DK
989 Cache[P].InstallVer == 0 || (P.CurrentVer() == Cache[P].InstallVer &&
990 (Cache[Pkg].iFlags & pkgDepCache::ReInstall) != pkgDepCache::ReInstall))
991 continue;
75a90b93 992 if (SmartUnPack(P, false, Depth + 1) == false)
30426f48 993 return false;
d77b985a 994 }
30426f48
DK
995 if (installed == false && Install(Pkg,FileNames[Pkg->ID]) == false)
996 return false;
997 for (PkgIterator P = Pkg.Group().PackageList();
998 P.end() == false; P = Pkg.Group().NextPkg(P))
999 {
1000 if (P->CurrentVer != 0 || P == Pkg || List->IsFlag(P,pkgOrderList::UnPacked) == true ||
2b8b1e7a 1001 List->IsFlag(P,pkgOrderList::Configured) == true ||
30426f48
DK
1002 Cache[P].InstallVer == 0 || (P.CurrentVer() == Cache[P].InstallVer &&
1003 (Cache[Pkg].iFlags & pkgDepCache::ReInstall) != pkgDepCache::ReInstall))
1004 continue;
75a90b93 1005 if (SmartUnPack(P, false, Depth + 1) == false)
30426f48
DK
1006 return false;
1007 }
1008 }
cd5e8444 1009 // packages which are already unpacked don't need to be unpacked again
d4b4e5ea
DK
1010 else if ((instVer != Pkg.CurrentVer() ||
1011 ((Cache[Pkg].iFlags & pkgDepCache::ReInstall) == pkgDepCache::ReInstall)) &&
1012 Install(Pkg,FileNames[Pkg->ID]) == false)
28166356
DK
1013 return false;
1014
d41d0e01 1015 if (Immediate == true) {
590f1923 1016 // Perform immedate configuration of the package.
d41d0e01 1017 if (SmartConfigure(Pkg, Depth + 1) == false)
0eb4af9d 1018 _error->Error(_("Could not perform immediate configuration on '%s'. "
90436124 1019 "Please see man 5 apt.conf under APT::Immediate-Configure for details. (%d)"),Pkg.FullName().c_str(),2);
590f1923 1020 }
6c139d6e
AL
1021
1022 return true;
1023}
1024 /*}}}*/
1025// PM::OrderInstall - Installation ordering routine /*{{{*/
1026// ---------------------------------------------------------------------
1027/* */
281daf46 1028pkgPackageManager::OrderResult pkgPackageManager::OrderInstall()
6c139d6e 1029{
7a1b1f8b 1030 if (CreateOrderList() == false)
281daf46
AL
1031 return Failed;
1032
1033 Reset();
6c139d6e 1034
30e1eab5 1035 if (Debug == true)
5e312de7 1036 clog << "Beginning to order" << endl;
6c139d6e 1037
5e312de7
DK
1038 bool const ordering =
1039 _config->FindB("PackageManager::UnpackAll",true) ?
1040 List->OrderUnpack(FileNames) : List->OrderCritical();
1041 if (ordering == false)
281daf46
AL
1042 {
1043 _error->Error("Internal ordering error");
1044 return Failed;
1045 }
1046
30e1eab5
AL
1047 if (Debug == true)
1048 clog << "Done ordering" << endl;
1049
281daf46 1050 bool DoneSomething = false;
91c03d37 1051 for (pkgOrderList::iterator I = List->begin(); I != List->end(); ++I)
6c139d6e
AL
1052 {
1053 PkgIterator Pkg(Cache,*I);
0caa5a4c 1054
281daf46
AL
1055 if (List->IsNow(Pkg) == false)
1056 {
0caa5a4c
DK
1057 if (Debug == true)
1058 clog << "Skipping already done " << Pkg.FullName() << endl;
281daf46
AL
1059 continue;
1060 }
0caa5a4c 1061
2fd65468 1062 if (List->IsMissing(Pkg) == true)
281daf46
AL
1063 {
1064 if (Debug == true)
90436124 1065 clog << "Sequence completed at " << Pkg.FullName() << endl;
281daf46
AL
1066 if (DoneSomething == false)
1067 {
1068 _error->Error("Internal Error, ordering was unable to handle the media swap");
1069 return Failed;
1070 }
1071 return Incomplete;
1072 }
6c139d6e
AL
1073
1074 // Sanity check
d0c59649
AL
1075 if (Cache[Pkg].Keep() == true &&
1076 Pkg.State() == pkgCache::PkgIterator::NeedsNothing &&
1077 (Cache[Pkg].iFlags & pkgDepCache::ReInstall) != pkgDepCache::ReInstall)
281daf46 1078 {
90436124 1079 _error->Error("Internal Error, trying to manipulate a kept package (%s)",Pkg.FullName().c_str());
281daf46
AL
1080 return Failed;
1081 }
6c139d6e
AL
1082
1083 // Perform a delete or an install
1084 if (Cache[Pkg].Delete() == true)
1085 {
1086 if (SmartRemove(Pkg) == false)
281daf46 1087 return Failed;
6c139d6e
AL
1088 }
1089 else
d41d0e01 1090 if (SmartUnPack(Pkg,List->IsFlag(Pkg,pkgOrderList::Immediate),0) == false)
281daf46
AL
1091 return Failed;
1092 DoneSomething = true;
590f1923
CB
1093
1094 if (ImmConfigureAll) {
1e3f4083 1095 /* ConfigureAll here to pick up and packages left unconfigured because they were unpacked in the
590f1923 1096 "PreUnpack Checks" section */
c7c7d3e8
CB
1097 if (!ConfigureAll())
1098 return Failed;
590f1923 1099 }
6c139d6e 1100 }
5e312de7 1101
6c139d6e
AL
1102 // Final run through the configure phase
1103 if (ConfigureAll() == false)
281daf46 1104 return Failed;
6c139d6e
AL
1105
1106 // Sanity check
91c03d37 1107 for (pkgOrderList::iterator I = List->begin(); I != List->end(); ++I)
281daf46 1108 {
6c139d6e 1109 if (List->IsFlag(*I,pkgOrderList::Configured) == false)
281daf46
AL
1110 {
1111 _error->Error("Internal error, packages left unconfigured. %s",
90436124 1112 PkgIterator(Cache,*I).FullName().c_str());
281daf46
AL
1113 return Failed;
1114 }
9fc57a59 1115 }
281daf46
AL
1116
1117 return Completed;
6c139d6e 1118}
3b1b0f29
MV
1119// PM::DoInstallPostFork - compat /*{{{*/
1120// ---------------------------------------------------------------------
1121 /*}}}*/
1122pkgPackageManager::OrderResult
1123pkgPackageManager::DoInstallPostFork(int statusFd)
1124{
bd5f39b3
MV
1125 APT::Progress::PackageManager *progress = new
1126 APT::Progress::PackageManagerProgressFd(statusFd);
1127 pkgPackageManager::OrderResult res = DoInstallPostFork(progress);
1128 delete progress;
1129 return res;
1130}
6c139d6e 1131 /*}}}*/
1d6386f3
MV
1132// PM::DoInstallPostFork - Does install part that happens after the fork /*{{{*/
1133// ---------------------------------------------------------------------
1134pkgPackageManager::OrderResult
e6ad8031 1135pkgPackageManager::DoInstallPostFork(APT::Progress::PackageManager *progress)
1d6386f3 1136{
5e9458e2
MV
1137 bool goResult = Go(progress);
1138 if(goResult == false)
1139 return Failed;
1140
1141 return Res;
bf3ad91f 1142}
e6ad8031 1143 /*}}}*/
2a7e07c7
MV
1144// PM::DoInstall - Does the installation /*{{{*/
1145// ---------------------------------------------------------------------
3b1b0f29
MV
1146/* compat */
1147pkgPackageManager::OrderResult
1148pkgPackageManager::DoInstall(int statusFd)
1149{
1150 APT::Progress::PackageManager *progress = new
1151 APT::Progress::PackageManagerProgressFd(statusFd);
1152 OrderResult res = DoInstall(progress);
1153 delete progress;
1154 return res;
1155 }
1156 /*}}}*/
1157// PM::DoInstall - Does the installation /*{{{*/
1158// ---------------------------------------------------------------------
2a7e07c7
MV
1159/* This uses the filenames in FileNames and the information in the
1160 DepCache to perform the installation of packages.*/
e6ad8031
MV
1161pkgPackageManager::OrderResult
1162pkgPackageManager::DoInstall(APT::Progress::PackageManager *progress)
2a7e07c7
MV
1163{
1164 if(DoInstallPreFork() == Failed)
1165 return Failed;
1166
e6ad8031 1167 return DoInstallPostFork(progress);
2a7e07c7 1168}
eef71338 1169 /*}}}*/