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