]>
Commit | Line | Data |
---|---|---|
6c139d6e AL |
1 | // -*- mode: cpp; mode: fold -*- |
2 | // Description /*{{{*/ | |
b9c0654c | 3 | // $Id: packagemanager.cc,v 1.30 2003/04/27 03:04:15 doogie Exp $ |
6c139d6e AL |
4 | /* ###################################################################### |
5 | ||
6 | Package Manager - Abstacts the package manager | |
7 | ||
8 | More work is needed in the area of transitioning provides, ie exim | |
9 | replacing smail. This can cause interesing side effects. | |
10 | ||
11 | Other cases involving conflicts+replaces should be tested. | |
12 | ||
13 | ##################################################################### */ | |
14 | /*}}}*/ | |
15 | // Include Files /*{{{*/ | |
094a497d AL |
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> | |
03e39e59 | 21 | #include <apt-pkg/acquire-item.h> |
30e1eab5 AL |
22 | #include <apt-pkg/algorithms.h> |
23 | #include <apt-pkg/configuration.h> | |
b2e465d6 AL |
24 | #include <apt-pkg/sptr.h> |
25 | ||
26 | #include <apti18n.h> | |
5819a761 | 27 | #include <iostream> |
1d6386f3 | 28 | #include <fcntl.h> |
92fcbfc1 | 29 | /*}}}*/ |
5819a761 AL |
30 | using namespace std; |
31 | ||
6c139d6e AL |
32 | // PM::PackageManager - Constructor /*{{{*/ |
33 | // --------------------------------------------------------------------- | |
34 | /* */ | |
b2e465d6 | 35 | pkgPackageManager::pkgPackageManager(pkgDepCache *pCache) : Cache(*pCache) |
6c139d6e AL |
36 | { |
37 | FileNames = new string[Cache.Head().PackageCount]; | |
38 | List = 0; | |
30e1eab5 | 39 | Debug = _config->FindB("Debug::pkgPackageManager",false); |
6c139d6e AL |
40 | } |
41 | /*}}}*/ | |
42 | // PM::PackageManager - Destructor /*{{{*/ | |
43 | // --------------------------------------------------------------------- | |
44 | /* */ | |
45 | pkgPackageManager::~pkgPackageManager() | |
46 | { | |
47 | delete List; | |
48 | delete [] FileNames; | |
49 | } | |
50 | /*}}}*/ | |
03e39e59 AL |
51 | // PM::GetArchives - Queue the archives for download /*{{{*/ |
52 | // --------------------------------------------------------------------- | |
53 | /* */ | |
54 | bool pkgPackageManager::GetArchives(pkgAcquire *Owner,pkgSourceList *Sources, | |
55 | pkgRecords *Recs) | |
56 | { | |
7a1b1f8b AL |
57 | if (CreateOrderList() == false) |
58 | return false; | |
59 | ||
5e312de7 DK |
60 | bool const ordering = |
61 | _config->FindB("PackageManager::UnpackAll",true) ? | |
62 | List->OrderUnpack() : List->OrderCritical(); | |
63 | if (ordering == false) | |
7a1b1f8b AL |
64 | return _error->Error("Internal ordering error"); |
65 | ||
66 | for (pkgOrderList::iterator I = List->begin(); I != List->end(); I++) | |
67 | { | |
68 | PkgIterator Pkg(Cache,*I); | |
281daf46 AL |
69 | FileNames[Pkg->ID] = string(); |
70 | ||
7a1b1f8b AL |
71 | // Skip packages to erase |
72 | if (Cache[Pkg].Delete() == true) | |
03e39e59 | 73 | continue; |
d38b7b3d AL |
74 | |
75 | // Skip Packages that need configure only. | |
9dbb421f AL |
76 | if (Pkg.State() == pkgCache::PkgIterator::NeedsConfigure && |
77 | Cache[Pkg].Keep() == true) | |
d38b7b3d | 78 | continue; |
281daf46 AL |
79 | |
80 | // Skip already processed packages | |
81 | if (List->IsNow(Pkg) == false) | |
82 | continue; | |
803ea2a8 DK |
83 | |
84 | if (pkgCache::VerIterator(Cache, Cache[Pkg].CandidateVer).Pseudo() == true) | |
85 | continue; | |
86 | ||
7a1b1f8b AL |
87 | new pkgAcqArchive(Owner,Sources,Recs,Cache[Pkg].InstVerIter(Cache), |
88 | FileNames[Pkg->ID]); | |
03e39e59 | 89 | } |
7a1b1f8b | 90 | |
03e39e59 AL |
91 | return true; |
92 | } | |
93 | /*}}}*/ | |
6c139d6e AL |
94 | // PM::FixMissing - Keep all missing packages /*{{{*/ |
95 | // --------------------------------------------------------------------- | |
96 | /* This is called to correct the installation when packages could not | |
97 | be downloaded. */ | |
98 | bool pkgPackageManager::FixMissing() | |
bdae53f1 | 99 | { |
e6756cde | 100 | pkgDepCache::ActionGroup group(Cache); |
b2e465d6 | 101 | pkgProblemResolver Resolve(&Cache); |
2fd65468 | 102 | List->SetFileList(FileNames); |
e6756cde | 103 | |
9dbb421f | 104 | bool Bad = false; |
6c139d6e AL |
105 | for (PkgIterator I = Cache.PkgBegin(); I.end() == false; I++) |
106 | { | |
2fd65468 | 107 | if (List->IsMissing(I) == false) |
9dbb421f | 108 | continue; |
2fd65468 | 109 | |
9dbb421f AL |
110 | // Okay, this file is missing and we need it. Mark it for keep |
111 | Bad = true; | |
74a05226 | 112 | Cache.MarkKeep(I, false, false); |
6c139d6e | 113 | } |
bdae53f1 AL |
114 | |
115 | // We have to empty the list otherwise it will not have the new changes | |
116 | delete List; | |
117 | List = 0; | |
6c139d6e | 118 | |
9dbb421f AL |
119 | if (Bad == false) |
120 | return true; | |
121 | ||
6c139d6e | 122 | // Now downgrade everything that is broken |
30e1eab5 | 123 | return Resolve.ResolveByKeep() == true && Cache.BrokenCount() == 0; |
6c139d6e AL |
124 | } |
125 | /*}}}*/ | |
3a6d37fd MV |
126 | // PM::ImmediateAdd - Add the immediate flag recursivly /*{{{*/ |
127 | // --------------------------------------------------------------------- | |
128 | /* This adds the immediate flag to the pkg and recursively to the | |
129 | dependendies | |
130 | */ | |
d183f850 | 131 | void pkgPackageManager::ImmediateAdd(PkgIterator I, bool UseInstallVer, unsigned const int &Depth) |
3a6d37fd MV |
132 | { |
133 | DepIterator D; | |
134 | ||
135 | if(UseInstallVer) | |
136 | { | |
137 | if(Cache[I].InstallVer == 0) | |
138 | return; | |
139 | D = Cache[I].InstVerIter(Cache).DependsList(); | |
140 | } else { | |
141 | if (I->CurrentVer == 0) | |
142 | return; | |
143 | D = I.CurrentVer().DependsList(); | |
144 | } | |
145 | ||
146 | for ( /* nothing */ ; D.end() == false; D++) | |
147 | if (D->Type == pkgCache::Dep::Depends || D->Type == pkgCache::Dep::PreDepends) | |
148 | { | |
149 | if(!List->IsFlag(D.TargetPkg(), pkgOrderList::Immediate)) | |
150 | { | |
151 | if(Debug) | |
d183f850 | 152 | clog << OutputInDepth(Depth) << "ImmediateAdd(): Adding Immediate flag to " << D.TargetPkg() << " cause of " << D.DepType() << " " << I.Name() << endl; |
3a6d37fd | 153 | List->Flag(D.TargetPkg(),pkgOrderList::Immediate); |
d183f850 | 154 | ImmediateAdd(D.TargetPkg(), UseInstallVer, Depth + 1); |
3a6d37fd MV |
155 | } |
156 | } | |
157 | return; | |
158 | } | |
159 | /*}}}*/ | |
7a1b1f8b AL |
160 | // PM::CreateOrderList - Create the ordering class /*{{{*/ |
161 | // --------------------------------------------------------------------- | |
162 | /* This populates the ordering list with all the packages that are | |
163 | going to change. */ | |
164 | bool pkgPackageManager::CreateOrderList() | |
165 | { | |
281daf46 AL |
166 | if (List != 0) |
167 | return true; | |
168 | ||
7a1b1f8b | 169 | delete List; |
b2e465d6 | 170 | List = new pkgOrderList(&Cache); |
7a1b1f8b | 171 | |
5e312de7 | 172 | static bool const NoImmConfigure = !_config->FindB("APT::Immediate-Configure",true); |
079cc404 | 173 | |
7a1b1f8b AL |
174 | // Generate the list of affected packages and sort it |
175 | for (PkgIterator I = Cache.PkgBegin(); I.end() == false; I++) | |
176 | { | |
e7b470ee AL |
177 | // Ignore no-version packages |
178 | if (I->VersionList == 0) | |
179 | continue; | |
180 | ||
138d4b3d AL |
181 | // Mark the package and its dependends for immediate configuration |
182 | if (((I->Flags & pkgCache::Flag::Essential) == pkgCache::Flag::Essential || | |
183 | (I->Flags & pkgCache::Flag::Important) == pkgCache::Flag::Important) && | |
079cc404 | 184 | NoImmConfigure == false) |
7a1b1f8b | 185 | { |
3a6d37fd MV |
186 | if(Debug) |
187 | clog << "CreateOrderList(): Adding Immediate flag for " << I.Name() << endl; | |
7a1b1f8b | 188 | List->Flag(I,pkgOrderList::Immediate); |
3a6d37fd MV |
189 | |
190 | // Look for other install packages to make immediate configurea | |
191 | ImmediateAdd(I, true); | |
d38b7b3d AL |
192 | |
193 | // And again with the current version. | |
3a6d37fd | 194 | ImmediateAdd(I, false); |
7a1b1f8b AL |
195 | } |
196 | ||
197 | // Not interesting | |
198 | if ((Cache[I].Keep() == true || | |
199 | Cache[I].InstVerIter(Cache) == I.CurrentVer()) && | |
d556d1a1 | 200 | I.State() == pkgCache::PkgIterator::NeedsNothing && |
d0c59649 | 201 | (Cache[I].iFlags & pkgDepCache::ReInstall) != pkgDepCache::ReInstall && |
d556d1a1 AL |
202 | (I.Purge() != false || Cache[I].Mode != pkgDepCache::ModeDelete || |
203 | (Cache[I].iFlags & pkgDepCache::Purge) != pkgDepCache::Purge)) | |
7a1b1f8b AL |
204 | continue; |
205 | ||
206 | // Append it to the list | |
138d4b3d | 207 | List->push_back(I); |
7a1b1f8b AL |
208 | } |
209 | ||
210 | return true; | |
211 | } | |
212 | /*}}}*/ | |
6c139d6e AL |
213 | // PM::DepAlwaysTrue - Returns true if this dep is irrelevent /*{{{*/ |
214 | // --------------------------------------------------------------------- | |
215 | /* The restriction on provides is to eliminate the case when provides | |
216 | are transitioning between valid states [ie exim to smail] */ | |
217 | bool pkgPackageManager::DepAlwaysTrue(DepIterator D) | |
218 | { | |
219 | if (D.TargetPkg()->ProvidesList != 0) | |
220 | return false; | |
221 | ||
222 | if ((Cache[D] & pkgDepCache::DepInstall) != 0 && | |
223 | (Cache[D] & pkgDepCache::DepNow) != 0) | |
224 | return true; | |
225 | return false; | |
226 | } | |
227 | /*}}}*/ | |
228 | // PM::CheckRConflicts - Look for reverse conflicts /*{{{*/ | |
229 | // --------------------------------------------------------------------- | |
230 | /* This looks over the reverses for a conflicts line that needs early | |
231 | removal. */ | |
232 | bool pkgPackageManager::CheckRConflicts(PkgIterator Pkg,DepIterator D, | |
233 | const char *Ver) | |
234 | { | |
235 | for (;D.end() == false; D++) | |
236 | { | |
b2e465d6 AL |
237 | if (D->Type != pkgCache::Dep::Conflicts && |
238 | D->Type != pkgCache::Dep::Obsoletes) | |
6c139d6e | 239 | continue; |
5af32db6 AL |
240 | |
241 | // The package hasnt been changed | |
242 | if (List->IsNow(Pkg) == false) | |
243 | continue; | |
6c139d6e | 244 | |
5af32db6 AL |
245 | // Ignore self conflicts, ignore conflicts from irrelevent versions |
246 | if (D.ParentPkg() == Pkg || D.ParentVer() != D.ParentPkg().CurrentVer()) | |
6c139d6e AL |
247 | continue; |
248 | ||
b2e465d6 | 249 | if (Cache.VS().CheckDep(Ver,D->CompareOp,D.TargetVer()) == false) |
6c139d6e | 250 | continue; |
b2e465d6 | 251 | |
6c139d6e | 252 | if (EarlyRemove(D.ParentPkg()) == false) |
5af32db6 AL |
253 | return _error->Error("Reverse conflicts early remove for package '%s' failed", |
254 | Pkg.Name()); | |
255 | } | |
6c139d6e AL |
256 | return true; |
257 | } | |
258 | /*}}}*/ | |
259 | // PM::ConfigureAll - Run the all out configuration /*{{{*/ | |
260 | // --------------------------------------------------------------------- | |
261 | /* This configures every package. It is assumed they are all unpacked and | |
262 | that the final configuration is valid. */ | |
263 | bool pkgPackageManager::ConfigureAll() | |
264 | { | |
b2e465d6 | 265 | pkgOrderList OList(&Cache); |
6c139d6e AL |
266 | |
267 | // Populate the order list | |
268 | for (pkgOrderList::iterator I = List->begin(); I != List->end(); I++) | |
269 | if (List->IsFlag(pkgCache::PkgIterator(Cache,*I), | |
270 | pkgOrderList::UnPacked) == true) | |
271 | OList.push_back(*I); | |
272 | ||
273 | if (OList.OrderConfigure() == false) | |
274 | return false; | |
5e312de7 DK |
275 | |
276 | std::string const conf = _config->Find("PackageManager::Configure","all"); | |
277 | bool const ConfigurePkgs = (conf == "all"); | |
278 | ||
6c139d6e AL |
279 | // Perform the configuring |
280 | for (pkgOrderList::iterator I = OList.begin(); I != OList.end(); I++) | |
281 | { | |
282 | PkgIterator Pkg(Cache,*I); | |
803ea2a8 DK |
283 | |
284 | if (ConfigurePkgs == true && | |
285 | pkgCache::VerIterator(Cache, Cache[Pkg].CandidateVer).Pseudo() == false && | |
286 | Configure(Pkg) == false) | |
6c139d6e AL |
287 | return false; |
288 | ||
289 | List->Flag(Pkg,pkgOrderList::Configured,pkgOrderList::States); | |
290 | } | |
291 | ||
292 | return true; | |
293 | } | |
294 | /*}}}*/ | |
295 | // PM::SmartConfigure - Perform immediate configuration of the pkg /*{{{*/ | |
296 | // --------------------------------------------------------------------- | |
297 | /* This routine scheduals the configuration of the given package and all | |
298 | of it's dependents. */ | |
299 | bool pkgPackageManager::SmartConfigure(PkgIterator Pkg) | |
300 | { | |
b2e465d6 | 301 | pkgOrderList OList(&Cache); |
6c139d6e AL |
302 | |
303 | if (DepAdd(OList,Pkg) == false) | |
304 | return false; | |
5e312de7 DK |
305 | |
306 | static std::string const conf = _config->Find("PackageManager::Configure","all"); | |
307 | static bool const ConfigurePkgs = (conf == "all" || conf == "smart"); | |
308 | ||
309 | if (ConfigurePkgs == true) | |
310 | if (OList.OrderConfigure() == false) | |
311 | return false; | |
312 | ||
6c139d6e AL |
313 | // Perform the configuring |
314 | for (pkgOrderList::iterator I = OList.begin(); I != OList.end(); I++) | |
315 | { | |
316 | PkgIterator Pkg(Cache,*I); | |
317 | ||
803ea2a8 DK |
318 | if (ConfigurePkgs == true && |
319 | pkgCache::VerIterator(Cache, Cache[Pkg].CandidateVer).Pseudo() == false && | |
320 | Configure(Pkg) == false) | |
6c139d6e AL |
321 | return false; |
322 | ||
323 | List->Flag(Pkg,pkgOrderList::Configured,pkgOrderList::States); | |
324 | } | |
325 | ||
326 | // Sanity Check | |
327 | if (List->IsFlag(Pkg,pkgOrderList::Configured) == false) | |
20382bad DK |
328 | return _error->Error(_("Could not perform immediate configuration on '%s'." |
329 | "Please see man 5 apt.conf under APT::Immediate-Configure for details. (%d)"),Pkg.Name(),1); | |
330 | ||
6c139d6e AL |
331 | return true; |
332 | } | |
333 | /*}}}*/ | |
334 | // PM::DepAdd - Add all dependents to the oder list /*{{{*/ | |
335 | // --------------------------------------------------------------------- | |
336 | /* This recursively adds all dependents to the order list */ | |
337 | bool pkgPackageManager::DepAdd(pkgOrderList &OList,PkgIterator Pkg,int Depth) | |
338 | { | |
339 | if (OList.IsFlag(Pkg,pkgOrderList::Added) == true) | |
340 | return true; | |
341 | if (List->IsFlag(Pkg,pkgOrderList::Configured) == true) | |
342 | return true; | |
343 | if (List->IsFlag(Pkg,pkgOrderList::UnPacked) == false) | |
344 | return false; | |
b2e465d6 | 345 | |
6c139d6e AL |
346 | // Put the package on the list |
347 | OList.push_back(Pkg); | |
348 | OList.Flag(Pkg,pkgOrderList::Added); | |
349 | Depth++; | |
350 | ||
351 | // Check the dependencies to see if they are all satisfied. | |
352 | bool Bad = false; | |
353 | for (DepIterator D = Cache[Pkg].InstVerIter(Cache).DependsList(); D.end() == false;) | |
354 | { | |
b50b2c97 | 355 | if (D->Type != pkgCache::Dep::Depends && D->Type != pkgCache::Dep::PreDepends) |
6c139d6e AL |
356 | { |
357 | D++; | |
358 | continue; | |
359 | } | |
360 | ||
361 | // Grok or groups | |
362 | Bad = true; | |
363 | for (bool LastOR = true; D.end() == false && LastOR == true; D++) | |
364 | { | |
b50b2c97 | 365 | LastOR = (D->CompareOp & pkgCache::Dep::Or) == pkgCache::Dep::Or; |
6c139d6e AL |
366 | |
367 | if (Bad == false) | |
368 | continue; | |
369 | ||
b2e465d6 | 370 | SPtrArray<Version *> VList = D.AllTargets(); |
6c139d6e AL |
371 | for (Version **I = VList; *I != 0 && Bad == true; I++) |
372 | { | |
373 | VerIterator Ver(Cache,*I); | |
374 | PkgIterator Pkg = Ver.ParentPkg(); | |
375 | ||
376 | // See if the current version is ok | |
377 | if (Pkg.CurrentVer() == Ver && List->IsNow(Pkg) == true && | |
378 | Pkg.State() == PkgIterator::NeedsNothing) | |
379 | { | |
380 | Bad = false; | |
381 | continue; | |
382 | } | |
383 | ||
384 | // Not the install version | |
385 | if (Cache[Pkg].InstallVer != *I || | |
386 | (Cache[Pkg].Keep() == true && Pkg.State() == PkgIterator::NeedsNothing)) | |
387 | continue; | |
b2e465d6 | 388 | |
6c139d6e AL |
389 | if (List->IsFlag(Pkg,pkgOrderList::UnPacked) == true) |
390 | Bad = !DepAdd(OList,Pkg,Depth); | |
391 | if (List->IsFlag(Pkg,pkgOrderList::Configured) == true) | |
392 | Bad = false; | |
393 | } | |
6c139d6e AL |
394 | } |
395 | ||
396 | if (Bad == true) | |
397 | { | |
398 | OList.Flag(Pkg,0,pkgOrderList::Added); | |
399 | OList.pop_back(); | |
400 | Depth--; | |
401 | return false; | |
402 | } | |
403 | } | |
404 | ||
405 | Depth--; | |
406 | return true; | |
407 | } | |
408 | /*}}}*/ | |
409 | // PM::EarlyRemove - Perform removal of packages before their time /*{{{*/ | |
410 | // --------------------------------------------------------------------- | |
411 | /* This is called to deal with conflicts arising from unpacking */ | |
412 | bool pkgPackageManager::EarlyRemove(PkgIterator Pkg) | |
413 | { | |
414 | if (List->IsNow(Pkg) == false) | |
415 | return true; | |
416 | ||
417 | // Already removed it | |
418 | if (List->IsFlag(Pkg,pkgOrderList::Removed) == true) | |
419 | return true; | |
420 | ||
421 | // Woops, it will not be re-installed! | |
422 | if (List->IsFlag(Pkg,pkgOrderList::InList) == false) | |
423 | return false; | |
9d4c8f67 AL |
424 | |
425 | // Essential packages get special treatment | |
5af32db6 | 426 | bool IsEssential = false; |
9d4c8f67 | 427 | if ((Pkg->Flags & pkgCache::Flag::Essential) != 0) |
5af32db6 AL |
428 | IsEssential = true; |
429 | ||
430 | /* Check for packages that are the dependents of essential packages and | |
431 | promote them too */ | |
432 | if (Pkg->CurrentVer != 0) | |
433 | { | |
434 | for (DepIterator D = Pkg.RevDependsList(); D.end() == false && | |
435 | IsEssential == false; D++) | |
436 | if (D->Type == pkgCache::Dep::Depends || D->Type == pkgCache::Dep::PreDepends) | |
437 | if ((D.ParentPkg()->Flags & pkgCache::Flag::Essential) != 0) | |
438 | IsEssential = true; | |
439 | } | |
440 | ||
441 | if (IsEssential == true) | |
9d4c8f67 AL |
442 | { |
443 | if (_config->FindB("APT::Force-LoopBreak",false) == false) | |
b2e465d6 AL |
444 | return _error->Error(_("This installation run will require temporarily " |
445 | "removing the essential package %s due to a " | |
446 | "Conflicts/Pre-Depends loop. This is often bad, " | |
447 | "but if you really want to do it, activate the " | |
448 | "APT::Force-LoopBreak option."),Pkg.Name()); | |
9d4c8f67 | 449 | } |
6c139d6e AL |
450 | |
451 | bool Res = SmartRemove(Pkg); | |
452 | if (Cache[Pkg].Delete() == false) | |
453 | List->Flag(Pkg,pkgOrderList::Removed,pkgOrderList::States); | |
454 | ||
455 | return Res; | |
456 | } | |
457 | /*}}}*/ | |
458 | // PM::SmartRemove - Removal Helper /*{{{*/ | |
459 | // --------------------------------------------------------------------- | |
460 | /* */ | |
461 | bool pkgPackageManager::SmartRemove(PkgIterator Pkg) | |
462 | { | |
463 | if (List->IsNow(Pkg) == false) | |
464 | return true; | |
465 | ||
466 | List->Flag(Pkg,pkgOrderList::Configured,pkgOrderList::States); | |
803ea2a8 DK |
467 | |
468 | if (pkgCache::VerIterator(Cache, Cache[Pkg].CandidateVer).Pseudo() == false) | |
469 | return Remove(Pkg,(Cache[Pkg].iFlags & pkgDepCache::Purge) == pkgDepCache::Purge); | |
470 | return true; | |
6c139d6e AL |
471 | } |
472 | /*}}}*/ | |
473 | // PM::SmartUnPack - Install helper /*{{{*/ | |
474 | // --------------------------------------------------------------------- | |
475 | /* This performs the task of handling pre-depends. */ | |
476 | bool pkgPackageManager::SmartUnPack(PkgIterator Pkg) | |
477 | { | |
478 | // Check if it is already unpacked | |
479 | if (Pkg.State() == pkgCache::PkgIterator::NeedsConfigure && | |
480 | Cache[Pkg].Keep() == true) | |
481 | { | |
482 | List->Flag(Pkg,pkgOrderList::UnPacked,pkgOrderList::States); | |
483 | if (List->IsFlag(Pkg,pkgOrderList::Immediate) == true) | |
484 | if (SmartConfigure(Pkg) == false) | |
20382bad | 485 | return _error->Error(_("Could not perform immediate configuration on already unpacked '%s'." |
f66a64c2 | 486 | "Please see man 5 apt.conf under APT::Immediate-Configure for details."),Pkg.Name()); |
6c139d6e AL |
487 | return true; |
488 | } | |
981d20eb | 489 | |
6c139d6e AL |
490 | /* See if this packages install version has any predependencies |
491 | that are not met by 'now' packages. */ | |
492 | for (DepIterator D = Cache[Pkg].InstVerIter(Cache).DependsList(); | |
421c8d10 | 493 | D.end() == false; ) |
6c139d6e | 494 | { |
421c8d10 AL |
495 | // Compute a single dependency element (glob or) |
496 | pkgCache::DepIterator Start; | |
497 | pkgCache::DepIterator End; | |
498 | D.GlobOr(Start,End); | |
499 | ||
500 | while (End->Type == pkgCache::Dep::PreDepends) | |
6c139d6e AL |
501 | { |
502 | // Look for possible ok targets. | |
b2e465d6 | 503 | SPtrArray<Version *> VList = Start.AllTargets(); |
6c139d6e AL |
504 | bool Bad = true; |
505 | for (Version **I = VList; *I != 0 && Bad == true; I++) | |
506 | { | |
507 | VerIterator Ver(Cache,*I); | |
508 | PkgIterator Pkg = Ver.ParentPkg(); | |
509 | ||
510 | // See if the current version is ok | |
511 | if (Pkg.CurrentVer() == Ver && List->IsNow(Pkg) == true && | |
512 | Pkg.State() == PkgIterator::NeedsNothing) | |
513 | { | |
514 | Bad = false; | |
515 | continue; | |
516 | } | |
517 | } | |
518 | ||
519 | // Look for something that could be configured. | |
520 | for (Version **I = VList; *I != 0 && Bad == true; I++) | |
521 | { | |
522 | VerIterator Ver(Cache,*I); | |
523 | PkgIterator Pkg = Ver.ParentPkg(); | |
524 | ||
525 | // Not the install version | |
526 | if (Cache[Pkg].InstallVer != *I || | |
527 | (Cache[Pkg].Keep() == true && Pkg.State() == PkgIterator::NeedsNothing)) | |
528 | continue; | |
529 | ||
530 | Bad = !SmartConfigure(Pkg); | |
531 | } | |
1006601e | 532 | |
421c8d10 | 533 | /* If this or element did not match then continue on to the |
1006601e | 534 | next or element until a matching element is found */ |
421c8d10 | 535 | if (Bad == true) |
1006601e AL |
536 | { |
537 | // This triggers if someone make a pre-depends/depend loop. | |
421c8d10 | 538 | if (Start == End) |
1006601e AL |
539 | return _error->Error("Couldn't configure pre-depend %s for %s, " |
540 | "probably a dependency cycle.", | |
541 | End.TargetPkg().Name(),Pkg.Name()); | |
421c8d10 AL |
542 | Start++; |
543 | } | |
544 | else | |
545 | break; | |
6c139d6e AL |
546 | } |
547 | ||
b2e465d6 AL |
548 | if (End->Type == pkgCache::Dep::Conflicts || |
549 | End->Type == pkgCache::Dep::Obsoletes) | |
6c139d6e AL |
550 | { |
551 | /* Look for conflicts. Two packages that are both in the install | |
552 | state cannot conflict so we don't check.. */ | |
b2e465d6 | 553 | SPtrArray<Version *> VList = End.AllTargets(); |
6c139d6e AL |
554 | for (Version **I = VList; *I != 0; I++) |
555 | { | |
556 | VerIterator Ver(Cache,*I); | |
557 | PkgIterator Pkg = Ver.ParentPkg(); | |
558 | ||
559 | // See if the current version is conflicting | |
560 | if (Pkg.CurrentVer() == Ver && List->IsNow(Pkg) == true) | |
561 | { | |
562 | if (EarlyRemove(Pkg) == false) | |
563 | return _error->Error("Internal Error, Could not early remove %s",Pkg.Name()); | |
564 | } | |
565 | } | |
6c139d6e AL |
566 | } |
567 | } | |
568 | ||
569 | // Check for reverse conflicts. | |
5af32db6 AL |
570 | if (CheckRConflicts(Pkg,Pkg.RevDependsList(), |
571 | Cache[Pkg].InstVerIter(Cache).VerStr()) == false) | |
572 | return false; | |
573 | ||
6c139d6e AL |
574 | for (PrvIterator P = Cache[Pkg].InstVerIter(Cache).ProvidesList(); |
575 | P.end() == false; P++) | |
576 | CheckRConflicts(Pkg,P.ParentPkg().RevDependsList(),P.ProvideVersion()); | |
577 | ||
803ea2a8 DK |
578 | if (pkgCache::VerIterator(Cache, Cache[Pkg].CandidateVer).Pseudo() == false && |
579 | Install(Pkg,FileNames[Pkg->ID]) == false) | |
6c139d6e AL |
580 | return false; |
581 | ||
582 | List->Flag(Pkg,pkgOrderList::UnPacked,pkgOrderList::States); | |
583 | ||
584 | // Perform immedate configuration of the package. | |
585 | if (List->IsFlag(Pkg,pkgOrderList::Immediate) == true) | |
586 | if (SmartConfigure(Pkg) == false) | |
20382bad DK |
587 | return _error->Error(_("Could not perform immediate configuration on '%s'." |
588 | "Please see man 5 apt.conf under APT::Immediate-Configure for details. (%d)"),Pkg.Name(),2); | |
6c139d6e AL |
589 | |
590 | return true; | |
591 | } | |
592 | /*}}}*/ | |
593 | // PM::OrderInstall - Installation ordering routine /*{{{*/ | |
594 | // --------------------------------------------------------------------- | |
595 | /* */ | |
281daf46 | 596 | pkgPackageManager::OrderResult pkgPackageManager::OrderInstall() |
6c139d6e | 597 | { |
7a1b1f8b | 598 | if (CreateOrderList() == false) |
281daf46 AL |
599 | return Failed; |
600 | ||
601 | Reset(); | |
6c139d6e | 602 | |
30e1eab5 | 603 | if (Debug == true) |
5e312de7 | 604 | clog << "Beginning to order" << endl; |
6c139d6e | 605 | |
5e312de7 DK |
606 | bool const ordering = |
607 | _config->FindB("PackageManager::UnpackAll",true) ? | |
608 | List->OrderUnpack(FileNames) : List->OrderCritical(); | |
609 | if (ordering == false) | |
281daf46 AL |
610 | { |
611 | _error->Error("Internal ordering error"); | |
612 | return Failed; | |
613 | } | |
614 | ||
30e1eab5 AL |
615 | if (Debug == true) |
616 | clog << "Done ordering" << endl; | |
617 | ||
281daf46 | 618 | bool DoneSomething = false; |
6c139d6e AL |
619 | for (pkgOrderList::iterator I = List->begin(); I != List->end(); I++) |
620 | { | |
621 | PkgIterator Pkg(Cache,*I); | |
281daf46 AL |
622 | |
623 | if (List->IsNow(Pkg) == false) | |
624 | { | |
625 | if (Debug == true) | |
626 | clog << "Skipping already done " << Pkg.Name() << endl; | |
627 | continue; | |
628 | } | |
629 | ||
2fd65468 | 630 | if (List->IsMissing(Pkg) == true) |
281daf46 AL |
631 | { |
632 | if (Debug == true) | |
a3eaf954 | 633 | clog << "Sequence completed at " << Pkg.Name() << endl; |
281daf46 AL |
634 | if (DoneSomething == false) |
635 | { | |
636 | _error->Error("Internal Error, ordering was unable to handle the media swap"); | |
637 | return Failed; | |
638 | } | |
639 | return Incomplete; | |
640 | } | |
6c139d6e AL |
641 | |
642 | // Sanity check | |
d0c59649 AL |
643 | if (Cache[Pkg].Keep() == true && |
644 | Pkg.State() == pkgCache::PkgIterator::NeedsNothing && | |
645 | (Cache[Pkg].iFlags & pkgDepCache::ReInstall) != pkgDepCache::ReInstall) | |
281daf46 | 646 | { |
71a174ee | 647 | _error->Error("Internal Error, trying to manipulate a kept package (%s)",Pkg.Name()); |
281daf46 AL |
648 | return Failed; |
649 | } | |
6c139d6e AL |
650 | |
651 | // Perform a delete or an install | |
652 | if (Cache[Pkg].Delete() == true) | |
653 | { | |
654 | if (SmartRemove(Pkg) == false) | |
281daf46 | 655 | return Failed; |
6c139d6e AL |
656 | } |
657 | else | |
658 | if (SmartUnPack(Pkg) == false) | |
281daf46 AL |
659 | return Failed; |
660 | DoneSomething = true; | |
6c139d6e | 661 | } |
5e312de7 | 662 | |
6c139d6e AL |
663 | // Final run through the configure phase |
664 | if (ConfigureAll() == false) | |
281daf46 | 665 | return Failed; |
6c139d6e AL |
666 | |
667 | // Sanity check | |
668 | for (pkgOrderList::iterator I = List->begin(); I != List->end(); I++) | |
281daf46 | 669 | { |
6c139d6e | 670 | if (List->IsFlag(*I,pkgOrderList::Configured) == false) |
281daf46 AL |
671 | { |
672 | _error->Error("Internal error, packages left unconfigured. %s", | |
673 | PkgIterator(Cache,*I).Name()); | |
674 | return Failed; | |
675 | } | |
676 | } | |
677 | ||
678 | return Completed; | |
6c139d6e AL |
679 | } |
680 | /*}}}*/ | |
1d6386f3 MV |
681 | // PM::DoInstallPostFork - Does install part that happens after the fork /*{{{*/ |
682 | // --------------------------------------------------------------------- | |
683 | pkgPackageManager::OrderResult | |
684 | pkgPackageManager::DoInstallPostFork(int statusFd) | |
685 | { | |
686 | if(statusFd > 0) | |
687 | // FIXME: use SetCloseExec here once it taught about throwing | |
688 | // exceptions instead of doing _exit(100) on failure | |
689 | fcntl(statusFd,F_SETFD,FD_CLOEXEC); | |
690 | bool goResult = Go(statusFd); | |
691 | if(goResult == false) | |
692 | return Failed; | |
693 | ||
1d6386f3 MV |
694 | return Res; |
695 | }; | |
696 | ||
2a7e07c7 MV |
697 | // PM::DoInstall - Does the installation /*{{{*/ |
698 | // --------------------------------------------------------------------- | |
699 | /* This uses the filenames in FileNames and the information in the | |
700 | DepCache to perform the installation of packages.*/ | |
701 | pkgPackageManager::OrderResult pkgPackageManager::DoInstall(int statusFd) | |
702 | { | |
703 | if(DoInstallPreFork() == Failed) | |
704 | return Failed; | |
705 | ||
7230ad48 | 706 | return DoInstallPostFork(statusFd); |
2a7e07c7 MV |
707 | } |
708 | /*}}}*/ |