1 // -*- mode: cpp; mode: fold -*-
3 // $Id: packagemanager.cc,v 1.30 2003/04/27 03:04:15 doogie Exp $
4 /* ######################################################################
6 Package Manager - Abstacts the package manager
8 More work is needed in the area of transitioning provides, ie exim
9 replacing smail. This can cause interesing side effects.
11 Other cases involving conflicts+replaces should be tested.
13 ##################################################################### */
15 // Include Files /*{{{*/
16 #include <apt-pkg/packagemanager.h>
17 #include <apt-pkg/orderlist.h>
18 #include <apt-pkg/depcache.h>
19 #include <apt-pkg/error.h>
20 #include <apt-pkg/version.h>
21 #include <apt-pkg/acquire-item.h>
22 #include <apt-pkg/algorithms.h>
23 #include <apt-pkg/configuration.h>
24 #include <apt-pkg/sptr.h>
32 // PM::PackageManager - Constructor /*{{{*/
33 // ---------------------------------------------------------------------
35 pkgPackageManager::pkgPackageManager(pkgDepCache
*pCache
) : Cache(*pCache
)
37 FileNames
= new string
[Cache
.Head().PackageCount
];
39 Debug
= _config
->FindB("Debug::pkgPackageManager",false);
42 // PM::PackageManager - Destructor /*{{{*/
43 // ---------------------------------------------------------------------
45 pkgPackageManager::~pkgPackageManager()
51 // PM::GetArchives - Queue the archives for download /*{{{*/
52 // ---------------------------------------------------------------------
54 bool pkgPackageManager::GetArchives(pkgAcquire
*Owner
,pkgSourceList
*Sources
,
57 if (CreateOrderList() == false)
61 _config
->FindB("PackageManager::UnpackAll",true) ?
62 List
->OrderUnpack() : List
->OrderCritical();
63 if (ordering
== false)
64 return _error
->Error("Internal ordering error");
66 for (pkgOrderList::iterator I
= List
->begin(); I
!= List
->end(); I
++)
68 PkgIterator
Pkg(Cache
,*I
);
69 FileNames
[Pkg
->ID
] = string();
71 // Skip packages to erase
72 if (Cache
[Pkg
].Delete() == true)
75 // Skip Packages that need configure only.
76 if (Pkg
.State() == pkgCache::PkgIterator::NeedsConfigure
&&
77 Cache
[Pkg
].Keep() == true)
80 // Skip already processed packages
81 if (List
->IsNow(Pkg
) == false)
84 new pkgAcqArchive(Owner
,Sources
,Recs
,Cache
[Pkg
].InstVerIter(Cache
),
91 // PM::FixMissing - Keep all missing packages /*{{{*/
92 // ---------------------------------------------------------------------
93 /* This is called to correct the installation when packages could not
95 bool pkgPackageManager::FixMissing()
97 pkgDepCache::ActionGroup
group(Cache
);
98 pkgProblemResolver
Resolve(&Cache
);
99 List
->SetFileList(FileNames
);
102 for (PkgIterator I
= Cache
.PkgBegin(); I
.end() == false; I
++)
104 if (List
->IsMissing(I
) == false)
107 // Okay, this file is missing and we need it. Mark it for keep
109 Cache
.MarkKeep(I
, false, false);
112 // We have to empty the list otherwise it will not have the new changes
119 // Now downgrade everything that is broken
120 return Resolve
.ResolveByKeep() == true && Cache
.BrokenCount() == 0;
123 // PM::ImmediateAdd - Add the immediate flag recursivly /*{{{*/
124 // ---------------------------------------------------------------------
125 /* This adds the immediate flag to the pkg and recursively to the
128 void pkgPackageManager::ImmediateAdd(PkgIterator I
, bool UseInstallVer
, unsigned const int &Depth
)
134 if(Cache
[I
].InstallVer
== 0)
136 D
= Cache
[I
].InstVerIter(Cache
).DependsList();
138 if (I
->CurrentVer
== 0)
140 D
= I
.CurrentVer().DependsList();
143 for ( /* nothing */ ; D
.end() == false; D
++)
144 if (D
->Type
== pkgCache::Dep::Depends
|| D
->Type
== pkgCache::Dep::PreDepends
)
146 if(!List
->IsFlag(D
.TargetPkg(), pkgOrderList::Immediate
))
149 clog
<< OutputInDepth(Depth
) << "ImmediateAdd(): Adding Immediate flag to " << D
.TargetPkg() << " cause of " << D
.DepType() << " " << I
.Name() << endl
;
150 List
->Flag(D
.TargetPkg(),pkgOrderList::Immediate
);
151 ImmediateAdd(D
.TargetPkg(), UseInstallVer
, Depth
+ 1);
157 // PM::CreateOrderList - Create the ordering class /*{{{*/
158 // ---------------------------------------------------------------------
159 /* This populates the ordering list with all the packages that are
161 bool pkgPackageManager::CreateOrderList()
167 List
= new pkgOrderList(&Cache
);
169 static bool const NoImmConfigure
= !_config
->FindB("APT::Immediate-Configure",true);
170 ImmConfigureAll
= _config
->FindB("APT::Immediate-Configure-All",true);
172 if (Debug
&& ImmConfigureAll
)
173 clog
<< "CreateOrderList(): Adding Immediate flag for all packages because of APT::Immediate-Configure-All" << endl
;
175 // Generate the list of affected packages and sort it
176 for (PkgIterator I
= Cache
.PkgBegin(); I
.end() == false; I
++)
178 // Ignore no-version packages
179 if (I
->VersionList
== 0)
182 // Mark the package and its dependends for immediate configuration
183 if ((((I
->Flags
& pkgCache::Flag::Essential
) == pkgCache::Flag::Essential
||
184 (I
->Flags
& pkgCache::Flag::Important
) == pkgCache::Flag::Important
) &&
185 NoImmConfigure
== false) || ImmConfigureAll
)
187 if(Debug
&& !ImmConfigureAll
)
188 clog
<< "CreateOrderList(): Adding Immediate flag for " << I
.Name() << endl
;
189 List
->Flag(I
,pkgOrderList::Immediate
);
191 if (!ImmConfigureAll
) {
194 // Look for other install packages to make immediate configurea
195 ImmediateAdd(I
, true);
197 // And again with the current version.
198 ImmediateAdd(I
, false);
203 if ((Cache
[I
].Keep() == true ||
204 Cache
[I
].InstVerIter(Cache
) == I
.CurrentVer()) &&
205 I
.State() == pkgCache::PkgIterator::NeedsNothing
&&
206 (Cache
[I
].iFlags
& pkgDepCache::ReInstall
) != pkgDepCache::ReInstall
&&
207 (I
.Purge() != false || Cache
[I
].Mode
!= pkgDepCache::ModeDelete
||
208 (Cache
[I
].iFlags
& pkgDepCache::Purge
) != pkgDepCache::Purge
))
211 // Append it to the list
218 // PM::DepAlwaysTrue - Returns true if this dep is irrelevent /*{{{*/
219 // ---------------------------------------------------------------------
220 /* The restriction on provides is to eliminate the case when provides
221 are transitioning between valid states [ie exim to smail] */
222 bool pkgPackageManager::DepAlwaysTrue(DepIterator D
)
224 if (D
.TargetPkg()->ProvidesList
!= 0)
227 if ((Cache
[D
] & pkgDepCache::DepInstall
) != 0 &&
228 (Cache
[D
] & pkgDepCache::DepNow
) != 0)
233 // PM::CheckRConflicts - Look for reverse conflicts /*{{{*/
234 // ---------------------------------------------------------------------
235 /* This looks over the reverses for a conflicts line that needs early
237 bool pkgPackageManager::CheckRConflicts(PkgIterator Pkg
,DepIterator D
,
240 for (;D
.end() == false; D
++)
242 if (D
->Type
!= pkgCache::Dep::Conflicts
&&
243 D
->Type
!= pkgCache::Dep::Obsoletes
)
246 // The package hasnt been changed
247 if (List
->IsNow(Pkg
) == false)
250 // Ignore self conflicts, ignore conflicts from irrelevent versions
251 if (D
.ParentPkg() == Pkg
|| D
.ParentVer() != D
.ParentPkg().CurrentVer())
254 if (Cache
.VS().CheckDep(Ver
,D
->CompareOp
,D
.TargetVer()) == false)
257 if (EarlyRemove(D
.ParentPkg()) == false)
258 return _error
->Error("Reverse conflicts early remove for package '%s' failed",
264 // PM::ConfigureAll - Run the all out configuration /*{{{*/
265 // ---------------------------------------------------------------------
266 /* This configures every package. It is assumed they are all unpacked and
267 that the final configuration is valid. */
268 bool pkgPackageManager::ConfigureAll()
270 pkgOrderList
OList(&Cache
);
272 // Populate the order list
273 for (pkgOrderList::iterator I
= List
->begin(); I
!= List
->end(); I
++)
274 if (List
->IsFlag(pkgCache::PkgIterator(Cache
,*I
),
275 pkgOrderList::UnPacked
) == true)
278 if (OList
.OrderConfigure() == false)
281 std::string
const conf
= _config
->Find("PackageManager::Configure","all");
282 bool const ConfigurePkgs
= (conf
== "all");
284 // Perform the configuring
285 for (pkgOrderList::iterator I
= OList
.begin(); I
!= OList
.end(); I
++)
287 PkgIterator
Pkg(Cache
,*I
);
289 if (ConfigurePkgs
== true && VerifyAndConfigure(Pkg
,OList
) == false)
292 List
->Flag(Pkg
,pkgOrderList::Configured
,pkgOrderList::States
);
298 // PM::SmartConfigure - Perform immediate configuration of the pkg /*{{{*/
299 // ---------------------------------------------------------------------
300 /* This routine scheduals the configuration of the given package and all
301 of it's dependents. */
302 bool pkgPackageManager::SmartConfigure(PkgIterator Pkg
)
305 clog
<< "SmartConfigure " << Pkg
.Name() << endl
;
307 pkgOrderList
OList(&Cache
);
309 if (DepAdd(OList
,Pkg
) == false)
312 static std::string
const conf
= _config
->Find("PackageManager::Configure","all");
313 static bool const ConfigurePkgs
= (conf
== "all" || conf
== "smart");
315 if (ConfigurePkgs
== true)
316 if (OList
.OrderConfigure() == false)
319 // Perform the configuring
320 for (pkgOrderList::iterator I
= OList
.begin(); I
!= OList
.end(); I
++)
322 PkgIterator
Pkg(Cache
,*I
);
324 if (ConfigurePkgs
== true && VerifyAndConfigure(Pkg
,OList
) == false)
327 List
->Flag(Pkg
,pkgOrderList::Configured
,pkgOrderList::States
);
330 if (Cache
[Pkg
].InstVerIter(Cache
)->MultiArch
== pkgCache::Version::Same
)
331 for (PkgIterator P
= Pkg
.Group().PackageList();
332 P
.end() == false; P
= Pkg
.Group().NextPkg(P
))
334 if (Pkg
== P
|| List
->IsFlag(P
,pkgOrderList::Configured
) == true ||
335 Cache
[P
].InstallVer
== 0 || (P
.CurrentVer() == Cache
[P
].InstallVer
&&
336 (Cache
[Pkg
].iFlags
& pkgDepCache::ReInstall
) != pkgDepCache::ReInstall
))
342 if (List
->IsFlag(Pkg
,pkgOrderList::Configured
) == false)
343 return _error
->Error(_("Could not perform immediate configuration on '%s'. "
344 "Please see man 5 apt.conf under APT::Immediate-Configure for details. (%d)"),Pkg
.Name(),1);
349 // PM::VerifyConfigure - Check configuration of dependancies /*{{{*/
350 // ---------------------------------------------------------------------
351 /* This routine checks that all a packages dependancies have been
352 configured, before it is going to be configured. If this gives a warning
353 on a virtual package, it means that the package thats providing it is not
355 bool pkgPackageManager::VerifyConfigure(PkgIterator Pkg
, pkgOrderList
&OList
)
357 // If this is true at the end, then the package should not be configured
359 // This holds the the OR status of the previous dependancy
360 bool previousOr
=false;
362 // First iterate through the dependancies of Pkg
363 for (DepIterator D
= Cache
[Pkg
].InstVerIter(Cache
).DependsList(); D
.end() == false; D
++)
366 /* If the dependancy is of type Depends or PreDepends, we need to check it, but only if it is going to be
367 configured at some point */
368 if (D
->Type
== pkgCache::Dep::Depends
|| D
->Type
== pkgCache::Dep::PreDepends
) {
370 /* If the previous package and this package are OR dependancies, and the previous package satisfied the dependancy
371 then skip this dependancy as it is not relevent, this will repeat for the next package if the situation is the
373 if (previousOr
&& !error
) { // As error has not been reset, this refers to the previous dependancy
374 previousOr
= (D
->CompareOp
& pkgCache::Dep::Or
) == pkgCache::Dep::Or
;
381 // Check thorugh all possible versions of this dependancy (D)
382 SPtrArray
<Version
*> VList
= D
.AllTargets();
383 for (Version
**I
= VList
; *I
!= 0; I
++)
385 VerIterator
DepVer(Cache
,*I
);
386 PkgIterator DepPkg
= DepVer
.ParentPkg();
387 VerIterator
DepInstallVer(Cache
,Cache
[DepPkg
].InstallVer
);
389 if (DepPkg
.CurrentVer() == DepVer
&& !List
->IsFlag(DepPkg
,pkgOrderList::UnPacked
)) {
394 if (Cache
[DepPkg
].InstallVer
== DepVer
&&
395 (List
->IsFlag(DepPkg
,pkgOrderList::Configured
) || OList
.IsFlag(DepPkg
,pkgOrderList::InList
))) {
401 /* Only worry here if this package is a OR with the next, as even though this package does not satisfy the OR
402 the next one might */
403 if (error
&& !((D
->CompareOp
& pkgCache::Dep::Or
) == pkgCache::Dep::Or
)) {
404 _error
->Error("Package %s should not be configured because package %s is not configured",Pkg
.Name(),D
.TargetPkg().Name());
406 /* If the previous package is a OR but not this package, but there is still an error then fail as it will not
408 } else if (error
&& previousOr
&& !((D
->CompareOp
& pkgCache::Dep::Or
) == pkgCache::Dep::Or
)) {
409 _error
->Error("Package %s should not be configured because package %s (or any alternatives) are not configured",Pkg
.Name(),D
.TargetPkg().Name());
413 previousOr
= (D
->CompareOp
& pkgCache::Dep::Or
) == pkgCache::Dep::Or
;
421 // PM::VerifyAndConfigure - Check configuration of dependancies /*{{{*/
422 // ---------------------------------------------------------------------
423 /* This routine verifies if a package can be configured and if so
425 bool pkgPackageManager::VerifyAndConfigure(PkgIterator Pkg
, pkgOrderList
&OList
)
427 if (VerifyConfigure(Pkg
, OList
))
428 return Configure(Pkg
);
434 // PM::DepAdd - Add all dependents to the oder list /*{{{*/
435 // ---------------------------------------------------------------------
436 /* This recursively adds all dependents to the order list */
437 bool pkgPackageManager::DepAdd(pkgOrderList
&OList
,PkgIterator Pkg
,int Depth
)
439 if (OList
.IsFlag(Pkg
,pkgOrderList::Added
) == true)
441 if (List
->IsFlag(Pkg
,pkgOrderList::Configured
) == true)
443 if (List
->IsFlag(Pkg
,pkgOrderList::UnPacked
) == false)
447 std::clog
<< OutputInDepth(Depth
) << "DepAdd: " << Pkg
.Name() << std::endl
;
449 // Put the package on the list
450 OList
.push_back(Pkg
);
451 OList
.Flag(Pkg
,pkgOrderList::Added
);
454 // Check the dependencies to see if they are all satisfied.
456 for (DepIterator D
= Cache
[Pkg
].InstVerIter(Cache
).DependsList(); D
.end() == false;)
458 if (D
->Type
!= pkgCache::Dep::Depends
&& D
->Type
!= pkgCache::Dep::PreDepends
)
466 for (bool LastOR
= true; D
.end() == false && LastOR
== true; D
++)
468 LastOR
= (D
->CompareOp
& pkgCache::Dep::Or
) == pkgCache::Dep::Or
;
473 SPtrArray
<Version
*> VList
= D
.AllTargets();
474 for (Version
**I
= VList
; *I
!= 0 && Bad
== true; I
++)
476 VerIterator
Ver(Cache
,*I
);
477 PkgIterator Pkg
= Ver
.ParentPkg();
478 VerIterator
InstallVer(Cache
,Cache
[Pkg
].InstallVer
);
479 VerIterator
CandVer(Cache
,Cache
[Pkg
].CandidateVer
);
481 if (Debug
&& false) {
483 cout
<< OutputInDepth(Depth
) << "Checking if " << Ver
<< " of " << Pkg
.Name() << " satisfies this dependancy" << endl
;
485 cout
<< OutputInDepth(Depth
) << "Checking if " << Ver
.VerStr() << " of " << Pkg
.Name() << " satisfies this dependancy" << endl
;
488 if (Pkg
.CurrentVer()==0) {
489 cout
<< OutputInDepth(Depth
) << " CurrentVer " << Pkg
.CurrentVer() << " IsNow " << List
->IsNow(Pkg
) << " NeedsNothing " << (Pkg
.State() == PkgIterator::NeedsNothing
) << endl
;
491 cout
<< OutputInDepth(Depth
) << " CurrentVer " << Pkg
.CurrentVer().VerStr() << " IsNow " << List
->IsNow(Pkg
) << " NeedsNothing " << (Pkg
.State() == PkgIterator::NeedsNothing
) << endl
;
495 cout
<< OutputInDepth(Depth
)<< " InstallVer " << InstallVer
<< endl
;
497 cout
<< OutputInDepth(Depth
)<< " InstallVer " << InstallVer
.VerStr() << endl
;
500 cout
<< " CandVer " << CandVer
.VerStr() << endl
;
502 cout
<< OutputInDepth(Depth
) << " Keep " << Cache
[Pkg
].Keep() << " Unpacked " << List
->IsFlag(Pkg
,pkgOrderList::UnPacked
) << " Configured " << List
->IsFlag(Pkg
,pkgOrderList::Configured
) << endl
;
505 // See if the current version is ok
506 if (Pkg
.CurrentVer() == Ver
&& List
->IsNow(Pkg
) == true &&
507 Pkg
.State() == PkgIterator::NeedsNothing
)
513 // Not the install version
514 if ((Cache
[Pkg
].InstallVer
!= *I
&& Cache
[Pkg
].CandidateVer
!= *I
) ||
515 (Cache
[Pkg
].Keep() == true && Pkg
.State() == PkgIterator::NeedsNothing
&&
516 (Cache
[Pkg
].iFlags
& pkgDepCache::ReInstall
) != pkgDepCache::ReInstall
))
519 if (List
->IsFlag(Pkg
,pkgOrderList::UnPacked
) == true)
520 Bad
= !DepAdd(OList
,Pkg
,Depth
);
521 if (List
->IsFlag(Pkg
,pkgOrderList::Configured
) == true)
529 std::clog
<< OutputInDepth(Depth
) << "DepAdd FAILS on: " << Pkg
.Name() << std::endl
;
530 OList
.Flag(Pkg
,0,pkgOrderList::Added
);
541 // PM::EarlyRemove - Perform removal of packages before their time /*{{{*/
542 // ---------------------------------------------------------------------
543 /* This is called to deal with conflicts arising from unpacking */
544 bool pkgPackageManager::EarlyRemove(PkgIterator Pkg
)
546 if (List
->IsNow(Pkg
) == false)
549 // Already removed it
550 if (List
->IsFlag(Pkg
,pkgOrderList::Removed
) == true)
553 // Woops, it will not be re-installed!
554 if (List
->IsFlag(Pkg
,pkgOrderList::InList
) == false)
557 // Essential packages get special treatment
558 bool IsEssential
= false;
559 if ((Pkg
->Flags
& pkgCache::Flag::Essential
) != 0)
562 /* Check for packages that are the dependents of essential packages and
564 if (Pkg
->CurrentVer
!= 0)
566 for (DepIterator D
= Pkg
.RevDependsList(); D
.end() == false &&
567 IsEssential
== false; D
++)
568 if (D
->Type
== pkgCache::Dep::Depends
|| D
->Type
== pkgCache::Dep::PreDepends
)
569 if ((D
.ParentPkg()->Flags
& pkgCache::Flag::Essential
) != 0)
573 if (IsEssential
== true)
575 if (_config
->FindB("APT::Force-LoopBreak",false) == false)
576 return _error
->Error(_("This installation run will require temporarily "
577 "removing the essential package %s due to a "
578 "Conflicts/Pre-Depends loop. This is often bad, "
579 "but if you really want to do it, activate the "
580 "APT::Force-LoopBreak option."),Pkg
.Name());
583 bool Res
= SmartRemove(Pkg
);
584 if (Cache
[Pkg
].Delete() == false)
585 List
->Flag(Pkg
,pkgOrderList::Removed
,pkgOrderList::States
);
590 // PM::SmartRemove - Removal Helper /*{{{*/
591 // ---------------------------------------------------------------------
593 bool pkgPackageManager::SmartRemove(PkgIterator Pkg
)
595 if (List
->IsNow(Pkg
) == false)
598 List
->Flag(Pkg
,pkgOrderList::Configured
,pkgOrderList::States
);
600 return Remove(Pkg
,(Cache
[Pkg
].iFlags
& pkgDepCache::Purge
) == pkgDepCache::Purge
);
604 // PM::SmartUnPack - Install helper /*{{{*/
605 // ---------------------------------------------------------------------
606 /* This performs the task of handling pre-depends. */
607 bool pkgPackageManager::SmartUnPack(PkgIterator Pkg
)
609 return SmartUnPack(Pkg
, true);
611 bool pkgPackageManager::SmartUnPack(PkgIterator Pkg
, bool const Immediate
)
614 clog
<< "SmartUnPack " << Pkg
.Name() << endl
;
616 // Check if it is already unpacked
617 if (Pkg
.State() == pkgCache::PkgIterator::NeedsConfigure
&&
618 Cache
[Pkg
].Keep() == true)
620 List
->Flag(Pkg
,pkgOrderList::UnPacked
,pkgOrderList::States
);
621 if (Immediate
== true &&
622 List
->IsFlag(Pkg
,pkgOrderList::Immediate
) == true)
623 if (SmartConfigure(Pkg
) == false)
624 return _error
->Error(_("Could not perform immediate configuration on already unpacked '%s'. "
625 "Please see man 5 apt.conf under APT::Immediate-Configure for details."),Pkg
.Name());
629 VerIterator
const instVer
= Cache
[Pkg
].InstVerIter(Cache
);
631 /* See if this packages install version has any predependencies
632 that are not met by 'now' packages. */
633 for (DepIterator D
= instVer
.DependsList();
636 // Compute a single dependency element (glob or)
637 pkgCache::DepIterator Start
;
638 pkgCache::DepIterator End
;
641 while (End
->Type
== pkgCache::Dep::PreDepends
)
644 clog
<< "PreDepends order for " << Pkg
.Name() << std::endl
;
646 // Look for possible ok targets.
647 SPtrArray
<Version
*> VList
= Start
.AllTargets();
649 for (Version
**I
= VList
; *I
!= 0 && Bad
== true; I
++)
651 VerIterator
Ver(Cache
,*I
);
652 PkgIterator Pkg
= Ver
.ParentPkg();
654 // See if the current version is ok
655 if (Pkg
.CurrentVer() == Ver
&& List
->IsNow(Pkg
) == true &&
656 Pkg
.State() == PkgIterator::NeedsNothing
)
660 clog
<< "Found ok package " << Pkg
.Name() << endl
;
665 // Look for something that could be configured.
666 for (Version
**I
= VList
; *I
!= 0 && Bad
== true; I
++)
668 VerIterator
Ver(Cache
,*I
);
669 PkgIterator Pkg
= Ver
.ParentPkg();
671 // Not the install version
672 if (Cache
[Pkg
].InstallVer
!= *I
||
673 (Cache
[Pkg
].Keep() == true && Pkg
.State() == PkgIterator::NeedsNothing
))
677 clog
<< "Trying to SmartConfigure " << Pkg
.Name() << endl
;
678 Bad
= !SmartConfigure(Pkg
);
681 /* If this or element did not match then continue on to the
682 next or element until a matching element is found */
685 // This triggers if someone make a pre-depends/depend loop.
687 return _error
->Error("Couldn't configure pre-depend %s for %s, "
688 "probably a dependency cycle.",
689 End
.TargetPkg().Name(),Pkg
.Name());
696 if (End
->Type
== pkgCache::Dep::Conflicts
||
697 End
->Type
== pkgCache::Dep::Obsoletes
)
699 /* Look for conflicts. Two packages that are both in the install
700 state cannot conflict so we don't check.. */
701 SPtrArray
<Version
*> VList
= End
.AllTargets();
702 for (Version
**I
= VList
; *I
!= 0; I
++)
704 VerIterator
Ver(Cache
,*I
);
705 PkgIterator ConflictPkg
= Ver
.ParentPkg();
706 VerIterator
InstallVer(Cache
,Cache
[ConflictPkg
].InstallVer
);
709 cout
<< Pkg
.Name() << " conflicts with " << ConflictPkg
.Name() << endl
;
711 if (Debug
&& false) {
713 cout
<< " Checking if " << Ver
<< " of " << ConflictPkg
.Name() << " satisfies this dependancy" << endl
;
715 cout
<< " Checking if " << Ver
.VerStr() << " of " << ConflictPkg
.Name() << " satisfies this dependancy" << endl
;
718 if (ConflictPkg
.CurrentVer()==0) {
719 cout
<< " CurrentVer " << ConflictPkg
.CurrentVer() << " IsNow " << List
->IsNow(ConflictPkg
) << " NeedsNothing " << (ConflictPkg
.State() == PkgIterator::NeedsNothing
) << endl
;
721 cout
<< " CurrentVer " << ConflictPkg
.CurrentVer().VerStr() << " IsNow " << List
->IsNow(ConflictPkg
) << " NeedsNothing " << (ConflictPkg
.State() == PkgIterator::NeedsNothing
) << endl
;
725 cout
<< " InstallVer " << InstallVer
<< endl
;
727 cout
<< " InstallVer " << InstallVer
.VerStr() << endl
;
730 cout
<< " Keep " << Cache
[ConflictPkg
].Keep() << " Unpacked " << List
->IsFlag(ConflictPkg
,pkgOrderList::UnPacked
) << " Configured " << List
->IsFlag(ConflictPkg
,pkgOrderList::Configured
) << endl
;
731 cout
<< " Delete " << Cache
[ConflictPkg
].Delete() << endl
;
734 // See if the current version is conflicting
735 if (ConflictPkg
.CurrentVer() == Ver
&& List
->IsNow(ConflictPkg
))
737 if (Cache
[ConflictPkg
].Keep() == 0 && Cache
[ConflictPkg
].InstallVer
!= 0) {
738 cout
<< "Unpacking " << ConflictPkg
.Name() << " to prevent conflict" << endl
;
739 /* FIXME Setting the flag here prevents breakage loops, that can occur if BrokenPkg (or one of the
740 packages it breaks) breaks Pkg */
741 List
->Flag(Pkg
,pkgOrderList::UnPacked
,pkgOrderList::States
);
742 SmartUnPack(ConflictPkg
,false);
744 if (EarlyRemove(ConflictPkg
) == false)
745 return _error
->Error("Internal Error, Could not early remove %s",ConflictPkg
.Name());
752 if (End
->Type
== pkgCache::Dep::DpkgBreaks
) {
753 SPtrArray
<Version
*> VList
= End
.AllTargets();
754 for (Version
**I
= VList
; *I
!= 0; I
++)
756 VerIterator
Ver(Cache
,*I
);
757 PkgIterator BrokenPkg
= Ver
.ParentPkg();
758 // Check if it needs to be unpacked
759 if (List
->IsFlag(BrokenPkg
,pkgOrderList::InList
) && Cache
[BrokenPkg
].Delete() == false &&
760 !List
->IsFlag(BrokenPkg
,pkgOrderList::UnPacked
)) {
761 /* FIXME Setting the flag here prevents breakage loops, that can occur if BrokenPkg (or one of the
762 packages it breaks) breaks Pkg */
763 List
->Flag(Pkg
,pkgOrderList::UnPacked
,pkgOrderList::States
);
764 // Found a break, so unpack the package
766 cout
<< " Unpacking " << BrokenPkg
.Name() << " to avoid break" << endl
;
767 SmartUnPack(BrokenPkg
, false);
769 // Check if a package needs to be removed
770 if (Cache
[BrokenPkg
].Delete() == true) {
772 cout
<< " Removing " << BrokenPkg
.Name() << " to avoid break" << endl
;
773 SmartRemove(BrokenPkg
);
779 // FIXME: Crude but effective fix, allows the SmartUnPack method to be used for packages that new to the system
781 //cout << "Check for reverse conflicts on " << Pkg.Name() << " " << instVer.VerStr() << endl;
783 // Check for reverse conflicts.
784 if (CheckRConflicts(Pkg
,Pkg
.RevDependsList(),
785 instVer
.VerStr()) == false)
788 for (PrvIterator P
= instVer
.ProvidesList();
789 P
.end() == false; P
++)
790 CheckRConflicts(Pkg
,P
.ParentPkg().RevDependsList(),P
.ProvideVersion());
792 List
->Flag(Pkg
,pkgOrderList::UnPacked
,pkgOrderList::States
);
794 if (instVer
->MultiArch
== pkgCache::Version::Same
)
795 for (PkgIterator P
= Pkg
.Group().PackageList();
796 P
.end() == false; P
= Pkg
.Group().NextPkg(P
))
798 if (Pkg
== P
|| List
->IsFlag(P
,pkgOrderList::UnPacked
) == true ||
799 Cache
[P
].InstallVer
== 0 || (P
.CurrentVer() == Cache
[P
].InstallVer
&&
800 (Cache
[Pkg
].iFlags
& pkgDepCache::ReInstall
) != pkgDepCache::ReInstall
))
802 SmartUnPack(P
, false);
806 VerIterator
InstallVer(Cache
,Cache
[Pkg
].InstallVer
);
807 //cout << "Check for reverse conflicts on " << Pkg.Name() << " " << InstallVer.VerStr() << endl;
809 // Check for reverse conflicts.
810 if (CheckRConflicts(Pkg
,Pkg
.RevDependsList(),
811 InstallVer
.VerStr()) == false)
814 List
->Flag(Pkg
,pkgOrderList::UnPacked
,pkgOrderList::States
);
817 if(Install(Pkg
,FileNames
[Pkg
->ID
]) == false)
820 /* Because of the ordered list, most dependancies should be unpacked,
821 however if there is a loop this is not the case, so check for dependancies before configuring.
822 This is done after the package installation as it makes it easier to deal with conflicts problems */
823 for (DepIterator D
= instVer
.DependsList();
826 // Compute a single dependency element (glob or)
827 pkgCache::DepIterator Start
;
828 pkgCache::DepIterator End
;
831 // Check for dependanices that have not been unpacked, probably due to loops.
833 while (End
->Type
== pkgCache::Dep::Depends
) {
835 VerIterator InstallVer
;
836 SPtrArray
<Version
*> VList
= Start
.AllTargets();
838 for (Version
**I
= VList
; *I
!= 0; I
++) {
839 VerIterator
Ver(Cache
,*I
);
840 DepPkg
= Ver
.ParentPkg();
844 InstallVer
= VerIterator(Cache
,Cache
[DepPkg
].InstallVer
);
845 VerIterator
CandVer(Cache
,Cache
[DepPkg
].CandidateVer
);
847 if (Debug
&& false) {
849 cout
<< " Checking if " << Ver
<< " of " << DepPkg
.Name() << " satisfies this dependancy" << endl
;
851 cout
<< " Checking if " << Ver
.VerStr() << " of " << DepPkg
.Name() << " satisfies this dependancy" << endl
;
854 if (DepPkg
.CurrentVer()==0) {
855 cout
<< " CurrentVer " << DepPkg
.CurrentVer() << " IsNow " << List
->IsNow(DepPkg
) << " NeedsNothing " << (DepPkg
.State() == PkgIterator::NeedsNothing
) << endl
;
857 cout
<< " CurrentVer " << DepPkg
.CurrentVer().VerStr() << " IsNow " << List
->IsNow(DepPkg
) << " NeedsNothing " << (DepPkg
.State() == PkgIterator::NeedsNothing
) << endl
;
861 cout
<< " InstallVer " << InstallVer
<< endl
;
863 cout
<< " InstallVer " << InstallVer
.VerStr() << endl
;
866 cout
<< " CandVer " << CandVer
.VerStr() << endl
;
868 cout
<< " Keep " << Cache
[DepPkg
].Keep() << " Unpacked " << List
->IsFlag(DepPkg
,pkgOrderList::UnPacked
) << " Configured " << List
->IsFlag(DepPkg
,pkgOrderList::Configured
) << endl
;
872 // Check if it satisfies this dependancy
873 if (DepPkg
.CurrentVer() == Ver
&& List
->IsNow(DepPkg
) == true &&
874 DepPkg
.State() == PkgIterator::NeedsNothing
)
880 if (Cache
[DepPkg
].InstallVer
== *I
&& !List
->IsNow(DepPkg
)) {
887 if (InstallVer
!= 0 && Bad
) {
889 // FIXME Setting the flag here prevents a loop forming
890 List
->Flag(Pkg
,pkgOrderList::UnPacked
,pkgOrderList::States
);
891 // Found a break, so unpack the package
893 cout
<< " Unpacking " << DepPkg
.Name() << " to avoid loop" << endl
;
894 SmartUnPack(DepPkg
, false);
900 _error
->Error("Could not satisfy dependancies for %s",Pkg
.Name());
910 // Perform immedate configuration of the package.
911 if (Immediate
== true &&
912 List
->IsFlag(Pkg
,pkgOrderList::Immediate
) == true)
913 if (SmartConfigure(Pkg
) == false)
915 _error
->Error(_("Could not perform immediate configuration on '%s'. "
916 "Please see man 5 apt.conf under APT::Immediate-Configure for details. (%d)"),Pkg
.Name(),2);
921 // PM::OrderInstall - Installation ordering routine /*{{{*/
922 // ---------------------------------------------------------------------
924 pkgPackageManager::OrderResult
pkgPackageManager::OrderInstall()
926 if (CreateOrderList() == false)
932 clog
<< "Beginning to order" << endl
;
934 bool const ordering
=
935 _config
->FindB("PackageManager::UnpackAll",true) ?
936 List
->OrderUnpack(FileNames
) : List
->OrderCritical();
937 if (ordering
== false)
939 _error
->Error("Internal ordering error");
944 clog
<< "Done ordering" << endl
;
946 bool DoneSomething
= false;
947 for (pkgOrderList::iterator I
= List
->begin(); I
!= List
->end(); I
++)
949 PkgIterator
Pkg(Cache
,*I
);
951 if (List
->IsNow(Pkg
) == false)
954 clog
<< "Skipping already done " << Pkg
.Name() << endl
;
958 if (List
->IsMissing(Pkg
) == true)
961 clog
<< "Sequence completed at " << Pkg
.Name() << endl
;
962 if (DoneSomething
== false)
964 _error
->Error("Internal Error, ordering was unable to handle the media swap");
971 if (Cache
[Pkg
].Keep() == true &&
972 Pkg
.State() == pkgCache::PkgIterator::NeedsNothing
&&
973 (Cache
[Pkg
].iFlags
& pkgDepCache::ReInstall
) != pkgDepCache::ReInstall
)
975 _error
->Error("Internal Error, trying to manipulate a kept package (%s)",Pkg
.Name());
979 // Perform a delete or an install
980 if (Cache
[Pkg
].Delete() == true)
982 if (SmartRemove(Pkg
) == false)
986 if (SmartUnPack(Pkg
) == false)
988 DoneSomething
= true;
991 // Final run through the configure phase
992 if (ConfigureAll() == false)
996 for (pkgOrderList::iterator I
= List
->begin(); I
!= List
->end(); I
++)
998 if (List
->IsFlag(*I
,pkgOrderList::Configured
) == false)
1000 _error
->Error("Internal error, packages left unconfigured. %s",
1001 PkgIterator(Cache
,*I
).Name());
1009 // PM::DoInstallPostFork - Does install part that happens after the fork /*{{{*/
1010 // ---------------------------------------------------------------------
1011 pkgPackageManager::OrderResult
1012 pkgPackageManager::DoInstallPostFork(int statusFd
)
1015 // FIXME: use SetCloseExec here once it taught about throwing
1016 // exceptions instead of doing _exit(100) on failure
1017 fcntl(statusFd
,F_SETFD
,FD_CLOEXEC
);
1018 bool goResult
= Go(statusFd
);
1019 if(goResult
== false)
1025 // PM::DoInstall - Does the installation /*{{{*/
1026 // ---------------------------------------------------------------------
1027 /* This uses the filenames in FileNames and the information in the
1028 DepCache to perform the installation of packages.*/
1029 pkgPackageManager::OrderResult
pkgPackageManager::DoInstall(int statusFd
)
1031 if(DoInstallPreFork() == Failed
)
1034 return DoInstallPostFork(statusFd
);