]>
git.saurik.com Git - apt.git/blob - apt-pkg/packagemanager.cc
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",false);
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
) {
192 // Look for other install packages to make immediate configurea
193 ImmediateAdd(I
, true);
195 // And again with the current version.
196 ImmediateAdd(I
, false);
201 if ((Cache
[I
].Keep() == true ||
202 Cache
[I
].InstVerIter(Cache
) == I
.CurrentVer()) &&
203 I
.State() == pkgCache::PkgIterator::NeedsNothing
&&
204 (Cache
[I
].iFlags
& pkgDepCache::ReInstall
) != pkgDepCache::ReInstall
&&
205 (I
.Purge() != false || Cache
[I
].Mode
!= pkgDepCache::ModeDelete
||
206 (Cache
[I
].iFlags
& pkgDepCache::Purge
) != pkgDepCache::Purge
))
209 // Append it to the list
216 // PM::DepAlwaysTrue - Returns true if this dep is irrelevent /*{{{*/
217 // ---------------------------------------------------------------------
218 /* The restriction on provides is to eliminate the case when provides
219 are transitioning between valid states [ie exim to smail] */
220 bool pkgPackageManager::DepAlwaysTrue(DepIterator D
)
222 if (D
.TargetPkg()->ProvidesList
!= 0)
225 if ((Cache
[D
] & pkgDepCache::DepInstall
) != 0 &&
226 (Cache
[D
] & pkgDepCache::DepNow
) != 0)
231 // PM::CheckRConflicts - Look for reverse conflicts /*{{{*/
232 // ---------------------------------------------------------------------
233 /* This looks over the reverses for a conflicts line that needs early
235 bool pkgPackageManager::CheckRConflicts(PkgIterator Pkg
,DepIterator D
,
238 for (;D
.end() == false; D
++)
240 if (D
->Type
!= pkgCache::Dep::Conflicts
&&
241 D
->Type
!= pkgCache::Dep::Obsoletes
)
244 // The package hasnt been changed
245 if (List
->IsNow(Pkg
) == false)
248 // Ignore self conflicts, ignore conflicts from irrelevent versions
249 if (D
.ParentPkg() == Pkg
|| D
.ParentVer() != D
.ParentPkg().CurrentVer())
252 if (Cache
.VS().CheckDep(Ver
,D
->CompareOp
,D
.TargetVer()) == false)
255 if (EarlyRemove(D
.ParentPkg()) == false)
256 return _error
->Error("Reverse conflicts early remove for package '%s' failed",
262 // PM::ConfigureAll - Run the all out configuration /*{{{*/
263 // ---------------------------------------------------------------------
264 /* This configures every package. It is assumed they are all unpacked and
265 that the final configuration is valid. */
266 bool pkgPackageManager::ConfigureAll()
268 pkgOrderList
OList(&Cache
);
270 // Populate the order list
271 for (pkgOrderList::iterator I
= List
->begin(); I
!= List
->end(); I
++)
272 if (List
->IsFlag(pkgCache::PkgIterator(Cache
,*I
),
273 pkgOrderList::UnPacked
) == true)
276 if (OList
.OrderConfigure() == false)
279 std::string
const conf
= _config
->Find("PackageManager::Configure","all");
280 bool const ConfigurePkgs
= (conf
== "all");
282 // Perform the configuring
283 for (pkgOrderList::iterator I
= OList
.begin(); I
!= OList
.end(); I
++)
285 PkgIterator
Pkg(Cache
,*I
);
287 if (ConfigurePkgs
== true && VerifyAndConfigure(Pkg
,OList
) == false)
290 List
->Flag(Pkg
,pkgOrderList::Configured
,pkgOrderList::States
);
296 // PM::SmartConfigure - Perform immediate configuration of the pkg /*{{{*/
297 // ---------------------------------------------------------------------
298 /* This routine scheduals the configuration of the given package and all
299 of it's dependents. */
300 bool pkgPackageManager::SmartConfigure(PkgIterator Pkg
)
303 clog
<< "SmartConfigure " << Pkg
.Name() << endl
;
305 pkgOrderList
OList(&Cache
);
307 if (DepAdd(OList
,Pkg
) == false)
310 static std::string
const conf
= _config
->Find("PackageManager::Configure","all");
311 static bool const ConfigurePkgs
= (conf
== "all" || conf
== "smart");
313 if (ConfigurePkgs
== true)
314 if (OList
.OrderConfigure() == false)
317 // Perform the configuring
318 for (pkgOrderList::iterator I
= OList
.begin(); I
!= OList
.end(); I
++)
320 PkgIterator
Pkg(Cache
,*I
);
322 if (ConfigurePkgs
== true && VerifyAndConfigure(Pkg
,OList
) == false)
325 List
->Flag(Pkg
,pkgOrderList::Configured
,pkgOrderList::States
);
328 if (Cache
[Pkg
].InstVerIter(Cache
)->MultiArch
== pkgCache::Version::Same
)
329 for (PkgIterator P
= Pkg
.Group().PackageList();
330 P
.end() == false; P
= Pkg
.Group().NextPkg(P
))
332 if (Pkg
== P
|| List
->IsFlag(P
,pkgOrderList::Configured
) == true ||
333 Cache
[P
].InstallVer
== 0 || (P
.CurrentVer() == Cache
[P
].InstallVer
&&
334 (Cache
[Pkg
].iFlags
& pkgDepCache::ReInstall
) != pkgDepCache::ReInstall
))
340 if (List
->IsFlag(Pkg
,pkgOrderList::Configured
) == false)
341 return _error
->Error(_("Could not perform immediate configuration on '%s'. "
342 "Please see man 5 apt.conf under APT::Immediate-Configure for details. (%d)"),Pkg
.Name(),1);
347 // PM::VerifyConfigure - Check configuration of dependancies /*{{{*/
348 // ---------------------------------------------------------------------
349 /* This routine checks that all a packages dependancies have been
350 configured, before it is going to be configured. If this gives a warning
351 on a virtual package, it means that the package thats providing it is not
353 bool pkgPackageManager::VerifyConfigure(PkgIterator Pkg
, pkgOrderList
&OList
)
355 // If this is true at the end, then the package should not be configured
357 // This holds the the OR status of the previous dependancy
358 bool previousOr
=false;
360 // First iterate through the dependancies of Pkg
361 for (DepIterator D
= Cache
[Pkg
].InstVerIter(Cache
).DependsList(); D
.end() == false; D
++)
364 /* If the dependancy is of type Depends or PreDepends, we need to check it, but only if it is going to be
365 configured at some point */
366 if (D
->Type
== pkgCache::Dep::Depends
|| D
->Type
== pkgCache::Dep::PreDepends
) {
368 /* If the previous package and this package are OR dependancies, and the previous package satisfied the dependancy
369 then skip this dependancy as it is not relevent, this will repeat for the next package if the situation is the
371 if (previousOr
&& !error
) { // As error has not been reset, this refers to the previous dependancy
372 previousOr
= (D
->CompareOp
& pkgCache::Dep::Or
) == pkgCache::Dep::Or
;
379 // Check thorugh all possible versions of this dependancy (D)
380 SPtrArray
<Version
*> VList
= D
.AllTargets();
381 for (Version
**I
= VList
; *I
!= 0; I
++)
383 VerIterator
DepVer(Cache
,*I
);
384 PkgIterator DepPkg
= DepVer
.ParentPkg();
385 VerIterator
DepInstallVer(Cache
,Cache
[DepPkg
].InstallVer
);
387 if (DepPkg
.CurrentVer() == DepVer
&& !List
->IsFlag(DepPkg
,pkgOrderList::UnPacked
)) {
392 if (Cache
[DepPkg
].InstallVer
== DepVer
&&
393 (List
->IsFlag(DepPkg
,pkgOrderList::Configured
) || OList
.IsFlag(DepPkg
,pkgOrderList::InList
))) {
399 /* Only worry here if this package is a OR with the next, as even though this package does not satisfy the OR
400 the next one might */
401 if (error
&& !((D
->CompareOp
& pkgCache::Dep::Or
) == pkgCache::Dep::Or
)) {
402 _error
->Error("Package %s should not be configured because package %s is not configured",Pkg
.Name(),D
.TargetPkg().Name());
404 /* If the previous package is a OR but not this package, but there is still an error then fail as it will not
406 } else if (error
&& previousOr
&& !((D
->CompareOp
& pkgCache::Dep::Or
) == pkgCache::Dep::Or
)) {
407 _error
->Error("Package %s should not be configured because package %s (or any alternatives) are not configured",Pkg
.Name(),D
.TargetPkg().Name());
411 previousOr
= (D
->CompareOp
& pkgCache::Dep::Or
) == pkgCache::Dep::Or
;
419 // PM::VerifyAndConfigure - Check configuration of dependancies /*{{{*/
420 // ---------------------------------------------------------------------
421 /* This routine verifies if a package can be configured and if so
423 bool pkgPackageManager::VerifyAndConfigure(PkgIterator Pkg
, pkgOrderList
&OList
)
425 if (VerifyConfigure(Pkg
, OList
))
426 return Configure(Pkg
);
432 // PM::DepAdd - Add all dependents to the oder list /*{{{*/
433 // ---------------------------------------------------------------------
434 /* This recursively adds all dependents to the order list */
435 bool pkgPackageManager::DepAdd(pkgOrderList
&OList
,PkgIterator Pkg
,int Depth
)
437 if (OList
.IsFlag(Pkg
,pkgOrderList::Added
) == true)
439 if (List
->IsFlag(Pkg
,pkgOrderList::Configured
) == true)
441 if (List
->IsFlag(Pkg
,pkgOrderList::UnPacked
) == false)
445 std::clog
<< OutputInDepth(Depth
) << "DepAdd: " << Pkg
.Name() << std::endl
;
447 // Put the package on the list
448 OList
.push_back(Pkg
);
449 OList
.Flag(Pkg
,pkgOrderList::Added
);
452 // Check the dependencies to see if they are all satisfied.
454 for (DepIterator D
= Cache
[Pkg
].InstVerIter(Cache
).DependsList(); D
.end() == false;)
456 if (D
->Type
!= pkgCache::Dep::Depends
&& D
->Type
!= pkgCache::Dep::PreDepends
)
464 for (bool LastOR
= true; D
.end() == false && LastOR
== true; D
++)
466 LastOR
= (D
->CompareOp
& pkgCache::Dep::Or
) == pkgCache::Dep::Or
;
471 SPtrArray
<Version
*> VList
= D
.AllTargets();
472 for (Version
**I
= VList
; *I
!= 0 && Bad
== true; I
++)
474 VerIterator
Ver(Cache
,*I
);
475 PkgIterator Pkg
= Ver
.ParentPkg();
476 VerIterator
InstallVer(Cache
,Cache
[Pkg
].InstallVer
);
477 VerIterator
CandVer(Cache
,Cache
[Pkg
].CandidateVer
);
479 if (Debug
&& false) {
481 cout
<< OutputInDepth(Depth
) << "Checking if " << Ver
<< " of " << Pkg
.Name() << " satisfies this dependancy" << endl
;
483 cout
<< OutputInDepth(Depth
) << "Checking if " << Ver
.VerStr() << " of " << Pkg
.Name() << " satisfies this dependancy" << endl
;
486 if (Pkg
.CurrentVer()==0) {
487 cout
<< OutputInDepth(Depth
) << " CurrentVer " << Pkg
.CurrentVer() << " IsNow " << List
->IsNow(Pkg
) << " NeedsNothing " << (Pkg
.State() == PkgIterator::NeedsNothing
) << endl
;
489 cout
<< OutputInDepth(Depth
) << " CurrentVer " << Pkg
.CurrentVer().VerStr() << " IsNow " << List
->IsNow(Pkg
) << " NeedsNothing " << (Pkg
.State() == PkgIterator::NeedsNothing
) << endl
;
493 cout
<< OutputInDepth(Depth
)<< " InstallVer " << InstallVer
<< endl
;
495 cout
<< OutputInDepth(Depth
)<< " InstallVer " << InstallVer
.VerStr() << endl
;
498 cout
<< " CandVer " << CandVer
.VerStr() << endl
;
500 cout
<< OutputInDepth(Depth
) << " Keep " << Cache
[Pkg
].Keep() << " Unpacked " << List
->IsFlag(Pkg
,pkgOrderList::UnPacked
) << " Configured " << List
->IsFlag(Pkg
,pkgOrderList::Configured
) << endl
;
503 // See if the current version is ok
504 if (Pkg
.CurrentVer() == Ver
&& List
->IsNow(Pkg
) == true &&
505 Pkg
.State() == PkgIterator::NeedsNothing
)
511 // Not the install version
512 if ((Cache
[Pkg
].InstallVer
!= *I
&& Cache
[Pkg
].CandidateVer
!= *I
) ||
513 (Cache
[Pkg
].Keep() == true && Pkg
.State() == PkgIterator::NeedsNothing
&&
514 (Cache
[Pkg
].iFlags
& pkgDepCache::ReInstall
) != pkgDepCache::ReInstall
))
517 if (List
->IsFlag(Pkg
,pkgOrderList::UnPacked
) == true)
518 Bad
= !DepAdd(OList
,Pkg
,Depth
);
519 if (List
->IsFlag(Pkg
,pkgOrderList::Configured
) == true)
527 std::clog
<< OutputInDepth(Depth
) << "DepAdd FAILS on: " << Pkg
.Name() << std::endl
;
528 OList
.Flag(Pkg
,0,pkgOrderList::Added
);
539 // PM::EarlyRemove - Perform removal of packages before their time /*{{{*/
540 // ---------------------------------------------------------------------
541 /* This is called to deal with conflicts arising from unpacking */
542 bool pkgPackageManager::EarlyRemove(PkgIterator Pkg
)
544 if (List
->IsNow(Pkg
) == false)
547 // Already removed it
548 if (List
->IsFlag(Pkg
,pkgOrderList::Removed
) == true)
551 // Woops, it will not be re-installed!
552 if (List
->IsFlag(Pkg
,pkgOrderList::InList
) == false)
555 // Essential packages get special treatment
556 bool IsEssential
= false;
557 if ((Pkg
->Flags
& pkgCache::Flag::Essential
) != 0)
560 /* Check for packages that are the dependents of essential packages and
562 if (Pkg
->CurrentVer
!= 0)
564 for (DepIterator D
= Pkg
.RevDependsList(); D
.end() == false &&
565 IsEssential
== false; D
++)
566 if (D
->Type
== pkgCache::Dep::Depends
|| D
->Type
== pkgCache::Dep::PreDepends
)
567 if ((D
.ParentPkg()->Flags
& pkgCache::Flag::Essential
) != 0)
571 if (IsEssential
== true)
573 if (_config
->FindB("APT::Force-LoopBreak",false) == false)
574 return _error
->Error(_("This installation run will require temporarily "
575 "removing the essential package %s due to a "
576 "Conflicts/Pre-Depends loop. This is often bad, "
577 "but if you really want to do it, activate the "
578 "APT::Force-LoopBreak option."),Pkg
.Name());
581 bool Res
= SmartRemove(Pkg
);
582 if (Cache
[Pkg
].Delete() == false)
583 List
->Flag(Pkg
,pkgOrderList::Removed
,pkgOrderList::States
);
588 // PM::SmartRemove - Removal Helper /*{{{*/
589 // ---------------------------------------------------------------------
591 bool pkgPackageManager::SmartRemove(PkgIterator Pkg
)
593 if (List
->IsNow(Pkg
) == false)
596 List
->Flag(Pkg
,pkgOrderList::Configured
,pkgOrderList::States
);
598 return Remove(Pkg
,(Cache
[Pkg
].iFlags
& pkgDepCache::Purge
) == pkgDepCache::Purge
);
602 // PM::SmartUnPack - Install helper /*{{{*/
603 // ---------------------------------------------------------------------
604 /* This performs the task of handling pre-depends. */
605 bool pkgPackageManager::SmartUnPack(PkgIterator Pkg
)
607 return SmartUnPack(Pkg
, true);
609 bool pkgPackageManager::SmartUnPack(PkgIterator Pkg
, bool const Immediate
)
612 clog
<< "SmartUnPack " << Pkg
.Name() << endl
;
614 // Check if it is already unpacked
615 if (Pkg
.State() == pkgCache::PkgIterator::NeedsConfigure
&&
616 Cache
[Pkg
].Keep() == true)
618 List
->Flag(Pkg
,pkgOrderList::UnPacked
,pkgOrderList::States
);
619 if (Immediate
== true &&
620 List
->IsFlag(Pkg
,pkgOrderList::Immediate
) == true)
621 if (SmartConfigure(Pkg
) == false)
622 return _error
->Error(_("Could not perform immediate configuration on already unpacked '%s'. "
623 "Please see man 5 apt.conf under APT::Immediate-Configure for details."),Pkg
.Name());
627 VerIterator
const instVer
= Cache
[Pkg
].InstVerIter(Cache
);
629 /* See if this packages install version has any predependencies
630 that are not met by 'now' packages. */
631 for (DepIterator D
= instVer
.DependsList();
634 // Compute a single dependency element (glob or)
635 pkgCache::DepIterator Start
;
636 pkgCache::DepIterator End
;
639 while (End
->Type
== pkgCache::Dep::PreDepends
)
642 clog
<< "PreDepends order for " << Pkg
.Name() << std::endl
;
644 // Look for possible ok targets.
645 SPtrArray
<Version
*> VList
= Start
.AllTargets();
647 for (Version
**I
= VList
; *I
!= 0 && Bad
== true; I
++)
649 VerIterator
Ver(Cache
,*I
);
650 PkgIterator Pkg
= Ver
.ParentPkg();
652 // See if the current version is ok
653 if (Pkg
.CurrentVer() == Ver
&& List
->IsNow(Pkg
) == true &&
654 Pkg
.State() == PkgIterator::NeedsNothing
)
658 clog
<< "Found ok package " << Pkg
.Name() << endl
;
663 // Look for something that could be configured.
664 for (Version
**I
= VList
; *I
!= 0 && Bad
== true; I
++)
666 VerIterator
Ver(Cache
,*I
);
667 PkgIterator Pkg
= Ver
.ParentPkg();
669 // Not the install version
670 if (Cache
[Pkg
].InstallVer
!= *I
||
671 (Cache
[Pkg
].Keep() == true && Pkg
.State() == PkgIterator::NeedsNothing
))
675 clog
<< "Trying to SmartConfigure " << Pkg
.Name() << endl
;
676 Bad
= !SmartConfigure(Pkg
);
679 /* If this or element did not match then continue on to the
680 next or element until a matching element is found */
683 // This triggers if someone make a pre-depends/depend loop.
685 return _error
->Error("Couldn't configure pre-depend %s for %s, "
686 "probably a dependency cycle.",
687 End
.TargetPkg().Name(),Pkg
.Name());
694 if (End
->Type
== pkgCache::Dep::Conflicts
||
695 End
->Type
== pkgCache::Dep::Obsoletes
)
697 /* Look for conflicts. Two packages that are both in the install
698 state cannot conflict so we don't check.. */
699 SPtrArray
<Version
*> VList
= End
.AllTargets();
700 for (Version
**I
= VList
; *I
!= 0; I
++)
702 VerIterator
Ver(Cache
,*I
);
703 PkgIterator ConflictPkg
= Ver
.ParentPkg();
704 VerIterator
InstallVer(Cache
,Cache
[ConflictPkg
].InstallVer
);
706 // See if the current version is conflicting
707 if (ConflictPkg
.CurrentVer() == Ver
&& !List
->IsFlag(ConflictPkg
,pkgOrderList::UnPacked
))
710 cout
<< " " << Pkg
.Name() << " conflicts with " << ConflictPkg
.Name() << endl
;
712 if (Debug
&& false) {
714 cout
<< " Checking if " << Ver
<< " of " << ConflictPkg
.Name() << " satisfies this dependancy" << endl
;
716 cout
<< " Checking if " << Ver
.VerStr() << " of " << ConflictPkg
.Name() << " satisfies this dependancy" << endl
;
719 if (ConflictPkg
.CurrentVer()==0) {
720 cout
<< " CurrentVer " << ConflictPkg
.CurrentVer() << " IsNow " << List
->IsNow(ConflictPkg
) << " NeedsNothing " << (ConflictPkg
.State() == PkgIterator::NeedsNothing
) << endl
;
722 cout
<< " CurrentVer " << ConflictPkg
.CurrentVer().VerStr() << " IsNow " << List
->IsNow(ConflictPkg
) << " NeedsNothing " << (ConflictPkg
.State() == PkgIterator::NeedsNothing
) << endl
;
726 cout
<< " InstallVer " << InstallVer
<< endl
;
728 cout
<< " InstallVer " << InstallVer
.VerStr() << endl
;
731 cout
<< " Keep " << Cache
[ConflictPkg
].Keep() << " Unpacked " << List
->IsFlag(ConflictPkg
,pkgOrderList::UnPacked
) << " Configured " << List
->IsFlag(ConflictPkg
,pkgOrderList::Configured
) << " Removed " << List
->IsFlag(ConflictPkg
,pkgOrderList::Removed
) << " Loop " << List
->IsFlag(ConflictPkg
,pkgOrderList::Loop
) << endl
;
732 cout
<< " Delete " << Cache
[ConflictPkg
].Delete() << endl
;
735 if (!List
->IsFlag(ConflictPkg
,pkgOrderList::Loop
)) {
736 if (Cache
[ConflictPkg
].Keep() == 0 && Cache
[ConflictPkg
].InstallVer
!= 0) {
737 cout
<< "Unpacking " << ConflictPkg
.Name() << " to prevent conflict" << endl
;
738 List
->Flag(Pkg
,pkgOrderList::Loop
);
739 SmartUnPack(ConflictPkg
,false);
741 if (EarlyRemove(ConflictPkg
) == false)
742 return _error
->Error("Internal Error, Could not early remove %s",ConflictPkg
.Name());
745 if (!List
->IsFlag(ConflictPkg
,pkgOrderList::Removed
)) {
746 cout
<< "Because of conficts knot, removing " << ConflictPkg
.Name() << " to conflict violation" << endl
;
747 if (EarlyRemove(ConflictPkg
) == false)
748 return _error
->Error("Internal Error, Could not early remove %s",ConflictPkg
.Name());
756 if (End
->Type
== pkgCache::Dep::DpkgBreaks
) {
757 SPtrArray
<Version
*> VList
= End
.AllTargets();
758 for (Version
**I
= VList
; *I
!= 0; I
++)
760 VerIterator
Ver(Cache
,*I
);
761 PkgIterator BrokenPkg
= Ver
.ParentPkg();
762 VerIterator
InstallVer(Cache
,Cache
[BrokenPkg
].InstallVer
);
764 cout
<< " " << Pkg
.Name() << " breaks " << BrokenPkg
.Name() << endl
;
765 if (Debug
&& false) {
767 cout
<< " Checking if " << Ver
<< " of " << BrokenPkg
.Name() << " satisfies this dependancy" << endl
;
769 cout
<< " Checking if " << Ver
.VerStr() << " of " << BrokenPkg
.Name() << " satisfies this dependancy" << endl
;
772 if (BrokenPkg
.CurrentVer()==0) {
773 cout
<< " CurrentVer " << BrokenPkg
.CurrentVer() << " IsNow " << List
->IsNow(BrokenPkg
) << " NeedsNothing " << (BrokenPkg
.State() == PkgIterator::NeedsNothing
) << endl
;
775 cout
<< " CurrentVer " << BrokenPkg
.CurrentVer().VerStr() << " IsNow " << List
->IsNow(BrokenPkg
) << " NeedsNothing " << (BrokenPkg
.State() == PkgIterator::NeedsNothing
) << endl
;
779 cout
<< " InstallVer " << InstallVer
<< endl
;
781 cout
<< " InstallVer " << InstallVer
.VerStr() << endl
;
784 cout
<< " Keep " << Cache
[BrokenPkg
].Keep() << " Unpacked " << List
->IsFlag(BrokenPkg
,pkgOrderList::UnPacked
) << " Configured " << List
->IsFlag(BrokenPkg
,pkgOrderList::Configured
) << " Removed " << List
->IsFlag(BrokenPkg
,pkgOrderList::Removed
) << " Loop " << List
->IsFlag(BrokenPkg
,pkgOrderList::Loop
) << " InList " << List
->IsFlag(BrokenPkg
,pkgOrderList::InList
) << endl
;
785 cout
<< " Delete " << Cache
[BrokenPkg
].Delete() << endl
;
787 // Check if it needs to be unpacked
788 if (List
->IsFlag(BrokenPkg
,pkgOrderList::InList
) && Cache
[BrokenPkg
].Delete() == false &&
789 !List
->IsFlag(BrokenPkg
,pkgOrderList::Loop
) && List
->IsNow(BrokenPkg
)) {
790 List
->Flag(Pkg
,pkgOrderList::Loop
);
791 // Found a break, so unpack the package
793 cout
<< " Unpacking " << BrokenPkg
.Name() << " to avoid break" << endl
;
794 SmartUnPack(BrokenPkg
, false);
796 // Check if a package needs to be removed
797 if (Cache
[BrokenPkg
].Delete() == true && !List
->IsFlag(BrokenPkg
,pkgOrderList::Configured
)) {
799 cout
<< " Removing " << BrokenPkg
.Name() << " to avoid break" << endl
;
800 SmartRemove(BrokenPkg
);
806 // FIXME: Crude but effective fix, allows the SmartUnPack method to be used for packages that new to the system
808 //cout << "Check for reverse conflicts on " << Pkg.Name() << " " << instVer.VerStr() << endl;
810 // Check for reverse conflicts.
811 if (CheckRConflicts(Pkg
,Pkg
.RevDependsList(),
812 instVer
.VerStr()) == false)
815 for (PrvIterator P
= instVer
.ProvidesList();
816 P
.end() == false; P
++)
817 CheckRConflicts(Pkg
,P
.ParentPkg().RevDependsList(),P
.ProvideVersion());
819 List
->Flag(Pkg
,pkgOrderList::UnPacked
,pkgOrderList::States
);
821 if (instVer
->MultiArch
== pkgCache::Version::Same
)
822 for (PkgIterator P
= Pkg
.Group().PackageList();
823 P
.end() == false; P
= Pkg
.Group().NextPkg(P
))
825 if (Pkg
== P
|| List
->IsFlag(P
,pkgOrderList::UnPacked
) == true ||
826 Cache
[P
].InstallVer
== 0 || (P
.CurrentVer() == Cache
[P
].InstallVer
&&
827 (Cache
[Pkg
].iFlags
& pkgDepCache::ReInstall
) != pkgDepCache::ReInstall
))
829 SmartUnPack(P
, false);
833 VerIterator
InstallVer(Cache
,Cache
[Pkg
].InstallVer
);
834 //cout << "Check for reverse conflicts on " << Pkg.Name() << " " << InstallVer.VerStr() << endl;
836 // Check for reverse conflicts.
837 if (CheckRConflicts(Pkg
,Pkg
.RevDependsList(),
838 InstallVer
.VerStr()) == false)
841 List
->Flag(Pkg
,pkgOrderList::UnPacked
,pkgOrderList::States
);
844 if(Install(Pkg
,FileNames
[Pkg
->ID
]) == false)
847 /* Because of the ordered list, most dependancies should be unpacked,
848 however if there is a loop this is not the case, so check for dependancies before configuring.
849 This is done after the package installation as it makes it easier to deal with conflicts problems */
850 for (DepIterator D
= instVer
.DependsList();
853 // Compute a single dependency element (glob or)
854 pkgCache::DepIterator Start
;
855 pkgCache::DepIterator End
;
858 // Check for dependanices that have not been unpacked, probably due to loops.
860 while (End
->Type
== pkgCache::Dep::Depends
) {
862 VerIterator InstallVer
;
863 SPtrArray
<Version
*> VList
= Start
.AllTargets();
865 for (Version
**I
= VList
; *I
!= 0; I
++) {
866 VerIterator
Ver(Cache
,*I
);
867 DepPkg
= Ver
.ParentPkg();
871 InstallVer
= VerIterator(Cache
,Cache
[DepPkg
].InstallVer
);
872 VerIterator
CandVer(Cache
,Cache
[DepPkg
].CandidateVer
);
874 if (Debug
&& false) {
876 cout
<< " Checking if " << Ver
<< " of " << DepPkg
.Name() << " satisfies this dependancy" << endl
;
878 cout
<< " Checking if " << Ver
.VerStr() << " of " << DepPkg
.Name() << " satisfies this dependancy" << endl
;
881 if (DepPkg
.CurrentVer()==0) {
882 cout
<< " CurrentVer " << DepPkg
.CurrentVer() << " IsNow " << List
->IsNow(DepPkg
) << " NeedsNothing " << (DepPkg
.State() == PkgIterator::NeedsNothing
) << endl
;
884 cout
<< " CurrentVer " << DepPkg
.CurrentVer().VerStr() << " IsNow " << List
->IsNow(DepPkg
) << " NeedsNothing " << (DepPkg
.State() == PkgIterator::NeedsNothing
) << endl
;
888 cout
<< " InstallVer " << InstallVer
<< endl
;
890 cout
<< " InstallVer " << InstallVer
.VerStr() << endl
;
893 cout
<< " CandVer " << CandVer
.VerStr() << endl
;
895 cout
<< " Keep " << Cache
[DepPkg
].Keep() << " Unpacked " << List
->IsFlag(DepPkg
,pkgOrderList::UnPacked
) << " Configured " << List
->IsFlag(DepPkg
,pkgOrderList::Configured
) << endl
;
899 // Check if it satisfies this dependancy
900 if (DepPkg
.CurrentVer() == Ver
&& List
->IsNow(DepPkg
) == true &&
901 DepPkg
.State() == PkgIterator::NeedsNothing
)
907 if (Cache
[DepPkg
].InstallVer
== *I
&& !List
->IsNow(DepPkg
)) {
913 if (InstallVer
!= 0 && Bad
) {
915 // Found a break, so unpack the package
916 List
->Flag(Pkg
,pkgOrderList::Loop
);
917 if (!List
->IsFlag(DepPkg
,pkgOrderList::Loop
)) {
919 cout
<< " Unpacking " << DepPkg
.Name() << " to avoid loop" << endl
;
920 SmartUnPack(DepPkg
, false);
927 _error
->Error("Could not satisfy dependancies for %s",Pkg
.Name());
937 // Perform immedate configuration of the package.
938 if (Immediate
== true &&
939 List
->IsFlag(Pkg
,pkgOrderList::Immediate
) == true)
940 if (SmartConfigure(Pkg
) == false)
942 _error
->Error(_("Could not perform immediate configuration on '%s'. "
943 "Please see man 5 apt.conf under APT::Immediate-Configure for details. (%d)"),Pkg
.Name(),2);
948 // PM::OrderInstall - Installation ordering routine /*{{{*/
949 // ---------------------------------------------------------------------
951 pkgPackageManager::OrderResult
pkgPackageManager::OrderInstall()
953 if (CreateOrderList() == false)
959 clog
<< "Beginning to order" << endl
;
961 bool const ordering
=
962 _config
->FindB("PackageManager::UnpackAll",true) ?
963 List
->OrderUnpack(FileNames
) : List
->OrderCritical();
964 if (ordering
== false)
966 _error
->Error("Internal ordering error");
971 clog
<< "Done ordering" << endl
;
973 bool DoneSomething
= false;
974 for (pkgOrderList::iterator I
= List
->begin(); I
!= List
->end(); I
++)
976 PkgIterator
Pkg(Cache
,*I
);
978 if (List
->IsNow(Pkg
) == false)
981 clog
<< "Skipping already done " << Pkg
.Name() << endl
;
985 if (List
->IsMissing(Pkg
) == true)
988 clog
<< "Sequence completed at " << Pkg
.Name() << endl
;
989 if (DoneSomething
== false)
991 _error
->Error("Internal Error, ordering was unable to handle the media swap");
998 if (Cache
[Pkg
].Keep() == true &&
999 Pkg
.State() == pkgCache::PkgIterator::NeedsNothing
&&
1000 (Cache
[Pkg
].iFlags
& pkgDepCache::ReInstall
) != pkgDepCache::ReInstall
)
1002 _error
->Error("Internal Error, trying to manipulate a kept package (%s)",Pkg
.Name());
1006 // Perform a delete or an install
1007 if (Cache
[Pkg
].Delete() == true)
1009 if (SmartRemove(Pkg
) == false)
1013 if (SmartUnPack(Pkg
) == false)
1015 DoneSomething
= true;
1018 // Final run through the configure phase
1019 if (ConfigureAll() == false)
1023 for (pkgOrderList::iterator I
= List
->begin(); I
!= List
->end(); I
++)
1025 if (List
->IsFlag(*I
,pkgOrderList::Configured
) == false)
1027 _error
->Error("Internal error, packages left unconfigured. %s",
1028 PkgIterator(Cache
,*I
).Name());
1036 // PM::DoInstallPostFork - Does install part that happens after the fork /*{{{*/
1037 // ---------------------------------------------------------------------
1038 pkgPackageManager::OrderResult
1039 pkgPackageManager::DoInstallPostFork(int statusFd
)
1042 // FIXME: use SetCloseExec here once it taught about throwing
1043 // exceptions instead of doing _exit(100) on failure
1044 fcntl(statusFd
,F_SETFD
,FD_CLOEXEC
);
1045 bool goResult
= Go(statusFd
);
1046 if(goResult
== false)
1052 // PM::DoInstall - Does the installation /*{{{*/
1053 // ---------------------------------------------------------------------
1054 /* This uses the filenames in FileNames and the information in the
1055 DepCache to perform the installation of packages.*/
1056 pkgPackageManager::OrderResult
pkgPackageManager::DoInstall(int statusFd
)
1058 if(DoInstallPreFork() == Failed
)
1061 return DoInstallPostFork(statusFd
);