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