]>
git.saurik.com Git - apt.git/blob - apt-pkg/packagemanager.cc
9e2eee969e9edda3e6f0f85bf9bfce1f9e9f5d16
1 // -*- mode: cpp; mode: fold -*-
3 // $Id: packagemanager.cc,v 1.16 1999/07/04 23:22:53 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
108 // Now downgrade everything that is broken
109 return Resolve
.ResolveByKeep() == true && Cache
.BrokenCount() == 0;
113 // PM::CreateOrderList - Create the ordering class /*{{{*/
114 // ---------------------------------------------------------------------
115 /* This populates the ordering list with all the packages that are
117 bool pkgPackageManager::CreateOrderList()
123 List
= new pkgOrderList(Cache
);
125 bool NoImmConfigure
= _config
->FindB("APT::Immediate-Configure",false);
127 // Generate the list of affected packages and sort it
128 for (PkgIterator I
= Cache
.PkgBegin(); I
.end() == false; I
++)
130 // Mark the package and its dependends for immediate configuration
131 if (((I
->Flags
& pkgCache::Flag::Essential
) == pkgCache::Flag::Essential
||
132 (I
->Flags
& pkgCache::Flag::Important
) == pkgCache::Flag::Important
) &&
133 NoImmConfigure
== false)
135 List
->Flag(I
,pkgOrderList::Immediate
);
137 // Look for other packages to make immediate configurea
138 if (Cache
[I
].InstallVer
!= 0)
139 for (DepIterator D
= Cache
[I
].InstVerIter(Cache
).DependsList();
140 D
.end() == false; D
++)
141 if (D
->Type
== pkgCache::Dep::Depends
|| D
->Type
== pkgCache::Dep::PreDepends
)
142 List
->Flag(D
.TargetPkg(),pkgOrderList::Immediate
);
144 // And again with the current version.
145 if (I
->CurrentVer
!= 0)
146 for (DepIterator D
= I
.CurrentVer().DependsList();
147 D
.end() == false; D
++)
148 if (D
->Type
== pkgCache::Dep::Depends
|| D
->Type
== pkgCache::Dep::PreDepends
)
149 List
->Flag(D
.TargetPkg(),pkgOrderList::Immediate
);
153 if ((Cache
[I
].Keep() == true ||
154 Cache
[I
].InstVerIter(Cache
) == I
.CurrentVer()) &&
155 I
.State() == pkgCache::PkgIterator::NeedsNothing
)
158 // Append it to the list
165 // PM::DepAlwaysTrue - Returns true if this dep is irrelevent /*{{{*/
166 // ---------------------------------------------------------------------
167 /* The restriction on provides is to eliminate the case when provides
168 are transitioning between valid states [ie exim to smail] */
169 bool pkgPackageManager::DepAlwaysTrue(DepIterator D
)
171 if (D
.TargetPkg()->ProvidesList
!= 0)
174 if ((Cache
[D
] & pkgDepCache::DepInstall
) != 0 &&
175 (Cache
[D
] & pkgDepCache::DepNow
) != 0)
180 // PM::CheckRConflicts - Look for reverse conflicts /*{{{*/
181 // ---------------------------------------------------------------------
182 /* This looks over the reverses for a conflicts line that needs early
184 bool pkgPackageManager::CheckRConflicts(PkgIterator Pkg
,DepIterator D
,
187 for (;D
.end() == false; D
++)
189 if (D
->Type
!= pkgCache::Dep::Conflicts
)
192 if (D
.ParentPkg() == Pkg
)
195 if (pkgCheckDep(D
.TargetVer(),Ver
,D
->CompareOp
) == false)
198 if (List
->IsNow(Pkg
) == false)
201 if (EarlyRemove(D
.ParentPkg()) == false)
207 // PM::ConfigureAll - Run the all out configuration /*{{{*/
208 // ---------------------------------------------------------------------
209 /* This configures every package. It is assumed they are all unpacked and
210 that the final configuration is valid. */
211 bool pkgPackageManager::ConfigureAll()
213 pkgOrderList
OList(Cache
);
215 // Populate the order list
216 for (pkgOrderList::iterator I
= List
->begin(); I
!= List
->end(); I
++)
217 if (List
->IsFlag(pkgCache::PkgIterator(Cache
,*I
),
218 pkgOrderList::UnPacked
) == true)
221 if (OList
.OrderConfigure() == false)
224 // Perform the configuring
225 for (pkgOrderList::iterator I
= OList
.begin(); I
!= OList
.end(); I
++)
227 PkgIterator
Pkg(Cache
,*I
);
229 if (Configure(Pkg
) == false)
232 List
->Flag(Pkg
,pkgOrderList::Configured
,pkgOrderList::States
);
238 // PM::SmartConfigure - Perform immediate configuration of the pkg /*{{{*/
239 // ---------------------------------------------------------------------
240 /* This routine scheduals the configuration of the given package and all
241 of it's dependents. */
242 bool pkgPackageManager::SmartConfigure(PkgIterator Pkg
)
244 pkgOrderList
OList(Cache
);
246 if (DepAdd(OList
,Pkg
) == false)
249 if (OList
.OrderConfigure() == false)
252 // Perform the configuring
253 for (pkgOrderList::iterator I
= OList
.begin(); I
!= OList
.end(); I
++)
255 PkgIterator
Pkg(Cache
,*I
);
257 if (Configure(Pkg
) == false)
260 List
->Flag(Pkg
,pkgOrderList::Configured
,pkgOrderList::States
);
264 if (List
->IsFlag(Pkg
,pkgOrderList::Configured
) == false)
265 return _error
->Error("Internal error, could not immediate configure %s",Pkg
.Name());
270 // PM::DepAdd - Add all dependents to the oder list /*{{{*/
271 // ---------------------------------------------------------------------
272 /* This recursively adds all dependents to the order list */
273 bool pkgPackageManager::DepAdd(pkgOrderList
&OList
,PkgIterator Pkg
,int Depth
)
275 if (OList
.IsFlag(Pkg
,pkgOrderList::Added
) == true)
277 if (List
->IsFlag(Pkg
,pkgOrderList::Configured
) == true)
279 if (List
->IsFlag(Pkg
,pkgOrderList::UnPacked
) == false)
283 // Put the package on the list
284 OList
.push_back(Pkg
);
285 OList
.Flag(Pkg
,pkgOrderList::Added
);
288 // Check the dependencies to see if they are all satisfied.
290 for (DepIterator D
= Cache
[Pkg
].InstVerIter(Cache
).DependsList(); D
.end() == false;)
292 if (D
->Type
!= pkgCache::Dep::Depends
&& D
->Type
!= pkgCache::Dep::PreDepends
)
300 for (bool LastOR
= true; D
.end() == false && LastOR
== true; D
++)
302 LastOR
= (D
->CompareOp
& pkgCache::Dep::Or
) == pkgCache::Dep::Or
;
307 Version
**VList
= D
.AllTargets();
308 for (Version
**I
= VList
; *I
!= 0 && Bad
== true; I
++)
310 VerIterator
Ver(Cache
,*I
);
311 PkgIterator Pkg
= Ver
.ParentPkg();
313 // See if the current version is ok
314 if (Pkg
.CurrentVer() == Ver
&& List
->IsNow(Pkg
) == true &&
315 Pkg
.State() == PkgIterator::NeedsNothing
)
321 // Not the install version
322 if (Cache
[Pkg
].InstallVer
!= *I
||
323 (Cache
[Pkg
].Keep() == true && Pkg
.State() == PkgIterator::NeedsNothing
))
325 if (List
->IsFlag(Pkg
,pkgOrderList::UnPacked
) == true)
326 Bad
= !DepAdd(OList
,Pkg
,Depth
);
327 if (List
->IsFlag(Pkg
,pkgOrderList::Configured
) == true)
335 OList
.Flag(Pkg
,0,pkgOrderList::Added
);
346 // PM::EarlyRemove - Perform removal of packages before their time /*{{{*/
347 // ---------------------------------------------------------------------
348 /* This is called to deal with conflicts arising from unpacking */
349 bool pkgPackageManager::EarlyRemove(PkgIterator Pkg
)
351 if (List
->IsNow(Pkg
) == false)
354 // Already removed it
355 if (List
->IsFlag(Pkg
,pkgOrderList::Removed
) == true)
358 // Woops, it will not be re-installed!
359 if (List
->IsFlag(Pkg
,pkgOrderList::InList
) == false)
362 bool Res
= SmartRemove(Pkg
);
363 if (Cache
[Pkg
].Delete() == false)
364 List
->Flag(Pkg
,pkgOrderList::Removed
,pkgOrderList::States
);
369 // PM::SmartRemove - Removal Helper /*{{{*/
370 // ---------------------------------------------------------------------
372 bool pkgPackageManager::SmartRemove(PkgIterator Pkg
)
374 if (List
->IsNow(Pkg
) == false)
377 List
->Flag(Pkg
,pkgOrderList::Configured
,pkgOrderList::States
);
381 // PM::SmartUnPack - Install helper /*{{{*/
382 // ---------------------------------------------------------------------
383 /* This performs the task of handling pre-depends. */
384 bool pkgPackageManager::SmartUnPack(PkgIterator Pkg
)
386 // Check if it is already unpacked
387 if (Pkg
.State() == pkgCache::PkgIterator::NeedsConfigure
&&
388 Cache
[Pkg
].Keep() == true)
390 List
->Flag(Pkg
,pkgOrderList::UnPacked
,pkgOrderList::States
);
391 if (List
->IsFlag(Pkg
,pkgOrderList::Immediate
) == true)
392 if (SmartConfigure(Pkg
) == false)
393 return _error
->Error("Internal Error, Could not perform immediate configuraton");
397 /* See if this packages install version has any predependencies
398 that are not met by 'now' packages. */
399 for (DepIterator D
= Cache
[Pkg
].InstVerIter(Cache
).DependsList();
400 D
.end() == false; D
++)
402 if (D
->Type
== pkgCache::Dep::PreDepends
)
404 // Look for possible ok targets.
405 Version
**VList
= D
.AllTargets();
407 for (Version
**I
= VList
; *I
!= 0 && Bad
== true; I
++)
409 VerIterator
Ver(Cache
,*I
);
410 PkgIterator Pkg
= Ver
.ParentPkg();
412 // See if the current version is ok
413 if (Pkg
.CurrentVer() == Ver
&& List
->IsNow(Pkg
) == true &&
414 Pkg
.State() == PkgIterator::NeedsNothing
)
421 // Look for something that could be configured.
422 for (Version
**I
= VList
; *I
!= 0 && Bad
== true; I
++)
424 VerIterator
Ver(Cache
,*I
);
425 PkgIterator Pkg
= Ver
.ParentPkg();
427 // Not the install version
428 if (Cache
[Pkg
].InstallVer
!= *I
||
429 (Cache
[Pkg
].Keep() == true && Pkg
.State() == PkgIterator::NeedsNothing
))
432 Bad
= !SmartConfigure(Pkg
);
438 return _error
->Error("Internal Error, Couldn't configure a pre-depend");
443 if (D
->Type
== pkgCache::Dep::Conflicts
)
445 /* Look for conflicts. Two packages that are both in the install
446 state cannot conflict so we don't check.. */
447 Version
**VList
= D
.AllTargets();
448 for (Version
**I
= VList
; *I
!= 0; I
++)
450 VerIterator
Ver(Cache
,*I
);
451 PkgIterator Pkg
= Ver
.ParentPkg();
453 // See if the current version is conflicting
454 if (Pkg
.CurrentVer() == Ver
&& List
->IsNow(Pkg
) == true)
456 if (EarlyRemove(Pkg
) == false)
457 return _error
->Error("Internal Error, Could not early remove %s",Pkg
.Name());
464 // Check for reverse conflicts.
465 CheckRConflicts(Pkg
,Pkg
.RevDependsList(),
466 Cache
[Pkg
].InstVerIter(Cache
).VerStr());
467 for (PrvIterator P
= Cache
[Pkg
].InstVerIter(Cache
).ProvidesList();
468 P
.end() == false; P
++)
469 CheckRConflicts(Pkg
,P
.ParentPkg().RevDependsList(),P
.ProvideVersion());
471 if (Install(Pkg
,FileNames
[Pkg
->ID
]) == false)
474 List
->Flag(Pkg
,pkgOrderList::UnPacked
,pkgOrderList::States
);
476 // Perform immedate configuration of the package.
477 if (List
->IsFlag(Pkg
,pkgOrderList::Immediate
) == true)
478 if (SmartConfigure(Pkg
) == false)
479 return _error
->Error("Internal Error, Could not perform immediate configuraton");
484 // PM::OrderInstall - Installation ordering routine /*{{{*/
485 // ---------------------------------------------------------------------
487 pkgPackageManager::OrderResult
pkgPackageManager::OrderInstall()
489 if (CreateOrderList() == false)
495 clog
<< "Begining to order" << endl
;
497 if (List
->OrderUnpack(FileNames
) == false)
499 _error
->Error("Internal ordering error");
504 clog
<< "Done ordering" << endl
;
506 bool DoneSomething
= false;
507 for (pkgOrderList::iterator I
= List
->begin(); I
!= List
->end(); I
++)
509 PkgIterator
Pkg(Cache
,*I
);
511 if (List
->IsNow(Pkg
) == false)
514 clog
<< "Skipping already done " << Pkg
.Name() << endl
;
518 if (List
->IsMissing(Pkg
) == true)
521 clog
<< "Sequence completed at" << Pkg
.Name() << endl
;
522 if (DoneSomething
== false)
524 _error
->Error("Internal Error, ordering was unable to handle the media swap");
531 if (Cache
[Pkg
].Keep() == true && Pkg
.State() == pkgCache::PkgIterator::NeedsNothing
)
533 _error
->Error("Internal Error, trying to manipulate a kept package");
537 // Perform a delete or an install
538 if (Cache
[Pkg
].Delete() == true)
540 if (SmartRemove(Pkg
) == false)
544 if (SmartUnPack(Pkg
) == false)
546 DoneSomething
= true;
549 // Final run through the configure phase
550 if (ConfigureAll() == false)
554 for (pkgOrderList::iterator I
= List
->begin(); I
!= List
->end(); I
++)
556 if (List
->IsFlag(*I
,pkgOrderList::Configured
) == false)
558 _error
->Error("Internal error, packages left unconfigured. %s",
559 PkgIterator(Cache
,*I
).Name());
567 // PM::DoInstall - Does the installation /*{{{*/
568 // ---------------------------------------------------------------------
569 /* This uses the filenames in FileNames and the information in the
570 DepCache to perform the installation of packages.*/
571 pkgPackageManager::OrderResult
pkgPackageManager::DoInstall()
573 OrderResult Res
= OrderInstall();