]>
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 /*{{{*/ | |
453b82a3 | 16 | #include <config.h> |
ea542140 | 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> |
453b82a3 DK |
27 | #include <apt-pkg/macros.h> |
28 | #include <apt-pkg/pkgcache.h> | |
29 | #include <apt-pkg/cacheiterators.h> | |
30 | #include <apt-pkg/strutl.h> | |
b58f28d4 | 31 | #include <apt-pkg/install-progress.h> |
453b82a3 DK |
32 | |
33 | #include <stddef.h> | |
34 | #include <list> | |
35 | #include <string> | |
5819a761 | 36 | #include <iostream> |
a00a9b44 DK |
37 | |
38 | #include <apti18n.h> | |
92fcbfc1 | 39 | /*}}}*/ |
5819a761 AL |
40 | using namespace std; |
41 | ||
590f1923 CB |
42 | bool pkgPackageManager::SigINTStop = false; |
43 | ||
6c139d6e AL |
44 | // PM::PackageManager - Constructor /*{{{*/ |
45 | // --------------------------------------------------------------------- | |
46 | /* */ | |
dcaa1185 DK |
47 | pkgPackageManager::pkgPackageManager(pkgDepCache *pCache) : Cache(*pCache), |
48 | List(NULL), Res(Incomplete) | |
6c139d6e AL |
49 | { |
50 | FileNames = new string[Cache.Head().PackageCount]; | |
30e1eab5 | 51 | Debug = _config->FindB("Debug::pkgPackageManager",false); |
dcaa1185 DK |
52 | NoImmConfigure = !_config->FindB("APT::Immediate-Configure",true); |
53 | ImmConfigureAll = _config->FindB("APT::Immediate-Configure-All",false); | |
6c139d6e AL |
54 | } |
55 | /*}}}*/ | |
56 | // PM::PackageManager - Destructor /*{{{*/ | |
57 | // --------------------------------------------------------------------- | |
58 | /* */ | |
59 | pkgPackageManager::~pkgPackageManager() | |
60 | { | |
61 | delete List; | |
62 | delete [] FileNames; | |
63 | } | |
64 | /*}}}*/ | |
03e39e59 AL |
65 | // PM::GetArchives - Queue the archives for download /*{{{*/ |
66 | // --------------------------------------------------------------------- | |
67 | /* */ | |
68 | bool pkgPackageManager::GetArchives(pkgAcquire *Owner,pkgSourceList *Sources, | |
69 | pkgRecords *Recs) | |
70 | { | |
7a1b1f8b AL |
71 | if (CreateOrderList() == false) |
72 | return false; | |
73 | ||
5e312de7 DK |
74 | bool const ordering = |
75 | _config->FindB("PackageManager::UnpackAll",true) ? | |
76 | List->OrderUnpack() : List->OrderCritical(); | |
77 | if (ordering == false) | |
7a1b1f8b AL |
78 | return _error->Error("Internal ordering error"); |
79 | ||
91c03d37 | 80 | for (pkgOrderList::iterator I = List->begin(); I != List->end(); ++I) |
7a1b1f8b AL |
81 | { |
82 | PkgIterator Pkg(Cache,*I); | |
281daf46 AL |
83 | FileNames[Pkg->ID] = string(); |
84 | ||
7a1b1f8b AL |
85 | // Skip packages to erase |
86 | if (Cache[Pkg].Delete() == true) | |
03e39e59 | 87 | continue; |
d38b7b3d AL |
88 | |
89 | // Skip Packages that need configure only. | |
9dbb421f AL |
90 | if (Pkg.State() == pkgCache::PkgIterator::NeedsConfigure && |
91 | Cache[Pkg].Keep() == true) | |
d38b7b3d | 92 | continue; |
281daf46 AL |
93 | |
94 | // Skip already processed packages | |
95 | if (List->IsNow(Pkg) == false) | |
96 | continue; | |
803ea2a8 | 97 | |
7a1b1f8b AL |
98 | new pkgAcqArchive(Owner,Sources,Recs,Cache[Pkg].InstVerIter(Cache), |
99 | FileNames[Pkg->ID]); | |
03e39e59 | 100 | } |
7a1b1f8b | 101 | |
03e39e59 AL |
102 | return true; |
103 | } | |
104 | /*}}}*/ | |
6c139d6e AL |
105 | // PM::FixMissing - Keep all missing packages /*{{{*/ |
106 | // --------------------------------------------------------------------- | |
107 | /* This is called to correct the installation when packages could not | |
108 | be downloaded. */ | |
109 | bool pkgPackageManager::FixMissing() | |
bdae53f1 | 110 | { |
e6756cde | 111 | pkgDepCache::ActionGroup group(Cache); |
b2e465d6 | 112 | pkgProblemResolver Resolve(&Cache); |
2fd65468 | 113 | List->SetFileList(FileNames); |
e6756cde | 114 | |
9dbb421f | 115 | bool Bad = false; |
f7f0d6c7 | 116 | for (PkgIterator I = Cache.PkgBegin(); I.end() == false; ++I) |
6c139d6e | 117 | { |
2fd65468 | 118 | if (List->IsMissing(I) == false) |
9dbb421f | 119 | continue; |
2fd65468 | 120 | |
9dbb421f AL |
121 | // Okay, this file is missing and we need it. Mark it for keep |
122 | Bad = true; | |
74a05226 | 123 | Cache.MarkKeep(I, false, false); |
6c139d6e | 124 | } |
bdae53f1 AL |
125 | |
126 | // We have to empty the list otherwise it will not have the new changes | |
127 | delete List; | |
128 | List = 0; | |
6c139d6e | 129 | |
9dbb421f AL |
130 | if (Bad == false) |
131 | return true; | |
132 | ||
6c139d6e | 133 | // Now downgrade everything that is broken |
30e1eab5 | 134 | return Resolve.ResolveByKeep() == true && Cache.BrokenCount() == 0; |
6c139d6e AL |
135 | } |
136 | /*}}}*/ | |
3a6d37fd MV |
137 | // PM::ImmediateAdd - Add the immediate flag recursivly /*{{{*/ |
138 | // --------------------------------------------------------------------- | |
139 | /* This adds the immediate flag to the pkg and recursively to the | |
140 | dependendies | |
141 | */ | |
d183f850 | 142 | void pkgPackageManager::ImmediateAdd(PkgIterator I, bool UseInstallVer, unsigned const int &Depth) |
3a6d37fd MV |
143 | { |
144 | DepIterator D; | |
145 | ||
146 | if(UseInstallVer) | |
147 | { | |
148 | if(Cache[I].InstallVer == 0) | |
149 | return; | |
150 | D = Cache[I].InstVerIter(Cache).DependsList(); | |
151 | } else { | |
152 | if (I->CurrentVer == 0) | |
153 | return; | |
154 | D = I.CurrentVer().DependsList(); | |
155 | } | |
156 | ||
f7f0d6c7 | 157 | for ( /* nothing */ ; D.end() == false; ++D) |
3a6d37fd MV |
158 | if (D->Type == pkgCache::Dep::Depends || D->Type == pkgCache::Dep::PreDepends) |
159 | { | |
160 | if(!List->IsFlag(D.TargetPkg(), pkgOrderList::Immediate)) | |
161 | { | |
162 | if(Debug) | |
90436124 | 163 | clog << OutputInDepth(Depth) << "ImmediateAdd(): Adding Immediate flag to " << D.TargetPkg() << " cause of " << D.DepType() << " " << I.FullName() << endl; |
3a6d37fd | 164 | List->Flag(D.TargetPkg(),pkgOrderList::Immediate); |
d183f850 | 165 | ImmediateAdd(D.TargetPkg(), UseInstallVer, Depth + 1); |
3a6d37fd MV |
166 | } |
167 | } | |
168 | return; | |
169 | } | |
170 | /*}}}*/ | |
7a1b1f8b AL |
171 | // PM::CreateOrderList - Create the ordering class /*{{{*/ |
172 | // --------------------------------------------------------------------- | |
173 | /* This populates the ordering list with all the packages that are | |
174 | going to change. */ | |
175 | bool pkgPackageManager::CreateOrderList() | |
176 | { | |
281daf46 AL |
177 | if (List != 0) |
178 | return true; | |
179 | ||
7a1b1f8b | 180 | delete List; |
b2e465d6 | 181 | List = new pkgOrderList(&Cache); |
dcaa1185 | 182 | |
a6c8798a CB |
183 | if (Debug && ImmConfigureAll) |
184 | clog << "CreateOrderList(): Adding Immediate flag for all packages because of APT::Immediate-Configure-All" << endl; | |
079cc404 | 185 | |
7a1b1f8b | 186 | // Generate the list of affected packages and sort it |
f7f0d6c7 | 187 | for (PkgIterator I = Cache.PkgBegin(); I.end() == false; ++I) |
7a1b1f8b | 188 | { |
e7b470ee AL |
189 | // Ignore no-version packages |
190 | if (I->VersionList == 0) | |
191 | continue; | |
192 | ||
138d4b3d | 193 | // Mark the package and its dependends for immediate configuration |
fb805d80 | 194 | if ((((I->Flags & pkgCache::Flag::Essential) == pkgCache::Flag::Essential) && |
a6c8798a | 195 | NoImmConfigure == false) || ImmConfigureAll) |
7a1b1f8b | 196 | { |
a6c8798a | 197 | if(Debug && !ImmConfigureAll) |
90436124 | 198 | clog << "CreateOrderList(): Adding Immediate flag for " << I.FullName() << endl; |
7a1b1f8b | 199 | List->Flag(I,pkgOrderList::Immediate); |
d38b7b3d | 200 | |
a6c8798a | 201 | if (!ImmConfigureAll) { |
a6c8798a CB |
202 | // Look for other install packages to make immediate configurea |
203 | ImmediateAdd(I, true); | |
e2a5ff0c | 204 | |
a6c8798a CB |
205 | // And again with the current version. |
206 | ImmediateAdd(I, false); | |
207 | } | |
7a1b1f8b AL |
208 | } |
209 | ||
210 | // Not interesting | |
211 | if ((Cache[I].Keep() == true || | |
212 | Cache[I].InstVerIter(Cache) == I.CurrentVer()) && | |
d556d1a1 | 213 | I.State() == pkgCache::PkgIterator::NeedsNothing && |
d0c59649 | 214 | (Cache[I].iFlags & pkgDepCache::ReInstall) != pkgDepCache::ReInstall && |
d556d1a1 AL |
215 | (I.Purge() != false || Cache[I].Mode != pkgDepCache::ModeDelete || |
216 | (Cache[I].iFlags & pkgDepCache::Purge) != pkgDepCache::Purge)) | |
7a1b1f8b AL |
217 | continue; |
218 | ||
219 | // Append it to the list | |
138d4b3d | 220 | List->push_back(I); |
7a1b1f8b AL |
221 | } |
222 | ||
223 | return true; | |
224 | } | |
225 | /*}}}*/ | |
1e3f4083 | 226 | // PM::DepAlwaysTrue - Returns true if this dep is irrelevant /*{{{*/ |
6c139d6e AL |
227 | // --------------------------------------------------------------------- |
228 | /* The restriction on provides is to eliminate the case when provides | |
229 | are transitioning between valid states [ie exim to smail] */ | |
230 | bool pkgPackageManager::DepAlwaysTrue(DepIterator D) | |
231 | { | |
232 | if (D.TargetPkg()->ProvidesList != 0) | |
233 | return false; | |
234 | ||
235 | if ((Cache[D] & pkgDepCache::DepInstall) != 0 && | |
236 | (Cache[D] & pkgDepCache::DepNow) != 0) | |
237 | return true; | |
238 | return false; | |
239 | } | |
240 | /*}}}*/ | |
241 | // PM::CheckRConflicts - Look for reverse conflicts /*{{{*/ | |
242 | // --------------------------------------------------------------------- | |
243 | /* This looks over the reverses for a conflicts line that needs early | |
244 | removal. */ | |
245 | bool pkgPackageManager::CheckRConflicts(PkgIterator Pkg,DepIterator D, | |
246 | const char *Ver) | |
247 | { | |
f7f0d6c7 | 248 | for (;D.end() == false; ++D) |
6c139d6e | 249 | { |
b2e465d6 AL |
250 | if (D->Type != pkgCache::Dep::Conflicts && |
251 | D->Type != pkgCache::Dep::Obsoletes) | |
6c139d6e | 252 | continue; |
5af32db6 | 253 | |
1e3f4083 | 254 | // The package hasn't been changed |
5af32db6 AL |
255 | if (List->IsNow(Pkg) == false) |
256 | continue; | |
6c139d6e | 257 | |
1e3f4083 | 258 | // Ignore self conflicts, ignore conflicts from irrelevant versions |
85434114 | 259 | if (D.IsIgnorable(Pkg) || D.ParentVer() != D.ParentPkg().CurrentVer()) |
6c139d6e AL |
260 | continue; |
261 | ||
b2e465d6 | 262 | if (Cache.VS().CheckDep(Ver,D->CompareOp,D.TargetVer()) == false) |
6c139d6e | 263 | continue; |
b2e465d6 | 264 | |
6c139d6e | 265 | if (EarlyRemove(D.ParentPkg()) == false) |
5af32db6 | 266 | return _error->Error("Reverse conflicts early remove for package '%s' failed", |
90436124 | 267 | Pkg.FullName().c_str()); |
5af32db6 | 268 | } |
6c139d6e AL |
269 | return true; |
270 | } | |
271 | /*}}}*/ | |
272 | // PM::ConfigureAll - Run the all out configuration /*{{{*/ | |
273 | // --------------------------------------------------------------------- | |
274 | /* This configures every package. It is assumed they are all unpacked and | |
590f1923 CB |
275 | that the final configuration is valid. This is also used to catch packages |
276 | that have not been configured when using ImmConfigureAll */ | |
6c139d6e AL |
277 | bool pkgPackageManager::ConfigureAll() |
278 | { | |
b2e465d6 | 279 | pkgOrderList OList(&Cache); |
6c139d6e AL |
280 | |
281 | // Populate the order list | |
91c03d37 | 282 | for (pkgOrderList::iterator I = List->begin(); I != List->end(); ++I) |
6c139d6e AL |
283 | if (List->IsFlag(pkgCache::PkgIterator(Cache,*I), |
284 | pkgOrderList::UnPacked) == true) | |
285 | OList.push_back(*I); | |
286 | ||
287 | if (OList.OrderConfigure() == false) | |
288 | return false; | |
5e312de7 DK |
289 | |
290 | std::string const conf = _config->Find("PackageManager::Configure","all"); | |
291 | bool const ConfigurePkgs = (conf == "all"); | |
292 | ||
6c139d6e | 293 | // Perform the configuring |
91c03d37 | 294 | for (pkgOrderList::iterator I = OList.begin(); I != OList.end(); ++I) |
6c139d6e AL |
295 | { |
296 | PkgIterator Pkg(Cache,*I); | |
17182c0c CB |
297 | |
298 | /* Check if the package has been configured, this can happen if SmartConfigure | |
299 | calls its self */ | |
300 | if (List->IsFlag(Pkg,pkgOrderList::Configured)) continue; | |
803ea2a8 | 301 | |
d41d0e01 | 302 | if (ConfigurePkgs == true && SmartConfigure(Pkg, 0) == false) { |
c7c7d3e8 CB |
303 | if (ImmConfigureAll) |
304 | _error->Error(_("Could not perform immediate configuration on '%s'. " | |
90436124 | 305 | "Please see man 5 apt.conf under APT::Immediate-Configure for details. (%d)"),Pkg.FullName().c_str(),1); |
c7c7d3e8 | 306 | else |
90436124 | 307 | _error->Error("Internal error, packages left unconfigured. %s",Pkg.FullName().c_str()); |
6c139d6e | 308 | return false; |
634985f8 | 309 | } |
6c139d6e AL |
310 | |
311 | List->Flag(Pkg,pkgOrderList::Configured,pkgOrderList::States); | |
312 | } | |
313 | ||
314 | return true; | |
315 | } | |
316 | /*}}}*/ | |
317 | // PM::SmartConfigure - Perform immediate configuration of the pkg /*{{{*/ | |
318 | // --------------------------------------------------------------------- | |
c7c7d3e8 CB |
319 | /* This function tries to put the system in a state where Pkg can be configured. |
320 | This involves checking each of Pkg's dependanies and unpacking and | |
321 | configuring packages where needed. | |
322 | ||
323 | Note on failure: This method can fail, without causing any problems. | |
324 | This can happen when using Immediate-Configure-All, SmartUnPack may call | |
1e3f4083 | 325 | SmartConfigure, it may fail because of a complex dependency situation, but |
c7c7d3e8 CB |
326 | a error will only be reported if ConfigureAll fails. This is why some of the |
327 | messages this function reports on failure (return false;) as just warnings | |
328 | only shown when debuging*/ | |
d41d0e01 | 329 | bool pkgPackageManager::SmartConfigure(PkgIterator Pkg, int const Depth) |
6c139d6e | 330 | { |
38ff3de6 | 331 | // If this is true, only check and correct and dependencies without the Loop flag |
2dd2c801 | 332 | bool const PkgLoop = List->IsFlag(Pkg,pkgOrderList::Loop); |
d41d0e01 | 333 | |
987d8d03 CB |
334 | if (Debug) { |
335 | VerIterator InstallVer = VerIterator(Cache,Cache[Pkg].InstallVer); | |
90436124 | 336 | clog << OutputInDepth(Depth) << "SmartConfigure " << Pkg.FullName() << " (" << InstallVer.VerStr() << ")"; |
d41d0e01 | 337 | if (PkgLoop) |
38ff3de6 | 338 | clog << " (Only Correct Dependencies)"; |
d41d0e01 | 339 | clog << endl; |
987d8d03 | 340 | } |
0eacf067 | 341 | |
590f1923 | 342 | VerIterator const instVer = Cache[Pkg].InstVerIter(Cache); |
b2e465d6 | 343 | |
38ff3de6 | 344 | /* Because of the ordered list, most dependencies should be unpacked, |
c7c7d3e8 | 345 | however if there is a loop (A depends on B, B depends on A) this will not |
38ff3de6 | 346 | be the case, so check for dependencies before configuring. */ |
2dd2c801 | 347 | bool Bad = false, Changed = false; |
9c5104cf | 348 | const unsigned int max_loops = _config->FindI("APT::pkgPackageManager::MaxLoopCount", 5000); |
bce4caa3 | 349 | unsigned int i=0; |
42d51f33 | 350 | std::list<DepIterator> needConfigure; |
bce4caa3 MV |
351 | do |
352 | { | |
2dd2c801 DK |
353 | Changed = false; |
354 | for (DepIterator D = instVer.DependsList(); D.end() == false; ) | |
355 | { | |
356 | // Compute a single dependency element (glob or) | |
357 | pkgCache::DepIterator Start, End; | |
358 | D.GlobOr(Start,End); | |
359 | ||
360 | if (End->Type != pkgCache::Dep::Depends) | |
361 | continue; | |
362 | Bad = true; | |
363 | ||
42d51f33 | 364 | // Check for dependencies that have not been unpacked, probably due to loops. |
2dd2c801 DK |
365 | for (DepIterator Cur = Start; true; ++Cur) |
366 | { | |
367 | SPtrArray<Version *> VList = Cur.AllTargets(); | |
368 | ||
369 | for (Version **I = VList; *I != 0; ++I) | |
6c139d6e | 370 | { |
2dd2c801 DK |
371 | VerIterator Ver(Cache,*I); |
372 | PkgIterator DepPkg = Ver.ParentPkg(); | |
373 | ||
374 | // Check if the current version of the package is available and will satisfy this dependency | |
375 | if (DepPkg.CurrentVer() == Ver && List->IsNow(DepPkg) == true && | |
376 | List->IsFlag(DepPkg,pkgOrderList::Removed) == false && | |
377 | DepPkg.State() == PkgIterator::NeedsNothing) | |
378 | { | |
379 | Bad = false; | |
380 | break; | |
381 | } | |
382 | ||
383 | // Check if the version that is going to be installed will satisfy the dependency | |
42d51f33 | 384 | if (Cache[DepPkg].InstallVer != *I || List->IsNow(DepPkg) == false) |
2dd2c801 DK |
385 | continue; |
386 | ||
42d51f33 | 387 | if (PkgLoop == true) |
2dd2c801 | 388 | { |
42d51f33 DK |
389 | if (Debug) |
390 | std::clog << OutputInDepth(Depth) << "Package " << Pkg << " loops in SmartConfigure" << std::endl; | |
391 | Bad = false; | |
392 | break; | |
393 | } | |
394 | else | |
395 | { | |
396 | if (Debug) | |
397 | clog << OutputInDepth(Depth) << "Unpacking " << DepPkg.FullName() << " to avoid loop " << Cur << endl; | |
2dd2c801 DK |
398 | if (PkgLoop == false) |
399 | List->Flag(Pkg,pkgOrderList::Loop); | |
42d51f33 | 400 | if (SmartUnPack(DepPkg, true, Depth + 1) == true) |
2dd2c801 DK |
401 | { |
402 | Bad = false; | |
403 | if (List->IsFlag(DepPkg,pkgOrderList::Loop) == false) | |
42d51f33 | 404 | Changed = true; |
2dd2c801 DK |
405 | } |
406 | if (PkgLoop == false) | |
42d51f33 | 407 | List->RmFlag(Pkg,pkgOrderList::Loop); |
2dd2c801 DK |
408 | if (Bad == false) |
409 | break; | |
410 | } | |
590f1923 | 411 | } |
42d51f33 DK |
412 | |
413 | if (Cur == End || Bad == false) | |
2dd2c801 | 414 | break; |
42d51f33 | 415 | } |
2dd2c801 DK |
416 | |
417 | if (Bad == false) | |
418 | continue; | |
419 | ||
42d51f33 DK |
420 | needConfigure.push_back(Start); |
421 | } | |
422 | if (i++ > max_loops) | |
423 | return _error->Error("Internal error: MaxLoopCount reached in SmartUnPack (1) for %s, aborting", Pkg.FullName().c_str()); | |
424 | } while (Changed == true); | |
425 | ||
426 | Bad = false, Changed = false, i = 0; | |
427 | do | |
428 | { | |
429 | Changed = false; | |
6420c00e | 430 | for (std::list<DepIterator>::const_iterator D = needConfigure.begin(); D != needConfigure.end(); ++D) |
42d51f33 | 431 | { |
6420c00e | 432 | // Compute a single dependency element (glob or) without modifying D |
42d51f33 | 433 | pkgCache::DepIterator Start, End; |
6420c00e DK |
434 | { |
435 | pkgCache::DepIterator Discard = *D; | |
436 | Discard.GlobOr(Start,End); | |
437 | } | |
42d51f33 DK |
438 | |
439 | if (End->Type != pkgCache::Dep::Depends) | |
440 | continue; | |
441 | Bad = true; | |
442 | ||
443 | // Search for dependencies which are unpacked but aren't configured yet (maybe loops) | |
2dd2c801 DK |
444 | for (DepIterator Cur = Start; true; ++Cur) |
445 | { | |
446 | SPtrArray<Version *> VList = Cur.AllTargets(); | |
447 | ||
448 | for (Version **I = VList; *I != 0; ++I) | |
449 | { | |
450 | VerIterator Ver(Cache,*I); | |
451 | PkgIterator DepPkg = Ver.ParentPkg(); | |
452 | ||
453 | // Check if the version that is going to be installed will satisfy the dependency | |
42d51f33 | 454 | if (Cache[DepPkg].InstallVer != *I) |
2dd2c801 DK |
455 | continue; |
456 | ||
42d51f33 | 457 | if (List->IsFlag(DepPkg,pkgOrderList::UnPacked)) |
d9f6c795 | 458 | { |
42d51f33 DK |
459 | if (List->IsFlag(DepPkg,pkgOrderList::Loop) && PkgLoop) |
460 | { | |
461 | // This dependency has already been dealt with by another SmartConfigure on Pkg | |
462 | Bad = false; | |
463 | break; | |
464 | } | |
465 | /* Check for a loop to prevent one forming | |
466 | If A depends on B and B depends on A, SmartConfigure will | |
467 | just hop between them if this is not checked. Dont remove the | |
468 | loop flag after finishing however as loop is already set. | |
469 | This means that there is another SmartConfigure call for this | |
470 | package and it will remove the loop flag */ | |
2dd2c801 DK |
471 | if (PkgLoop == false) |
472 | List->Flag(Pkg,pkgOrderList::Loop); | |
42d51f33 | 473 | if (SmartConfigure(DepPkg, Depth + 1) == true) |
2dd2c801 DK |
474 | { |
475 | Bad = false; | |
476 | if (List->IsFlag(DepPkg,pkgOrderList::Loop) == false) | |
42d51f33 | 477 | Changed = true; |
2dd2c801 DK |
478 | } |
479 | if (PkgLoop == false) | |
42d51f33 DK |
480 | List->RmFlag(Pkg,pkgOrderList::Loop); |
481 | // If SmartConfigure was succesfull, Bad is false, so break | |
2dd2c801 DK |
482 | if (Bad == false) |
483 | break; | |
d9f6c795 | 484 | } |
42d51f33 DK |
485 | else if (List->IsFlag(DepPkg,pkgOrderList::Configured)) |
486 | { | |
487 | Bad = false; | |
488 | break; | |
489 | } | |
590f1923 | 490 | } |
42d51f33 | 491 | if (Cur == End || Bad == false) |
2dd2c801 | 492 | break; |
42d51f33 DK |
493 | } |
494 | ||
495 | ||
2dd2c801 | 496 | if (Bad == true && Changed == false && Debug == true) |
6420c00e | 497 | std::clog << OutputInDepth(Depth) << "Could not satisfy " << *D << std::endl; |
6c139d6e | 498 | } |
bce4caa3 | 499 | if (i++ > max_loops) |
42d51f33 | 500 | return _error->Error("Internal error: MaxLoopCount reached in SmartUnPack (2) for %s, aborting", Pkg.FullName().c_str()); |
2dd2c801 | 501 | } while (Changed == true); |
c7c7d3e8 CB |
502 | |
503 | if (Bad) { | |
504 | if (Debug) | |
90436124 | 505 | _error->Warning(_("Could not configure '%s'. "),Pkg.FullName().c_str()); |
6c139d6e | 506 | return false; |
c7c7d3e8 | 507 | } |
a99d02a8 CB |
508 | |
509 | if (PkgLoop) return true; | |
5e312de7 DK |
510 | |
511 | static std::string const conf = _config->Find("PackageManager::Configure","all"); | |
512 | static bool const ConfigurePkgs = (conf == "all" || conf == "smart"); | |
513 | ||
17182c0c | 514 | if (List->IsFlag(Pkg,pkgOrderList::Configured)) |
90436124 | 515 | return _error->Error("Internal configure error on '%s'.", Pkg.FullName().c_str()); |
5e312de7 | 516 | |
590f1923 CB |
517 | if (ConfigurePkgs == true && Configure(Pkg) == false) |
518 | return false; | |
75a90b93 | 519 | |
590f1923 | 520 | List->Flag(Pkg,pkgOrderList::Configured,pkgOrderList::States); |
6c139d6e | 521 | |
894d672e | 522 | if ((Cache[Pkg].InstVerIter(Cache)->MultiArch & pkgCache::Version::Same) == pkgCache::Version::Same) |
d77b985a DK |
523 | for (PkgIterator P = Pkg.Group().PackageList(); |
524 | P.end() == false; P = Pkg.Group().NextPkg(P)) | |
525 | { | |
526 | if (Pkg == P || List->IsFlag(P,pkgOrderList::Configured) == true || | |
2b8b1e7a | 527 | List->IsFlag(P,pkgOrderList::UnPacked) == false || |
d77b985a DK |
528 | Cache[P].InstallVer == 0 || (P.CurrentVer() == Cache[P].InstallVer && |
529 | (Cache[Pkg].iFlags & pkgDepCache::ReInstall) != pkgDepCache::ReInstall)) | |
530 | continue; | |
d41d0e01 | 531 | SmartConfigure(P, (Depth +1)); |
d77b985a DK |
532 | } |
533 | ||
6c139d6e AL |
534 | // Sanity Check |
535 | if (List->IsFlag(Pkg,pkgOrderList::Configured) == false) | |
90436124 | 536 | return _error->Error(_("Could not configure '%s'. "),Pkg.FullName().c_str()); |
20382bad | 537 | |
6c139d6e AL |
538 | return true; |
539 | } | |
540 | /*}}}*/ | |
6c139d6e AL |
541 | // PM::EarlyRemove - Perform removal of packages before their time /*{{{*/ |
542 | // --------------------------------------------------------------------- | |
543 | /* This is called to deal with conflicts arising from unpacking */ | |
544 | bool pkgPackageManager::EarlyRemove(PkgIterator Pkg) | |
545 | { | |
546 | if (List->IsNow(Pkg) == false) | |
547 | return true; | |
548 | ||
549 | // Already removed it | |
550 | if (List->IsFlag(Pkg,pkgOrderList::Removed) == true) | |
551 | return true; | |
552 | ||
553 | // Woops, it will not be re-installed! | |
554 | if (List->IsFlag(Pkg,pkgOrderList::InList) == false) | |
555 | return false; | |
9d4c8f67 AL |
556 | |
557 | // Essential packages get special treatment | |
5af32db6 | 558 | bool IsEssential = false; |
c5200869 JAK |
559 | if ((Pkg->Flags & pkgCache::Flag::Essential) != 0 || |
560 | (Pkg->Flags & pkgCache::Flag::Important) != 0) | |
5af32db6 AL |
561 | IsEssential = true; |
562 | ||
563 | /* Check for packages that are the dependents of essential packages and | |
564 | promote them too */ | |
565 | if (Pkg->CurrentVer != 0) | |
566 | { | |
567 | for (DepIterator D = Pkg.RevDependsList(); D.end() == false && | |
f7f0d6c7 | 568 | IsEssential == false; ++D) |
5af32db6 | 569 | if (D->Type == pkgCache::Dep::Depends || D->Type == pkgCache::Dep::PreDepends) |
c5200869 JAK |
570 | if ((D.ParentPkg()->Flags & pkgCache::Flag::Essential) != 0 || |
571 | (D.ParentPkg()->Flags & pkgCache::Flag::Important) != 0) | |
5af32db6 AL |
572 | IsEssential = true; |
573 | } | |
574 | ||
575 | if (IsEssential == true) | |
9d4c8f67 AL |
576 | { |
577 | if (_config->FindB("APT::Force-LoopBreak",false) == false) | |
b2e465d6 AL |
578 | return _error->Error(_("This installation run will require temporarily " |
579 | "removing the essential package %s due to a " | |
580 | "Conflicts/Pre-Depends loop. This is often bad, " | |
581 | "but if you really want to do it, activate the " | |
90436124 | 582 | "APT::Force-LoopBreak option."),Pkg.FullName().c_str()); |
9d4c8f67 | 583 | } |
6c139d6e AL |
584 | |
585 | bool Res = SmartRemove(Pkg); | |
586 | if (Cache[Pkg].Delete() == false) | |
587 | List->Flag(Pkg,pkgOrderList::Removed,pkgOrderList::States); | |
588 | ||
589 | return Res; | |
590 | } | |
591 | /*}}}*/ | |
592 | // PM::SmartRemove - Removal Helper /*{{{*/ | |
593 | // --------------------------------------------------------------------- | |
594 | /* */ | |
595 | bool pkgPackageManager::SmartRemove(PkgIterator Pkg) | |
596 | { | |
597 | if (List->IsNow(Pkg) == false) | |
598 | return true; | |
599 | ||
600 | List->Flag(Pkg,pkgOrderList::Configured,pkgOrderList::States); | |
803ea2a8 | 601 | |
28166356 | 602 | return Remove(Pkg,(Cache[Pkg].iFlags & pkgDepCache::Purge) == pkgDepCache::Purge); |
6c139d6e AL |
603 | } |
604 | /*}}}*/ | |
605 | // PM::SmartUnPack - Install helper /*{{{*/ | |
606 | // --------------------------------------------------------------------- | |
1e3f4083 | 607 | /* This puts the system in a state where it can Unpack Pkg, if Pkg is already |
590f1923 | 608 | unpacked, or when it has been unpacked, if Immediate==true it configures it. */ |
6c139d6e | 609 | bool pkgPackageManager::SmartUnPack(PkgIterator Pkg) |
d77b985a | 610 | { |
d41d0e01 | 611 | return SmartUnPack(Pkg, true, 0); |
d77b985a | 612 | } |
d41d0e01 | 613 | bool pkgPackageManager::SmartUnPack(PkgIterator Pkg, bool const Immediate, int const Depth) |
6c139d6e | 614 | { |
d41d0e01 CB |
615 | bool PkgLoop = List->IsFlag(Pkg,pkgOrderList::Loop); |
616 | ||
987d8d03 | 617 | if (Debug) { |
90436124 | 618 | clog << OutputInDepth(Depth) << "SmartUnPack " << Pkg.FullName(); |
987d8d03 CB |
619 | VerIterator InstallVer = VerIterator(Cache,Cache[Pkg].InstallVer); |
620 | if (Pkg.CurrentVer() == 0) | |
c4f931f8 | 621 | clog << " (install version " << InstallVer.VerStr() << ")"; |
987d8d03 | 622 | else |
c4f931f8 | 623 | clog << " (replace version " << Pkg.CurrentVer().VerStr() << " with " << InstallVer.VerStr() << ")"; |
d41d0e01 | 624 | if (PkgLoop) |
c4f931f8 | 625 | clog << " (Only Perform PreUnpack Checks)"; |
0caa5a4c DK |
626 | if (Immediate) |
627 | clog << " immediately"; | |
c4f931f8 | 628 | clog << endl; |
987d8d03 | 629 | } |
cfcdf7fe | 630 | |
d77b985a DK |
631 | VerIterator const instVer = Cache[Pkg].InstVerIter(Cache); |
632 | ||
c7c7d3e8 | 633 | /* PreUnpack Checks: This loop checks and attempts to rectify and problems that would prevent the package being unpacked. |
98ee4922 | 634 | It addresses: PreDepends, Conflicts, Obsoletes and Breaks (DpkgBreaks). Any resolutions that do not require it should |
c7c7d3e8 | 635 | avoid configuration (calling SmartUnpack with Immediate=true), this is because when unpacking some packages with |
1e3f4083 | 636 | complex dependency structures, trying to configure some packages while breaking the loops can complicate things . |
98ee4922 | 637 | This will be either dealt with if the package is configured as a dependency of Pkg (if and when Pkg is configured), |
c7c7d3e8 | 638 | or by the ConfigureAll call at the end of the for loop in OrderInstall. */ |
98ee4922 | 639 | bool Changed = false; |
9c5104cf | 640 | const unsigned int max_loops = _config->FindI("APT::pkgPackageManager::MaxLoopCount", 5000); |
5ab7b53b | 641 | unsigned int i = 0; |
bce4caa3 MV |
642 | do |
643 | { | |
98ee4922 DK |
644 | Changed = false; |
645 | for (DepIterator D = instVer.DependsList(); D.end() == false; ) | |
6c139d6e | 646 | { |
98ee4922 DK |
647 | // Compute a single dependency element (glob or) |
648 | pkgCache::DepIterator Start, End; | |
649 | D.GlobOr(Start,End); | |
f4945db3 | 650 | |
98ee4922 DK |
651 | if (End->Type == pkgCache::Dep::PreDepends) |
652 | { | |
653 | bool Bad = true; | |
654 | if (Debug) | |
655 | clog << OutputInDepth(Depth) << "PreDepends order for " << Pkg.FullName() << std::endl; | |
656 | ||
657 | // Look for easy targets: packages that are already okay | |
658 | for (DepIterator Cur = Start; Bad == true; ++Cur) | |
6c139d6e | 659 | { |
d8e25d34 | 660 | SPtrArray<Version *> VList = Cur.AllTargets(); |
98ee4922 DK |
661 | for (Version **I = VList; *I != 0; ++I) |
662 | { | |
663 | VerIterator Ver(Cache,*I); | |
664 | PkgIterator Pkg = Ver.ParentPkg(); | |
665 | ||
666 | // See if the current version is ok | |
667 | if (Pkg.CurrentVer() == Ver && List->IsNow(Pkg) == true && | |
668 | Pkg.State() == PkgIterator::NeedsNothing) | |
669 | { | |
670 | Bad = false; | |
671 | if (Debug) | |
672 | clog << OutputInDepth(Depth) << "Found ok package " << Pkg.FullName() << endl; | |
673 | break; | |
674 | } | |
675 | } | |
676 | if (Cur == End) | |
677 | break; | |
17182c0c | 678 | } |
6c139d6e | 679 | |
98ee4922 | 680 | // Look for something that could be configured. |
275024e9 | 681 | for (DepIterator Cur = Start; Bad == true && Cur.end() == false; ++Cur) |
98ee4922 | 682 | { |
d8e25d34 | 683 | SPtrArray<Version *> VList = Cur.AllTargets(); |
98ee4922 DK |
684 | for (Version **I = VList; *I != 0; ++I) |
685 | { | |
686 | VerIterator Ver(Cache,*I); | |
687 | PkgIterator Pkg = Ver.ParentPkg(); | |
1006601e | 688 | |
98ee4922 DK |
689 | // Not the install version |
690 | if (Cache[Pkg].InstallVer != *I || | |
691 | (Cache[Pkg].Keep() == true && Pkg.State() == PkgIterator::NeedsNothing)) | |
692 | continue; | |
693 | ||
694 | if (List->IsFlag(Pkg,pkgOrderList::Configured)) | |
695 | { | |
696 | Bad = false; | |
697 | break; | |
698 | } | |
699 | ||
700 | // check if it needs unpack or if if configure is enough | |
701 | if (List->IsFlag(Pkg,pkgOrderList::UnPacked) == false) | |
702 | { | |
703 | if (Debug) | |
704 | clog << OutputInDepth(Depth) << "Trying to SmartUnpack " << Pkg.FullName() << endl; | |
705 | // SmartUnpack with the ImmediateFlag to ensure its really ready | |
706 | if (SmartUnPack(Pkg, true, Depth + 1) == true) | |
707 | { | |
708 | Bad = false; | |
709 | if (List->IsFlag(Pkg,pkgOrderList::Loop) == false) | |
710 | Changed = true; | |
711 | break; | |
712 | } | |
713 | } | |
714 | else | |
715 | { | |
716 | if (Debug) | |
717 | clog << OutputInDepth(Depth) << "Trying to SmartConfigure " << Pkg.FullName() << endl; | |
718 | if (SmartConfigure(Pkg, Depth + 1) == true) | |
719 | { | |
720 | Bad = false; | |
721 | if (List->IsFlag(Pkg,pkgOrderList::Loop) == false) | |
722 | Changed = true; | |
723 | break; | |
724 | } | |
725 | } | |
e2a5ff0c | 726 | } |
6c139d6e | 727 | } |
98ee4922 DK |
728 | |
729 | if (Bad == true) | |
730 | { | |
731 | if (Start == End) | |
732 | return _error->Error("Couldn't configure pre-depend %s for %s, " | |
733 | "probably a dependency cycle.", | |
734 | End.TargetPkg().FullName().c_str(),Pkg.FullName().c_str()); | |
735 | } | |
736 | else | |
737 | continue; | |
6c139d6e | 738 | } |
98ee4922 DK |
739 | else if (End->Type == pkgCache::Dep::Conflicts || |
740 | End->Type == pkgCache::Dep::Obsoletes) | |
cfcdf7fe | 741 | { |
98ee4922 DK |
742 | /* Look for conflicts. Two packages that are both in the install |
743 | state cannot conflict so we don't check.. */ | |
744 | SPtrArray<Version *> VList = End.AllTargets(); | |
745 | for (Version **I = VList; *I != 0; I++) | |
3e9ab9f0 | 746 | { |
98ee4922 DK |
747 | VerIterator Ver(Cache,*I); |
748 | PkgIterator ConflictPkg = Ver.ParentPkg(); | |
749 | VerIterator InstallVer(Cache,Cache[ConflictPkg].InstallVer); | |
3e9ab9f0 | 750 | |
98ee4922 DK |
751 | // See if the current version is conflicting |
752 | if (ConflictPkg.CurrentVer() == Ver && List->IsNow(ConflictPkg)) | |
753 | { | |
2252183c DK |
754 | if (Debug) |
755 | clog << OutputInDepth(Depth) << Pkg.FullName() << " conflicts with " << ConflictPkg.FullName() << endl; | |
98ee4922 DK |
756 | /* If a loop is not present or has not yet been detected, attempt to unpack packages |
757 | to resolve this conflict. If there is a loop present, remove packages to resolve this conflict */ | |
758 | if (List->IsFlag(ConflictPkg,pkgOrderList::Loop) == false) | |
440d3d65 | 759 | { |
98ee4922 | 760 | if (Cache[ConflictPkg].Keep() == 0 && Cache[ConflictPkg].InstallVer != 0) |
440d3d65 | 761 | { |
98ee4922 | 762 | if (Debug) |
544cc111 | 763 | clog << OutputInDepth(Depth) << OutputInDepth(Depth) << "Unpacking " << ConflictPkg.FullName() << " to prevent conflict" << endl; |
98ee4922 DK |
764 | List->Flag(Pkg,pkgOrderList::Loop); |
765 | if (SmartUnPack(ConflictPkg,false, Depth + 1) == true) | |
766 | if (List->IsFlag(ConflictPkg,pkgOrderList::Loop) == false) | |
767 | Changed = true; | |
768 | // Remove loop to allow it to be used later if needed | |
769 | List->RmFlag(Pkg,pkgOrderList::Loop); | |
440d3d65 | 770 | } |
98ee4922 DK |
771 | else if (EarlyRemove(ConflictPkg) == false) |
772 | return _error->Error("Internal Error, Could not early remove %s (1)",ConflictPkg.FullName().c_str()); | |
440d3d65 | 773 | } |
98ee4922 | 774 | else if (List->IsFlag(ConflictPkg,pkgOrderList::Removed) == false) |
440d3d65 DK |
775 | { |
776 | if (Debug) | |
544cc111 | 777 | clog << OutputInDepth(Depth) << "Because of conficts knot, removing " << ConflictPkg.FullName() << " to conflict violation" << endl; |
98ee4922 DK |
778 | if (EarlyRemove(ConflictPkg) == false) |
779 | return _error->Error("Internal Error, Could not early remove %s (2)",ConflictPkg.FullName().c_str()); | |
780 | } | |
781 | } | |
782 | } | |
783 | } | |
784 | else if (End->Type == pkgCache::Dep::DpkgBreaks) | |
785 | { | |
786 | SPtrArray<Version *> VList = End.AllTargets(); | |
787 | for (Version **I = VList; *I != 0; ++I) | |
788 | { | |
789 | VerIterator Ver(Cache,*I); | |
790 | PkgIterator BrokenPkg = Ver.ParentPkg(); | |
791 | if (BrokenPkg.CurrentVer() != Ver) | |
792 | { | |
793 | if (Debug) | |
794 | std::clog << OutputInDepth(Depth) << " Ignore not-installed version " << Ver.VerStr() << " of " << Pkg.FullName() << " for " << End << std::endl; | |
795 | continue; | |
796 | } | |
797 | ||
798 | // Check if it needs to be unpacked | |
799 | if (List->IsFlag(BrokenPkg,pkgOrderList::InList) && Cache[BrokenPkg].Delete() == false && | |
800 | List->IsNow(BrokenPkg)) | |
801 | { | |
802 | if (List->IsFlag(BrokenPkg,pkgOrderList::Loop) && PkgLoop) | |
803 | { | |
1e3f4083 | 804 | // This dependency has already been dealt with by another SmartUnPack on Pkg |
98ee4922 | 805 | break; |
440d3d65 DK |
806 | } |
807 | else | |
2264548f | 808 | { |
98ee4922 DK |
809 | // Found a break, so see if we can unpack the package to avoid it |
810 | // but do not set loop if another SmartUnPack already deals with it | |
811 | // Also, avoid it if the package we would unpack pre-depends on this one | |
812 | VerIterator InstallVer(Cache,Cache[BrokenPkg].InstallVer); | |
813 | bool circle = false; | |
814 | for (pkgCache::DepIterator D = InstallVer.DependsList(); D.end() == false; ++D) | |
440d3d65 | 815 | { |
98ee4922 DK |
816 | if (D->Type != pkgCache::Dep::PreDepends) |
817 | continue; | |
818 | SPtrArray<Version *> VL = D.AllTargets(); | |
819 | for (Version **I = VL; *I != 0; ++I) | |
820 | { | |
821 | VerIterator V(Cache,*I); | |
822 | PkgIterator P = V.ParentPkg(); | |
823 | // we are checking for installation as an easy 'protection' against or-groups and (unchosen) providers | |
177645ed | 824 | if (P != Pkg || (P.CurrentVer() != V && Cache[P].InstallVer != V)) |
98ee4922 DK |
825 | continue; |
826 | circle = true; | |
827 | break; | |
828 | } | |
829 | if (circle == true) | |
830 | break; | |
831 | } | |
832 | if (circle == true) | |
833 | { | |
834 | if (Debug) | |
544cc111 | 835 | clog << OutputInDepth(Depth) << " Avoiding " << End << " avoided as " << BrokenPkg.FullName() << " has a pre-depends on " << Pkg.FullName() << std::endl; |
98ee4922 DK |
836 | continue; |
837 | } | |
838 | else | |
839 | { | |
840 | if (Debug) | |
841 | { | |
544cc111 | 842 | clog << OutputInDepth(Depth) << " Unpacking " << BrokenPkg.FullName() << " to avoid " << End; |
98ee4922 | 843 | if (PkgLoop == true) |
544cc111 MV |
844 | clog << " (Looping)"; |
845 | clog << std::endl; | |
98ee4922 DK |
846 | } |
847 | if (PkgLoop == false) | |
848 | List->Flag(Pkg,pkgOrderList::Loop); | |
849 | if (SmartUnPack(BrokenPkg, false, Depth + 1) == true) | |
850 | { | |
851 | if (List->IsFlag(BrokenPkg,pkgOrderList::Loop) == false) | |
852 | Changed = true; | |
853 | } | |
854 | if (PkgLoop == false) | |
855 | List->RmFlag(Pkg,pkgOrderList::Loop); | |
440d3d65 | 856 | } |
2264548f | 857 | } |
6b92f60c | 858 | } |
6b92f60c | 859 | // Check if a package needs to be removed |
98ee4922 | 860 | else if (Cache[BrokenPkg].Delete() == true && List->IsFlag(BrokenPkg,pkgOrderList::Configured) == false) |
6b92f60c DK |
861 | { |
862 | if (Debug) | |
544cc111 | 863 | clog << OutputInDepth(Depth) << " Removing " << BrokenPkg.FullName() << " to avoid " << End << endl; |
6b92f60c DK |
864 | SmartRemove(BrokenPkg); |
865 | } | |
6c139d6e AL |
866 | } |
867 | } | |
6c139d6e | 868 | } |
bce4caa3 | 869 | if (i++ > max_loops) |
91ea3def | 870 | return _error->Error("Internal error: APT::pkgPackageManager::MaxLoopCount reached in SmartConfigure for %s, aborting", Pkg.FullName().c_str()); |
98ee4922 | 871 | } while (Changed == true); |
9fc57a59 | 872 | |
6c139d6e | 873 | // Check for reverse conflicts. |
5af32db6 | 874 | if (CheckRConflicts(Pkg,Pkg.RevDependsList(), |
d77b985a | 875 | instVer.VerStr()) == false) |
c7c7d3e8 | 876 | return false; |
5af32db6 | 877 | |
d77b985a | 878 | for (PrvIterator P = instVer.ProvidesList(); |
f7f0d6c7 | 879 | P.end() == false; ++P) |
32d9baea DK |
880 | if (Pkg->Group != P.OwnerPkg()->Group) |
881 | CheckRConflicts(Pkg,P.ParentPkg().RevDependsList(),P.ProvideVersion()); | |
70ae2409 | 882 | |
75a90b93 DK |
883 | if (PkgLoop) |
884 | return true; | |
940f2160 | 885 | |
d77b985a DK |
886 | List->Flag(Pkg,pkgOrderList::UnPacked,pkgOrderList::States); |
887 | ||
2a2a7ef4 | 888 | if (Immediate == true && (instVer->MultiArch & pkgCache::Version::Same) == pkgCache::Version::Same) |
30426f48 DK |
889 | { |
890 | /* Do lockstep M-A:same unpacking in two phases: | |
891 | First unpack all installed architectures, then the not installed. | |
892 | This way we avoid that M-A: enabled packages are installed before | |
893 | their older non-M-A enabled packages are replaced by newer versions */ | |
894 | bool const installed = Pkg->CurrentVer != 0; | |
36635720 DK |
895 | if (installed == true && |
896 | (instVer != Pkg.CurrentVer() || | |
897 | ((Cache[Pkg].iFlags & pkgDepCache::ReInstall) == pkgDepCache::ReInstall)) && | |
898 | Install(Pkg,FileNames[Pkg->ID]) == false) | |
30426f48 | 899 | return false; |
d77b985a DK |
900 | for (PkgIterator P = Pkg.Group().PackageList(); |
901 | P.end() == false; P = Pkg.Group().NextPkg(P)) | |
902 | { | |
30426f48 | 903 | if (P->CurrentVer == 0 || P == Pkg || List->IsFlag(P,pkgOrderList::UnPacked) == true || |
d77b985a DK |
904 | Cache[P].InstallVer == 0 || (P.CurrentVer() == Cache[P].InstallVer && |
905 | (Cache[Pkg].iFlags & pkgDepCache::ReInstall) != pkgDepCache::ReInstall)) | |
906 | continue; | |
75a90b93 | 907 | if (SmartUnPack(P, false, Depth + 1) == false) |
30426f48 | 908 | return false; |
d77b985a | 909 | } |
30426f48 DK |
910 | if (installed == false && Install(Pkg,FileNames[Pkg->ID]) == false) |
911 | return false; | |
912 | for (PkgIterator P = Pkg.Group().PackageList(); | |
913 | P.end() == false; P = Pkg.Group().NextPkg(P)) | |
914 | { | |
915 | if (P->CurrentVer != 0 || P == Pkg || List->IsFlag(P,pkgOrderList::UnPacked) == true || | |
2b8b1e7a | 916 | List->IsFlag(P,pkgOrderList::Configured) == true || |
30426f48 DK |
917 | Cache[P].InstallVer == 0 || (P.CurrentVer() == Cache[P].InstallVer && |
918 | (Cache[Pkg].iFlags & pkgDepCache::ReInstall) != pkgDepCache::ReInstall)) | |
919 | continue; | |
75a90b93 | 920 | if (SmartUnPack(P, false, Depth + 1) == false) |
30426f48 DK |
921 | return false; |
922 | } | |
923 | } | |
cd5e8444 | 924 | // packages which are already unpacked don't need to be unpacked again |
d4b4e5ea DK |
925 | else if ((instVer != Pkg.CurrentVer() || |
926 | ((Cache[Pkg].iFlags & pkgDepCache::ReInstall) == pkgDepCache::ReInstall)) && | |
927 | Install(Pkg,FileNames[Pkg->ID]) == false) | |
28166356 DK |
928 | return false; |
929 | ||
d41d0e01 | 930 | if (Immediate == true) { |
590f1923 | 931 | // Perform immedate configuration of the package. |
d41d0e01 | 932 | if (SmartConfigure(Pkg, Depth + 1) == false) |
590f1923 | 933 | _error->Warning(_("Could not perform immediate configuration on '%s'. " |
90436124 | 934 | "Please see man 5 apt.conf under APT::Immediate-Configure for details. (%d)"),Pkg.FullName().c_str(),2); |
590f1923 | 935 | } |
6c139d6e AL |
936 | |
937 | return true; | |
938 | } | |
939 | /*}}}*/ | |
940 | // PM::OrderInstall - Installation ordering routine /*{{{*/ | |
941 | // --------------------------------------------------------------------- | |
942 | /* */ | |
281daf46 | 943 | pkgPackageManager::OrderResult pkgPackageManager::OrderInstall() |
6c139d6e | 944 | { |
7a1b1f8b | 945 | if (CreateOrderList() == false) |
281daf46 AL |
946 | return Failed; |
947 | ||
948 | Reset(); | |
6c139d6e | 949 | |
30e1eab5 | 950 | if (Debug == true) |
5e312de7 | 951 | clog << "Beginning to order" << endl; |
6c139d6e | 952 | |
5e312de7 DK |
953 | bool const ordering = |
954 | _config->FindB("PackageManager::UnpackAll",true) ? | |
955 | List->OrderUnpack(FileNames) : List->OrderCritical(); | |
956 | if (ordering == false) | |
281daf46 AL |
957 | { |
958 | _error->Error("Internal ordering error"); | |
959 | return Failed; | |
960 | } | |
961 | ||
30e1eab5 AL |
962 | if (Debug == true) |
963 | clog << "Done ordering" << endl; | |
964 | ||
281daf46 | 965 | bool DoneSomething = false; |
91c03d37 | 966 | for (pkgOrderList::iterator I = List->begin(); I != List->end(); ++I) |
6c139d6e AL |
967 | { |
968 | PkgIterator Pkg(Cache,*I); | |
0caa5a4c | 969 | |
281daf46 AL |
970 | if (List->IsNow(Pkg) == false) |
971 | { | |
0caa5a4c DK |
972 | if (Debug == true) |
973 | clog << "Skipping already done " << Pkg.FullName() << endl; | |
281daf46 AL |
974 | continue; |
975 | } | |
0caa5a4c | 976 | |
2fd65468 | 977 | if (List->IsMissing(Pkg) == true) |
281daf46 AL |
978 | { |
979 | if (Debug == true) | |
90436124 | 980 | clog << "Sequence completed at " << Pkg.FullName() << endl; |
281daf46 AL |
981 | if (DoneSomething == false) |
982 | { | |
983 | _error->Error("Internal Error, ordering was unable to handle the media swap"); | |
984 | return Failed; | |
985 | } | |
986 | return Incomplete; | |
987 | } | |
6c139d6e AL |
988 | |
989 | // Sanity check | |
d0c59649 AL |
990 | if (Cache[Pkg].Keep() == true && |
991 | Pkg.State() == pkgCache::PkgIterator::NeedsNothing && | |
992 | (Cache[Pkg].iFlags & pkgDepCache::ReInstall) != pkgDepCache::ReInstall) | |
281daf46 | 993 | { |
90436124 | 994 | _error->Error("Internal Error, trying to manipulate a kept package (%s)",Pkg.FullName().c_str()); |
281daf46 AL |
995 | return Failed; |
996 | } | |
6c139d6e AL |
997 | |
998 | // Perform a delete or an install | |
999 | if (Cache[Pkg].Delete() == true) | |
1000 | { | |
1001 | if (SmartRemove(Pkg) == false) | |
281daf46 | 1002 | return Failed; |
6c139d6e AL |
1003 | } |
1004 | else | |
d41d0e01 | 1005 | if (SmartUnPack(Pkg,List->IsFlag(Pkg,pkgOrderList::Immediate),0) == false) |
281daf46 AL |
1006 | return Failed; |
1007 | DoneSomething = true; | |
590f1923 CB |
1008 | |
1009 | if (ImmConfigureAll) { | |
1e3f4083 | 1010 | /* ConfigureAll here to pick up and packages left unconfigured because they were unpacked in the |
590f1923 | 1011 | "PreUnpack Checks" section */ |
c7c7d3e8 CB |
1012 | if (!ConfigureAll()) |
1013 | return Failed; | |
590f1923 | 1014 | } |
6c139d6e | 1015 | } |
5e312de7 | 1016 | |
6c139d6e AL |
1017 | // Final run through the configure phase |
1018 | if (ConfigureAll() == false) | |
281daf46 | 1019 | return Failed; |
6c139d6e AL |
1020 | |
1021 | // Sanity check | |
91c03d37 | 1022 | for (pkgOrderList::iterator I = List->begin(); I != List->end(); ++I) |
281daf46 | 1023 | { |
6c139d6e | 1024 | if (List->IsFlag(*I,pkgOrderList::Configured) == false) |
281daf46 AL |
1025 | { |
1026 | _error->Error("Internal error, packages left unconfigured. %s", | |
90436124 | 1027 | PkgIterator(Cache,*I).FullName().c_str()); |
281daf46 AL |
1028 | return Failed; |
1029 | } | |
9fc57a59 | 1030 | } |
281daf46 AL |
1031 | |
1032 | return Completed; | |
6c139d6e | 1033 | } |
3b1b0f29 MV |
1034 | // PM::DoInstallPostFork - compat /*{{{*/ |
1035 | // --------------------------------------------------------------------- | |
1036 | /*}}}*/ | |
bd5f39b3 | 1037 | #if (APT_PKG_MAJOR >= 4 && APT_PKG_MINOR >= 13) |
3b1b0f29 MV |
1038 | pkgPackageManager::OrderResult |
1039 | pkgPackageManager::DoInstallPostFork(int statusFd) | |
1040 | { | |
bd5f39b3 MV |
1041 | APT::Progress::PackageManager *progress = new |
1042 | APT::Progress::PackageManagerProgressFd(statusFd); | |
1043 | pkgPackageManager::OrderResult res = DoInstallPostFork(progress); | |
1044 | delete progress; | |
1045 | return res; | |
1046 | } | |
6c139d6e | 1047 | /*}}}*/ |
1d6386f3 MV |
1048 | // PM::DoInstallPostFork - Does install part that happens after the fork /*{{{*/ |
1049 | // --------------------------------------------------------------------- | |
1050 | pkgPackageManager::OrderResult | |
e6ad8031 | 1051 | pkgPackageManager::DoInstallPostFork(APT::Progress::PackageManager *progress) |
1d6386f3 | 1052 | { |
5e9458e2 MV |
1053 | bool goResult = Go(progress); |
1054 | if(goResult == false) | |
1055 | return Failed; | |
1056 | ||
1057 | return Res; | |
1d6386f3 | 1058 | }; |
bd5f39b3 MV |
1059 | #else |
1060 | pkgPackageManager::OrderResult | |
1061 | pkgPackageManager::DoInstallPostFork(int statusFd) | |
1062 | { | |
1063 | bool goResult = Go(statusFd); | |
1064 | if(goResult == false) | |
1065 | return Failed; | |
1066 | ||
1067 | return Res; | |
1068 | } | |
1069 | #endif | |
e6ad8031 | 1070 | /*}}}*/ |
2a7e07c7 MV |
1071 | // PM::DoInstall - Does the installation /*{{{*/ |
1072 | // --------------------------------------------------------------------- | |
3b1b0f29 | 1073 | /* compat */ |
bd5f39b3 | 1074 | #if (APT_PKG_MAJOR >= 4 && APT_PKG_MINOR >= 13) |
3b1b0f29 MV |
1075 | pkgPackageManager::OrderResult |
1076 | pkgPackageManager::DoInstall(int statusFd) | |
1077 | { | |
1078 | APT::Progress::PackageManager *progress = new | |
1079 | APT::Progress::PackageManagerProgressFd(statusFd); | |
1080 | OrderResult res = DoInstall(progress); | |
1081 | delete progress; | |
1082 | return res; | |
1083 | } | |
bd5f39b3 MV |
1084 | #else |
1085 | pkgPackageManager::OrderResult pkgPackageManager::DoInstall(int statusFd) | |
1086 | { | |
1087 | if(DoInstallPreFork() == Failed) | |
1088 | return Failed; | |
1089 | ||
1090 | return DoInstallPostFork(statusFd); | |
1091 | } | |
1092 | #endif | |
3b1b0f29 MV |
1093 | /*}}}*/ |
1094 | // PM::DoInstall - Does the installation /*{{{*/ | |
1095 | // --------------------------------------------------------------------- | |
2a7e07c7 MV |
1096 | /* This uses the filenames in FileNames and the information in the |
1097 | DepCache to perform the installation of packages.*/ | |
bd5f39b3 | 1098 | #if (APT_PKG_MAJOR >= 4 && APT_PKG_MINOR >= 13) |
e6ad8031 MV |
1099 | pkgPackageManager::OrderResult |
1100 | pkgPackageManager::DoInstall(APT::Progress::PackageManager *progress) | |
2a7e07c7 MV |
1101 | { |
1102 | if(DoInstallPreFork() == Failed) | |
1103 | return Failed; | |
1104 | ||
e6ad8031 | 1105 | return DoInstallPostFork(progress); |
2a7e07c7 | 1106 | } |
bd5f39b3 | 1107 | #endif |
eef71338 | 1108 | /*}}}*/ |