]>
git.saurik.com Git - apt.git/blob - apt-pkg/packagemanager.cc
e6222f003f18892681a98e3e924e75f0c4d328bd
1 // -*- mode: cpp; mode: fold -*-
3 // $Id: packagemanager.cc,v 1.6 1998/11/22 03:20:33 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 pkgCache::PkgIterator I
= Cache
.PkgBegin();
55 for (;I
.end() != true; I
++)
58 if ((Cache
[I
].InstallVer
== (pkgCache::Version
*)I
.CurrentVer() &&
59 I
.State() != pkgCache::PkgIterator::NeedsUnpack
) ||
60 Cache
[I
].Delete() == true)
63 new pkgAcqArchive(Owner
,Sources
,Recs
,Cache
[I
].InstVerIter(Cache
),
69 // PM::FixMissing - Keep all missing packages /*{{{*/
70 // ---------------------------------------------------------------------
71 /* This is called to correct the installation when packages could not
73 bool pkgPackageManager::FixMissing()
75 pkgProblemResolver
Resolve(Cache
);
77 for (PkgIterator I
= Cache
.PkgBegin(); I
.end() == false; I
++)
79 if (Cache
[I
].Keep() == true)
81 if (FileNames
[I
->ID
].empty() == false || Cache
[I
].Delete() == true)
86 // Now downgrade everything that is broken
87 return Resolve
.ResolveByKeep() == true && Cache
.BrokenCount() == 0;
91 // PM::DepAlwaysTrue - Returns true if this dep is irrelevent /*{{{*/
92 // ---------------------------------------------------------------------
93 /* The restriction on provides is to eliminate the case when provides
94 are transitioning between valid states [ie exim to smail] */
95 bool pkgPackageManager::DepAlwaysTrue(DepIterator D
)
97 if (D
.TargetPkg()->ProvidesList
!= 0)
100 if ((Cache
[D
] & pkgDepCache::DepInstall
) != 0 &&
101 (Cache
[D
] & pkgDepCache::DepNow
) != 0)
106 // PM::CheckRConflicts - Look for reverse conflicts /*{{{*/
107 // ---------------------------------------------------------------------
108 /* This looks over the reverses for a conflicts line that needs early
110 bool pkgPackageManager::CheckRConflicts(PkgIterator Pkg
,DepIterator D
,
113 for (;D
.end() == false; D
++)
115 if (D
->Type
!= pkgCache::Dep::Conflicts
)
118 if (D
.ParentPkg() == Pkg
)
121 if (pkgCheckDep(D
.TargetVer(),Ver
,D
->CompareOp
) == false)
124 if (List
->IsNow(Pkg
) == false)
127 if (EarlyRemove(D
.ParentPkg()) == false)
133 // PM::ConfigureAll - Run the all out configuration /*{{{*/
134 // ---------------------------------------------------------------------
135 /* This configures every package. It is assumed they are all unpacked and
136 that the final configuration is valid. */
137 bool pkgPackageManager::ConfigureAll()
139 pkgOrderList
OList(Cache
);
141 // Populate the order list
142 for (pkgOrderList::iterator I
= List
->begin(); I
!= List
->end(); I
++)
143 if (List
->IsFlag(pkgCache::PkgIterator(Cache
,*I
),
144 pkgOrderList::UnPacked
) == true)
147 if (OList
.OrderConfigure() == false)
150 // Perform the configuring
151 for (pkgOrderList::iterator I
= OList
.begin(); I
!= OList
.end(); I
++)
153 PkgIterator
Pkg(Cache
,*I
);
155 if (Configure(Pkg
) == false)
158 List
->Flag(Pkg
,pkgOrderList::Configured
,pkgOrderList::States
);
164 // PM::SmartConfigure - Perform immediate configuration of the pkg /*{{{*/
165 // ---------------------------------------------------------------------
166 /* This routine scheduals the configuration of the given package and all
167 of it's dependents. */
168 bool pkgPackageManager::SmartConfigure(PkgIterator Pkg
)
170 pkgOrderList
OList(Cache
);
172 if (DepAdd(OList
,Pkg
) == false)
175 if (OList
.OrderConfigure() == false)
178 // Perform the configuring
179 for (pkgOrderList::iterator I
= OList
.begin(); I
!= OList
.end(); I
++)
181 PkgIterator
Pkg(Cache
,*I
);
183 if (Configure(Pkg
) == false)
186 List
->Flag(Pkg
,pkgOrderList::Configured
,pkgOrderList::States
);
190 if (List
->IsFlag(Pkg
,pkgOrderList::Configured
) == false)
191 return _error
->Error("Internal error, could not immediate configure %s",Pkg
.Name());
196 // PM::DepAdd - Add all dependents to the oder list /*{{{*/
197 // ---------------------------------------------------------------------
198 /* This recursively adds all dependents to the order list */
199 bool pkgPackageManager::DepAdd(pkgOrderList
&OList
,PkgIterator Pkg
,int Depth
)
201 if (OList
.IsFlag(Pkg
,pkgOrderList::Added
) == true)
203 if (List
->IsFlag(Pkg
,pkgOrderList::Configured
) == true)
205 if (List
->IsFlag(Pkg
,pkgOrderList::UnPacked
) == false)
209 // Put the package on the list
210 OList
.push_back(Pkg
);
211 OList
.Flag(Pkg
,pkgOrderList::Added
);
214 // Check the dependencies to see if they are all satisfied.
216 for (DepIterator D
= Cache
[Pkg
].InstVerIter(Cache
).DependsList(); D
.end() == false;)
218 if (D
->Type
!= pkgCache::Dep::Depends
&& D
->Type
!= pkgCache::Dep::PreDepends
)
226 for (bool LastOR
= true; D
.end() == false && LastOR
== true; D
++)
228 LastOR
= (D
->CompareOp
& pkgCache::Dep::Or
) == pkgCache::Dep::Or
;
233 Version
**VList
= D
.AllTargets();
234 for (Version
**I
= VList
; *I
!= 0 && Bad
== true; I
++)
236 VerIterator
Ver(Cache
,*I
);
237 PkgIterator Pkg
= Ver
.ParentPkg();
239 // See if the current version is ok
240 if (Pkg
.CurrentVer() == Ver
&& List
->IsNow(Pkg
) == true &&
241 Pkg
.State() == PkgIterator::NeedsNothing
)
247 // Not the install version
248 if (Cache
[Pkg
].InstallVer
!= *I
||
249 (Cache
[Pkg
].Keep() == true && Pkg
.State() == PkgIterator::NeedsNothing
))
251 if (List
->IsFlag(Pkg
,pkgOrderList::UnPacked
) == true)
252 Bad
= !DepAdd(OList
,Pkg
,Depth
);
253 if (List
->IsFlag(Pkg
,pkgOrderList::Configured
) == true)
261 OList
.Flag(Pkg
,0,pkgOrderList::Added
);
272 // PM::EarlyRemove - Perform removal of packages before their time /*{{{*/
273 // ---------------------------------------------------------------------
274 /* This is called to deal with conflicts arising from unpacking */
275 bool pkgPackageManager::EarlyRemove(PkgIterator Pkg
)
277 if (List
->IsNow(Pkg
) == false)
280 // Already removed it
281 if (List
->IsFlag(Pkg
,pkgOrderList::Removed
) == true)
284 // Woops, it will not be re-installed!
285 if (List
->IsFlag(Pkg
,pkgOrderList::InList
) == false)
288 bool Res
= SmartRemove(Pkg
);
289 if (Cache
[Pkg
].Delete() == false)
290 List
->Flag(Pkg
,pkgOrderList::Removed
,pkgOrderList::States
);
295 // PM::SmartRemove - Removal Helper /*{{{*/
296 // ---------------------------------------------------------------------
298 bool pkgPackageManager::SmartRemove(PkgIterator Pkg
)
300 if (List
->IsNow(Pkg
) == false)
303 List
->Flag(Pkg
,pkgOrderList::Configured
,pkgOrderList::States
);
307 // PM::SmartUnPack - Install helper /*{{{*/
308 // ---------------------------------------------------------------------
309 /* This performs the task of handling pre-depends. */
310 bool pkgPackageManager::SmartUnPack(PkgIterator Pkg
)
312 // Check if it is already unpacked
313 if (Pkg
.State() == pkgCache::PkgIterator::NeedsConfigure
&&
314 Cache
[Pkg
].Keep() == true)
316 List
->Flag(Pkg
,pkgOrderList::UnPacked
,pkgOrderList::States
);
317 if (List
->IsFlag(Pkg
,pkgOrderList::Immediate
) == true)
318 if (SmartConfigure(Pkg
) == false)
319 return _error
->Error("Internal Error, Could not perform immediate configuraton");
323 /* See if this packages install version has any predependencies
324 that are not met by 'now' packages. */
325 for (DepIterator D
= Cache
[Pkg
].InstVerIter(Cache
).DependsList();
326 D
.end() == false; D
++)
328 if (D
->Type
== pkgCache::Dep::PreDepends
)
330 // Look for possible ok targets.
331 Version
**VList
= D
.AllTargets();
333 for (Version
**I
= VList
; *I
!= 0 && Bad
== true; I
++)
335 VerIterator
Ver(Cache
,*I
);
336 PkgIterator Pkg
= Ver
.ParentPkg();
338 // See if the current version is ok
339 if (Pkg
.CurrentVer() == Ver
&& List
->IsNow(Pkg
) == true &&
340 Pkg
.State() == PkgIterator::NeedsNothing
)
347 // Look for something that could be configured.
348 for (Version
**I
= VList
; *I
!= 0 && Bad
== true; I
++)
350 VerIterator
Ver(Cache
,*I
);
351 PkgIterator Pkg
= Ver
.ParentPkg();
353 // Not the install version
354 if (Cache
[Pkg
].InstallVer
!= *I
||
355 (Cache
[Pkg
].Keep() == true && Pkg
.State() == PkgIterator::NeedsNothing
))
358 Bad
= !SmartConfigure(Pkg
);
364 return _error
->Error("Internal Error, Couldn't configure a pre-depend");
369 if (D
->Type
== pkgCache::Dep::Conflicts
)
371 /* Look for conflicts. Two packages that are both in the install
372 state cannot conflict so we don't check.. */
373 Version
**VList
= D
.AllTargets();
374 for (Version
**I
= VList
; *I
!= 0; I
++)
376 VerIterator
Ver(Cache
,*I
);
377 PkgIterator Pkg
= Ver
.ParentPkg();
379 // See if the current version is conflicting
380 if (Pkg
.CurrentVer() == Ver
&& List
->IsNow(Pkg
) == true)
382 if (EarlyRemove(Pkg
) == false)
383 return _error
->Error("Internal Error, Could not early remove %s",Pkg
.Name());
390 // Check for reverse conflicts.
391 CheckRConflicts(Pkg
,Pkg
.RevDependsList(),
392 Cache
[Pkg
].InstVerIter(Cache
).VerStr());
393 for (PrvIterator P
= Cache
[Pkg
].InstVerIter(Cache
).ProvidesList();
394 P
.end() == false; P
++)
395 CheckRConflicts(Pkg
,P
.ParentPkg().RevDependsList(),P
.ProvideVersion());
397 if (Install(Pkg
,FileNames
[Pkg
->ID
]) == false)
400 List
->Flag(Pkg
,pkgOrderList::UnPacked
,pkgOrderList::States
);
402 // Perform immedate configuration of the package.
403 if (List
->IsFlag(Pkg
,pkgOrderList::Immediate
) == true)
404 if (SmartConfigure(Pkg
) == false)
405 return _error
->Error("Internal Error, Could not perform immediate configuraton");
410 // PM::OrderInstall - Installation ordering routine /*{{{*/
411 // ---------------------------------------------------------------------
413 bool pkgPackageManager::OrderInstall()
416 List
= new pkgOrderList(Cache
);
418 // Generate the list of affected packages and sort it
419 for (PkgIterator I
= Cache
.PkgBegin(); I
.end() == false; I
++)
421 // Consider all depends
422 if ((I
->Flags
& pkgCache::Flag::Essential
) == pkgCache::Flag::Essential
)
424 List
->Flag(I
,pkgOrderList::Immediate
);
425 if (Cache
[I
].InstallVer
!= 0)
426 for (DepIterator D
= Cache
[I
].InstVerIter(Cache
).DependsList();
427 D
.end() == false; D
++)
428 if (D
->Type
== pkgCache::Dep::Depends
|| D
->Type
== pkgCache::Dep::PreDepends
)
429 List
->Flag(D
.TargetPkg(),pkgOrderList::Immediate
);
430 if (I
->CurrentVer
!= 0)
431 for (DepIterator D
= I
.CurrentVer().DependsList();
432 D
.end() == false; D
++)
433 if (D
->Type
== pkgCache::Dep::Depends
|| D
->Type
== pkgCache::Dep::PreDepends
)
434 List
->Flag(D
.TargetPkg(),pkgOrderList::Immediate
);
438 if ((Cache
[I
].Keep() == true ||
439 Cache
[I
].InstVerIter(Cache
) == I
.CurrentVer()) &&
440 I
.State() == pkgCache::PkgIterator::NeedsNothing
)
443 // Append it to the list
446 if ((I
->Flags
& pkgCache::Flag::ImmediateConf
) == pkgCache::Flag::ImmediateConf
)
447 List
->Flag(I
,pkgOrderList::Immediate
);
451 clog
<< "Begining to order" << endl
;
453 if (List
->OrderUnpack() == false)
454 return _error
->Error("Internal ordering error");
457 clog
<< "Done ordering" << endl
;
459 for (pkgOrderList::iterator I
= List
->begin(); I
!= List
->end(); I
++)
461 PkgIterator
Pkg(Cache
,*I
);
464 if (Cache
[Pkg
].Keep() == true && Pkg
.State() == pkgCache::PkgIterator::NeedsNothing
)
465 return _error
->Error("Internal Error, trying to manipulate a kept package");
467 // Perform a delete or an install
468 if (Cache
[Pkg
].Delete() == true)
470 if (SmartRemove(Pkg
) == false)
474 if (SmartUnPack(Pkg
) == false)
478 // Final run through the configure phase
479 if (ConfigureAll() == false)
483 for (pkgOrderList::iterator I
= List
->begin(); I
!= List
->end(); I
++)
484 if (List
->IsFlag(*I
,pkgOrderList::Configured
) == false)
485 return _error
->Error("Internal error, packages left unconfigured. %s",
486 PkgIterator(Cache
,*I
).Name());
491 // PM::DoInstall - Does the installation /*{{{*/
492 // ---------------------------------------------------------------------
493 /* This uses the filenames in FileNames and the information in the
494 DepCache to perform the installation of packages.*/
495 bool pkgPackageManager::DoInstall()
497 return OrderInstall() && Go();