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