]>
Commit | Line | Data |
---|---|---|
5ec427c2 AL |
1 | // -*- mode: cpp; mode: fold -*- |
2 | // Description /*{{{*/ | |
076d01b0 | 3 | // $Id: apt-get.cc,v 1.107 2001/05/27 04:45:49 jgg Exp $ |
5ec427c2 AL |
4 | /* ###################################################################### |
5 | ||
6 | apt-get - Cover for dpkg | |
7 | ||
8 | This is an allout cover for dpkg implementing a safer front end. It is | |
9 | based largely on libapt-pkg. | |
10 | ||
11 | The syntax is different, | |
12 | apt-get [opt] command [things] | |
13 | Where command is: | |
14 | update - Resyncronize the package files from their sources | |
15 | upgrade - Smart-Download the newest versions of all packages | |
16 | dselect-upgrade - Follows dselect's changes to the Status: field | |
17 | and installes new and removes old packages | |
18 | dist-upgrade - Powerfull upgrader designed to handle the issues with | |
19 | a new distribution. | |
20 | install - Download and install a given package (by name, not by .deb) | |
21 | check - Update the package cache and check for broken packages | |
22 | clean - Erase the .debs downloaded to /var/cache/apt/archives and | |
23 | the partial dir too | |
24 | ||
25 | ##################################################################### */ | |
26 | /*}}}*/ | |
27 | // Include Files /*{{{*/ | |
0a8e3465 AL |
28 | #include <apt-pkg/error.h> |
29 | #include <apt-pkg/cmndline.h> | |
30 | #include <apt-pkg/init.h> | |
31 | #include <apt-pkg/depcache.h> | |
32 | #include <apt-pkg/sourcelist.h> | |
0a8e3465 | 33 | #include <apt-pkg/algorithms.h> |
0919e3f9 | 34 | #include <apt-pkg/acquire-item.h> |
cdcc6d34 | 35 | #include <apt-pkg/strutl.h> |
1bc849af | 36 | #include <apt-pkg/clean.h> |
36375005 AL |
37 | #include <apt-pkg/srcrecords.h> |
38 | #include <apt-pkg/version.h> | |
2d11135a | 39 | #include <apt-pkg/cachefile.h> |
b2e465d6 AL |
40 | #include <apt-pkg/sptr.h> |
41 | #include <apt-pkg/versionmatch.h> | |
42 | ||
0a8e3465 | 43 | #include <config.h> |
b2e465d6 | 44 | #include <apti18n.h> |
0a8e3465 | 45 | |
0919e3f9 AL |
46 | #include "acqprogress.h" |
47 | ||
0a8e3465 | 48 | #include <fstream.h> |
d7827aca AL |
49 | #include <termios.h> |
50 | #include <sys/ioctl.h> | |
1bc849af | 51 | #include <sys/stat.h> |
101030ab | 52 | #include <sys/statvfs.h> |
d7827aca | 53 | #include <signal.h> |
65a1e968 | 54 | #include <unistd.h> |
3e3221ba | 55 | #include <stdio.h> |
d6e79b75 | 56 | #include <errno.h> |
c373c37a | 57 | #include <regex.h> |
54676e1a | 58 | #include <sys/wait.h> |
0a8e3465 AL |
59 | /*}}}*/ |
60 | ||
076d01b0 AL |
61 | using namespace std; |
62 | ||
63 | ostream c0out(0); | |
64 | ostream c1out(0); | |
65 | ostream c2out(0); | |
0a8e3465 AL |
66 | ofstream devnull("/dev/null"); |
67 | unsigned int ScreenWidth = 80; | |
68 | ||
1089ca89 AL |
69 | // class CacheFile - Cover class for some dependency cache functions /*{{{*/ |
70 | // --------------------------------------------------------------------- | |
71 | /* */ | |
72 | class CacheFile : public pkgCacheFile | |
73 | { | |
74 | static pkgCache *SortCache; | |
75 | static int NameComp(const void *a,const void *b); | |
76 | ||
77 | public: | |
78 | pkgCache::Package **List; | |
79 | ||
80 | void Sort(); | |
81 | bool CheckDeps(bool AllowBroken = false); | |
82 | bool Open(bool WithLock = true) | |
83 | { | |
84 | OpTextProgress Prog(*_config); | |
85 | if (pkgCacheFile::Open(Prog,WithLock) == false) | |
86 | return false; | |
87 | Sort(); | |
b2e465d6 | 88 | |
1089ca89 AL |
89 | return true; |
90 | }; | |
91 | CacheFile() : List(0) {}; | |
92 | }; | |
93 | /*}}}*/ | |
94 | ||
a6568219 AL |
95 | // YnPrompt - Yes No Prompt. /*{{{*/ |
96 | // --------------------------------------------------------------------- | |
97 | /* Returns true on a Yes.*/ | |
98 | bool YnPrompt() | |
99 | { | |
b2e465d6 AL |
100 | // This needs to be a capital |
101 | const char *Yes = _("Y"); | |
102 | ||
a6568219 AL |
103 | if (_config->FindB("APT::Get::Assume-Yes",false) == true) |
104 | { | |
b2e465d6 | 105 | c1out << Yes << endl; |
a6568219 AL |
106 | return true; |
107 | } | |
108 | ||
109 | char C = 0; | |
110 | char Jnk = 0; | |
b2e465d6 AL |
111 | if (read(STDIN_FILENO,&C,1) != 1) |
112 | return false; | |
113 | while (C != '\n' && Jnk != '\n') | |
114 | if (read(STDIN_FILENO,&Jnk,1) != 1) | |
115 | return false; | |
a6568219 | 116 | |
b2e465d6 | 117 | if (!(toupper(C) == *Yes || C == '\n' || C == '\r')) |
a6568219 AL |
118 | return false; |
119 | return true; | |
120 | } | |
121 | /*}}}*/ | |
6f86c974 AL |
122 | // AnalPrompt - Annoying Yes No Prompt. /*{{{*/ |
123 | // --------------------------------------------------------------------- | |
124 | /* Returns true on a Yes.*/ | |
125 | bool AnalPrompt(const char *Text) | |
126 | { | |
127 | char Buf[1024]; | |
128 | cin.getline(Buf,sizeof(Buf)); | |
129 | if (strcmp(Buf,Text) == 0) | |
130 | return true; | |
131 | return false; | |
132 | } | |
133 | /*}}}*/ | |
0a8e3465 AL |
134 | // ShowList - Show a list /*{{{*/ |
135 | // --------------------------------------------------------------------- | |
b2e465d6 | 136 | /* This prints out a string of space separated words with a title and |
0a8e3465 | 137 | a two space indent line wraped to the current screen width. */ |
83d89a9f | 138 | bool ShowList(ostream &out,string Title,string List) |
0a8e3465 AL |
139 | { |
140 | if (List.empty() == true) | |
83d89a9f | 141 | return true; |
0a8e3465 AL |
142 | |
143 | // Acount for the leading space | |
144 | int ScreenWidth = ::ScreenWidth - 3; | |
145 | ||
146 | out << Title << endl; | |
147 | string::size_type Start = 0; | |
148 | while (Start < List.size()) | |
149 | { | |
150 | string::size_type End; | |
151 | if (Start + ScreenWidth >= List.size()) | |
152 | End = List.size(); | |
153 | else | |
154 | End = List.rfind(' ',Start+ScreenWidth); | |
155 | ||
156 | if (End == string::npos || End < Start) | |
157 | End = Start + ScreenWidth; | |
158 | out << " " << string(List,Start,End - Start) << endl; | |
159 | Start = End + 1; | |
160 | } | |
83d89a9f | 161 | return false; |
0a8e3465 AL |
162 | } |
163 | /*}}}*/ | |
164 | // ShowBroken - Debugging aide /*{{{*/ | |
165 | // --------------------------------------------------------------------- | |
166 | /* This prints out the names of all the packages that are broken along | |
167 | with the name of each each broken dependency and a quite version | |
b2e465d6 AL |
168 | description. |
169 | ||
170 | The output looks like: | |
171 | Sorry, but the following packages have unmet dependencies: | |
172 | exim: Depends: libc6 (>= 2.1.94) but 2.1.3-10 is to be installed | |
173 | Depends: libldap2 (>= 2.0.2-2) but it is not going to be installed | |
174 | Depends: libsasl7 but it is not going to be installed | |
175 | */ | |
421c8d10 | 176 | void ShowBroken(ostream &out,CacheFile &Cache,bool Now) |
0a8e3465 | 177 | { |
b2e465d6 | 178 | out << _("Sorry, but the following packages have unmet dependencies:") << endl; |
1089ca89 | 179 | for (unsigned J = 0; J < Cache->Head().PackageCount; J++) |
0a8e3465 | 180 | { |
1089ca89 AL |
181 | pkgCache::PkgIterator I(Cache,Cache.List[J]); |
182 | ||
303a1703 AL |
183 | if (Cache[I].InstBroken() == false) |
184 | continue; | |
185 | ||
186 | // Print out each package and the failed dependencies | |
187 | out <<" " << I.Name() << ":"; | |
648e3cb4 | 188 | unsigned Indent = strlen(I.Name()) + 3; |
303a1703 AL |
189 | bool First = true; |
190 | if (Cache[I].InstVerIter(Cache).end() == true) | |
0a8e3465 | 191 | { |
303a1703 AL |
192 | cout << endl; |
193 | continue; | |
194 | } | |
195 | ||
30e1eab5 | 196 | for (pkgCache::DepIterator D = Cache[I].InstVerIter(Cache).DependsList(); D.end() == false;) |
303a1703 | 197 | { |
30e1eab5 AL |
198 | // Compute a single dependency element (glob or) |
199 | pkgCache::DepIterator Start; | |
200 | pkgCache::DepIterator End; | |
201 | D.GlobOr(Start,End); | |
76fbce56 | 202 | |
1089ca89 | 203 | if (Cache->IsImportantDep(End) == false || |
30e1eab5 | 204 | (Cache[End] & pkgDepCache::DepGInstall) == pkgDepCache::DepGInstall) |
303a1703 | 205 | continue; |
cc718e9a | 206 | |
648e3cb4 AL |
207 | bool FirstOr = true; |
208 | while (1) | |
0a8e3465 | 209 | { |
648e3cb4 AL |
210 | if (First == false) |
211 | for (unsigned J = 0; J != Indent; J++) | |
212 | out << ' '; | |
213 | First = false; | |
214 | ||
215 | if (FirstOr == false) | |
216 | { | |
217 | for (unsigned J = 0; J != strlen(End.DepType()) + 3; J++) | |
218 | out << ' '; | |
219 | } | |
0a8e3465 | 220 | else |
648e3cb4 AL |
221 | out << ' ' << End.DepType() << ": "; |
222 | FirstOr = false; | |
223 | ||
224 | out << Start.TargetPkg().Name(); | |
225 | ||
226 | // Show a quick summary of the version requirements | |
227 | if (Start.TargetVer() != 0) | |
b2e465d6 | 228 | out << " (" << Start.CompType() << " " << Start.TargetVer() << ")"; |
648e3cb4 AL |
229 | |
230 | /* Show a summary of the target package if possible. In the case | |
231 | of virtual packages we show nothing */ | |
232 | pkgCache::PkgIterator Targ = Start.TargetPkg(); | |
233 | if (Targ->ProvidesList == 0) | |
7e798dd7 | 234 | { |
b2e465d6 | 235 | out << ' '; |
648e3cb4 | 236 | pkgCache::VerIterator Ver = Cache[Targ].InstVerIter(Cache); |
f0ec51c2 AL |
237 | if (Now == true) |
238 | Ver = Targ.CurrentVer(); | |
239 | ||
648e3cb4 | 240 | if (Ver.end() == false) |
b2e465d6 AL |
241 | { |
242 | if (Now == true) | |
243 | ioprintf(out,_("but %s is installed"),Ver.VerStr()); | |
244 | else | |
245 | ioprintf(out,_("but %s is to be installed"),Ver.VerStr()); | |
246 | } | |
648e3cb4 | 247 | else |
303a1703 | 248 | { |
648e3cb4 AL |
249 | if (Cache[Targ].CandidateVerIter(Cache).end() == true) |
250 | { | |
251 | if (Targ->ProvidesList == 0) | |
b2e465d6 | 252 | out << _("but it is not installable"); |
648e3cb4 | 253 | else |
b2e465d6 | 254 | out << _("but it is a virtual package"); |
648e3cb4 | 255 | } |
303a1703 | 256 | else |
b2e465d6 | 257 | out << (Now?_("but it is not installed"):_("but it is not going to be installed")); |
648e3cb4 AL |
258 | } |
259 | } | |
260 | ||
261 | if (Start != End) | |
b2e465d6 | 262 | out << _(" or"); |
648e3cb4 AL |
263 | out << endl; |
264 | ||
265 | if (Start == End) | |
266 | break; | |
267 | Start++; | |
268 | } | |
303a1703 | 269 | } |
0a8e3465 AL |
270 | } |
271 | } | |
272 | /*}}}*/ | |
273 | // ShowNew - Show packages to newly install /*{{{*/ | |
274 | // --------------------------------------------------------------------- | |
275 | /* */ | |
1089ca89 | 276 | void ShowNew(ostream &out,CacheFile &Cache) |
0a8e3465 AL |
277 | { |
278 | /* Print out a list of packages that are going to be removed extra | |
279 | to what the user asked */ | |
0a8e3465 | 280 | string List; |
1089ca89 AL |
281 | for (unsigned J = 0; J < Cache->Head().PackageCount; J++) |
282 | { | |
283 | pkgCache::PkgIterator I(Cache,Cache.List[J]); | |
284 | if (Cache[I].NewInstall() == true) | |
0a8e3465 | 285 | List += string(I.Name()) + " "; |
1089ca89 AL |
286 | } |
287 | ||
b2e465d6 | 288 | ShowList(out,_("The following NEW packages will be installed:"),List); |
0a8e3465 AL |
289 | } |
290 | /*}}}*/ | |
291 | // ShowDel - Show packages to delete /*{{{*/ | |
292 | // --------------------------------------------------------------------- | |
293 | /* */ | |
1089ca89 | 294 | void ShowDel(ostream &out,CacheFile &Cache) |
0a8e3465 AL |
295 | { |
296 | /* Print out a list of packages that are going to be removed extra | |
297 | to what the user asked */ | |
0a8e3465 | 298 | string List; |
1089ca89 | 299 | for (unsigned J = 0; J < Cache->Head().PackageCount; J++) |
fc4b5c9f | 300 | { |
1089ca89 AL |
301 | pkgCache::PkgIterator I(Cache,Cache.List[J]); |
302 | if (Cache[I].Delete() == true) | |
fc4b5c9f | 303 | { |
1089ca89 | 304 | if ((Cache[I].iFlags & pkgDepCache::Purge) == pkgDepCache::Purge) |
fc4b5c9f AL |
305 | List += string(I.Name()) + "* "; |
306 | else | |
307 | List += string(I.Name()) + " "; | |
308 | } | |
309 | } | |
3d615484 | 310 | |
b2e465d6 | 311 | ShowList(out,_("The following packages will be REMOVED:"),List); |
0a8e3465 AL |
312 | } |
313 | /*}}}*/ | |
314 | // ShowKept - Show kept packages /*{{{*/ | |
315 | // --------------------------------------------------------------------- | |
316 | /* */ | |
f292686b | 317 | void ShowKept(ostream &out,CacheFile &Cache) |
0a8e3465 | 318 | { |
0a8e3465 | 319 | string List; |
f292686b | 320 | for (unsigned J = 0; J < Cache->Head().PackageCount; J++) |
0a8e3465 | 321 | { |
f292686b AL |
322 | pkgCache::PkgIterator I(Cache,Cache.List[J]); |
323 | ||
0a8e3465 | 324 | // Not interesting |
f292686b AL |
325 | if (Cache[I].Upgrade() == true || Cache[I].Upgradable() == false || |
326 | I->CurrentVer == 0 || Cache[I].Delete() == true) | |
0a8e3465 AL |
327 | continue; |
328 | ||
329 | List += string(I.Name()) + " "; | |
330 | } | |
b2e465d6 | 331 | ShowList(out,_("The following packages have been kept back"),List); |
0a8e3465 AL |
332 | } |
333 | /*}}}*/ | |
334 | // ShowUpgraded - Show upgraded packages /*{{{*/ | |
335 | // --------------------------------------------------------------------- | |
336 | /* */ | |
1089ca89 | 337 | void ShowUpgraded(ostream &out,CacheFile &Cache) |
0a8e3465 | 338 | { |
0a8e3465 | 339 | string List; |
1089ca89 | 340 | for (unsigned J = 0; J < Cache->Head().PackageCount; J++) |
0a8e3465 | 341 | { |
1089ca89 AL |
342 | pkgCache::PkgIterator I(Cache,Cache.List[J]); |
343 | ||
0a8e3465 | 344 | // Not interesting |
1089ca89 | 345 | if (Cache[I].Upgrade() == false || Cache[I].NewInstall() == true) |
0a8e3465 AL |
346 | continue; |
347 | ||
348 | List += string(I.Name()) + " "; | |
349 | } | |
b2e465d6 AL |
350 | ShowList(out,_("The following packages will be upgraded"),List); |
351 | } | |
352 | /*}}}*/ | |
353 | // ShowDowngraded - Show downgraded packages /*{{{*/ | |
354 | // --------------------------------------------------------------------- | |
355 | /* */ | |
356 | bool ShowDowngraded(ostream &out,CacheFile &Cache) | |
357 | { | |
358 | string List; | |
359 | for (unsigned J = 0; J < Cache->Head().PackageCount; J++) | |
360 | { | |
361 | pkgCache::PkgIterator I(Cache,Cache.List[J]); | |
362 | ||
363 | // Not interesting | |
364 | if (Cache[I].Downgrade() == false || Cache[I].NewInstall() == true) | |
365 | continue; | |
366 | ||
367 | List += string(I.Name()) + " "; | |
368 | } | |
369 | return ShowList(out,_("The following packages will be DOWNGRADED"),List); | |
0a8e3465 AL |
370 | } |
371 | /*}}}*/ | |
372 | // ShowHold - Show held but changed packages /*{{{*/ | |
373 | // --------------------------------------------------------------------- | |
374 | /* */ | |
1089ca89 | 375 | bool ShowHold(ostream &out,CacheFile &Cache) |
0a8e3465 | 376 | { |
0a8e3465 | 377 | string List; |
1089ca89 | 378 | for (unsigned J = 0; J < Cache->Head().PackageCount; J++) |
0a8e3465 | 379 | { |
1089ca89 AL |
380 | pkgCache::PkgIterator I(Cache,Cache.List[J]); |
381 | if (Cache[I].InstallVer != (pkgCache::Version *)I.CurrentVer() && | |
0a8e3465 AL |
382 | I->SelectedState == pkgCache::State::Hold) |
383 | List += string(I.Name()) + " "; | |
384 | } | |
385 | ||
b2e465d6 | 386 | return ShowList(out,_("The following held packages will be changed:"),List); |
0a8e3465 AL |
387 | } |
388 | /*}}}*/ | |
389 | // ShowEssential - Show an essential package warning /*{{{*/ | |
390 | // --------------------------------------------------------------------- | |
391 | /* This prints out a warning message that is not to be ignored. It shows | |
392 | all essential packages and their dependents that are to be removed. | |
393 | It is insanely risky to remove the dependents of an essential package! */ | |
1089ca89 | 394 | bool ShowEssential(ostream &out,CacheFile &Cache) |
0a8e3465 | 395 | { |
0a8e3465 | 396 | string List; |
b2e465d6 AL |
397 | bool *Added = new bool[Cache->Head().PackageCount]; |
398 | for (unsigned int I = 0; I != Cache->Head().PackageCount; I++) | |
0a8e3465 AL |
399 | Added[I] = false; |
400 | ||
1089ca89 | 401 | for (unsigned J = 0; J < Cache->Head().PackageCount; J++) |
0a8e3465 | 402 | { |
1089ca89 | 403 | pkgCache::PkgIterator I(Cache,Cache.List[J]); |
b2e465d6 AL |
404 | if ((I->Flags & pkgCache::Flag::Essential) != pkgCache::Flag::Essential && |
405 | (I->Flags & pkgCache::Flag::Important) != pkgCache::Flag::Important) | |
0a8e3465 AL |
406 | continue; |
407 | ||
408 | // The essential package is being removed | |
1089ca89 | 409 | if (Cache[I].Delete() == true) |
0a8e3465 AL |
410 | { |
411 | if (Added[I->ID] == false) | |
412 | { | |
413 | Added[I->ID] = true; | |
414 | List += string(I.Name()) + " "; | |
415 | } | |
416 | } | |
417 | ||
418 | if (I->CurrentVer == 0) | |
419 | continue; | |
420 | ||
421 | // Print out any essential package depenendents that are to be removed | |
b2e465d6 | 422 | for (pkgCache::DepIterator D = I.CurrentVer().DependsList(); D.end() == false; D++) |
0a8e3465 | 423 | { |
3e3221ba AL |
424 | // Skip everything but depends |
425 | if (D->Type != pkgCache::Dep::PreDepends && | |
426 | D->Type != pkgCache::Dep::Depends) | |
427 | continue; | |
428 | ||
0a8e3465 | 429 | pkgCache::PkgIterator P = D.SmartTargetPkg(); |
1089ca89 | 430 | if (Cache[P].Delete() == true) |
0a8e3465 AL |
431 | { |
432 | if (Added[P->ID] == true) | |
433 | continue; | |
434 | Added[P->ID] = true; | |
3e3221ba AL |
435 | |
436 | char S[300]; | |
20ebd488 | 437 | snprintf(S,sizeof(S),_("%s (due to %s) "),P.Name(),I.Name()); |
3e3221ba | 438 | List += S; |
0a8e3465 AL |
439 | } |
440 | } | |
441 | } | |
442 | ||
83d89a9f | 443 | delete [] Added; |
b2e465d6 AL |
444 | return ShowList(out,_("WARNING: The following essential packages will be removed\n" |
445 | "This should NOT be done unless you know exactly what you are doing!"),List); | |
0a8e3465 AL |
446 | } |
447 | /*}}}*/ | |
448 | // Stats - Show some statistics /*{{{*/ | |
449 | // --------------------------------------------------------------------- | |
450 | /* */ | |
451 | void Stats(ostream &out,pkgDepCache &Dep) | |
452 | { | |
453 | unsigned long Upgrade = 0; | |
b2e465d6 | 454 | unsigned long Downgrade = 0; |
0a8e3465 | 455 | unsigned long Install = 0; |
d0c59649 | 456 | unsigned long ReInstall = 0; |
0a8e3465 AL |
457 | for (pkgCache::PkgIterator I = Dep.PkgBegin(); I.end() == false; I++) |
458 | { | |
459 | if (Dep[I].NewInstall() == true) | |
460 | Install++; | |
461 | else | |
b2e465d6 | 462 | { |
0a8e3465 AL |
463 | if (Dep[I].Upgrade() == true) |
464 | Upgrade++; | |
b2e465d6 AL |
465 | else |
466 | if (Dep[I].Downgrade() == true) | |
467 | Downgrade++; | |
468 | } | |
469 | ||
d0c59649 AL |
470 | if (Dep[I].Delete() == false && (Dep[I].iFlags & pkgDepCache::ReInstall) == pkgDepCache::ReInstall) |
471 | ReInstall++; | |
0a8e3465 AL |
472 | } |
473 | ||
b2e465d6 AL |
474 | ioprintf(out,_("%lu packages upgraded, %lu newly installed, "), |
475 | Upgrade,Install); | |
476 | ||
d0c59649 | 477 | if (ReInstall != 0) |
b2e465d6 AL |
478 | ioprintf(out,_("%lu reinstalled, "),ReInstall); |
479 | if (Downgrade != 0) | |
480 | ioprintf(out,_("%lu downgraded, "),Downgrade); | |
0a8e3465 | 481 | |
b2e465d6 AL |
482 | ioprintf(out,_("%lu to remove and %lu not upgraded.\n"), |
483 | Dep.DelCount(),Dep.KeepCount()); | |
484 | ||
0a8e3465 | 485 | if (Dep.BadCount() != 0) |
b2e465d6 AL |
486 | ioprintf(out,_("%lu packages not fully installed or removed.\n"), |
487 | Dep.BadCount()); | |
0a8e3465 AL |
488 | } |
489 | /*}}}*/ | |
490 | ||
1089ca89 | 491 | // CacheFile::NameComp - QSort compare by name /*{{{*/ |
0a8e3465 AL |
492 | // --------------------------------------------------------------------- |
493 | /* */ | |
1089ca89 AL |
494 | pkgCache *CacheFile::SortCache = 0; |
495 | int CacheFile::NameComp(const void *a,const void *b) | |
0a8e3465 | 496 | { |
8508b1df AL |
497 | if (*(pkgCache::Package **)a == 0 || *(pkgCache::Package **)b == 0) |
498 | return *(pkgCache::Package **)a - *(pkgCache::Package **)b; | |
0a8e3465 | 499 | |
1089ca89 AL |
500 | const pkgCache::Package &A = **(pkgCache::Package **)a; |
501 | const pkgCache::Package &B = **(pkgCache::Package **)b; | |
502 | ||
503 | return strcmp(SortCache->StrP + A.Name,SortCache->StrP + B.Name); | |
504 | } | |
505 | /*}}}*/ | |
506 | // CacheFile::Sort - Sort by name /*{{{*/ | |
507 | // --------------------------------------------------------------------- | |
508 | /* */ | |
509 | void CacheFile::Sort() | |
510 | { | |
511 | delete [] List; | |
512 | List = new pkgCache::Package *[Cache->Head().PackageCount]; | |
513 | memset(List,0,sizeof(*List)*Cache->Head().PackageCount); | |
514 | pkgCache::PkgIterator I = Cache->PkgBegin(); | |
515 | for (;I.end() != true; I++) | |
516 | List[I->ID] = I; | |
517 | ||
518 | SortCache = *this; | |
519 | qsort(List,Cache->Head().PackageCount,sizeof(*List),NameComp); | |
520 | } | |
0a8e3465 | 521 | /*}}}*/ |
b2e465d6 | 522 | // CacheFile::CheckDeps - Open the cache file /*{{{*/ |
0a8e3465 AL |
523 | // --------------------------------------------------------------------- |
524 | /* This routine generates the caches and then opens the dependency cache | |
525 | and verifies that the system is OK. */ | |
2d11135a | 526 | bool CacheFile::CheckDeps(bool AllowBroken) |
0a8e3465 | 527 | { |
d38b7b3d AL |
528 | if (_error->PendingError() == true) |
529 | return false; | |
0a8e3465 | 530 | |
0a8e3465 | 531 | // Check that the system is OK |
b2e465d6 | 532 | if (DCache->DelCount() != 0 || DCache->InstCount() != 0) |
0a8e3465 AL |
533 | return _error->Error("Internal Error, non-zero counts"); |
534 | ||
535 | // Apply corrections for half-installed packages | |
b2e465d6 | 536 | if (pkgApplyStatus(*DCache) == false) |
0a8e3465 AL |
537 | return false; |
538 | ||
539 | // Nothing is broken | |
b2e465d6 | 540 | if (DCache->BrokenCount() == 0 || AllowBroken == true) |
0a8e3465 AL |
541 | return true; |
542 | ||
543 | // Attempt to fix broken things | |
544 | if (_config->FindB("APT::Get::Fix-Broken",false) == true) | |
545 | { | |
b2e465d6 AL |
546 | c1out << _("Correcting dependencies...") << flush; |
547 | if (pkgFixBroken(*DCache) == false || DCache->BrokenCount() != 0) | |
0a8e3465 | 548 | { |
b2e465d6 | 549 | c1out << _(" failed.") << endl; |
421c8d10 | 550 | ShowBroken(c1out,*this,true); |
0a8e3465 | 551 | |
b2e465d6 | 552 | return _error->Error(_("Unable to correct dependencies")); |
0a8e3465 | 553 | } |
b2e465d6 AL |
554 | if (pkgMinimizeUpgrade(*DCache) == false) |
555 | return _error->Error(_("Unable to minimize the upgrade set")); | |
0a8e3465 | 556 | |
b2e465d6 | 557 | c1out << _(" Done") << endl; |
0a8e3465 AL |
558 | } |
559 | else | |
560 | { | |
b2e465d6 | 561 | c1out << _("You might want to run `apt-get -f install' to correct these.") << endl; |
421c8d10 | 562 | ShowBroken(c1out,*this,true); |
0a8e3465 | 563 | |
b2e465d6 | 564 | return _error->Error(_("Unmet dependencies. Try using -f.")); |
0a8e3465 AL |
565 | } |
566 | ||
567 | return true; | |
568 | } | |
569 | /*}}}*/ | |
570 | ||
571 | // InstallPackages - Actually download and install the packages /*{{{*/ | |
572 | // --------------------------------------------------------------------- | |
573 | /* This displays the informative messages describing what is going to | |
574 | happen and then calls the download routines */ | |
a3eaf954 AL |
575 | bool InstallPackages(CacheFile &Cache,bool ShwKept,bool Ask = true, |
576 | bool Saftey = true) | |
0a8e3465 | 577 | { |
fc4b5c9f AL |
578 | if (_config->FindB("APT::Get::Purge",false) == true) |
579 | { | |
580 | pkgCache::PkgIterator I = Cache->PkgBegin(); | |
581 | for (; I.end() == false; I++) | |
d556d1a1 AL |
582 | { |
583 | if (I.Purge() == false && Cache[I].Mode == pkgDepCache::ModeDelete) | |
584 | Cache->MarkDelete(I,true); | |
585 | } | |
fc4b5c9f AL |
586 | } |
587 | ||
83d89a9f | 588 | bool Fail = false; |
6f86c974 | 589 | bool Essential = false; |
83d89a9f | 590 | |
a6568219 | 591 | // Show all the various warning indicators |
0a8e3465 AL |
592 | ShowDel(c1out,Cache); |
593 | ShowNew(c1out,Cache); | |
594 | if (ShwKept == true) | |
595 | ShowKept(c1out,Cache); | |
7a215bee | 596 | Fail |= !ShowHold(c1out,Cache); |
0a8e3465 AL |
597 | if (_config->FindB("APT::Get::Show-Upgraded",false) == true) |
598 | ShowUpgraded(c1out,Cache); | |
b2e465d6 | 599 | Fail |= !ShowDowngraded(c1out,Cache); |
6f86c974 AL |
600 | Essential = !ShowEssential(c1out,Cache); |
601 | Fail |= Essential; | |
0a8e3465 AL |
602 | Stats(c1out,Cache); |
603 | ||
604 | // Sanity check | |
d38b7b3d | 605 | if (Cache->BrokenCount() != 0) |
0a8e3465 | 606 | { |
421c8d10 | 607 | ShowBroken(c1out,Cache,false); |
0a8e3465 AL |
608 | return _error->Error("Internal Error, InstallPackages was called with broken packages!"); |
609 | } | |
610 | ||
d0c59649 | 611 | if (Cache->DelCount() == 0 && Cache->InstCount() == 0 && |
d38b7b3d | 612 | Cache->BadCount() == 0) |
c60d151b | 613 | return true; |
03e39e59 | 614 | |
d150b09d | 615 | // No remove flag |
b2e465d6 AL |
616 | if (Cache->DelCount() != 0 && _config->FindB("APT::Get::Remove",true) == false) |
617 | return _error->Error(_("Packages need to be removed but Remove is disabled.")); | |
d150b09d | 618 | |
03e39e59 AL |
619 | // Run the simulator .. |
620 | if (_config->FindB("APT::Get::Simulate") == true) | |
621 | { | |
622 | pkgSimulate PM(Cache); | |
281daf46 AL |
623 | pkgPackageManager::OrderResult Res = PM.DoInstall(); |
624 | if (Res == pkgPackageManager::Failed) | |
625 | return false; | |
626 | if (Res != pkgPackageManager::Completed) | |
627 | return _error->Error("Internal Error, Ordering didn't finish"); | |
628 | return true; | |
03e39e59 AL |
629 | } |
630 | ||
631 | // Create the text record parser | |
632 | pkgRecords Recs(Cache); | |
83d89a9f AL |
633 | if (_error->PendingError() == true) |
634 | return false; | |
635 | ||
d38b7b3d | 636 | // Lock the archive directory |
36375005 | 637 | FileFd Lock; |
d38b7b3d AL |
638 | if (_config->FindB("Debug::NoLocking",false) == false) |
639 | { | |
36375005 | 640 | Lock.Fd(GetLock(_config->FindDir("Dir::Cache::Archives") + "lock")); |
d38b7b3d | 641 | if (_error->PendingError() == true) |
b2e465d6 | 642 | return _error->Error(_("Unable to lock the download directory")); |
d38b7b3d | 643 | } |
03e39e59 AL |
644 | |
645 | // Create the download object | |
646 | AcqTextStatus Stat(ScreenWidth,_config->FindI("quiet",0)); | |
647 | pkgAcquire Fetcher(&Stat); | |
648 | ||
649 | // Read the source list | |
650 | pkgSourceList List; | |
651 | if (List.ReadMainList() == false) | |
b2e465d6 | 652 | return _error->Error(_("The list of sources could not be read.")); |
03e39e59 AL |
653 | |
654 | // Create the package manager and prepare to download | |
b2e465d6 AL |
655 | SPtr<pkgPackageManager> PM= _system->CreatePM(Cache); |
656 | if (PM->GetArchives(&Fetcher,&List,&Recs) == false || | |
424c3bc0 | 657 | _error->PendingError() == true) |
03e39e59 AL |
658 | return false; |
659 | ||
7a1b1f8b | 660 | // Display statistics |
b2e465d6 AL |
661 | double FetchBytes = Fetcher.FetchNeeded(); |
662 | double FetchPBytes = Fetcher.PartialPresent(); | |
663 | double DebBytes = Fetcher.TotalNeeded(); | |
d38b7b3d AL |
664 | if (DebBytes != Cache->DebSize()) |
665 | { | |
666 | c0out << DebBytes << ',' << Cache->DebSize() << endl; | |
a6568219 | 667 | c0out << "How odd.. The sizes didn't match, email apt@packages.debian.org" << endl; |
d38b7b3d | 668 | } |
138d4b3d | 669 | |
7a1b1f8b | 670 | // Number of bytes |
a6568219 | 671 | if (DebBytes != FetchBytes) |
b2e465d6 AL |
672 | ioprintf(c1out,_("Need to get %sB/%sB of archives. "), |
673 | SizeToStr(FetchBytes).c_str(),SizeToStr(DebBytes).c_str()); | |
a6568219 | 674 | else |
b2e465d6 AL |
675 | ioprintf(c1out,_("Need to get %sB of archives. "), |
676 | SizeToStr(DebBytes).c_str()); | |
677 | ||
10bb1f5f AL |
678 | // Size delta |
679 | if (Cache->UsrSize() >= 0) | |
b2e465d6 AL |
680 | ioprintf(c1out,_("After unpacking %sB will be used.\n"), |
681 | SizeToStr(Cache->UsrSize()).c_str()); | |
10bb1f5f | 682 | else |
b2e465d6 AL |
683 | ioprintf(c1out,_("After unpacking %sB will be freed.\n"), |
684 | SizeToStr(-1*Cache->UsrSize()).c_str()); | |
10bb1f5f AL |
685 | |
686 | if (_error->PendingError() == true) | |
687 | return false; | |
31a0531d | 688 | |
01b64152 AL |
689 | /* Check for enough free space, but only if we are actually going to |
690 | download */ | |
691 | if (_config->FindB("APT::Get::Print-URIs") == false) | |
692 | { | |
693 | struct statvfs Buf; | |
694 | string OutputDir = _config->FindDir("Dir::Cache::Archives"); | |
695 | if (statvfs(OutputDir.c_str(),&Buf) != 0) | |
696 | return _error->Errno("statvfs","Couldn't determine free space in %s", | |
697 | OutputDir.c_str()); | |
698 | if (unsigned(Buf.f_bfree) < (FetchBytes - FetchPBytes)/Buf.f_bsize) | |
b2e465d6 | 699 | return _error->Error(_("Sorry, you don't have enough free space in %s to hold all the .debs."), |
01b64152 AL |
700 | OutputDir.c_str()); |
701 | } | |
702 | ||
83d89a9f | 703 | // Fail safe check |
0c95c765 AL |
704 | if (_config->FindI("quiet",0) >= 2 || |
705 | _config->FindB("APT::Get::Assume-Yes",false) == true) | |
83d89a9f AL |
706 | { |
707 | if (Fail == true && _config->FindB("APT::Get::Force-Yes",false) == false) | |
b2e465d6 | 708 | return _error->Error(_("There are problems and -y was used without --force-yes")); |
83d89a9f | 709 | } |
83d89a9f | 710 | |
6f86c974 AL |
711 | if (Essential == true && Saftey == true) |
712 | { | |
d150b09d | 713 | if (_config->FindB("APT::Get::Trivial-Only",false) == true) |
b2e465d6 | 714 | return _error->Error(_("Trivial Only specified but this is not a trivial operation.")); |
d150b09d | 715 | |
b2e465d6 AL |
716 | const char *Prompt = _("Yes, do as I say!"); |
717 | ioprintf(c2out, | |
718 | _("You are about to do something potentially harmful\n" | |
719 | "To continue type in the phrase '%s'\n" | |
720 | " ?] "),Prompt); | |
721 | c2out << flush; | |
722 | if (AnalPrompt(Prompt) == false) | |
6f86c974 | 723 | { |
b2e465d6 | 724 | c2out << _("Abort.") << endl; |
a6568219 | 725 | exit(1); |
6f86c974 AL |
726 | } |
727 | } | |
728 | else | |
d150b09d | 729 | { |
6f86c974 | 730 | // Prompt to continue |
38262e68 | 731 | if (Ask == true || Fail == true) |
6f86c974 | 732 | { |
d150b09d | 733 | if (_config->FindB("APT::Get::Trivial-Only",false) == true) |
b2e465d6 | 734 | return _error->Error(_("Trivial Only specified but this is not a trivial operation.")); |
d150b09d | 735 | |
0c95c765 | 736 | if (_config->FindI("quiet",0) < 2 && |
6f86c974 | 737 | _config->FindB("APT::Get::Assume-Yes",false) == false) |
0c95c765 | 738 | { |
b2e465d6 | 739 | c2out << _("Do you want to continue? [Y/n] ") << flush; |
6f86c974 | 740 | |
0c95c765 AL |
741 | if (YnPrompt() == false) |
742 | { | |
b2e465d6 | 743 | c2out << _("Abort.") << endl; |
0c95c765 AL |
744 | exit(1); |
745 | } | |
746 | } | |
6f86c974 AL |
747 | } |
748 | } | |
749 | ||
36375005 | 750 | // Just print out the uris an exit if the --print-uris flag was used |
f7a08e33 AL |
751 | if (_config->FindB("APT::Get::Print-URIs") == true) |
752 | { | |
753 | pkgAcquire::UriIterator I = Fetcher.UriBegin(); | |
754 | for (; I != Fetcher.UriEnd(); I++) | |
755 | cout << '\'' << I->URI << "' " << flNotDir(I->Owner->DestFile) << ' ' << | |
756 | I->Owner->FileSize << ' ' << I->Owner->MD5Sum() << endl; | |
757 | return true; | |
758 | } | |
b2e465d6 AL |
759 | |
760 | /* Unlock the dpkg lock if we are not going to be doing an install | |
761 | after. */ | |
762 | if (_config->FindB("APT::Get::Download-Only",false) == true) | |
763 | _system->UnLock(); | |
83d89a9f | 764 | |
03e39e59 | 765 | // Run it |
281daf46 | 766 | while (1) |
30e1eab5 | 767 | { |
a3eaf954 | 768 | bool Transient = false; |
b2e465d6 | 769 | if (_config->FindB("APT::Get::Download",true) == false) |
a3eaf954 | 770 | { |
076d01b0 | 771 | for (pkgAcquire::ItemIterator I = Fetcher.ItemsBegin(); I < Fetcher.ItemsEnd();) |
a3eaf954 AL |
772 | { |
773 | if ((*I)->Local == true) | |
774 | { | |
775 | I++; | |
776 | continue; | |
777 | } | |
778 | ||
779 | // Close the item and check if it was found in cache | |
780 | (*I)->Finished(); | |
781 | if ((*I)->Complete == false) | |
782 | Transient = true; | |
783 | ||
784 | // Clear it out of the fetch list | |
785 | delete *I; | |
786 | I = Fetcher.ItemsBegin(); | |
787 | } | |
788 | } | |
789 | ||
790 | if (Fetcher.Run() == pkgAcquire::Failed) | |
791 | return false; | |
30e1eab5 | 792 | |
281daf46 AL |
793 | // Print out errors |
794 | bool Failed = false; | |
076d01b0 | 795 | for (pkgAcquire::ItemIterator I = Fetcher.ItemsBegin(); I != Fetcher.ItemsEnd(); I++) |
f01fe790 | 796 | { |
281daf46 AL |
797 | if ((*I)->Status == pkgAcquire::Item::StatDone && |
798 | (*I)->Complete == true) | |
799 | continue; | |
800 | ||
281daf46 AL |
801 | if ((*I)->Status == pkgAcquire::Item::StatIdle) |
802 | { | |
803 | Transient = true; | |
804 | // Failed = true; | |
805 | continue; | |
806 | } | |
a3eaf954 | 807 | |
b2e465d6 AL |
808 | fprintf(stderr,_("Failed to fetch %s %s\n"),(*I)->DescURI().c_str(), |
809 | (*I)->ErrorText.c_str()); | |
f01fe790 | 810 | Failed = true; |
f01fe790 | 811 | } |
5ec427c2 | 812 | |
a3eaf954 | 813 | /* If we are in no download mode and missing files and there were |
5ec427c2 AL |
814 | 'failures' then the user must specify -m. Furthermore, there |
815 | is no such thing as a transient error in no-download mode! */ | |
a3eaf954 | 816 | if (Transient == true && |
b2e465d6 | 817 | _config->FindB("APT::Get::Download",true) == false) |
5ec427c2 AL |
818 | { |
819 | Transient = false; | |
820 | Failed = true; | |
821 | } | |
f01fe790 | 822 | |
281daf46 AL |
823 | if (_config->FindB("APT::Get::Download-Only",false) == true) |
824 | { | |
825 | if (Failed == true && _config->FindB("APT::Get::Fix-Missing",false) == false) | |
b2e465d6 AL |
826 | return _error->Error(_("Some files failed to download")); |
827 | c1out << _("Download complete and in download only mode") << endl; | |
281daf46 AL |
828 | return true; |
829 | } | |
830 | ||
8195ae46 | 831 | if (Failed == true && _config->FindB("APT::Get::Fix-Missing",false) == false) |
f01fe790 | 832 | { |
b2e465d6 | 833 | return _error->Error(_("Unable to fetch some archives, maybe run apt-get update or try with --fix-missing?")); |
f01fe790 AL |
834 | } |
835 | ||
281daf46 | 836 | if (Transient == true && Failed == true) |
b2e465d6 | 837 | return _error->Error(_("--fix-missing and media swapping is not currently supported")); |
281daf46 AL |
838 | |
839 | // Try to deal with missing package files | |
b2e465d6 | 840 | if (Failed == true && PM->FixMissing() == false) |
281daf46 | 841 | { |
b2e465d6 AL |
842 | cerr << _("Unable to correct missing packages.") << endl; |
843 | return _error->Error(_("Aborting Install.")); | |
281daf46 | 844 | } |
a3eaf954 | 845 | |
b2e465d6 AL |
846 | _system->UnLock(); |
847 | pkgPackageManager::OrderResult Res = PM->DoInstall(); | |
281daf46 AL |
848 | if (Res == pkgPackageManager::Failed || _error->PendingError() == true) |
849 | return false; | |
850 | if (Res == pkgPackageManager::Completed) | |
851 | return true; | |
852 | ||
853 | // Reload the fetcher object and loop again for media swapping | |
854 | Fetcher.Shutdown(); | |
b2e465d6 | 855 | if (PM->GetArchives(&Fetcher,&List,&Recs) == false) |
281daf46 | 856 | return false; |
b2e465d6 AL |
857 | |
858 | _system->Lock(); | |
281daf46 | 859 | } |
0a8e3465 AL |
860 | } |
861 | /*}}}*/ | |
c373c37a AL |
862 | // TryToInstall - Try to install a single package /*{{{*/ |
863 | // --------------------------------------------------------------------- | |
864 | /* This used to be inlined in DoInstall, but with the advent of regex package | |
865 | name matching it was split out.. */ | |
866 | bool TryToInstall(pkgCache::PkgIterator Pkg,pkgDepCache &Cache, | |
867 | pkgProblemResolver &Fix,bool Remove,bool BrokenFix, | |
868 | unsigned int &ExpectedInst,bool AllowFail = true) | |
869 | { | |
870 | /* This is a pure virtual package and there is a single available | |
871 | provides */ | |
872 | if (Cache[Pkg].CandidateVer == 0 && Pkg->ProvidesList != 0 && | |
873 | Pkg.ProvidesList()->NextProvides == 0) | |
874 | { | |
875 | pkgCache::PkgIterator Tmp = Pkg.ProvidesList().OwnerPkg(); | |
b2e465d6 AL |
876 | ioprintf(c1out,_("Note, selecting %s instead of %s\n"), |
877 | Tmp.Name(),Pkg.Name()); | |
c373c37a AL |
878 | Pkg = Tmp; |
879 | } | |
880 | ||
881 | // Handle the no-upgrade case | |
b2e465d6 | 882 | if (_config->FindB("APT::Get::upgrade",true) == false && |
c373c37a AL |
883 | Pkg->CurrentVer != 0) |
884 | { | |
885 | if (AllowFail == true) | |
b2e465d6 AL |
886 | ioprintf(c1out,_("Skipping %s, it is already installed and upgrade is not set.\n"), |
887 | Pkg.Name()); | |
c373c37a AL |
888 | return true; |
889 | } | |
890 | ||
891 | // Check if there is something at all to install | |
892 | pkgDepCache::StateCache &State = Cache[Pkg]; | |
a146c927 | 893 | if (Remove == true && Pkg->CurrentVer == 0) |
10bb1f5f | 894 | { |
b2e465d6 AL |
895 | /* We want to continue searching for regex hits, so we return false here |
896 | otherwise this is not really an error. */ | |
10bb1f5f | 897 | if (AllowFail == false) |
b2e465d6 | 898 | return false; |
1156d969 | 899 | ioprintf(c1out,_("Package %s is not installed, so not removed\n"),Pkg.Name()); |
b2e465d6 | 900 | return true; |
10bb1f5f | 901 | } |
a146c927 AL |
902 | |
903 | if (State.CandidateVer == 0 && Remove == false) | |
c373c37a AL |
904 | { |
905 | if (AllowFail == false) | |
906 | return false; | |
907 | ||
908 | if (Pkg->ProvidesList != 0) | |
909 | { | |
b2e465d6 AL |
910 | ioprintf(c1out,_("Package %s is a virtual package provided by:\n"), |
911 | Pkg.Name()); | |
c373c37a AL |
912 | |
913 | pkgCache::PrvIterator I = Pkg.ProvidesList(); | |
914 | for (; I.end() == false; I++) | |
915 | { | |
916 | pkgCache::PkgIterator Pkg = I.OwnerPkg(); | |
917 | ||
918 | if (Cache[Pkg].CandidateVerIter(Cache) == I.OwnerVer()) | |
919 | { | |
920 | if (Cache[Pkg].Install() == true && Cache[Pkg].NewInstall() == false) | |
921 | c1out << " " << Pkg.Name() << " " << I.OwnerVer().VerStr() << | |
b2e465d6 | 922 | _(" [Installed]") << endl; |
c373c37a AL |
923 | else |
924 | c1out << " " << Pkg.Name() << " " << I.OwnerVer().VerStr() << endl; | |
925 | } | |
926 | } | |
b2e465d6 | 927 | c1out << _("You should explicitly select one to install.") << endl; |
c373c37a AL |
928 | } |
929 | else | |
930 | { | |
b2e465d6 AL |
931 | ioprintf(c1out, |
932 | _("Package %s has no available version, but exists in the database.\n" | |
933 | "This typically means that the package was mentioned in a dependency and\n" | |
934 | "never uploaded, has been obsoleted or is not available with the contents\n" | |
935 | "of sources.list\n"),Pkg.Name()); | |
c373c37a AL |
936 | |
937 | string List; | |
c82ffeb6 AL |
938 | SPtrArray<bool> Seen = new bool[Cache.Head().PackageCount]; |
939 | memset(Seen,0,Cache.Head().PackageCount*sizeof(*Seen)); | |
c373c37a AL |
940 | pkgCache::DepIterator Dep = Pkg.RevDependsList(); |
941 | for (; Dep.end() == false; Dep++) | |
942 | { | |
943 | if (Dep->Type != pkgCache::Dep::Replaces) | |
944 | continue; | |
b2e465d6 AL |
945 | if (Seen[Dep.ParentPkg()->ID] == true) |
946 | continue; | |
947 | Seen[Dep.ParentPkg()->ID] = true; | |
c373c37a AL |
948 | List += string(Dep.ParentPkg().Name()) + " "; |
949 | } | |
b2e465d6 | 950 | ShowList(c1out,_("However the following packages replace it:"),List); |
c373c37a AL |
951 | } |
952 | ||
b2e465d6 | 953 | _error->Error(_("Package %s has no installation candidate"),Pkg.Name()); |
c373c37a AL |
954 | return false; |
955 | } | |
61d6a8de AL |
956 | |
957 | Fix.Clear(Pkg); | |
70777d4b | 958 | Fix.Protect(Pkg); |
c373c37a AL |
959 | if (Remove == true) |
960 | { | |
961 | Fix.Remove(Pkg); | |
962 | Cache.MarkDelete(Pkg,_config->FindB("APT::Get::Purge",false)); | |
963 | return true; | |
964 | } | |
965 | ||
966 | // Install it | |
967 | Cache.MarkInstall(Pkg,false); | |
968 | if (State.Install() == false) | |
969 | { | |
d0c59649 AL |
970 | if (_config->FindB("APT::Get::ReInstall",false) == true) |
971 | { | |
972 | if (Pkg->CurrentVer == 0 || Pkg.CurrentVer().Downloadable() == false) | |
70d73d7e | 973 | ioprintf(c1out,_("Sorry, re-installation of %s is not possible, it cannot be downloaded.\n"), |
b2e465d6 | 974 | Pkg.Name()); |
d0c59649 AL |
975 | else |
976 | Cache.SetReInstall(Pkg,true); | |
977 | } | |
978 | else | |
979 | { | |
980 | if (AllowFail == true) | |
b2e465d6 AL |
981 | ioprintf(c1out,_("Sorry, %s is already the newest version.\n"), |
982 | Pkg.Name()); | |
d0c59649 | 983 | } |
c373c37a AL |
984 | } |
985 | else | |
986 | ExpectedInst++; | |
987 | ||
988 | // Install it with autoinstalling enabled. | |
989 | if (State.InstBroken() == true && BrokenFix == false) | |
990 | Cache.MarkInstall(Pkg,true); | |
991 | return true; | |
992 | } | |
993 | /*}}}*/ | |
b2e465d6 AL |
994 | // TryToChangeVer - Try to change a candidate version /*{{{*/ |
995 | // --------------------------------------------------------------------- | |
996 | /* */ | |
997 | bool TryToChangeVer(pkgCache::PkgIterator Pkg,pkgDepCache &Cache, | |
998 | const char *VerTag,bool IsRel) | |
999 | { | |
1000 | pkgVersionMatch Match(VerTag,(IsRel == true?pkgVersionMatch::Release:pkgVersionMatch::Version)); | |
1001 | ||
1002 | pkgCache::VerIterator Ver = Match.Find(Pkg); | |
1003 | ||
1004 | if (Ver.end() == true) | |
1005 | { | |
1006 | if (IsRel == true) | |
1007 | return _error->Error(_("Release '%s' for '%s' was not found"), | |
1008 | VerTag,Pkg.Name()); | |
1009 | return _error->Error(_("Version '%s' for '%s' was not found"), | |
1010 | VerTag,Pkg.Name()); | |
1011 | } | |
1012 | ||
1013 | if (strcmp(VerTag,Ver.VerStr()) != 0) | |
1014 | { | |
1015 | ioprintf(c1out,_("Selected version %s (%s) for %s\n"), | |
1016 | Ver.VerStr(),Ver.RelStr().c_str(),Pkg.Name()); | |
1017 | } | |
1018 | ||
1019 | Cache.SetCandidateVersion(Ver); | |
1020 | return true; | |
1021 | } | |
1022 | /*}}}*/ | |
1023 | // FindSrc - Find a source record /*{{{*/ | |
1024 | // --------------------------------------------------------------------- | |
1025 | /* */ | |
1026 | pkgSrcRecords::Parser *FindSrc(const char *Name,pkgRecords &Recs, | |
1027 | pkgSrcRecords &SrcRecs,string &Src, | |
1028 | pkgDepCache &Cache) | |
1029 | { | |
1030 | // We want to pull the version off the package specification.. | |
1031 | string VerTag; | |
1032 | string TmpSrc = Name; | |
1033 | string::size_type Slash = TmpSrc.rfind('='); | |
1034 | if (Slash != string::npos) | |
1035 | { | |
1036 | VerTag = string(TmpSrc.begin() + Slash + 1,TmpSrc.end()); | |
1037 | TmpSrc = string(TmpSrc.begin(),TmpSrc.begin() + Slash); | |
1038 | } | |
1039 | ||
1040 | /* Lookup the version of the package we would install if we were to | |
1041 | install a version and determine the source package name, then look | |
1042 | in the archive for a source package of the same name. In theory | |
1043 | we could stash the version string as well and match that too but | |
1044 | today there aren't multi source versions in the archive. */ | |
1045 | if (_config->FindB("APT::Get::Only-Source") == false && | |
1046 | VerTag.empty() == true) | |
1047 | { | |
1048 | pkgCache::PkgIterator Pkg = Cache.FindPkg(TmpSrc); | |
1049 | if (Pkg.end() == false) | |
1050 | { | |
1051 | pkgCache::VerIterator Ver = Cache.GetCandidateVer(Pkg); | |
1052 | if (Ver.end() == false) | |
1053 | { | |
1054 | pkgRecords::Parser &Parse = Recs.Lookup(Ver.FileList()); | |
1055 | Src = Parse.SourcePkg(); | |
1056 | } | |
1057 | } | |
1058 | } | |
1059 | ||
1060 | // No source package name.. | |
1061 | if (Src.empty() == true) | |
1062 | Src = TmpSrc; | |
1063 | ||
1064 | // The best hit | |
1065 | pkgSrcRecords::Parser *Last = 0; | |
1066 | unsigned long Offset = 0; | |
1067 | string Version; | |
1068 | bool IsMatch = false; | |
1069 | ||
1070 | // If we are matching by version then we need exact matches to be happy | |
1071 | if (VerTag.empty() == false) | |
1072 | IsMatch = true; | |
1073 | ||
1074 | /* Iterate over all of the hits, which includes the resulting | |
1075 | binary packages in the search */ | |
1076 | pkgSrcRecords::Parser *Parse; | |
1077 | SrcRecs.Restart(); | |
1078 | while ((Parse = SrcRecs.Find(Src.c_str(),false)) != 0) | |
1079 | { | |
1080 | string Ver = Parse->Version(); | |
1081 | ||
1082 | // Skip name mismatches | |
1083 | if (IsMatch == true && Parse->Package() != Src) | |
1084 | continue; | |
1085 | ||
1086 | if (VerTag.empty() == false) | |
1087 | { | |
1088 | /* Don't want to fall through because we are doing exact version | |
1089 | matching. */ | |
1090 | if (Cache.VS().CmpVersion(VerTag,Ver) != 0) | |
1091 | continue; | |
1092 | ||
1093 | Last = Parse; | |
1094 | Offset = Parse->Offset(); | |
1095 | break; | |
1096 | } | |
1097 | ||
1098 | // Newer version or an exact match | |
1099 | if (Last == 0 || Cache.VS().CmpVersion(Version,Ver) < 0 || | |
1100 | (Parse->Package() == Src && IsMatch == false)) | |
1101 | { | |
1102 | IsMatch = Parse->Package() == Src; | |
1103 | Last = Parse; | |
1104 | Offset = Parse->Offset(); | |
1105 | Version = Ver; | |
1106 | } | |
1107 | } | |
1108 | ||
1109 | if (Last == 0) | |
1110 | return 0; | |
1111 | ||
1112 | if (Last->Jump(Offset) == false) | |
1113 | return 0; | |
1114 | ||
1115 | return Last; | |
1116 | } | |
1117 | /*}}}*/ | |
0a8e3465 AL |
1118 | |
1119 | // DoUpdate - Update the package lists /*{{{*/ | |
1120 | // --------------------------------------------------------------------- | |
1121 | /* */ | |
b2e465d6 | 1122 | bool DoUpdate(CommandLine &CmdL) |
0a8e3465 | 1123 | { |
b2e465d6 AL |
1124 | if (CmdL.FileSize() != 1) |
1125 | return _error->Error(_("The update command takes no arguments")); | |
1126 | ||
0919e3f9 AL |
1127 | // Get the source list |
1128 | pkgSourceList List; | |
1129 | if (List.ReadMainList() == false) | |
1130 | return false; | |
1131 | ||
d38b7b3d | 1132 | // Lock the list directory |
36375005 | 1133 | FileFd Lock; |
d38b7b3d AL |
1134 | if (_config->FindB("Debug::NoLocking",false) == false) |
1135 | { | |
36375005 | 1136 | Lock.Fd(GetLock(_config->FindDir("Dir::State::Lists") + "lock")); |
d38b7b3d | 1137 | if (_error->PendingError() == true) |
b2e465d6 | 1138 | return _error->Error(_("Unable to lock the list directory")); |
d38b7b3d AL |
1139 | } |
1140 | ||
0919e3f9 AL |
1141 | // Create the download object |
1142 | AcqTextStatus Stat(ScreenWidth,_config->FindI("quiet",0)); | |
1143 | pkgAcquire Fetcher(&Stat); | |
1144 | ||
1145 | // Populate it with the source selection | |
b2e465d6 | 1146 | if (List.GetIndexes(&Fetcher) == false) |
0919e3f9 | 1147 | return false; |
0919e3f9 AL |
1148 | |
1149 | // Run it | |
024d1123 | 1150 | if (Fetcher.Run() == pkgAcquire::Failed) |
0919e3f9 AL |
1151 | return false; |
1152 | ||
9df71a5b | 1153 | bool Failed = false; |
076d01b0 | 1154 | for (pkgAcquire::ItemIterator I = Fetcher.ItemsBegin(); I != Fetcher.ItemsEnd(); I++) |
9df71a5b AL |
1155 | { |
1156 | if ((*I)->Status == pkgAcquire::Item::StatDone) | |
1157 | continue; | |
1158 | ||
1159 | (*I)->Finished(); | |
1160 | ||
b2e465d6 AL |
1161 | fprintf(stderr,_("Failed to fetch %s %s\n"),(*I)->DescURI().c_str(), |
1162 | (*I)->ErrorText.c_str()); | |
9df71a5b AL |
1163 | Failed = true; |
1164 | } | |
1165 | ||
7a7fa5f0 | 1166 | // Clean out any old list files |
67ff87bf | 1167 | if (_config->FindB("APT::Get::List-Cleanup",true) == true) |
9df71a5b AL |
1168 | { |
1169 | if (Fetcher.Clean(_config->FindDir("Dir::State::lists")) == false || | |
1170 | Fetcher.Clean(_config->FindDir("Dir::State::lists") + "partial/") == false) | |
1171 | return false; | |
1172 | } | |
7a7fa5f0 | 1173 | |
0919e3f9 AL |
1174 | // Prepare the cache. |
1175 | CacheFile Cache; | |
a65cbe33 | 1176 | if (Cache.Open() == false) |
0919e3f9 AL |
1177 | return false; |
1178 | ||
9df71a5b | 1179 | if (Failed == true) |
b2e465d6 AL |
1180 | return _error->Error(_("Some index files failed to download, they have been ignored, or old ones used instead.")); |
1181 | ||
0919e3f9 | 1182 | return true; |
0a8e3465 AL |
1183 | } |
1184 | /*}}}*/ | |
1185 | // DoUpgrade - Upgrade all packages /*{{{*/ | |
1186 | // --------------------------------------------------------------------- | |
1187 | /* Upgrade all packages without installing new packages or erasing old | |
1188 | packages */ | |
1189 | bool DoUpgrade(CommandLine &CmdL) | |
1190 | { | |
1191 | CacheFile Cache; | |
2d11135a | 1192 | if (Cache.Open() == false || Cache.CheckDeps() == false) |
0a8e3465 AL |
1193 | return false; |
1194 | ||
1195 | // Do the upgrade | |
0a8e3465 AL |
1196 | if (pkgAllUpgrade(Cache) == false) |
1197 | { | |
421c8d10 | 1198 | ShowBroken(c1out,Cache,false); |
b2e465d6 | 1199 | return _error->Error(_("Internal Error, AllUpgrade broke stuff")); |
0a8e3465 AL |
1200 | } |
1201 | ||
1202 | return InstallPackages(Cache,true); | |
1203 | } | |
1204 | /*}}}*/ | |
1205 | // DoInstall - Install packages from the command line /*{{{*/ | |
1206 | // --------------------------------------------------------------------- | |
1207 | /* Install named packages */ | |
1208 | bool DoInstall(CommandLine &CmdL) | |
1209 | { | |
1210 | CacheFile Cache; | |
2d11135a | 1211 | if (Cache.Open() == false || Cache.CheckDeps(CmdL.FileSize() != 1) == false) |
0a8e3465 AL |
1212 | return false; |
1213 | ||
7c57fe64 AL |
1214 | // Enter the special broken fixing mode if the user specified arguments |
1215 | bool BrokenFix = false; | |
1216 | if (Cache->BrokenCount() != 0) | |
1217 | BrokenFix = true; | |
1218 | ||
a6568219 AL |
1219 | unsigned int ExpectedInst = 0; |
1220 | unsigned int Packages = 0; | |
0a8e3465 AL |
1221 | pkgProblemResolver Fix(Cache); |
1222 | ||
303a1703 AL |
1223 | bool DefRemove = false; |
1224 | if (strcasecmp(CmdL.FileList[0],"remove") == 0) | |
1225 | DefRemove = true; | |
b2e465d6 | 1226 | |
0a8e3465 AL |
1227 | for (const char **I = CmdL.FileList + 1; *I != 0; I++) |
1228 | { | |
1229 | // Duplicate the string | |
1230 | unsigned int Length = strlen(*I); | |
1231 | char S[300]; | |
1232 | if (Length >= sizeof(S)) | |
1233 | continue; | |
1234 | strcpy(S,*I); | |
1235 | ||
b2e465d6 | 1236 | // See if we are removing and special indicators.. |
303a1703 | 1237 | bool Remove = DefRemove; |
b2e465d6 AL |
1238 | char *VerTag = 0; |
1239 | bool VerIsRel = false; | |
fc4b5c9f | 1240 | while (Cache->FindPkg(S).end() == true) |
0a8e3465 | 1241 | { |
2c3bc8bb AL |
1242 | // Handle an optional end tag indicating what to do |
1243 | if (S[Length - 1] == '-') | |
1244 | { | |
1245 | Remove = true; | |
1246 | S[--Length] = 0; | |
fc4b5c9f | 1247 | continue; |
2c3bc8bb | 1248 | } |
fc4b5c9f | 1249 | |
2c3bc8bb AL |
1250 | if (S[Length - 1] == '+') |
1251 | { | |
1252 | Remove = false; | |
1253 | S[--Length] = 0; | |
fc4b5c9f | 1254 | continue; |
2c3bc8bb | 1255 | } |
b2e465d6 AL |
1256 | |
1257 | char *Slash = strchr(S,'='); | |
1258 | if (Slash != 0) | |
1259 | { | |
1260 | VerIsRel = false; | |
1261 | *Slash = 0; | |
1262 | VerTag = Slash + 1; | |
1263 | } | |
1264 | ||
1265 | Slash = strchr(S,'/'); | |
1266 | if (Slash != 0) | |
1267 | { | |
1268 | VerIsRel = true; | |
1269 | *Slash = 0; | |
1270 | VerTag = Slash + 1; | |
1271 | } | |
1272 | ||
fc4b5c9f | 1273 | break; |
303a1703 | 1274 | } |
0a8e3465 AL |
1275 | |
1276 | // Locate the package | |
1277 | pkgCache::PkgIterator Pkg = Cache->FindPkg(S); | |
303a1703 | 1278 | Packages++; |
0a8e3465 | 1279 | if (Pkg.end() == true) |
2c3bc8bb | 1280 | { |
c373c37a AL |
1281 | // Check if the name is a regex |
1282 | const char *I; | |
1283 | for (I = S; *I != 0; I++) | |
b2e465d6 | 1284 | if (*I == '.' || *I == '?' || *I == '*' || *I == '|') |
c373c37a AL |
1285 | break; |
1286 | if (*I == 0) | |
b2e465d6 | 1287 | return _error->Error(_("Couldn't find package %s"),S); |
303a1703 | 1288 | |
c373c37a AL |
1289 | // Regexs must always be confirmed |
1290 | ExpectedInst += 1000; | |
1291 | ||
1292 | // Compile the regex pattern | |
1293 | regex_t Pattern; | |
b2e465d6 AL |
1294 | int Res; |
1295 | if ((Res = regcomp(&Pattern,S,REG_EXTENDED | REG_ICASE | | |
1296 | REG_NOSUB)) != 0) | |
1297 | { | |
1298 | char Error[300]; | |
1299 | regerror(Res,&Pattern,Error,sizeof(Error)); | |
1300 | return _error->Error(_("Regex compilation error - %s"),Error); | |
1301 | } | |
c373c37a AL |
1302 | |
1303 | // Run over the matches | |
1304 | bool Hit = false; | |
1305 | for (Pkg = Cache->PkgBegin(); Pkg.end() == false; Pkg++) | |
303a1703 | 1306 | { |
c373c37a AL |
1307 | if (regexec(&Pattern,Pkg.Name(),0,0,0) != 0) |
1308 | continue; | |
07801a6d | 1309 | |
b2e465d6 AL |
1310 | if (VerTag != 0) |
1311 | if (TryToChangeVer(Pkg,Cache,VerTag,VerIsRel) == false) | |
1312 | return false; | |
1313 | ||
c373c37a AL |
1314 | Hit |= TryToInstall(Pkg,Cache,Fix,Remove,BrokenFix, |
1315 | ExpectedInst,false); | |
303a1703 | 1316 | } |
c373c37a | 1317 | regfree(&Pattern); |
303a1703 | 1318 | |
c373c37a | 1319 | if (Hit == false) |
b2e465d6 | 1320 | return _error->Error(_("Couldn't find package %s"),S); |
0a8e3465 | 1321 | } |
0a8e3465 | 1322 | else |
c373c37a | 1323 | { |
b2e465d6 AL |
1324 | if (VerTag != 0) |
1325 | if (TryToChangeVer(Pkg,Cache,VerTag,VerIsRel) == false) | |
1326 | return false; | |
c373c37a AL |
1327 | if (TryToInstall(Pkg,Cache,Fix,Remove,BrokenFix,ExpectedInst) == false) |
1328 | return false; | |
1329 | } | |
0a8e3465 AL |
1330 | } |
1331 | ||
7c57fe64 AL |
1332 | /* If we are in the Broken fixing mode we do not attempt to fix the |
1333 | problems. This is if the user invoked install without -f and gave | |
1334 | packages */ | |
1335 | if (BrokenFix == true && Cache->BrokenCount() != 0) | |
1336 | { | |
b2e465d6 | 1337 | c1out << _("You might want to run `apt-get -f install' to correct these:") << endl; |
421c8d10 | 1338 | ShowBroken(c1out,Cache,false); |
7c57fe64 | 1339 | |
b2e465d6 | 1340 | return _error->Error(_("Unmet dependencies. Try 'apt-get -f install' with no packages (or specify a solution).")); |
7c57fe64 AL |
1341 | } |
1342 | ||
0a8e3465 | 1343 | // Call the scored problem resolver |
303a1703 | 1344 | Fix.InstallProtect(); |
0a8e3465 AL |
1345 | if (Fix.Resolve(true) == false) |
1346 | _error->Discard(); | |
1347 | ||
1348 | // Now we check the state of the packages, | |
1349 | if (Cache->BrokenCount() != 0) | |
1350 | { | |
b2e465d6 AL |
1351 | c1out << |
1352 | _("Some packages could not be installed. This may mean that you have\n" | |
1353 | "requested an impossible situation or if you are using the unstable\n" | |
1354 | "distribution that some required packages have not yet been created\n" | |
1355 | "or been moved out of Incoming.") << endl; | |
303a1703 AL |
1356 | if (Packages == 1) |
1357 | { | |
1358 | c1out << endl; | |
b2e465d6 AL |
1359 | c1out << |
1360 | _("Since you only requested a single operation it is extremely likely that\n" | |
1361 | "the package is simply not installable and a bug report against\n" | |
1362 | "that package should be filed.") << endl; | |
303a1703 AL |
1363 | } |
1364 | ||
b2e465d6 | 1365 | c1out << _("The following information may help to resolve the situation:") << endl; |
303a1703 | 1366 | c1out << endl; |
421c8d10 | 1367 | ShowBroken(c1out,Cache,false); |
b2e465d6 | 1368 | return _error->Error(_("Sorry, broken packages")); |
0a8e3465 AL |
1369 | } |
1370 | ||
1371 | /* Print out a list of packages that are going to be installed extra | |
1372 | to what the user asked */ | |
1373 | if (Cache->InstCount() != ExpectedInst) | |
1374 | { | |
1375 | string List; | |
1089ca89 | 1376 | for (unsigned J = 0; J < Cache->Head().PackageCount; J++) |
0a8e3465 | 1377 | { |
1089ca89 | 1378 | pkgCache::PkgIterator I(Cache,Cache.List[J]); |
0a8e3465 AL |
1379 | if ((*Cache)[I].Install() == false) |
1380 | continue; | |
1381 | ||
1382 | const char **J; | |
1383 | for (J = CmdL.FileList + 1; *J != 0; J++) | |
1384 | if (strcmp(*J,I.Name()) == 0) | |
1385 | break; | |
1386 | ||
1387 | if (*J == 0) | |
1388 | List += string(I.Name()) + " "; | |
1389 | } | |
1390 | ||
b2e465d6 | 1391 | ShowList(c1out,_("The following extra packages will be installed:"),List); |
0a8e3465 AL |
1392 | } |
1393 | ||
03e39e59 | 1394 | // See if we need to prompt |
2c3bc8bb | 1395 | if (Cache->InstCount() == ExpectedInst && Cache->DelCount() == 0) |
2c3bc8bb | 1396 | return InstallPackages(Cache,false,false); |
2c3bc8bb | 1397 | |
03e39e59 | 1398 | return InstallPackages(Cache,false); |
0a8e3465 AL |
1399 | } |
1400 | /*}}}*/ | |
1401 | // DoDistUpgrade - Automatic smart upgrader /*{{{*/ | |
1402 | // --------------------------------------------------------------------- | |
1403 | /* Intelligent upgrader that will install and remove packages at will */ | |
1404 | bool DoDistUpgrade(CommandLine &CmdL) | |
1405 | { | |
1406 | CacheFile Cache; | |
2d11135a | 1407 | if (Cache.Open() == false || Cache.CheckDeps() == false) |
0a8e3465 AL |
1408 | return false; |
1409 | ||
b2e465d6 | 1410 | c0out << _("Calculating Upgrade... ") << flush; |
0a8e3465 AL |
1411 | if (pkgDistUpgrade(*Cache) == false) |
1412 | { | |
b2e465d6 | 1413 | c0out << _("Failed") << endl; |
421c8d10 | 1414 | ShowBroken(c1out,Cache,false); |
0a8e3465 AL |
1415 | return false; |
1416 | } | |
1417 | ||
b2e465d6 | 1418 | c0out << _("Done") << endl; |
0a8e3465 AL |
1419 | |
1420 | return InstallPackages(Cache,true); | |
1421 | } | |
1422 | /*}}}*/ | |
1423 | // DoDSelectUpgrade - Do an upgrade by following dselects selections /*{{{*/ | |
1424 | // --------------------------------------------------------------------- | |
1425 | /* Follows dselect's selections */ | |
1426 | bool DoDSelectUpgrade(CommandLine &CmdL) | |
1427 | { | |
1428 | CacheFile Cache; | |
2d11135a | 1429 | if (Cache.Open() == false || Cache.CheckDeps() == false) |
0a8e3465 AL |
1430 | return false; |
1431 | ||
1432 | // Install everything with the install flag set | |
1433 | pkgCache::PkgIterator I = Cache->PkgBegin(); | |
1434 | for (;I.end() != true; I++) | |
1435 | { | |
1436 | /* Install the package only if it is a new install, the autoupgrader | |
1437 | will deal with the rest */ | |
1438 | if (I->SelectedState == pkgCache::State::Install) | |
1439 | Cache->MarkInstall(I,false); | |
1440 | } | |
1441 | ||
1442 | /* Now install their deps too, if we do this above then order of | |
1443 | the status file is significant for | groups */ | |
1444 | for (I = Cache->PkgBegin();I.end() != true; I++) | |
1445 | { | |
1446 | /* Install the package only if it is a new install, the autoupgrader | |
1447 | will deal with the rest */ | |
1448 | if (I->SelectedState == pkgCache::State::Install) | |
2f45c76a | 1449 | Cache->MarkInstall(I,true); |
0a8e3465 AL |
1450 | } |
1451 | ||
1452 | // Apply erasures now, they override everything else. | |
1453 | for (I = Cache->PkgBegin();I.end() != true; I++) | |
1454 | { | |
1455 | // Remove packages | |
1456 | if (I->SelectedState == pkgCache::State::DeInstall || | |
1457 | I->SelectedState == pkgCache::State::Purge) | |
d556d1a1 | 1458 | Cache->MarkDelete(I,I->SelectedState == pkgCache::State::Purge); |
0a8e3465 AL |
1459 | } |
1460 | ||
2f45c76a AL |
1461 | /* Resolve any problems that dselect created, allupgrade cannot handle |
1462 | such things. We do so quite agressively too.. */ | |
1463 | if (Cache->BrokenCount() != 0) | |
1464 | { | |
1465 | pkgProblemResolver Fix(Cache); | |
1466 | ||
1467 | // Hold back held packages. | |
b2e465d6 | 1468 | if (_config->FindB("APT::Ignore-Hold",false) == false) |
2f45c76a AL |
1469 | { |
1470 | for (pkgCache::PkgIterator I = Cache->PkgBegin(); I.end() == false; I++) | |
1471 | { | |
1472 | if (I->SelectedState == pkgCache::State::Hold) | |
1473 | { | |
1474 | Fix.Protect(I); | |
1475 | Cache->MarkKeep(I); | |
1476 | } | |
1477 | } | |
1478 | } | |
1479 | ||
1480 | if (Fix.Resolve() == false) | |
1481 | { | |
421c8d10 | 1482 | ShowBroken(c1out,Cache,false); |
2f45c76a AL |
1483 | return _error->Error("Internal Error, problem resolver broke stuff"); |
1484 | } | |
1485 | } | |
1486 | ||
1487 | // Now upgrade everything | |
0a8e3465 AL |
1488 | if (pkgAllUpgrade(Cache) == false) |
1489 | { | |
421c8d10 | 1490 | ShowBroken(c1out,Cache,false); |
2f45c76a | 1491 | return _error->Error("Internal Error, problem resolver broke stuff"); |
0a8e3465 AL |
1492 | } |
1493 | ||
1494 | return InstallPackages(Cache,false); | |
1495 | } | |
1496 | /*}}}*/ | |
1497 | // DoClean - Remove download archives /*{{{*/ | |
1498 | // --------------------------------------------------------------------- | |
1499 | /* */ | |
1500 | bool DoClean(CommandLine &CmdL) | |
1501 | { | |
8b067c22 AL |
1502 | if (_config->FindB("APT::Get::Simulate") == true) |
1503 | { | |
1504 | cout << "Del " << _config->FindDir("Dir::Cache::archives") << "* " << | |
1505 | _config->FindDir("Dir::Cache::archives") << "partial/*" << endl; | |
1506 | return true; | |
1507 | } | |
1508 | ||
1b6d659c AL |
1509 | // Lock the archive directory |
1510 | FileFd Lock; | |
1511 | if (_config->FindB("Debug::NoLocking",false) == false) | |
1512 | { | |
1513 | Lock.Fd(GetLock(_config->FindDir("Dir::Cache::Archives") + "lock")); | |
1514 | if (_error->PendingError() == true) | |
b2e465d6 | 1515 | return _error->Error(_("Unable to lock the download directory")); |
1b6d659c AL |
1516 | } |
1517 | ||
7a1b1f8b AL |
1518 | pkgAcquire Fetcher; |
1519 | Fetcher.Clean(_config->FindDir("Dir::Cache::archives")); | |
1520 | Fetcher.Clean(_config->FindDir("Dir::Cache::archives") + "partial/"); | |
0a8e3465 AL |
1521 | return true; |
1522 | } | |
1523 | /*}}}*/ | |
1bc849af AL |
1524 | // DoAutoClean - Smartly remove downloaded archives /*{{{*/ |
1525 | // --------------------------------------------------------------------- | |
1526 | /* This is similar to clean but it only purges things that cannot be | |
1527 | downloaded, that is old versions of cached packages. */ | |
65a1e968 AL |
1528 | class LogCleaner : public pkgArchiveCleaner |
1529 | { | |
1530 | protected: | |
1531 | virtual void Erase(const char *File,string Pkg,string Ver,struct stat &St) | |
1532 | { | |
4cc8bab0 | 1533 | c1out << "Del " << Pkg << " " << Ver << " [" << SizeToStr(St.st_size) << "B]" << endl; |
c1e78ee5 AL |
1534 | |
1535 | if (_config->FindB("APT::Get::Simulate") == false) | |
1536 | unlink(File); | |
65a1e968 AL |
1537 | }; |
1538 | }; | |
1539 | ||
1bc849af AL |
1540 | bool DoAutoClean(CommandLine &CmdL) |
1541 | { | |
1b6d659c AL |
1542 | // Lock the archive directory |
1543 | FileFd Lock; | |
1544 | if (_config->FindB("Debug::NoLocking",false) == false) | |
1545 | { | |
1546 | Lock.Fd(GetLock(_config->FindDir("Dir::Cache::Archives") + "lock")); | |
1547 | if (_error->PendingError() == true) | |
b2e465d6 | 1548 | return _error->Error(_("Unable to lock the download directory")); |
1b6d659c AL |
1549 | } |
1550 | ||
1bc849af | 1551 | CacheFile Cache; |
2d11135a | 1552 | if (Cache.Open() == false) |
1bc849af AL |
1553 | return false; |
1554 | ||
65a1e968 | 1555 | LogCleaner Cleaner; |
1bc849af AL |
1556 | |
1557 | return Cleaner.Go(_config->FindDir("Dir::Cache::archives"),*Cache) && | |
1558 | Cleaner.Go(_config->FindDir("Dir::Cache::archives") + "partial/",*Cache); | |
1559 | } | |
1560 | /*}}}*/ | |
0a8e3465 AL |
1561 | // DoCheck - Perform the check operation /*{{{*/ |
1562 | // --------------------------------------------------------------------- | |
1563 | /* Opening automatically checks the system, this command is mostly used | |
1564 | for debugging */ | |
1565 | bool DoCheck(CommandLine &CmdL) | |
1566 | { | |
1567 | CacheFile Cache; | |
1568 | Cache.Open(); | |
2d11135a | 1569 | Cache.CheckDeps(); |
0a8e3465 AL |
1570 | |
1571 | return true; | |
1572 | } | |
1573 | /*}}}*/ | |
36375005 AL |
1574 | // DoSource - Fetch a source archive /*{{{*/ |
1575 | // --------------------------------------------------------------------- | |
2d11135a | 1576 | /* Fetch souce packages */ |
fb0ee66e AL |
1577 | struct DscFile |
1578 | { | |
1579 | string Package; | |
1580 | string Version; | |
1581 | string Dsc; | |
1582 | }; | |
1583 | ||
36375005 AL |
1584 | bool DoSource(CommandLine &CmdL) |
1585 | { | |
1586 | CacheFile Cache; | |
2d11135a | 1587 | if (Cache.Open(false) == false) |
36375005 AL |
1588 | return false; |
1589 | ||
2d11135a | 1590 | if (CmdL.FileSize() <= 1) |
b2e465d6 | 1591 | return _error->Error(_("Must specify at least one package to fetch source for")); |
2d11135a | 1592 | |
36375005 AL |
1593 | // Read the source list |
1594 | pkgSourceList List; | |
1595 | if (List.ReadMainList() == false) | |
b2e465d6 | 1596 | return _error->Error(_("The list of sources could not be read.")); |
36375005 AL |
1597 | |
1598 | // Create the text record parsers | |
1599 | pkgRecords Recs(Cache); | |
1600 | pkgSrcRecords SrcRecs(List); | |
1601 | if (_error->PendingError() == true) | |
1602 | return false; | |
1603 | ||
1604 | // Create the download object | |
1605 | AcqTextStatus Stat(ScreenWidth,_config->FindI("quiet",0)); | |
1606 | pkgAcquire Fetcher(&Stat); | |
fb0ee66e AL |
1607 | |
1608 | DscFile *Dsc = new DscFile[CmdL.FileSize()]; | |
36375005 AL |
1609 | |
1610 | // Load the requestd sources into the fetcher | |
fb0ee66e AL |
1611 | unsigned J = 0; |
1612 | for (const char **I = CmdL.FileList + 1; *I != 0; I++, J++) | |
36375005 AL |
1613 | { |
1614 | string Src; | |
b2e465d6 | 1615 | pkgSrcRecords::Parser *Last = FindSrc(*I,Recs,SrcRecs,Src,*Cache); |
36375005 AL |
1616 | |
1617 | if (Last == 0) | |
b2e465d6 | 1618 | return _error->Error(_("Unable to find a source package for %s"),Src.c_str()); |
36375005 AL |
1619 | |
1620 | // Back track | |
1621 | vector<pkgSrcRecords::File> Lst; | |
b2e465d6 | 1622 | if (Last->Files(Lst) == false) |
36375005 AL |
1623 | return false; |
1624 | ||
1625 | // Load them into the fetcher | |
1626 | for (vector<pkgSrcRecords::File>::const_iterator I = Lst.begin(); | |
1627 | I != Lst.end(); I++) | |
1628 | { | |
1629 | // Try to guess what sort of file it is we are getting. | |
b2e465d6 | 1630 | if (I->Type == "dsc") |
fb0ee66e | 1631 | { |
fb0ee66e AL |
1632 | Dsc[J].Package = Last->Package(); |
1633 | Dsc[J].Version = Last->Version(); | |
1634 | Dsc[J].Dsc = flNotDir(I->Path); | |
1635 | } | |
1636 | ||
17c0e8e1 AL |
1637 | // Diff only mode only fetches .diff files |
1638 | if (_config->FindB("APT::Get::Diff-Only",false) == true && | |
b2e465d6 | 1639 | I->Type != "diff") |
17c0e8e1 AL |
1640 | continue; |
1641 | ||
1642 | // Tar only mode only fetches .tar files | |
1643 | if (_config->FindB("APT::Get::Tar-Only",false) == true && | |
b2e465d6 | 1644 | I->Type != "tar") |
17c0e8e1 AL |
1645 | continue; |
1646 | ||
b2e465d6 AL |
1647 | new pkgAcqFile(&Fetcher,Last->Index().ArchiveURI(I->Path), |
1648 | I->MD5Hash,I->Size, | |
1649 | Last->Index().SourceInfo(*Last,*I),Src); | |
36375005 AL |
1650 | } |
1651 | } | |
1652 | ||
1653 | // Display statistics | |
b2e465d6 AL |
1654 | double FetchBytes = Fetcher.FetchNeeded(); |
1655 | double FetchPBytes = Fetcher.PartialPresent(); | |
1656 | double DebBytes = Fetcher.TotalNeeded(); | |
36375005 AL |
1657 | |
1658 | // Check for enough free space | |
f332b62b | 1659 | struct statvfs Buf; |
36375005 | 1660 | string OutputDir = "."; |
f332b62b AL |
1661 | if (statvfs(OutputDir.c_str(),&Buf) != 0) |
1662 | return _error->Errno("statvfs","Couldn't determine free space in %s", | |
36375005 AL |
1663 | OutputDir.c_str()); |
1664 | if (unsigned(Buf.f_bfree) < (FetchBytes - FetchPBytes)/Buf.f_bsize) | |
b2e465d6 | 1665 | return _error->Error(_("Sorry, you don't have enough free space in %s"), |
36375005 AL |
1666 | OutputDir.c_str()); |
1667 | ||
1668 | // Number of bytes | |
36375005 | 1669 | if (DebBytes != FetchBytes) |
b2e465d6 AL |
1670 | ioprintf(c1out,_("Need to get %sB/%sB of source archives.\n"), |
1671 | SizeToStr(FetchBytes).c_str(),SizeToStr(DebBytes).c_str()); | |
36375005 | 1672 | else |
b2e465d6 AL |
1673 | ioprintf(c1out,_("Need to get %sB of source archives.\n"), |
1674 | SizeToStr(DebBytes).c_str()); | |
1675 | ||
2c0c53b3 AL |
1676 | if (_config->FindB("APT::Get::Simulate",false) == true) |
1677 | { | |
1678 | for (unsigned I = 0; I != J; I++) | |
b2e465d6 | 1679 | ioprintf(cout,_("Fetch Source %s\n"),Dsc[I].Package.c_str()); |
2c0c53b3 AL |
1680 | return true; |
1681 | } | |
1682 | ||
36375005 AL |
1683 | // Just print out the uris an exit if the --print-uris flag was used |
1684 | if (_config->FindB("APT::Get::Print-URIs") == true) | |
1685 | { | |
1686 | pkgAcquire::UriIterator I = Fetcher.UriBegin(); | |
1687 | for (; I != Fetcher.UriEnd(); I++) | |
1688 | cout << '\'' << I->URI << "' " << flNotDir(I->Owner->DestFile) << ' ' << | |
1689 | I->Owner->FileSize << ' ' << I->Owner->MD5Sum() << endl; | |
1690 | return true; | |
1691 | } | |
1692 | ||
1693 | // Run it | |
024d1123 | 1694 | if (Fetcher.Run() == pkgAcquire::Failed) |
36375005 AL |
1695 | return false; |
1696 | ||
1697 | // Print error messages | |
fb0ee66e | 1698 | bool Failed = false; |
076d01b0 | 1699 | for (pkgAcquire::ItemIterator I = Fetcher.ItemsBegin(); I != Fetcher.ItemsEnd(); I++) |
36375005 AL |
1700 | { |
1701 | if ((*I)->Status == pkgAcquire::Item::StatDone && | |
1702 | (*I)->Complete == true) | |
1703 | continue; | |
1704 | ||
b2e465d6 AL |
1705 | fprintf(stderr,_("Failed to fetch %s %s\n"),(*I)->DescURI().c_str(), |
1706 | (*I)->ErrorText.c_str()); | |
fb0ee66e | 1707 | Failed = true; |
36375005 | 1708 | } |
fb0ee66e | 1709 | if (Failed == true) |
b2e465d6 | 1710 | return _error->Error(_("Failed to fetch some archives.")); |
fb0ee66e AL |
1711 | |
1712 | if (_config->FindB("APT::Get::Download-only",false) == true) | |
b2e465d6 AL |
1713 | { |
1714 | c1out << _("Download complete and in download only mode") << endl; | |
fb0ee66e | 1715 | return true; |
b2e465d6 AL |
1716 | } |
1717 | ||
fb0ee66e | 1718 | // Unpack the sources |
54676e1a AL |
1719 | pid_t Process = ExecFork(); |
1720 | ||
1721 | if (Process == 0) | |
fb0ee66e | 1722 | { |
54676e1a | 1723 | for (unsigned I = 0; I != J; I++) |
fb0ee66e | 1724 | { |
b2e465d6 | 1725 | string Dir = Dsc[I].Package + '-' + Cache->VS().UpstreamVersion(Dsc[I].Version.c_str()); |
fb0ee66e | 1726 | |
17c0e8e1 AL |
1727 | // Diff only mode only fetches .diff files |
1728 | if (_config->FindB("APT::Get::Diff-Only",false) == true || | |
a3eaf954 AL |
1729 | _config->FindB("APT::Get::Tar-Only",false) == true || |
1730 | Dsc[I].Dsc.empty() == true) | |
17c0e8e1 | 1731 | continue; |
a3eaf954 | 1732 | |
54676e1a AL |
1733 | // See if the package is already unpacked |
1734 | struct stat Stat; | |
1735 | if (stat(Dir.c_str(),&Stat) == 0 && | |
1736 | S_ISDIR(Stat.st_mode) != 0) | |
1737 | { | |
b2e465d6 AL |
1738 | ioprintf(c0out ,_("Skipping unpack of already unpacked source in %s\n"), |
1739 | Dir.c_str()); | |
54676e1a AL |
1740 | } |
1741 | else | |
1742 | { | |
1743 | // Call dpkg-source | |
1744 | char S[500]; | |
1745 | snprintf(S,sizeof(S),"%s -x %s", | |
1746 | _config->Find("Dir::Bin::dpkg-source","dpkg-source").c_str(), | |
1747 | Dsc[I].Dsc.c_str()); | |
1748 | if (system(S) != 0) | |
1749 | { | |
b2e465d6 | 1750 | fprintf(stderr,_("Unpack command '%s' failed.\n"),S); |
54676e1a AL |
1751 | _exit(1); |
1752 | } | |
1753 | } | |
1754 | ||
1755 | // Try to compile it with dpkg-buildpackage | |
1756 | if (_config->FindB("APT::Get::Compile",false) == true) | |
1757 | { | |
1758 | // Call dpkg-buildpackage | |
1759 | char S[500]; | |
1760 | snprintf(S,sizeof(S),"cd %s && %s %s", | |
1761 | Dir.c_str(), | |
1762 | _config->Find("Dir::Bin::dpkg-buildpackage","dpkg-buildpackage").c_str(), | |
1763 | _config->Find("DPkg::Build-Options","-b -uc").c_str()); | |
1764 | ||
1765 | if (system(S) != 0) | |
1766 | { | |
b2e465d6 | 1767 | fprintf(stderr,_("Build command '%s' failed.\n"),S); |
54676e1a AL |
1768 | _exit(1); |
1769 | } | |
1770 | } | |
1771 | } | |
1772 | ||
1773 | _exit(0); | |
1774 | } | |
1775 | ||
1776 | // Wait for the subprocess | |
1777 | int Status = 0; | |
1778 | while (waitpid(Process,&Status,0) != Process) | |
1779 | { | |
1780 | if (errno == EINTR) | |
1781 | continue; | |
1782 | return _error->Errno("waitpid","Couldn't wait for subprocess"); | |
1783 | } | |
1784 | ||
1785 | if (WIFEXITED(Status) == 0 || WEXITSTATUS(Status) != 0) | |
b2e465d6 AL |
1786 | return _error->Error(_("Child process failed")); |
1787 | ||
1788 | return true; | |
1789 | } | |
1790 | /*}}}*/ | |
1791 | // DoBuildDep - Install/removes packages to satisfy build dependencies /*{{{*/ | |
1792 | // --------------------------------------------------------------------- | |
1793 | /* This function will look at the build depends list of the given source | |
1794 | package and install the necessary packages to make it true, or fail. */ | |
1795 | bool DoBuildDep(CommandLine &CmdL) | |
1796 | { | |
1797 | CacheFile Cache; | |
1798 | if (Cache.Open(true) == false) | |
1799 | return false; | |
1800 | ||
1801 | if (CmdL.FileSize() <= 1) | |
1802 | return _error->Error(_("Must specify at least one package to check builddeps for")); | |
1803 | ||
1804 | // Read the source list | |
1805 | pkgSourceList List; | |
1806 | if (List.ReadMainList() == false) | |
1807 | return _error->Error(_("The list of sources could not be read.")); | |
54676e1a | 1808 | |
b2e465d6 AL |
1809 | // Create the text record parsers |
1810 | pkgRecords Recs(Cache); | |
1811 | pkgSrcRecords SrcRecs(List); | |
1812 | if (_error->PendingError() == true) | |
1813 | return false; | |
1814 | ||
1815 | // Create the download object | |
1816 | AcqTextStatus Stat(ScreenWidth,_config->FindI("quiet",0)); | |
1817 | pkgAcquire Fetcher(&Stat); | |
1818 | ||
1819 | unsigned J = 0; | |
1820 | for (const char **I = CmdL.FileList + 1; *I != 0; I++, J++) | |
1821 | { | |
1822 | string Src; | |
1823 | pkgSrcRecords::Parser *Last = FindSrc(*I,Recs,SrcRecs,Src,*Cache); | |
1824 | if (Last == 0) | |
1825 | return _error->Error(_("Unable to find a source package for %s"),Src.c_str()); | |
1826 | ||
1827 | // Process the build-dependencies | |
1828 | vector<pkgSrcRecords::Parser::BuildDepRec> BuildDeps; | |
1829 | if (Last->BuildDepends(BuildDeps) == false) | |
1830 | return _error->Error(_("Unable to get build-dependency information for %s"),Src.c_str()); | |
1831 | ||
1832 | if (BuildDeps.size() == 0) | |
1833 | { | |
1834 | ioprintf(c1out,_("%s has no build depends.\n"),Src.c_str()); | |
1835 | continue; | |
1836 | } | |
1837 | ||
1838 | // Install the requested packages | |
1839 | unsigned int ExpectedInst = 0; | |
1840 | vector <pkgSrcRecords::Parser::BuildDepRec>::iterator D; | |
1841 | pkgProblemResolver Fix(Cache); | |
1842 | for (D = BuildDeps.begin(); D != BuildDeps.end(); D++) | |
1843 | { | |
1844 | pkgCache::PkgIterator Pkg = Cache->FindPkg((*D).Package); | |
1845 | if (Pkg.end() == true) | |
1846 | return _error->Error(_("%s dependency on %s cannot be satisfied because the package %s cannot be found"), | |
1847 | Last->BuildDepType((*D).Type),Src.c_str(),(*D).Package.c_str()); | |
1848 | pkgCache::VerIterator IV = (*Cache)[Pkg].InstVerIter(*Cache); | |
1849 | ||
1850 | if ((*D).Type == pkgSrcRecords::Parser::BuildConflict || | |
1851 | (*D).Type == pkgSrcRecords::Parser::BuildConflictIndep) | |
1852 | { | |
cfa5659c AL |
1853 | /* |
1854 | * conflict; need to remove if we have an installed version | |
1855 | * that satisfies the version criterial | |
1856 | */ | |
b2e465d6 AL |
1857 | if (IV.end() == false && |
1858 | Cache->VS().CheckDep(IV.VerStr(),(*D).Op,(*D).Version.c_str()) == true) | |
1859 | TryToInstall(Pkg,Cache,Fix,true,false,ExpectedInst); | |
1860 | } | |
1861 | else | |
1862 | { | |
cfa5659c AL |
1863 | /* |
1864 | * If this is a virtual package, we need to check the list of | |
1865 | * packages that provide it and see if any of those are | |
1866 | * installed | |
1867 | */ | |
1868 | pkgCache::PrvIterator Prv = Pkg.ProvidesList(); | |
1869 | for (; Prv.end() != true; Prv++) | |
1870 | if ((*Cache)[Prv.OwnerPkg()].InstVerIter(*Cache).end() == false) | |
1871 | break; | |
1872 | ||
1873 | if (Prv.end() == true) | |
1874 | { | |
1875 | /* | |
1876 | * depends; need to install or upgrade if we don't have the | |
1877 | * package installed or if the version does not satisfy the | |
1878 | * build dep. This is complicated by the fact that if we | |
1879 | * depend on a version lower than what we already have | |
1880 | * installed it is not clear what should be done; in practice | |
1881 | * this case should be rare though and right now nothing | |
1882 | * is done about it :-( | |
1883 | */ | |
1884 | if (IV.end() == true || | |
1885 | Cache->VS().CheckDep(IV.VerStr(),(*D).Op,(*D).Version.c_str()) == false) | |
1886 | TryToInstall(Pkg,Cache,Fix,false,false,ExpectedInst); | |
1887 | } | |
b2e465d6 AL |
1888 | } |
1889 | } | |
1890 | ||
1891 | Fix.InstallProtect(); | |
1892 | if (Fix.Resolve(true) == false) | |
1893 | _error->Discard(); | |
1894 | ||
1895 | // Now we check the state of the packages, | |
1896 | if (Cache->BrokenCount() != 0) | |
1897 | return _error->Error(_("Some broken packages were found while trying to process build-dependencies.\n" | |
1898 | "You might want to run `apt-get -f install' to correct these.")); | |
1899 | } | |
1900 | ||
1901 | if (InstallPackages(Cache, false, true) == false) | |
1902 | return _error->Error(_("Failed to process build dependencies")); | |
36375005 AL |
1903 | return true; |
1904 | } | |
1905 | /*}}}*/ | |
1906 | ||
b2e465d6 AL |
1907 | // DoMoo - Never Ask, Never Tell /*{{{*/ |
1908 | // --------------------------------------------------------------------- | |
1909 | /* */ | |
1910 | bool DoMoo(CommandLine &CmdL) | |
1911 | { | |
1912 | cout << | |
1913 | " (__) \n" | |
1914 | " (oo) \n" | |
1915 | " /------\\/ \n" | |
1916 | " / | || \n" | |
1917 | " * /\\---/\\ \n" | |
1918 | " ~~ ~~ \n" | |
1919 | "....\"Have you mooed today?\"...\n"; | |
1920 | ||
1921 | return true; | |
1922 | } | |
1923 | /*}}}*/ | |
0a8e3465 AL |
1924 | // ShowHelp - Show a help screen /*{{{*/ |
1925 | // --------------------------------------------------------------------- | |
1926 | /* */ | |
212ad54a | 1927 | bool ShowHelp(CommandLine &CmdL) |
0a8e3465 | 1928 | { |
b2e465d6 AL |
1929 | ioprintf(cout,_("%s %s for %s %s compiled on %s %s\n"),PACKAGE,VERSION, |
1930 | COMMON_OS,COMMON_CPU,__DATE__,__TIME__); | |
1931 | ||
04aa15a8 | 1932 | if (_config->FindB("version") == true) |
b2e465d6 AL |
1933 | { |
1934 | cout << _("Supported Modules:") << endl; | |
1935 | ||
1936 | for (unsigned I = 0; I != pkgVersioningSystem::GlobalListLen; I++) | |
1937 | { | |
1938 | pkgVersioningSystem *VS = pkgVersioningSystem::GlobalList[I]; | |
1939 | if (_system != 0 && _system->VS == VS) | |
1940 | cout << '*'; | |
1941 | else | |
1942 | cout << ' '; | |
1943 | cout << "Ver: " << VS->Label << endl; | |
1944 | ||
1945 | /* Print out all the packaging systems that will work with | |
1946 | this VS */ | |
1947 | for (unsigned J = 0; J != pkgSystem::GlobalListLen; J++) | |
1948 | { | |
1949 | pkgSystem *Sys = pkgSystem::GlobalList[J]; | |
1950 | if (_system == Sys) | |
1951 | cout << '*'; | |
1952 | else | |
1953 | cout << ' '; | |
1954 | if (Sys->VS->TestCompatibility(*VS) == true) | |
1955 | cout << "Pkg: " << Sys->Label << " (Priority " << Sys->Score(*_config) << ")" << endl; | |
1956 | } | |
1957 | } | |
1958 | ||
1959 | for (unsigned I = 0; I != pkgSourceList::Type::GlobalListLen; I++) | |
1960 | { | |
1961 | pkgSourceList::Type *Type = pkgSourceList::Type::GlobalList[I]; | |
1962 | cout << " S.L: '" << Type->Name << "' " << Type->Label << endl; | |
1963 | } | |
1964 | ||
1965 | for (unsigned I = 0; I != pkgIndexFile::Type::GlobalListLen; I++) | |
1966 | { | |
1967 | pkgIndexFile::Type *Type = pkgIndexFile::Type::GlobalList[I]; | |
1968 | cout << " Idx: " << Type->Label << endl; | |
1969 | } | |
1970 | ||
1971 | return true; | |
1972 | } | |
1973 | ||
1974 | cout << | |
1975 | _("Usage: apt-get [options] command\n" | |
1976 | " apt-get [options] install|remove pkg1 [pkg2 ...]\n" | |
1977 | " apt-get [options] source pkg1 [pkg2 ...]\n" | |
1978 | "\n" | |
1979 | "apt-get is a simple command line interface for downloading and\n" | |
1980 | "installing packages. The most frequently used commands are update\n" | |
1981 | "and install.\n" | |
1982 | "\n" | |
1983 | "Commands:\n" | |
1984 | " update - Retrieve new lists of packages\n" | |
1985 | " upgrade - Perform an upgrade\n" | |
1986 | " install - Install new packages (pkg is libc6 not libc6.deb)\n" | |
1987 | " remove - Remove packages\n" | |
1988 | " source - Download source archives\n" | |
1989 | " build-dep - Configure build-dependencies for source packages\n" | |
1990 | " dist-upgrade - Distribution upgrade, see apt-get(8)\n" | |
1991 | " dselect-upgrade - Follow dselect selections\n" | |
1992 | " clean - Erase downloaded archive files\n" | |
1993 | " autoclean - Erase old downloaded archive files\n" | |
1994 | " check - Verify that there are no broken dependencies\n" | |
1995 | "\n" | |
1996 | "Options:\n" | |
1997 | " -h This help text.\n" | |
1998 | " -q Loggable output - no progress indicator\n" | |
1999 | " -qq No output except for errors\n" | |
2000 | " -d Download only - do NOT install or unpack archives\n" | |
2001 | " -s No-act. Perform ordering simulation\n" | |
2002 | " -y Assume Yes to all queries and do not prompt\n" | |
2003 | " -f Attempt to continue if the integrity check fails\n" | |
2004 | " -m Attempt to continue if archives are unlocatable\n" | |
2005 | " -u Show a list of upgraded packages as well\n" | |
2006 | " -b Build the source package after fetching it\n" | |
2007 | " -c=? Read this configuration file\n" | |
2008 | " -o=? Set an arbitary configuration option, eg -o dir::cache=/tmp\n" | |
2009 | "See the apt-get(8), sources.list(5) and apt.conf(5) manual\n" | |
2010 | "pages for more information and options.\n" | |
2011 | " This APT has Super Cow Powers.\n"); | |
2012 | return true; | |
0a8e3465 AL |
2013 | } |
2014 | /*}}}*/ | |
2015 | // GetInitialize - Initialize things for apt-get /*{{{*/ | |
2016 | // --------------------------------------------------------------------- | |
2017 | /* */ | |
2018 | void GetInitialize() | |
2019 | { | |
2020 | _config->Set("quiet",0); | |
2021 | _config->Set("help",false); | |
2022 | _config->Set("APT::Get::Download-Only",false); | |
2023 | _config->Set("APT::Get::Simulate",false); | |
2024 | _config->Set("APT::Get::Assume-Yes",false); | |
2025 | _config->Set("APT::Get::Fix-Broken",false); | |
83d89a9f | 2026 | _config->Set("APT::Get::Force-Yes",false); |
9df71a5b | 2027 | _config->Set("APT::Get::APT::Get::No-List-Cleanup",true); |
0a8e3465 AL |
2028 | } |
2029 | /*}}}*/ | |
d7827aca AL |
2030 | // SigWinch - Window size change signal handler /*{{{*/ |
2031 | // --------------------------------------------------------------------- | |
2032 | /* */ | |
2033 | void SigWinch(int) | |
2034 | { | |
2035 | // Riped from GNU ls | |
2036 | #ifdef TIOCGWINSZ | |
2037 | struct winsize ws; | |
2038 | ||
2039 | if (ioctl(1, TIOCGWINSZ, &ws) != -1 && ws.ws_col >= 5) | |
2040 | ScreenWidth = ws.ws_col - 1; | |
2041 | #endif | |
2042 | } | |
2043 | /*}}}*/ | |
0a8e3465 AL |
2044 | |
2045 | int main(int argc,const char *argv[]) | |
2046 | { | |
2047 | CommandLine::Args Args[] = { | |
2048 | {'h',"help","help",0}, | |
04aa15a8 | 2049 | {'v',"version","version",0}, |
0a8e3465 AL |
2050 | {'q',"quiet","quiet",CommandLine::IntLevel}, |
2051 | {'q',"silent","quiet",CommandLine::IntLevel}, | |
2052 | {'d',"download-only","APT::Get::Download-Only",0}, | |
fb0ee66e AL |
2053 | {'b',"compile","APT::Get::Compile",0}, |
2054 | {'b',"build","APT::Get::Compile",0}, | |
d150b09d AL |
2055 | {'s',"simulate","APT::Get::Simulate",0}, |
2056 | {'s',"just-print","APT::Get::Simulate",0}, | |
2057 | {'s',"recon","APT::Get::Simulate",0}, | |
6df23d2f | 2058 | {'s',"dry-run","APT::Get::Simulate",0}, |
d150b09d AL |
2059 | {'s',"no-act","APT::Get::Simulate",0}, |
2060 | {'y',"yes","APT::Get::Assume-Yes",0}, | |
0a8e3465 AL |
2061 | {'y',"assume-yes","APT::Get::Assume-Yes",0}, |
2062 | {'f',"fix-broken","APT::Get::Fix-Broken",0}, | |
2063 | {'u',"show-upgraded","APT::Get::Show-Upgraded",0}, | |
30e1eab5 | 2064 | {'m',"ignore-missing","APT::Get::Fix-Missing",0}, |
b2e465d6 AL |
2065 | {'t',"target-release","APT::Default-Release",CommandLine::HasArg}, |
2066 | {'t',"default-release","APT::Default-Release",CommandLine::HasArg}, | |
2067 | {0,"download","APT::Get::Download",0}, | |
30e1eab5 | 2068 | {0,"fix-missing","APT::Get::Fix-Missing",0}, |
b2e465d6 AL |
2069 | {0,"ignore-hold","APT::Ignore-Hold",0}, |
2070 | {0,"upgrade","APT::Get::upgrade",0}, | |
83d89a9f | 2071 | {0,"force-yes","APT::Get::force-yes",0}, |
f7a08e33 | 2072 | {0,"print-uris","APT::Get::Print-URIs",0}, |
5fafc0ef AL |
2073 | {0,"diff-only","APT::Get::Diff-Only",0}, |
2074 | {0,"tar-only","APT::Get::tar-Only",0}, | |
fc4b5c9f | 2075 | {0,"purge","APT::Get::Purge",0}, |
9df71a5b | 2076 | {0,"list-cleanup","APT::Get::List-Cleanup",0}, |
d0c59649 | 2077 | {0,"reinstall","APT::Get::ReInstall",0}, |
d150b09d | 2078 | {0,"trivial-only","APT::Get::Trivial-Only",0}, |
b2e465d6 AL |
2079 | {0,"remove","APT::Get::Remove",0}, |
2080 | {0,"only-source","APT::Get::Only-Source",0}, | |
0a8e3465 AL |
2081 | {'c',"config-file",0,CommandLine::ConfigFile}, |
2082 | {'o',"option",0,CommandLine::ArbItem}, | |
2083 | {0,0,0,0}}; | |
83d89a9f AL |
2084 | CommandLine::Dispatch Cmds[] = {{"update",&DoUpdate}, |
2085 | {"upgrade",&DoUpgrade}, | |
2086 | {"install",&DoInstall}, | |
2087 | {"remove",&DoInstall}, | |
2088 | {"dist-upgrade",&DoDistUpgrade}, | |
2089 | {"dselect-upgrade",&DoDSelectUpgrade}, | |
b2e465d6 | 2090 | {"build-dep",&DoBuildDep}, |
83d89a9f | 2091 | {"clean",&DoClean}, |
1bc849af | 2092 | {"autoclean",&DoAutoClean}, |
83d89a9f | 2093 | {"check",&DoCheck}, |
36375005 | 2094 | {"source",&DoSource}, |
b2e465d6 | 2095 | {"moo",&DoMoo}, |
3d615484 | 2096 | {"help",&ShowHelp}, |
83d89a9f | 2097 | {0,0}}; |
0a8e3465 AL |
2098 | |
2099 | // Parse the command line and initialize the package library | |
2100 | CommandLine CmdL(Args,_config); | |
b2e465d6 AL |
2101 | if (pkgInitConfig(*_config) == false || |
2102 | CmdL.Parse(argc,argv) == false || | |
2103 | pkgInitSystem(*_config,_system) == false) | |
0a8e3465 | 2104 | { |
b2e465d6 AL |
2105 | if (_config->FindB("version") == true) |
2106 | ShowHelp(CmdL); | |
2107 | ||
0a8e3465 AL |
2108 | _error->DumpErrors(); |
2109 | return 100; | |
2110 | } | |
2111 | ||
2112 | // See if the help should be shown | |
2113 | if (_config->FindB("help") == true || | |
04aa15a8 | 2114 | _config->FindB("version") == true || |
0a8e3465 | 2115 | CmdL.FileSize() == 0) |
b2e465d6 AL |
2116 | { |
2117 | ShowHelp(CmdL); | |
2118 | return 0; | |
2119 | } | |
67ff87bf | 2120 | |
a9a5908d AL |
2121 | // Deal with stdout not being a tty |
2122 | if (ttyname(STDOUT_FILENO) == 0 && _config->FindI("quiet",0) < 1) | |
2123 | _config->Set("quiet","1"); | |
01b64152 | 2124 | |
0a8e3465 AL |
2125 | // Setup the output streams |
2126 | c0out.rdbuf(cout.rdbuf()); | |
2127 | c1out.rdbuf(cout.rdbuf()); | |
2128 | c2out.rdbuf(cout.rdbuf()); | |
2129 | if (_config->FindI("quiet",0) > 0) | |
2130 | c0out.rdbuf(devnull.rdbuf()); | |
2131 | if (_config->FindI("quiet",0) > 1) | |
2132 | c1out.rdbuf(devnull.rdbuf()); | |
d7827aca AL |
2133 | |
2134 | // Setup the signals | |
2135 | signal(SIGPIPE,SIG_IGN); | |
2136 | signal(SIGWINCH,SigWinch); | |
2137 | SigWinch(0); | |
b2e465d6 | 2138 | |
0a8e3465 | 2139 | // Match the operation |
83d89a9f | 2140 | CmdL.DispatchArg(Cmds); |
0a8e3465 AL |
2141 | |
2142 | // Print any errors or warnings found during parsing | |
2143 | if (_error->empty() == false) | |
2144 | { | |
2145 | bool Errors = _error->PendingError(); | |
2146 | _error->DumpErrors(); | |
0a8e3465 AL |
2147 | return Errors == true?100:0; |
2148 | } | |
2149 | ||
2150 | return 0; | |
2151 | } |