]>
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 | |
8d89cda7 | 9 | replacing smail. This can cause interesting side effects. |
6c139d6e AL |
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> | |
453b82a3 DK |
26 | #include <apt-pkg/macros.h> |
27 | #include <apt-pkg/pkgcache.h> | |
28 | #include <apt-pkg/cacheiterators.h> | |
29 | #include <apt-pkg/strutl.h> | |
b58f28d4 | 30 | #include <apt-pkg/install-progress.h> |
84573326 | 31 | #include <apt-pkg/prettyprinters.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 | 47 | pkgPackageManager::pkgPackageManager(pkgDepCache *pCache) : Cache(*pCache), |
6c55f07a | 48 | List(NULL), Res(Incomplete), d(NULL) |
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 | |
8d89cda7 | 140 | dependencies |
3a6d37fd | 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) | |
84573326 | 163 | clog << OutputInDepth(Depth) << "ImmediateAdd(): Adding Immediate flag to " << APT::PrettyPkg(&Cache, 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 | ||
8d89cda7 | 193 | // Mark the package and its dependents 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 | |
0eb4af9d | 265 | if (EarlyRemove(D.ParentPkg(), &D) == 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 | /*}}}*/ | |
9106d7c9 DK |
272 | // PM::CheckRBreaks - Look for reverse breaks /*{{{*/ |
273 | bool pkgPackageManager::CheckRBreaks(PkgIterator const &Pkg, DepIterator D, | |
274 | const char * const Ver) | |
275 | { | |
276 | for (;D.end() == false; ++D) | |
277 | { | |
278 | if (D->Type != pkgCache::Dep::DpkgBreaks) | |
279 | continue; | |
280 | ||
281 | PkgIterator const DP = D.ParentPkg(); | |
282 | if (Cache[DP].Delete() == false) | |
283 | continue; | |
284 | ||
285 | // Ignore self conflicts, ignore conflicts from irrelevant versions | |
286 | if (D.IsIgnorable(Pkg) || D.ParentVer() != DP.CurrentVer()) | |
287 | continue; | |
288 | ||
289 | if (Cache.VS().CheckDep(Ver, D->CompareOp, D.TargetVer()) == false) | |
290 | continue; | |
291 | ||
292 | // no earlyremove() here as user has already agreed to the permanent removal | |
293 | if (SmartRemove(DP) == false) | |
294 | return _error->Error("Internal Error, Could not early remove %s (%d)",DP.FullName().c_str(), 4); | |
295 | } | |
296 | return true; | |
297 | } | |
298 | /*}}}*/ | |
6c139d6e AL |
299 | // PM::ConfigureAll - Run the all out configuration /*{{{*/ |
300 | // --------------------------------------------------------------------- | |
301 | /* This configures every package. It is assumed they are all unpacked and | |
590f1923 CB |
302 | that the final configuration is valid. This is also used to catch packages |
303 | that have not been configured when using ImmConfigureAll */ | |
6c139d6e AL |
304 | bool pkgPackageManager::ConfigureAll() |
305 | { | |
b2e465d6 | 306 | pkgOrderList OList(&Cache); |
6c139d6e AL |
307 | |
308 | // Populate the order list | |
91c03d37 | 309 | for (pkgOrderList::iterator I = List->begin(); I != List->end(); ++I) |
6c139d6e AL |
310 | if (List->IsFlag(pkgCache::PkgIterator(Cache,*I), |
311 | pkgOrderList::UnPacked) == true) | |
312 | OList.push_back(*I); | |
313 | ||
314 | if (OList.OrderConfigure() == false) | |
315 | return false; | |
5e312de7 DK |
316 | |
317 | std::string const conf = _config->Find("PackageManager::Configure","all"); | |
318 | bool const ConfigurePkgs = (conf == "all"); | |
319 | ||
6c139d6e | 320 | // Perform the configuring |
91c03d37 | 321 | for (pkgOrderList::iterator I = OList.begin(); I != OList.end(); ++I) |
6c139d6e AL |
322 | { |
323 | PkgIterator Pkg(Cache,*I); | |
17182c0c CB |
324 | |
325 | /* Check if the package has been configured, this can happen if SmartConfigure | |
326 | calls its self */ | |
327 | if (List->IsFlag(Pkg,pkgOrderList::Configured)) continue; | |
803ea2a8 | 328 | |
d41d0e01 | 329 | if (ConfigurePkgs == true && SmartConfigure(Pkg, 0) == false) { |
c7c7d3e8 CB |
330 | if (ImmConfigureAll) |
331 | _error->Error(_("Could not perform immediate configuration on '%s'. " | |
90436124 | 332 | "Please see man 5 apt.conf under APT::Immediate-Configure for details. (%d)"),Pkg.FullName().c_str(),1); |
c7c7d3e8 | 333 | else |
90436124 | 334 | _error->Error("Internal error, packages left unconfigured. %s",Pkg.FullName().c_str()); |
6c139d6e | 335 | return false; |
634985f8 | 336 | } |
6c139d6e AL |
337 | |
338 | List->Flag(Pkg,pkgOrderList::Configured,pkgOrderList::States); | |
339 | } | |
340 | ||
341 | return true; | |
342 | } | |
343 | /*}}}*/ | |
0eb4af9d DK |
344 | // PM::NonLoopingSmart - helper to avoid loops while calling Smart methods /*{{{*/ |
345 | // ----------------------------------------------------------------------- | |
346 | /* ensures that a loop of the form A depends B, B depends A (and similar) | |
347 | is not leading us down into infinite recursion segfault land */ | |
348 | bool pkgPackageManager::NonLoopingSmart(SmartAction const action, pkgCache::PkgIterator &Pkg, | |
349 | pkgCache::PkgIterator DepPkg, int const Depth, bool const PkgLoop, | |
350 | bool * const Bad, bool * const Changed) | |
351 | { | |
352 | if (PkgLoop == false) | |
353 | List->Flag(Pkg,pkgOrderList::Loop); | |
354 | bool success = false; | |
355 | switch(action) | |
356 | { | |
357 | case UNPACK_IMMEDIATE: success = SmartUnPack(DepPkg, true, Depth + 1); break; | |
358 | case UNPACK: success = SmartUnPack(DepPkg, false, Depth + 1); break; | |
359 | case CONFIGURE: success = SmartConfigure(DepPkg, Depth + 1); break; | |
360 | } | |
361 | if (PkgLoop == false) | |
362 | List->RmFlag(Pkg,pkgOrderList::Loop); | |
363 | ||
364 | if (success == false) | |
365 | return false; | |
366 | ||
367 | if (Bad != NULL) | |
368 | *Bad = false; | |
369 | if (Changed != NULL && List->IsFlag(DepPkg,pkgOrderList::Loop) == false) | |
370 | *Changed = true; | |
371 | return true; | |
372 | } | |
373 | /*}}}*/ | |
6c139d6e AL |
374 | // PM::SmartConfigure - Perform immediate configuration of the pkg /*{{{*/ |
375 | // --------------------------------------------------------------------- | |
c7c7d3e8 | 376 | /* This function tries to put the system in a state where Pkg can be configured. |
0eb4af9d DK |
377 | This involves checking each of Pkg's dependencies and unpacking and |
378 | configuring packages where needed. */ | |
d41d0e01 | 379 | bool pkgPackageManager::SmartConfigure(PkgIterator Pkg, int const Depth) |
6c139d6e | 380 | { |
38ff3de6 | 381 | // If this is true, only check and correct and dependencies without the Loop flag |
2dd2c801 | 382 | bool const PkgLoop = List->IsFlag(Pkg,pkgOrderList::Loop); |
d41d0e01 | 383 | |
987d8d03 CB |
384 | if (Debug) { |
385 | VerIterator InstallVer = VerIterator(Cache,Cache[Pkg].InstallVer); | |
90436124 | 386 | clog << OutputInDepth(Depth) << "SmartConfigure " << Pkg.FullName() << " (" << InstallVer.VerStr() << ")"; |
d41d0e01 | 387 | if (PkgLoop) |
38ff3de6 | 388 | clog << " (Only Correct Dependencies)"; |
d41d0e01 | 389 | clog << endl; |
987d8d03 | 390 | } |
0eacf067 | 391 | |
590f1923 | 392 | VerIterator const instVer = Cache[Pkg].InstVerIter(Cache); |
0eb4af9d DK |
393 | |
394 | /* Because of the ordered list, most dependencies should be unpacked, | |
395 | however if there is a loop (A depends on B, B depends on A) this will not | |
38ff3de6 | 396 | be the case, so check for dependencies before configuring. */ |
2dd2c801 | 397 | bool Bad = false, Changed = false; |
9c5104cf | 398 | const unsigned int max_loops = _config->FindI("APT::pkgPackageManager::MaxLoopCount", 5000); |
bce4caa3 | 399 | unsigned int i=0; |
42d51f33 | 400 | std::list<DepIterator> needConfigure; |
bce4caa3 MV |
401 | do |
402 | { | |
2f589691 MV |
403 | // Check each dependency and see if anything needs to be done |
404 | // so that it can be configured | |
2dd2c801 DK |
405 | Changed = false; |
406 | for (DepIterator D = instVer.DependsList(); D.end() == false; ) | |
407 | { | |
408 | // Compute a single dependency element (glob or) | |
409 | pkgCache::DepIterator Start, End; | |
410 | D.GlobOr(Start,End); | |
411 | ||
c75e60eb | 412 | if (End->Type != pkgCache::Dep::Depends && End->Type != pkgCache::Dep::PreDepends) |
2dd2c801 DK |
413 | continue; |
414 | Bad = true; | |
415 | ||
2f589691 MV |
416 | // the first pass checks if we its all good, i.e. if we have |
417 | // to do anything at all | |
2dd2c801 DK |
418 | for (DepIterator Cur = Start; true; ++Cur) |
419 | { | |
93a0805b | 420 | std::unique_ptr<Version *[]> VList(Cur.AllTargets()); |
2dd2c801 | 421 | |
98cc7fd2 | 422 | for (Version **I = VList.get(); *I != 0; ++I) |
6c139d6e | 423 | { |
2dd2c801 DK |
424 | VerIterator Ver(Cache,*I); |
425 | PkgIterator DepPkg = Ver.ParentPkg(); | |
426 | ||
427 | // Check if the current version of the package is available and will satisfy this dependency | |
428 | if (DepPkg.CurrentVer() == Ver && List->IsNow(DepPkg) == true && | |
429 | List->IsFlag(DepPkg,pkgOrderList::Removed) == false && | |
4e6a7e26 DK |
430 | DepPkg.State() == PkgIterator::NeedsNothing && |
431 | (Cache[DepPkg].iFlags & pkgDepCache::ReInstall) != pkgDepCache::ReInstall) | |
2dd2c801 DK |
432 | { |
433 | Bad = false; | |
434 | break; | |
435 | } | |
436 | ||
2f589691 MV |
437 | // Check if the version that is going to be installed will satisfy the dependency |
438 | if (Cache[DepPkg].InstallVer != *I || List->IsNow(DepPkg) == false) | |
439 | continue; | |
440 | ||
441 | if (PkgLoop == true) | |
442 | { | |
443 | if (Debug) | |
84573326 | 444 | std::clog << OutputInDepth(Depth) << "Package " << APT::PrettyPkg(&Cache, Pkg) << " loops in SmartConfigure"; |
4e6a7e26 DK |
445 | if (List->IsFlag(DepPkg,pkgOrderList::UnPacked)) |
446 | Bad = false; | |
447 | else if (Debug) | |
448 | std::clog << ", but it isn't unpacked yet"; | |
449 | if (Debug) | |
450 | std::clog << std::endl; | |
2f589691 MV |
451 | } |
452 | } | |
453 | ||
454 | if (Cur == End || Bad == false) | |
455 | break; | |
456 | } | |
457 | ||
458 | // this dependency is in a good state, so we can stop | |
459 | if (Bad == false) | |
460 | { | |
461 | if (Debug) | |
84573326 | 462 | std::clog << OutputInDepth(Depth) << "Found ok dep " << APT::PrettyPkg(&Cache, Start.TargetPkg()) << std::endl; |
2f589691 MV |
463 | continue; |
464 | } | |
465 | ||
466 | // Check for dependencies that have not been unpacked, | |
467 | // probably due to loops. | |
468 | for (DepIterator Cur = Start; true; ++Cur) | |
469 | { | |
93a0805b | 470 | std::unique_ptr<Version *[]> VList(Cur.AllTargets()); |
2f589691 | 471 | |
98cc7fd2 | 472 | for (Version **I = VList.get(); *I != 0; ++I) |
2f589691 MV |
473 | { |
474 | VerIterator Ver(Cache,*I); | |
475 | PkgIterator DepPkg = Ver.ParentPkg(); | |
476 | ||
477 | // Check if the current version of the package is available and will satisfy this dependency | |
478 | if (DepPkg.CurrentVer() == Ver && List->IsNow(DepPkg) == true && | |
479 | List->IsFlag(DepPkg,pkgOrderList::Removed) == false && | |
4e6a7e26 DK |
480 | DepPkg.State() == PkgIterator::NeedsNothing && |
481 | (Cache[DepPkg].iFlags & pkgDepCache::ReInstall) != pkgDepCache::ReInstall) | |
2f589691 MV |
482 | continue; |
483 | ||
2dd2c801 | 484 | // Check if the version that is going to be installed will satisfy the dependency |
42d51f33 | 485 | if (Cache[DepPkg].InstallVer != *I || List->IsNow(DepPkg) == false) |
2dd2c801 DK |
486 | continue; |
487 | ||
42d51f33 | 488 | if (PkgLoop == true) |
2dd2c801 | 489 | { |
42d51f33 | 490 | if (Debug) |
84573326 | 491 | std::clog << OutputInDepth(Depth) << "Package " << APT::PrettyPkg(&Cache, Pkg) << " loops in SmartConfigure"; |
4e6a7e26 DK |
492 | if (List->IsFlag(DepPkg,pkgOrderList::UnPacked)) |
493 | Bad = false; | |
494 | else if (Debug) | |
495 | std::clog << ", but it isn't unpacked yet"; | |
496 | if (Debug) | |
497 | std::clog << std::endl; | |
42d51f33 DK |
498 | } |
499 | else | |
500 | { | |
501 | if (Debug) | |
84573326 | 502 | clog << OutputInDepth(Depth) << "Unpacking " << DepPkg.FullName() << " to avoid loop " << APT::PrettyDep(&Cache, Cur) << endl; |
0eb4af9d | 503 | if (NonLoopingSmart(UNPACK_IMMEDIATE, Pkg, DepPkg, Depth, PkgLoop, &Bad, &Changed) == false) |
71e7a0f3 | 504 | return false; |
2dd2c801 | 505 | } |
2f589691 MV |
506 | // at this point we either unpacked a Dep or we are in a loop, |
507 | // no need to unpack a second one | |
0eb4af9d | 508 | break; |
590f1923 | 509 | } |
42d51f33 DK |
510 | |
511 | if (Cur == End || Bad == false) | |
2dd2c801 | 512 | break; |
42d51f33 | 513 | } |
2dd2c801 DK |
514 | |
515 | if (Bad == false) | |
516 | continue; | |
517 | ||
42d51f33 DK |
518 | needConfigure.push_back(Start); |
519 | } | |
520 | if (i++ > max_loops) | |
521 | return _error->Error("Internal error: MaxLoopCount reached in SmartUnPack (1) for %s, aborting", Pkg.FullName().c_str()); | |
522 | } while (Changed == true); | |
523 | ||
2f589691 | 524 | // now go over anything that needs configuring |
42d51f33 DK |
525 | Bad = false, Changed = false, i = 0; |
526 | do | |
527 | { | |
528 | Changed = false; | |
6420c00e | 529 | for (std::list<DepIterator>::const_iterator D = needConfigure.begin(); D != needConfigure.end(); ++D) |
42d51f33 | 530 | { |
6420c00e | 531 | // Compute a single dependency element (glob or) without modifying D |
42d51f33 | 532 | pkgCache::DepIterator Start, End; |
6420c00e DK |
533 | { |
534 | pkgCache::DepIterator Discard = *D; | |
535 | Discard.GlobOr(Start,End); | |
536 | } | |
42d51f33 | 537 | |
c75e60eb | 538 | if (End->Type != pkgCache::Dep::Depends && End->Type != pkgCache::Dep::PreDepends) |
42d51f33 DK |
539 | continue; |
540 | Bad = true; | |
541 | ||
542 | // Search for dependencies which are unpacked but aren't configured yet (maybe loops) | |
2dd2c801 DK |
543 | for (DepIterator Cur = Start; true; ++Cur) |
544 | { | |
93a0805b | 545 | std::unique_ptr<Version *[]> VList(Cur.AllTargets()); |
2dd2c801 | 546 | |
98cc7fd2 | 547 | for (Version **I = VList.get(); *I != 0; ++I) |
2dd2c801 DK |
548 | { |
549 | VerIterator Ver(Cache,*I); | |
550 | PkgIterator DepPkg = Ver.ParentPkg(); | |
551 | ||
552 | // Check if the version that is going to be installed will satisfy the dependency | |
42d51f33 | 553 | if (Cache[DepPkg].InstallVer != *I) |
2dd2c801 DK |
554 | continue; |
555 | ||
42d51f33 | 556 | if (List->IsFlag(DepPkg,pkgOrderList::UnPacked)) |
d9f6c795 | 557 | { |
42d51f33 DK |
558 | if (List->IsFlag(DepPkg,pkgOrderList::Loop) && PkgLoop) |
559 | { | |
560 | // This dependency has already been dealt with by another SmartConfigure on Pkg | |
561 | Bad = false; | |
562 | break; | |
563 | } | |
0eb4af9d | 564 | if (Debug) |
84573326 | 565 | std::clog << OutputInDepth(Depth) << "Configure already unpacked " << APT::PrettyPkg(&Cache, DepPkg) << std::endl; |
0eb4af9d | 566 | if (NonLoopingSmart(CONFIGURE, Pkg, DepPkg, Depth, PkgLoop, &Bad, &Changed) == false) |
71e7a0f3 | 567 | return false; |
71e7a0f3 | 568 | break; |
0eb4af9d | 569 | |
d9f6c795 | 570 | } |
42d51f33 DK |
571 | else if (List->IsFlag(DepPkg,pkgOrderList::Configured)) |
572 | { | |
573 | Bad = false; | |
574 | break; | |
575 | } | |
590f1923 | 576 | } |
42d51f33 | 577 | if (Cur == End || Bad == false) |
2dd2c801 | 578 | break; |
42d51f33 DK |
579 | } |
580 | ||
581 | ||
2dd2c801 | 582 | if (Bad == true && Changed == false && Debug == true) |
84573326 | 583 | std::clog << OutputInDepth(Depth) << "Could not satisfy " << APT::PrettyDep(&Cache, *D) << std::endl; |
6c139d6e | 584 | } |
bce4caa3 | 585 | if (i++ > max_loops) |
42d51f33 | 586 | return _error->Error("Internal error: MaxLoopCount reached in SmartUnPack (2) for %s, aborting", Pkg.FullName().c_str()); |
2dd2c801 | 587 | } while (Changed == true); |
0eb4af9d | 588 | |
71e7a0f3 DK |
589 | if (Bad == true) |
590 | return _error->Error(_("Could not configure '%s'. "),Pkg.FullName().c_str()); | |
0eb4af9d | 591 | |
9106d7c9 DK |
592 | // Check for reverse conflicts. |
593 | if (CheckRBreaks(Pkg,Pkg.RevDependsList(), instVer.VerStr()) == false) | |
594 | return false; | |
595 | ||
596 | for (PrvIterator P = instVer.ProvidesList(); P.end() == false; ++P) | |
597 | if (Pkg->Group != P.OwnerPkg()->Group) | |
598 | CheckRBreaks(Pkg,P.ParentPkg().RevDependsList(),P.ProvideVersion()); | |
599 | ||
a99d02a8 | 600 | if (PkgLoop) return true; |
5e312de7 DK |
601 | |
602 | static std::string const conf = _config->Find("PackageManager::Configure","all"); | |
603 | static bool const ConfigurePkgs = (conf == "all" || conf == "smart"); | |
604 | ||
0eb4af9d | 605 | if (List->IsFlag(Pkg,pkgOrderList::Configured)) |
90436124 | 606 | return _error->Error("Internal configure error on '%s'.", Pkg.FullName().c_str()); |
5e312de7 | 607 | |
590f1923 CB |
608 | if (ConfigurePkgs == true && Configure(Pkg) == false) |
609 | return false; | |
75a90b93 | 610 | |
590f1923 | 611 | List->Flag(Pkg,pkgOrderList::Configured,pkgOrderList::States); |
6c139d6e | 612 | |
894d672e | 613 | if ((Cache[Pkg].InstVerIter(Cache)->MultiArch & pkgCache::Version::Same) == pkgCache::Version::Same) |
d77b985a DK |
614 | for (PkgIterator P = Pkg.Group().PackageList(); |
615 | P.end() == false; P = Pkg.Group().NextPkg(P)) | |
616 | { | |
617 | if (Pkg == P || List->IsFlag(P,pkgOrderList::Configured) == true || | |
2b8b1e7a | 618 | List->IsFlag(P,pkgOrderList::UnPacked) == false || |
d77b985a DK |
619 | Cache[P].InstallVer == 0 || (P.CurrentVer() == Cache[P].InstallVer && |
620 | (Cache[Pkg].iFlags & pkgDepCache::ReInstall) != pkgDepCache::ReInstall)) | |
621 | continue; | |
71e7a0f3 DK |
622 | if (SmartConfigure(P, (Depth +1)) == false) |
623 | return false; | |
d77b985a DK |
624 | } |
625 | ||
6c139d6e AL |
626 | // Sanity Check |
627 | if (List->IsFlag(Pkg,pkgOrderList::Configured) == false) | |
90436124 | 628 | return _error->Error(_("Could not configure '%s'. "),Pkg.FullName().c_str()); |
20382bad | 629 | |
6c139d6e AL |
630 | return true; |
631 | } | |
632 | /*}}}*/ | |
6c139d6e AL |
633 | // PM::EarlyRemove - Perform removal of packages before their time /*{{{*/ |
634 | // --------------------------------------------------------------------- | |
635 | /* This is called to deal with conflicts arising from unpacking */ | |
636 | bool pkgPackageManager::EarlyRemove(PkgIterator Pkg) | |
0eb4af9d DK |
637 | { |
638 | return EarlyRemove(Pkg, NULL); | |
639 | } | |
640 | bool pkgPackageManager::EarlyRemove(PkgIterator Pkg, DepIterator const * const Dep) | |
6c139d6e AL |
641 | { |
642 | if (List->IsNow(Pkg) == false) | |
643 | return true; | |
0eb4af9d | 644 | |
6c139d6e AL |
645 | // Already removed it |
646 | if (List->IsFlag(Pkg,pkgOrderList::Removed) == true) | |
647 | return true; | |
0eb4af9d | 648 | |
6c139d6e AL |
649 | // Woops, it will not be re-installed! |
650 | if (List->IsFlag(Pkg,pkgOrderList::InList) == false) | |
651 | return false; | |
9d4c8f67 | 652 | |
0eb4af9d DK |
653 | // these breaks on M-A:same packages can be dealt with. They 'loop' by design |
654 | if (Dep != NULL && (*Dep)->Type == pkgCache::Dep::DpkgBreaks && Dep->IsMultiArchImplicit() == true) | |
655 | return true; | |
656 | ||
9d4c8f67 | 657 | // Essential packages get special treatment |
5af32db6 | 658 | bool IsEssential = false; |
c5200869 JAK |
659 | if ((Pkg->Flags & pkgCache::Flag::Essential) != 0 || |
660 | (Pkg->Flags & pkgCache::Flag::Important) != 0) | |
5af32db6 AL |
661 | IsEssential = true; |
662 | ||
0eb4af9d | 663 | /* Check for packages that are the dependents of essential packages and |
5af32db6 AL |
664 | promote them too */ |
665 | if (Pkg->CurrentVer != 0) | |
666 | { | |
0eb4af9d | 667 | for (pkgCache::DepIterator D = Pkg.RevDependsList(); D.end() == false && |
f7f0d6c7 | 668 | IsEssential == false; ++D) |
5af32db6 | 669 | if (D->Type == pkgCache::Dep::Depends || D->Type == pkgCache::Dep::PreDepends) |
c5200869 JAK |
670 | if ((D.ParentPkg()->Flags & pkgCache::Flag::Essential) != 0 || |
671 | (D.ParentPkg()->Flags & pkgCache::Flag::Important) != 0) | |
5af32db6 AL |
672 | IsEssential = true; |
673 | } | |
674 | ||
675 | if (IsEssential == true) | |
9d4c8f67 AL |
676 | { |
677 | if (_config->FindB("APT::Force-LoopBreak",false) == false) | |
b2e465d6 AL |
678 | return _error->Error(_("This installation run will require temporarily " |
679 | "removing the essential package %s due to a " | |
680 | "Conflicts/Pre-Depends loop. This is often bad, " | |
681 | "but if you really want to do it, activate the " | |
90436124 | 682 | "APT::Force-LoopBreak option."),Pkg.FullName().c_str()); |
9d4c8f67 | 683 | } |
0eb4af9d DK |
684 | // dpkg will auto-deconfigure it, no need for the big remove hammer |
685 | else if (Dep != NULL && (*Dep)->Type == pkgCache::Dep::DpkgBreaks) | |
686 | return true; | |
687 | ||
6c139d6e AL |
688 | bool Res = SmartRemove(Pkg); |
689 | if (Cache[Pkg].Delete() == false) | |
690 | List->Flag(Pkg,pkgOrderList::Removed,pkgOrderList::States); | |
0eb4af9d | 691 | |
6c139d6e AL |
692 | return Res; |
693 | } | |
694 | /*}}}*/ | |
695 | // PM::SmartRemove - Removal Helper /*{{{*/ | |
696 | // --------------------------------------------------------------------- | |
697 | /* */ | |
698 | bool pkgPackageManager::SmartRemove(PkgIterator Pkg) | |
699 | { | |
700 | if (List->IsNow(Pkg) == false) | |
701 | return true; | |
702 | ||
703 | List->Flag(Pkg,pkgOrderList::Configured,pkgOrderList::States); | |
803ea2a8 | 704 | |
28166356 | 705 | return Remove(Pkg,(Cache[Pkg].iFlags & pkgDepCache::Purge) == pkgDepCache::Purge); |
6c139d6e AL |
706 | } |
707 | /*}}}*/ | |
708 | // PM::SmartUnPack - Install helper /*{{{*/ | |
709 | // --------------------------------------------------------------------- | |
1e3f4083 | 710 | /* This puts the system in a state where it can Unpack Pkg, if Pkg is already |
590f1923 | 711 | unpacked, or when it has been unpacked, if Immediate==true it configures it. */ |
6c139d6e | 712 | bool pkgPackageManager::SmartUnPack(PkgIterator Pkg) |
d77b985a | 713 | { |
d41d0e01 | 714 | return SmartUnPack(Pkg, true, 0); |
d77b985a | 715 | } |
d41d0e01 | 716 | bool pkgPackageManager::SmartUnPack(PkgIterator Pkg, bool const Immediate, int const Depth) |
6c139d6e | 717 | { |
d41d0e01 CB |
718 | bool PkgLoop = List->IsFlag(Pkg,pkgOrderList::Loop); |
719 | ||
987d8d03 | 720 | if (Debug) { |
90436124 | 721 | clog << OutputInDepth(Depth) << "SmartUnPack " << Pkg.FullName(); |
987d8d03 CB |
722 | VerIterator InstallVer = VerIterator(Cache,Cache[Pkg].InstallVer); |
723 | if (Pkg.CurrentVer() == 0) | |
c4f931f8 | 724 | clog << " (install version " << InstallVer.VerStr() << ")"; |
987d8d03 | 725 | else |
c4f931f8 | 726 | clog << " (replace version " << Pkg.CurrentVer().VerStr() << " with " << InstallVer.VerStr() << ")"; |
d41d0e01 | 727 | if (PkgLoop) |
c4f931f8 | 728 | clog << " (Only Perform PreUnpack Checks)"; |
0caa5a4c DK |
729 | if (Immediate) |
730 | clog << " immediately"; | |
c4f931f8 | 731 | clog << endl; |
987d8d03 | 732 | } |
cfcdf7fe | 733 | |
d77b985a DK |
734 | VerIterator const instVer = Cache[Pkg].InstVerIter(Cache); |
735 | ||
0eb4af9d | 736 | /* PreUnpack Checks: This loop checks and attempts to rectify any problems that would prevent the package being unpacked. |
98ee4922 | 737 | It addresses: PreDepends, Conflicts, Obsoletes and Breaks (DpkgBreaks). Any resolutions that do not require it should |
c7c7d3e8 | 738 | avoid configuration (calling SmartUnpack with Immediate=true), this is because when unpacking some packages with |
0eb4af9d | 739 | complex dependency structures, trying to configure some packages while breaking the loops can complicate things. |
98ee4922 | 740 | This will be either dealt with if the package is configured as a dependency of Pkg (if and when Pkg is configured), |
c7c7d3e8 | 741 | or by the ConfigureAll call at the end of the for loop in OrderInstall. */ |
0eb4af9d DK |
742 | bool SomethingBad = false, Changed = false; |
743 | bool couldBeTemporaryRemoved = Depth != 0 && List->IsFlag(Pkg,pkgOrderList::Removed) == false; | |
9c5104cf | 744 | const unsigned int max_loops = _config->FindI("APT::pkgPackageManager::MaxLoopCount", 5000); |
5ab7b53b | 745 | unsigned int i = 0; |
bce4caa3 MV |
746 | do |
747 | { | |
98ee4922 DK |
748 | Changed = false; |
749 | for (DepIterator D = instVer.DependsList(); D.end() == false; ) | |
6c139d6e | 750 | { |
98ee4922 DK |
751 | // Compute a single dependency element (glob or) |
752 | pkgCache::DepIterator Start, End; | |
753 | D.GlobOr(Start,End); | |
f4945db3 | 754 | |
98ee4922 DK |
755 | if (End->Type == pkgCache::Dep::PreDepends) |
756 | { | |
757 | bool Bad = true; | |
758 | if (Debug) | |
759 | clog << OutputInDepth(Depth) << "PreDepends order for " << Pkg.FullName() << std::endl; | |
760 | ||
761 | // Look for easy targets: packages that are already okay | |
762 | for (DepIterator Cur = Start; Bad == true; ++Cur) | |
6c139d6e | 763 | { |
93a0805b | 764 | std::unique_ptr<Version *[]> VList(Cur.AllTargets()); |
98cc7fd2 | 765 | for (Version **I = VList.get(); *I != 0; ++I) |
98ee4922 DK |
766 | { |
767 | VerIterator Ver(Cache,*I); | |
768 | PkgIterator Pkg = Ver.ParentPkg(); | |
769 | ||
770 | // See if the current version is ok | |
771 | if (Pkg.CurrentVer() == Ver && List->IsNow(Pkg) == true && | |
4e6a7e26 DK |
772 | Pkg.State() == PkgIterator::NeedsNothing && |
773 | (Cache[Pkg].iFlags & pkgDepCache::ReInstall) != pkgDepCache::ReInstall) | |
98ee4922 DK |
774 | { |
775 | Bad = false; | |
776 | if (Debug) | |
777 | clog << OutputInDepth(Depth) << "Found ok package " << Pkg.FullName() << endl; | |
778 | break; | |
779 | } | |
780 | } | |
781 | if (Cur == End) | |
782 | break; | |
17182c0c | 783 | } |
6c139d6e | 784 | |
98ee4922 | 785 | // Look for something that could be configured. |
275024e9 | 786 | for (DepIterator Cur = Start; Bad == true && Cur.end() == false; ++Cur) |
98ee4922 | 787 | { |
98cc7fd2 JAK |
788 | std::unique_ptr<Version *[]> VList(Cur.AllTargets()); |
789 | for (Version **I = VList.get(); *I != 0; ++I) | |
98ee4922 DK |
790 | { |
791 | VerIterator Ver(Cache,*I); | |
0eb4af9d | 792 | PkgIterator DepPkg = Ver.ParentPkg(); |
1006601e | 793 | |
98ee4922 | 794 | // Not the install version |
4e6a7e26 DK |
795 | if (Cache[DepPkg].InstallVer != *I) |
796 | continue; | |
797 | ||
798 | if (Cache[DepPkg].Keep() == true && DepPkg.State() == PkgIterator::NeedsNothing && | |
799 | (Cache[DepPkg].iFlags & pkgDepCache::ReInstall) != pkgDepCache::ReInstall) | |
98ee4922 DK |
800 | continue; |
801 | ||
0eb4af9d | 802 | if (List->IsFlag(DepPkg,pkgOrderList::Configured)) |
98ee4922 DK |
803 | { |
804 | Bad = false; | |
805 | break; | |
806 | } | |
807 | ||
808 | // check if it needs unpack or if if configure is enough | |
0eb4af9d | 809 | if (List->IsFlag(DepPkg,pkgOrderList::UnPacked) == false) |
98ee4922 | 810 | { |
4e6a7e26 DK |
811 | // two packages pre-depending on each other can't be handled sanely |
812 | if (List->IsFlag(DepPkg,pkgOrderList::Loop) && PkgLoop) | |
813 | { | |
814 | // this isn't an error as there is potential for something else to satisfy it | |
815 | // (like a provides or an or-group member) | |
816 | if (Debug) | |
817 | clog << OutputInDepth(Depth) << "Unpack loop detected between " << DepPkg.FullName() << " and " << Pkg.FullName() << endl; | |
818 | continue; | |
819 | } | |
820 | ||
98ee4922 | 821 | if (Debug) |
0eb4af9d DK |
822 | clog << OutputInDepth(Depth) << "Trying to SmartUnpack " << DepPkg.FullName() << endl; |
823 | if (NonLoopingSmart(UNPACK_IMMEDIATE, Pkg, DepPkg, Depth, PkgLoop, &Bad, &Changed) == false) | |
71e7a0f3 | 824 | return false; |
98ee4922 DK |
825 | } |
826 | else | |
827 | { | |
828 | if (Debug) | |
0eb4af9d DK |
829 | clog << OutputInDepth(Depth) << "Trying to SmartConfigure " << DepPkg.FullName() << endl; |
830 | if (NonLoopingSmart(CONFIGURE, Pkg, DepPkg, Depth, PkgLoop, &Bad, &Changed) == false) | |
71e7a0f3 | 831 | return false; |
98ee4922 | 832 | } |
0eb4af9d | 833 | break; |
e2a5ff0c | 834 | } |
6c139d6e | 835 | } |
98ee4922 DK |
836 | |
837 | if (Bad == true) | |
0eb4af9d | 838 | SomethingBad = true; |
6c139d6e | 839 | } |
98ee4922 | 840 | else if (End->Type == pkgCache::Dep::Conflicts || |
0eb4af9d DK |
841 | End->Type == pkgCache::Dep::Obsoletes || |
842 | End->Type == pkgCache::Dep::DpkgBreaks) | |
cfcdf7fe | 843 | { |
98cc7fd2 JAK |
844 | std::unique_ptr<Version *[]> VList(End.AllTargets()); |
845 | for (Version **I = VList.get(); *I != 0; ++I) | |
3e9ab9f0 | 846 | { |
98ee4922 DK |
847 | VerIterator Ver(Cache,*I); |
848 | PkgIterator ConflictPkg = Ver.ParentPkg(); | |
0eb4af9d DK |
849 | if (ConflictPkg.CurrentVer() != Ver) |
850 | { | |
851 | if (Debug) | |
84573326 | 852 | std::clog << OutputInDepth(Depth) << "Ignore not-installed version " << Ver.VerStr() << " of " << ConflictPkg.FullName() << " for " << APT::PrettyDep(&Cache, End) << std::endl; |
0eb4af9d DK |
853 | continue; |
854 | } | |
3e9ab9f0 | 855 | |
0eb4af9d | 856 | if (List->IsNow(ConflictPkg) == false) |
98ee4922 | 857 | { |
2252183c | 858 | if (Debug) |
84573326 | 859 | std::clog << OutputInDepth(Depth) << "Ignore already dealt-with version " << Ver.VerStr() << " of " << ConflictPkg.FullName() << " for " << APT::PrettyDep(&Cache, End) << std::endl; |
0eb4af9d DK |
860 | continue; |
861 | } | |
3e9ab9f0 | 862 | |
0eb4af9d | 863 | if (List->IsFlag(ConflictPkg,pkgOrderList::Removed) == true) |
98ee4922 | 864 | { |
2252183c | 865 | if (Debug) |
84573326 | 866 | clog << OutputInDepth(Depth) << "Ignoring " << APT::PrettyDep(&Cache, End) << " as " << ConflictPkg.FullName() << "was temporarily removed" << endl; |
0eb4af9d DK |
867 | continue; |
868 | } | |
869 | ||
870 | if (List->IsFlag(ConflictPkg,pkgOrderList::Loop) && PkgLoop) | |
871 | { | |
872 | if (End->Type == pkgCache::Dep::DpkgBreaks && End.IsMultiArchImplicit() == true) | |
440d3d65 DK |
873 | { |
874 | if (Debug) | |
84573326 | 875 | clog << OutputInDepth(Depth) << "Because dependency is MultiArchImplicit we ignored looping on: " << APT::PrettyPkg(&Cache, ConflictPkg) << endl; |
0eb4af9d | 876 | continue; |
98ee4922 | 877 | } |
98ee4922 | 878 | if (Debug) |
440d3d65 | 879 | { |
0eb4af9d DK |
880 | if (End->Type == pkgCache::Dep::DpkgBreaks) |
881 | clog << OutputInDepth(Depth) << "Because of breaks knot, deconfigure " << ConflictPkg.FullName() << " temporarily" << endl; | |
882 | else | |
71e7a0f3 | 883 | clog << OutputInDepth(Depth) << "Because of conflict knot, removing " << ConflictPkg.FullName() << " temporarily" << endl; |
98ee4922 | 884 | } |
0eb4af9d | 885 | if (EarlyRemove(ConflictPkg, &End) == false) |
9106d7c9 | 886 | return _error->Error("Internal Error, Could not early remove %s (%d)",ConflictPkg.FullName().c_str(), 3); |
0eb4af9d | 887 | SomethingBad = true; |
98ee4922 DK |
888 | continue; |
889 | } | |
890 | ||
0eb4af9d | 891 | if (Cache[ConflictPkg].Delete() == false) |
98ee4922 | 892 | { |
0eb4af9d | 893 | if (Debug) |
98ee4922 | 894 | { |
84573326 | 895 | clog << OutputInDepth(Depth) << "Unpacking " << ConflictPkg.FullName() << " to avoid " << APT::PrettyDep(&Cache, End); |
0eb4af9d DK |
896 | if (PkgLoop == true) |
897 | clog << " (Looping)"; | |
898 | clog << std::endl; | |
440d3d65 | 899 | } |
0eb4af9d DK |
900 | // we would like to avoid temporary removals and all that at best via a simple unpack |
901 | _error->PushToStack(); | |
902 | if (NonLoopingSmart(UNPACK, Pkg, ConflictPkg, Depth, PkgLoop, NULL, &Changed) == false) | |
2264548f | 903 | { |
0eb4af9d DK |
904 | // but if it fails ignore this failure and look for alternative ways of solving |
905 | if (Debug) | |
440d3d65 | 906 | { |
84573326 | 907 | clog << OutputInDepth(Depth) << "Avoidance unpack of " << ConflictPkg.FullName() << " failed for " << APT::PrettyDep(&Cache, End) << " ignoring:" << std::endl; |
95278287 | 908 | _error->DumpErrors(std::clog, GlobalError::DEBUG, false); |
0eb4af9d DK |
909 | } |
910 | _error->RevertToStack(); | |
911 | // ignorance can only happen if a) one of the offenders is already gone | |
912 | if (List->IsFlag(ConflictPkg,pkgOrderList::Removed) == true) | |
440d3d65 | 913 | { |
0eb4af9d | 914 | if (Debug) |
84573326 | 915 | clog << OutputInDepth(Depth) << "But " << ConflictPkg.FullName() << " was temporarily removed in the meantime to satisfy " << APT::PrettyDep(&Cache, End) << endl; |
98ee4922 | 916 | } |
0eb4af9d | 917 | else if (List->IsFlag(Pkg,pkgOrderList::Removed) == true) |
98ee4922 DK |
918 | { |
919 | if (Debug) | |
84573326 | 920 | clog << OutputInDepth(Depth) << "But " << Pkg.FullName() << " was temporarily removed in the meantime to satisfy " << APT::PrettyDep(&Cache, End) << endl; |
98ee4922 | 921 | } |
0eb4af9d | 922 | // or b) we can make one go (removal or dpkg auto-deconfigure) |
98ee4922 DK |
923 | else |
924 | { | |
925 | if (Debug) | |
84573326 | 926 | clog << OutputInDepth(Depth) << "So temprorary remove/deconfigure " << ConflictPkg.FullName() << " to satisfy " << APT::PrettyDep(&Cache, End) << endl; |
0eb4af9d | 927 | if (EarlyRemove(ConflictPkg, &End) == false) |
9106d7c9 | 928 | return _error->Error("Internal Error, Could not early remove %s (%d)",ConflictPkg.FullName().c_str(), 2); |
440d3d65 | 929 | } |
2264548f | 930 | } |
0eb4af9d DK |
931 | else |
932 | _error->MergeWithStack(); | |
6b92f60c | 933 | } |
0eb4af9d | 934 | else |
6b92f60c DK |
935 | { |
936 | if (Debug) | |
84573326 | 937 | clog << OutputInDepth(Depth) << "Removing " << ConflictPkg.FullName() << " now to avoid " << APT::PrettyDep(&Cache, End) << endl; |
0eb4af9d DK |
938 | // no earlyremove() here as user has already agreed to the permanent removal |
939 | if (SmartRemove(Pkg) == false) | |
9106d7c9 | 940 | return _error->Error("Internal Error, Could not early remove %s (%d)",ConflictPkg.FullName().c_str(), 1); |
6b92f60c | 941 | } |
6c139d6e AL |
942 | } |
943 | } | |
6c139d6e | 944 | } |
bce4caa3 | 945 | if (i++ > max_loops) |
91ea3def | 946 | return _error->Error("Internal error: APT::pkgPackageManager::MaxLoopCount reached in SmartConfigure for %s, aborting", Pkg.FullName().c_str()); |
98ee4922 | 947 | } while (Changed == true); |
0eb4af9d DK |
948 | |
949 | if (SomethingBad == true) | |
950 | return _error->Error("Couldn't configure %s, probably a dependency cycle.", Pkg.FullName().c_str()); | |
951 | ||
952 | if (couldBeTemporaryRemoved == true && List->IsFlag(Pkg,pkgOrderList::Removed) == true) | |
953 | { | |
954 | if (Debug) | |
84573326 | 955 | std::clog << OutputInDepth(Depth) << "Prevent unpack as " << APT::PrettyPkg(&Cache, Pkg) << " is currently temporarily removed" << std::endl; |
0eb4af9d DK |
956 | return true; |
957 | } | |
958 | ||
6c139d6e | 959 | // Check for reverse conflicts. |
5af32db6 | 960 | if (CheckRConflicts(Pkg,Pkg.RevDependsList(), |
d77b985a | 961 | instVer.VerStr()) == false) |
c7c7d3e8 | 962 | return false; |
5af32db6 | 963 | |
d77b985a | 964 | for (PrvIterator P = instVer.ProvidesList(); |
f7f0d6c7 | 965 | P.end() == false; ++P) |
32d9baea DK |
966 | if (Pkg->Group != P.OwnerPkg()->Group) |
967 | CheckRConflicts(Pkg,P.ParentPkg().RevDependsList(),P.ProvideVersion()); | |
70ae2409 | 968 | |
75a90b93 DK |
969 | if (PkgLoop) |
970 | return true; | |
940f2160 | 971 | |
d77b985a DK |
972 | List->Flag(Pkg,pkgOrderList::UnPacked,pkgOrderList::States); |
973 | ||
2a2a7ef4 | 974 | if (Immediate == true && (instVer->MultiArch & pkgCache::Version::Same) == pkgCache::Version::Same) |
30426f48 DK |
975 | { |
976 | /* Do lockstep M-A:same unpacking in two phases: | |
977 | First unpack all installed architectures, then the not installed. | |
978 | This way we avoid that M-A: enabled packages are installed before | |
979 | their older non-M-A enabled packages are replaced by newer versions */ | |
980 | bool const installed = Pkg->CurrentVer != 0; | |
36635720 DK |
981 | if (installed == true && |
982 | (instVer != Pkg.CurrentVer() || | |
983 | ((Cache[Pkg].iFlags & pkgDepCache::ReInstall) == pkgDepCache::ReInstall)) && | |
984 | Install(Pkg,FileNames[Pkg->ID]) == false) | |
30426f48 | 985 | return false; |
d77b985a DK |
986 | for (PkgIterator P = Pkg.Group().PackageList(); |
987 | P.end() == false; P = Pkg.Group().NextPkg(P)) | |
988 | { | |
30426f48 | 989 | if (P->CurrentVer == 0 || P == Pkg || List->IsFlag(P,pkgOrderList::UnPacked) == true || |
d77b985a DK |
990 | Cache[P].InstallVer == 0 || (P.CurrentVer() == Cache[P].InstallVer && |
991 | (Cache[Pkg].iFlags & pkgDepCache::ReInstall) != pkgDepCache::ReInstall)) | |
992 | continue; | |
75a90b93 | 993 | if (SmartUnPack(P, false, Depth + 1) == false) |
30426f48 | 994 | return false; |
d77b985a | 995 | } |
30426f48 DK |
996 | if (installed == false && Install(Pkg,FileNames[Pkg->ID]) == false) |
997 | return false; | |
998 | for (PkgIterator P = Pkg.Group().PackageList(); | |
999 | P.end() == false; P = Pkg.Group().NextPkg(P)) | |
1000 | { | |
1001 | if (P->CurrentVer != 0 || P == Pkg || List->IsFlag(P,pkgOrderList::UnPacked) == true || | |
2b8b1e7a | 1002 | List->IsFlag(P,pkgOrderList::Configured) == true || |
30426f48 DK |
1003 | Cache[P].InstallVer == 0 || (P.CurrentVer() == Cache[P].InstallVer && |
1004 | (Cache[Pkg].iFlags & pkgDepCache::ReInstall) != pkgDepCache::ReInstall)) | |
1005 | continue; | |
75a90b93 | 1006 | if (SmartUnPack(P, false, Depth + 1) == false) |
30426f48 DK |
1007 | return false; |
1008 | } | |
1009 | } | |
cd5e8444 | 1010 | // packages which are already unpacked don't need to be unpacked again |
d4b4e5ea DK |
1011 | else if ((instVer != Pkg.CurrentVer() || |
1012 | ((Cache[Pkg].iFlags & pkgDepCache::ReInstall) == pkgDepCache::ReInstall)) && | |
1013 | Install(Pkg,FileNames[Pkg->ID]) == false) | |
28166356 DK |
1014 | return false; |
1015 | ||
d41d0e01 | 1016 | if (Immediate == true) { |
590f1923 | 1017 | // Perform immedate configuration of the package. |
d41d0e01 | 1018 | if (SmartConfigure(Pkg, Depth + 1) == false) |
0eb4af9d | 1019 | _error->Error(_("Could not perform immediate configuration on '%s'. " |
90436124 | 1020 | "Please see man 5 apt.conf under APT::Immediate-Configure for details. (%d)"),Pkg.FullName().c_str(),2); |
590f1923 | 1021 | } |
6c139d6e AL |
1022 | |
1023 | return true; | |
1024 | } | |
1025 | /*}}}*/ | |
1026 | // PM::OrderInstall - Installation ordering routine /*{{{*/ | |
1027 | // --------------------------------------------------------------------- | |
1028 | /* */ | |
281daf46 | 1029 | pkgPackageManager::OrderResult pkgPackageManager::OrderInstall() |
6c139d6e | 1030 | { |
7a1b1f8b | 1031 | if (CreateOrderList() == false) |
281daf46 AL |
1032 | return Failed; |
1033 | ||
1034 | Reset(); | |
6c139d6e | 1035 | |
30e1eab5 | 1036 | if (Debug == true) |
5e312de7 | 1037 | clog << "Beginning to order" << endl; |
6c139d6e | 1038 | |
5e312de7 DK |
1039 | bool const ordering = |
1040 | _config->FindB("PackageManager::UnpackAll",true) ? | |
1041 | List->OrderUnpack(FileNames) : List->OrderCritical(); | |
1042 | if (ordering == false) | |
281daf46 AL |
1043 | { |
1044 | _error->Error("Internal ordering error"); | |
1045 | return Failed; | |
1046 | } | |
1047 | ||
30e1eab5 AL |
1048 | if (Debug == true) |
1049 | clog << "Done ordering" << endl; | |
1050 | ||
281daf46 | 1051 | bool DoneSomething = false; |
91c03d37 | 1052 | for (pkgOrderList::iterator I = List->begin(); I != List->end(); ++I) |
6c139d6e AL |
1053 | { |
1054 | PkgIterator Pkg(Cache,*I); | |
0caa5a4c | 1055 | |
281daf46 AL |
1056 | if (List->IsNow(Pkg) == false) |
1057 | { | |
0caa5a4c DK |
1058 | if (Debug == true) |
1059 | clog << "Skipping already done " << Pkg.FullName() << endl; | |
281daf46 AL |
1060 | continue; |
1061 | } | |
0caa5a4c | 1062 | |
2fd65468 | 1063 | if (List->IsMissing(Pkg) == true) |
281daf46 AL |
1064 | { |
1065 | if (Debug == true) | |
90436124 | 1066 | clog << "Sequence completed at " << Pkg.FullName() << endl; |
281daf46 AL |
1067 | if (DoneSomething == false) |
1068 | { | |
1069 | _error->Error("Internal Error, ordering was unable to handle the media swap"); | |
1070 | return Failed; | |
1071 | } | |
1072 | return Incomplete; | |
1073 | } | |
6c139d6e AL |
1074 | |
1075 | // Sanity check | |
d0c59649 AL |
1076 | if (Cache[Pkg].Keep() == true && |
1077 | Pkg.State() == pkgCache::PkgIterator::NeedsNothing && | |
1078 | (Cache[Pkg].iFlags & pkgDepCache::ReInstall) != pkgDepCache::ReInstall) | |
281daf46 | 1079 | { |
90436124 | 1080 | _error->Error("Internal Error, trying to manipulate a kept package (%s)",Pkg.FullName().c_str()); |
281daf46 AL |
1081 | return Failed; |
1082 | } | |
6c139d6e AL |
1083 | |
1084 | // Perform a delete or an install | |
1085 | if (Cache[Pkg].Delete() == true) | |
1086 | { | |
1087 | if (SmartRemove(Pkg) == false) | |
281daf46 | 1088 | return Failed; |
6c139d6e AL |
1089 | } |
1090 | else | |
d41d0e01 | 1091 | if (SmartUnPack(Pkg,List->IsFlag(Pkg,pkgOrderList::Immediate),0) == false) |
281daf46 AL |
1092 | return Failed; |
1093 | DoneSomething = true; | |
590f1923 CB |
1094 | |
1095 | if (ImmConfigureAll) { | |
1e3f4083 | 1096 | /* ConfigureAll here to pick up and packages left unconfigured because they were unpacked in the |
590f1923 | 1097 | "PreUnpack Checks" section */ |
c7c7d3e8 CB |
1098 | if (!ConfigureAll()) |
1099 | return Failed; | |
590f1923 | 1100 | } |
6c139d6e | 1101 | } |
5e312de7 | 1102 | |
6c139d6e AL |
1103 | // Final run through the configure phase |
1104 | if (ConfigureAll() == false) | |
281daf46 | 1105 | return Failed; |
6c139d6e AL |
1106 | |
1107 | // Sanity check | |
91c03d37 | 1108 | for (pkgOrderList::iterator I = List->begin(); I != List->end(); ++I) |
281daf46 | 1109 | { |
6c139d6e | 1110 | if (List->IsFlag(*I,pkgOrderList::Configured) == false) |
281daf46 AL |
1111 | { |
1112 | _error->Error("Internal error, packages left unconfigured. %s", | |
90436124 | 1113 | PkgIterator(Cache,*I).FullName().c_str()); |
281daf46 AL |
1114 | return Failed; |
1115 | } | |
9fc57a59 | 1116 | } |
281daf46 AL |
1117 | |
1118 | return Completed; | |
6c139d6e | 1119 | } |
3b1b0f29 MV |
1120 | // PM::DoInstallPostFork - compat /*{{{*/ |
1121 | // --------------------------------------------------------------------- | |
1122 | /*}}}*/ | |
1123 | pkgPackageManager::OrderResult | |
1124 | pkgPackageManager::DoInstallPostFork(int statusFd) | |
1125 | { | |
bd5f39b3 MV |
1126 | APT::Progress::PackageManager *progress = new |
1127 | APT::Progress::PackageManagerProgressFd(statusFd); | |
1128 | pkgPackageManager::OrderResult res = DoInstallPostFork(progress); | |
1129 | delete progress; | |
1130 | return res; | |
1131 | } | |
6c139d6e | 1132 | /*}}}*/ |
1d6386f3 MV |
1133 | // PM::DoInstallPostFork - Does install part that happens after the fork /*{{{*/ |
1134 | // --------------------------------------------------------------------- | |
1135 | pkgPackageManager::OrderResult | |
e6ad8031 | 1136 | pkgPackageManager::DoInstallPostFork(APT::Progress::PackageManager *progress) |
1d6386f3 | 1137 | { |
5e9458e2 MV |
1138 | bool goResult = Go(progress); |
1139 | if(goResult == false) | |
1140 | return Failed; | |
1141 | ||
1142 | return Res; | |
bf3ad91f | 1143 | } |
e6ad8031 | 1144 | /*}}}*/ |
2a7e07c7 MV |
1145 | // PM::DoInstall - Does the installation /*{{{*/ |
1146 | // --------------------------------------------------------------------- | |
3b1b0f29 MV |
1147 | /* compat */ |
1148 | pkgPackageManager::OrderResult | |
1149 | pkgPackageManager::DoInstall(int statusFd) | |
1150 | { | |
1151 | APT::Progress::PackageManager *progress = new | |
1152 | APT::Progress::PackageManagerProgressFd(statusFd); | |
1153 | OrderResult res = DoInstall(progress); | |
1154 | delete progress; | |
1155 | return res; | |
1156 | } | |
1157 | /*}}}*/ | |
1158 | // PM::DoInstall - Does the installation /*{{{*/ | |
1159 | // --------------------------------------------------------------------- | |
2a7e07c7 MV |
1160 | /* This uses the filenames in FileNames and the information in the |
1161 | DepCache to perform the installation of packages.*/ | |
e6ad8031 MV |
1162 | pkgPackageManager::OrderResult |
1163 | pkgPackageManager::DoInstall(APT::Progress::PackageManager *progress) | |
2a7e07c7 MV |
1164 | { |
1165 | if(DoInstallPreFork() == Failed) | |
1166 | return Failed; | |
1167 | ||
e6ad8031 | 1168 | return DoInstallPostFork(progress); |
2a7e07c7 | 1169 | } |
eef71338 | 1170 | /*}}}*/ |