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