]>
git.saurik.com Git - apt.git/blob - apt-pkg/packagemanager.cc
b76f78b3cf2dddb124aa4e0fc3af9bca518ee6ef
1 // -*- mode: cpp; mode: fold -*-
3 // $Id: packagemanager.cc,v 1.21 1999/09/30 06:30:34 jgg 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 /*{{{*/
17 #pragma implementation "apt-pkg/packagemanager.h"
19 #include <apt-pkg/packagemanager.h>
20 #include <apt-pkg/orderlist.h>
21 #include <apt-pkg/depcache.h>
22 #include <apt-pkg/error.h>
23 #include <apt-pkg/version.h>
24 #include <apt-pkg/acquire-item.h>
25 #include <apt-pkg/algorithms.h>
26 #include <apt-pkg/configuration.h>
29 // PM::PackageManager - Constructor /*{{{*/
30 // ---------------------------------------------------------------------
32 pkgPackageManager::pkgPackageManager(pkgDepCache
&Cache
) : Cache(Cache
)
34 FileNames
= new string
[Cache
.Head().PackageCount
];
36 Debug
= _config
->FindB("Debug::pkgPackageManager",false);
39 // PM::PackageManager - Destructor /*{{{*/
40 // ---------------------------------------------------------------------
42 pkgPackageManager::~pkgPackageManager()
48 // PM::GetArchives - Queue the archives for download /*{{{*/
49 // ---------------------------------------------------------------------
51 bool pkgPackageManager::GetArchives(pkgAcquire
*Owner
,pkgSourceList
*Sources
,
54 if (CreateOrderList() == false)
57 if (List
->OrderUnpack() == false)
58 return _error
->Error("Internal ordering error");
60 for (pkgOrderList::iterator I
= List
->begin(); I
!= List
->end(); I
++)
62 PkgIterator
Pkg(Cache
,*I
);
63 FileNames
[Pkg
->ID
] = string();
65 // Skip packages to erase
66 if (Cache
[Pkg
].Delete() == true)
69 // Skip Packages that need configure only.
70 if (Pkg
.State() == pkgCache::PkgIterator::NeedsConfigure
&&
71 Cache
[Pkg
].Keep() == true)
74 // Skip already processed packages
75 if (List
->IsNow(Pkg
) == false)
78 new pkgAcqArchive(Owner
,Sources
,Recs
,Cache
[Pkg
].InstVerIter(Cache
),
85 // PM::FixMissing - Keep all missing packages /*{{{*/
86 // ---------------------------------------------------------------------
87 /* This is called to correct the installation when packages could not
89 bool pkgPackageManager::FixMissing()
91 pkgProblemResolver
Resolve(Cache
);
92 List
->SetFileList(FileNames
);
95 for (PkgIterator I
= Cache
.PkgBegin(); I
.end() == false; I
++)
97 if (List
->IsMissing(I
) == false)
100 // Okay, this file is missing and we need it. Mark it for keep
105 // We have to empty the list otherwise it will not have the new changes
112 // Now downgrade everything that is broken
113 return Resolve
.ResolveByKeep() == true && Cache
.BrokenCount() == 0;
117 // PM::CreateOrderList - Create the ordering class /*{{{*/
118 // ---------------------------------------------------------------------
119 /* This populates the ordering list with all the packages that are
121 bool pkgPackageManager::CreateOrderList()
127 List
= new pkgOrderList(Cache
);
129 bool NoImmConfigure
= _config
->FindB("APT::Immediate-Configure",false);
131 // Generate the list of affected packages and sort it
132 for (PkgIterator I
= Cache
.PkgBegin(); I
.end() == false; I
++)
134 // Mark the package and its dependends for immediate configuration
135 if (((I
->Flags
& pkgCache::Flag::Essential
) == pkgCache::Flag::Essential
||
136 (I
->Flags
& pkgCache::Flag::Important
) == pkgCache::Flag::Important
) &&
137 NoImmConfigure
== false)
139 List
->Flag(I
,pkgOrderList::Immediate
);
141 // Look for other packages to make immediate configurea
142 if (Cache
[I
].InstallVer
!= 0)
143 for (DepIterator D
= Cache
[I
].InstVerIter(Cache
).DependsList();
144 D
.end() == false; D
++)
145 if (D
->Type
== pkgCache::Dep::Depends
|| D
->Type
== pkgCache::Dep::PreDepends
)
146 List
->Flag(D
.TargetPkg(),pkgOrderList::Immediate
);
148 // And again with the current version.
149 if (I
->CurrentVer
!= 0)
150 for (DepIterator D
= I
.CurrentVer().DependsList();
151 D
.end() == false; D
++)
152 if (D
->Type
== pkgCache::Dep::Depends
|| D
->Type
== pkgCache::Dep::PreDepends
)
153 List
->Flag(D
.TargetPkg(),pkgOrderList::Immediate
);
157 if ((Cache
[I
].Keep() == true ||
158 Cache
[I
].InstVerIter(Cache
) == I
.CurrentVer()) &&
159 I
.State() == pkgCache::PkgIterator::NeedsNothing
&&
160 (I
.Purge() != false || Cache
[I
].Mode
!= pkgDepCache::ModeDelete
||
161 (Cache
[I
].iFlags
& pkgDepCache::Purge
) != pkgDepCache::Purge
))
164 // Append it to the list
171 // PM::DepAlwaysTrue - Returns true if this dep is irrelevent /*{{{*/
172 // ---------------------------------------------------------------------
173 /* The restriction on provides is to eliminate the case when provides
174 are transitioning between valid states [ie exim to smail] */
175 bool pkgPackageManager::DepAlwaysTrue(DepIterator D
)
177 if (D
.TargetPkg()->ProvidesList
!= 0)
180 if ((Cache
[D
] & pkgDepCache::DepInstall
) != 0 &&
181 (Cache
[D
] & pkgDepCache::DepNow
) != 0)
186 // PM::CheckRConflicts - Look for reverse conflicts /*{{{*/
187 // ---------------------------------------------------------------------
188 /* This looks over the reverses for a conflicts line that needs early
190 bool pkgPackageManager::CheckRConflicts(PkgIterator Pkg
,DepIterator D
,
193 for (;D
.end() == false; D
++)
195 if (D
->Type
!= pkgCache::Dep::Conflicts
)
198 if (D
.ParentPkg() == Pkg
)
201 if (pkgCheckDep(D
.TargetVer(),Ver
,D
->CompareOp
) == false)
204 if (List
->IsNow(Pkg
) == false)
207 if (EarlyRemove(D
.ParentPkg()) == false)
213 // PM::ConfigureAll - Run the all out configuration /*{{{*/
214 // ---------------------------------------------------------------------
215 /* This configures every package. It is assumed they are all unpacked and
216 that the final configuration is valid. */
217 bool pkgPackageManager::ConfigureAll()
219 pkgOrderList
OList(Cache
);
221 // Populate the order list
222 for (pkgOrderList::iterator I
= List
->begin(); I
!= List
->end(); I
++)
223 if (List
->IsFlag(pkgCache::PkgIterator(Cache
,*I
),
224 pkgOrderList::UnPacked
) == true)
227 if (OList
.OrderConfigure() == false)
230 // Perform the configuring
231 for (pkgOrderList::iterator I
= OList
.begin(); I
!= OList
.end(); I
++)
233 PkgIterator
Pkg(Cache
,*I
);
235 if (Configure(Pkg
) == false)
238 List
->Flag(Pkg
,pkgOrderList::Configured
,pkgOrderList::States
);
244 // PM::SmartConfigure - Perform immediate configuration of the pkg /*{{{*/
245 // ---------------------------------------------------------------------
246 /* This routine scheduals the configuration of the given package and all
247 of it's dependents. */
248 bool pkgPackageManager::SmartConfigure(PkgIterator Pkg
)
250 pkgOrderList
OList(Cache
);
252 if (DepAdd(OList
,Pkg
) == false)
255 if (OList
.OrderConfigure() == false)
258 // Perform the configuring
259 for (pkgOrderList::iterator I
= OList
.begin(); I
!= OList
.end(); I
++)
261 PkgIterator
Pkg(Cache
,*I
);
263 if (Configure(Pkg
) == false)
266 List
->Flag(Pkg
,pkgOrderList::Configured
,pkgOrderList::States
);
270 if (List
->IsFlag(Pkg
,pkgOrderList::Configured
) == false)
271 return _error
->Error("Internal error, could not immediate configure %s",Pkg
.Name());
276 // PM::DepAdd - Add all dependents to the oder list /*{{{*/
277 // ---------------------------------------------------------------------
278 /* This recursively adds all dependents to the order list */
279 bool pkgPackageManager::DepAdd(pkgOrderList
&OList
,PkgIterator Pkg
,int Depth
)
281 if (OList
.IsFlag(Pkg
,pkgOrderList::Added
) == true)
283 if (List
->IsFlag(Pkg
,pkgOrderList::Configured
) == true)
285 if (List
->IsFlag(Pkg
,pkgOrderList::UnPacked
) == false)
289 // Put the package on the list
290 OList
.push_back(Pkg
);
291 OList
.Flag(Pkg
,pkgOrderList::Added
);
294 // Check the dependencies to see if they are all satisfied.
296 for (DepIterator D
= Cache
[Pkg
].InstVerIter(Cache
).DependsList(); D
.end() == false;)
298 if (D
->Type
!= pkgCache::Dep::Depends
&& D
->Type
!= pkgCache::Dep::PreDepends
)
306 for (bool LastOR
= true; D
.end() == false && LastOR
== true; D
++)
308 LastOR
= (D
->CompareOp
& pkgCache::Dep::Or
) == pkgCache::Dep::Or
;
313 Version
**VList
= D
.AllTargets();
314 for (Version
**I
= VList
; *I
!= 0 && Bad
== true; I
++)
316 VerIterator
Ver(Cache
,*I
);
317 PkgIterator Pkg
= Ver
.ParentPkg();
319 // See if the current version is ok
320 if (Pkg
.CurrentVer() == Ver
&& List
->IsNow(Pkg
) == true &&
321 Pkg
.State() == PkgIterator::NeedsNothing
)
327 // Not the install version
328 if (Cache
[Pkg
].InstallVer
!= *I
||
329 (Cache
[Pkg
].Keep() == true && Pkg
.State() == PkgIterator::NeedsNothing
))
331 if (List
->IsFlag(Pkg
,pkgOrderList::UnPacked
) == true)
332 Bad
= !DepAdd(OList
,Pkg
,Depth
);
333 if (List
->IsFlag(Pkg
,pkgOrderList::Configured
) == true)
341 OList
.Flag(Pkg
,0,pkgOrderList::Added
);
352 // PM::EarlyRemove - Perform removal of packages before their time /*{{{*/
353 // ---------------------------------------------------------------------
354 /* This is called to deal with conflicts arising from unpacking */
355 bool pkgPackageManager::EarlyRemove(PkgIterator Pkg
)
357 if (List
->IsNow(Pkg
) == false)
360 // Already removed it
361 if (List
->IsFlag(Pkg
,pkgOrderList::Removed
) == true)
364 // Woops, it will not be re-installed!
365 if (List
->IsFlag(Pkg
,pkgOrderList::InList
) == false)
368 // Essential packages get special treatment
369 if ((Pkg
->Flags
& pkgCache::Flag::Essential
) != 0)
371 if (_config
->FindB("APT::Force-LoopBreak",false) == false)
372 return _error
->Error("This installation run will require temporarily "
373 "removing the essential package %s due to a "
374 "Conflicts/Pre-Depends loop. This is often bad, "
375 "but if you really want to do it, activate the "
376 "APT::Force-LoopBreak option.",Pkg
.Name());
379 bool Res
= SmartRemove(Pkg
);
380 if (Cache
[Pkg
].Delete() == false)
381 List
->Flag(Pkg
,pkgOrderList::Removed
,pkgOrderList::States
);
386 // PM::SmartRemove - Removal Helper /*{{{*/
387 // ---------------------------------------------------------------------
389 bool pkgPackageManager::SmartRemove(PkgIterator Pkg
)
391 if (List
->IsNow(Pkg
) == false)
394 List
->Flag(Pkg
,pkgOrderList::Configured
,pkgOrderList::States
);
395 return Remove(Pkg
,(Cache
[Pkg
].iFlags
& pkgDepCache::Purge
) == pkgDepCache::Purge
);
398 // PM::SmartUnPack - Install helper /*{{{*/
399 // ---------------------------------------------------------------------
400 /* This performs the task of handling pre-depends. */
401 bool pkgPackageManager::SmartUnPack(PkgIterator Pkg
)
403 // Check if it is already unpacked
404 if (Pkg
.State() == pkgCache::PkgIterator::NeedsConfigure
&&
405 Cache
[Pkg
].Keep() == true)
407 List
->Flag(Pkg
,pkgOrderList::UnPacked
,pkgOrderList::States
);
408 if (List
->IsFlag(Pkg
,pkgOrderList::Immediate
) == true)
409 if (SmartConfigure(Pkg
) == false)
410 return _error
->Error("Internal Error, Could not perform immediate configuraton");
414 /* See if this packages install version has any predependencies
415 that are not met by 'now' packages. */
416 for (DepIterator D
= Cache
[Pkg
].InstVerIter(Cache
).DependsList();
419 // Compute a single dependency element (glob or)
420 pkgCache::DepIterator Start
;
421 pkgCache::DepIterator End
;
424 while (End
->Type
== pkgCache::Dep::PreDepends
)
426 // Look for possible ok targets.
427 Version
**VList
= Start
.AllTargets();
429 for (Version
**I
= VList
; *I
!= 0 && Bad
== true; I
++)
431 VerIterator
Ver(Cache
,*I
);
432 PkgIterator Pkg
= Ver
.ParentPkg();
434 // See if the current version is ok
435 if (Pkg
.CurrentVer() == Ver
&& List
->IsNow(Pkg
) == true &&
436 Pkg
.State() == PkgIterator::NeedsNothing
)
443 // Look for something that could be configured.
444 for (Version
**I
= VList
; *I
!= 0 && Bad
== true; I
++)
446 VerIterator
Ver(Cache
,*I
);
447 PkgIterator Pkg
= Ver
.ParentPkg();
449 // Not the install version
450 if (Cache
[Pkg
].InstallVer
!= *I
||
451 (Cache
[Pkg
].Keep() == true && Pkg
.State() == PkgIterator::NeedsNothing
))
454 Bad
= !SmartConfigure(Pkg
);
459 /* If this or element did not match then continue on to the
460 next or element until a matching element is found*/
464 return _error
->Error("Internal Error, Couldn't configure a pre-depend");
471 if (End
->Type
== pkgCache::Dep::Conflicts
)
473 /* Look for conflicts. Two packages that are both in the install
474 state cannot conflict so we don't check.. */
475 Version
**VList
= End
.AllTargets();
476 for (Version
**I
= VList
; *I
!= 0; I
++)
478 VerIterator
Ver(Cache
,*I
);
479 PkgIterator Pkg
= Ver
.ParentPkg();
481 // See if the current version is conflicting
482 if (Pkg
.CurrentVer() == Ver
&& List
->IsNow(Pkg
) == true)
484 if (EarlyRemove(Pkg
) == false)
485 return _error
->Error("Internal Error, Could not early remove %s",Pkg
.Name());
492 // Check for reverse conflicts.
493 CheckRConflicts(Pkg
,Pkg
.RevDependsList(),
494 Cache
[Pkg
].InstVerIter(Cache
).VerStr());
495 for (PrvIterator P
= Cache
[Pkg
].InstVerIter(Cache
).ProvidesList();
496 P
.end() == false; P
++)
497 CheckRConflicts(Pkg
,P
.ParentPkg().RevDependsList(),P
.ProvideVersion());
499 if (Install(Pkg
,FileNames
[Pkg
->ID
]) == false)
502 List
->Flag(Pkg
,pkgOrderList::UnPacked
,pkgOrderList::States
);
504 // Perform immedate configuration of the package.
505 if (List
->IsFlag(Pkg
,pkgOrderList::Immediate
) == true)
506 if (SmartConfigure(Pkg
) == false)
507 return _error
->Error("Internal Error, Could not perform immediate configuraton");
512 // PM::OrderInstall - Installation ordering routine /*{{{*/
513 // ---------------------------------------------------------------------
515 pkgPackageManager::OrderResult
pkgPackageManager::OrderInstall()
517 if (CreateOrderList() == false)
523 clog
<< "Begining to order" << endl
;
525 if (List
->OrderUnpack(FileNames
) == false)
527 _error
->Error("Internal ordering error");
532 clog
<< "Done ordering" << endl
;
534 bool DoneSomething
= false;
535 for (pkgOrderList::iterator I
= List
->begin(); I
!= List
->end(); I
++)
537 PkgIterator
Pkg(Cache
,*I
);
539 if (List
->IsNow(Pkg
) == false)
542 clog
<< "Skipping already done " << Pkg
.Name() << endl
;
546 if (List
->IsMissing(Pkg
) == true)
549 clog
<< "Sequence completed at" << Pkg
.Name() << endl
;
550 if (DoneSomething
== false)
552 _error
->Error("Internal Error, ordering was unable to handle the media swap");
559 if (Cache
[Pkg
].Keep() == true && Pkg
.State() == pkgCache::PkgIterator::NeedsNothing
)
561 _error
->Error("Internal Error, trying to manipulate a kept package");
565 // Perform a delete or an install
566 if (Cache
[Pkg
].Delete() == true)
568 if (SmartRemove(Pkg
) == false)
572 if (SmartUnPack(Pkg
) == false)
574 DoneSomething
= true;
577 // Final run through the configure phase
578 if (ConfigureAll() == false)
582 for (pkgOrderList::iterator I
= List
->begin(); I
!= List
->end(); I
++)
584 if (List
->IsFlag(*I
,pkgOrderList::Configured
) == false)
586 _error
->Error("Internal error, packages left unconfigured. %s",
587 PkgIterator(Cache
,*I
).Name());
595 // PM::DoInstall - Does the installation /*{{{*/
596 // ---------------------------------------------------------------------
597 /* This uses the filenames in FileNames and the information in the
598 DepCache to perform the installation of packages.*/
599 pkgPackageManager::OrderResult
pkgPackageManager::DoInstall()
601 OrderResult Res
= OrderInstall();