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