]>
Commit | Line | Data |
---|---|---|
5ec427c2 AL |
1 | // -*- mode: cpp; mode: fold -*- |
2 | // Description /*{{{*/ | |
640c5d94 | 3 | // $Id: apt-get.cc,v 1.156 2004/08/28 01:05:16 mdz 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 /*{{{*/ | |
4b12ea90 JAK |
28 | #define _LARGEFILE_SOURCE |
29 | #define _LARGEFILE64_SOURCE | |
30 | ||
086bb6d7 | 31 | #include <apt-pkg/aptconfiguration.h> |
0a8e3465 AL |
32 | #include <apt-pkg/error.h> |
33 | #include <apt-pkg/cmndline.h> | |
34 | #include <apt-pkg/init.h> | |
35 | #include <apt-pkg/depcache.h> | |
36 | #include <apt-pkg/sourcelist.h> | |
0a8e3465 | 37 | #include <apt-pkg/algorithms.h> |
0919e3f9 | 38 | #include <apt-pkg/acquire-item.h> |
cdcc6d34 | 39 | #include <apt-pkg/strutl.h> |
1bc849af | 40 | #include <apt-pkg/clean.h> |
36375005 AL |
41 | #include <apt-pkg/srcrecords.h> |
42 | #include <apt-pkg/version.h> | |
2d11135a | 43 | #include <apt-pkg/cachefile.h> |
8fde7239 | 44 | #include <apt-pkg/cacheset.h> |
b2e465d6 | 45 | #include <apt-pkg/sptr.h> |
092ae175 | 46 | #include <apt-pkg/md5.h> |
b2e465d6 | 47 | #include <apt-pkg/versionmatch.h> |
ffee1c2b | 48 | |
0a8e3465 | 49 | #include <config.h> |
b2e465d6 | 50 | #include <apti18n.h> |
0a8e3465 | 51 | |
0919e3f9 AL |
52 | #include "acqprogress.h" |
53 | ||
092ae175 | 54 | #include <set> |
233c2b66 | 55 | #include <locale.h> |
c8ca0ce1 | 56 | #include <langinfo.h> |
90f057fd | 57 | #include <fstream> |
d7827aca AL |
58 | #include <termios.h> |
59 | #include <sys/ioctl.h> | |
1bc849af | 60 | #include <sys/stat.h> |
885d204b | 61 | #include <sys/statfs.h> |
101030ab | 62 | #include <sys/statvfs.h> |
d7827aca | 63 | #include <signal.h> |
65a1e968 | 64 | #include <unistd.h> |
3e3221ba | 65 | #include <stdio.h> |
d6e79b75 | 66 | #include <errno.h> |
c373c37a | 67 | #include <regex.h> |
54676e1a | 68 | #include <sys/wait.h> |
afb1e2e3 | 69 | #include <sstream> |
4b12ea90 JAK |
70 | |
71 | #define statfs statfs64 | |
72 | #define statvfs statvfs64 | |
0a8e3465 AL |
73 | /*}}}*/ |
74 | ||
885d204b OS |
75 | #define RAMFS_MAGIC 0x858458f6 |
76 | ||
076d01b0 AL |
77 | using namespace std; |
78 | ||
79 | ostream c0out(0); | |
80 | ostream c1out(0); | |
81 | ostream c2out(0); | |
0a8e3465 | 82 | ofstream devnull("/dev/null"); |
463870e4 | 83 | unsigned int ScreenWidth = 80 - 1; /* - 1 for the cursor */ |
0a8e3465 | 84 | |
1089ca89 AL |
85 | // class CacheFile - Cover class for some dependency cache functions /*{{{*/ |
86 | // --------------------------------------------------------------------- | |
87 | /* */ | |
88 | class CacheFile : public pkgCacheFile | |
89 | { | |
90 | static pkgCache *SortCache; | |
91 | static int NameComp(const void *a,const void *b); | |
92 | ||
93 | public: | |
94 | pkgCache::Package **List; | |
95 | ||
96 | void Sort(); | |
97 | bool CheckDeps(bool AllowBroken = false); | |
0077d829 AL |
98 | bool BuildCaches(bool WithLock = true) |
99 | { | |
100 | OpTextProgress Prog(*_config); | |
ea4b220b | 101 | if (pkgCacheFile::BuildCaches(&Prog,WithLock) == false) |
0077d829 AL |
102 | return false; |
103 | return true; | |
104 | } | |
1089ca89 AL |
105 | bool Open(bool WithLock = true) |
106 | { | |
107 | OpTextProgress Prog(*_config); | |
ea4b220b | 108 | if (pkgCacheFile::Open(&Prog,WithLock) == false) |
1089ca89 AL |
109 | return false; |
110 | Sort(); | |
b2e465d6 | 111 | |
1089ca89 AL |
112 | return true; |
113 | }; | |
c37b9502 AL |
114 | bool OpenForInstall() |
115 | { | |
116 | if (_config->FindB("APT::Get::Print-URIs") == true) | |
079a992d | 117 | return Open(false); |
c37b9502 | 118 | else |
079a992d | 119 | return Open(true); |
c37b9502 | 120 | } |
1089ca89 | 121 | CacheFile() : List(0) {}; |
7a9f09bd MV |
122 | ~CacheFile() { |
123 | delete[] List; | |
124 | } | |
1089ca89 AL |
125 | }; |
126 | /*}}}*/ | |
127 | ||
a6568219 AL |
128 | // YnPrompt - Yes No Prompt. /*{{{*/ |
129 | // --------------------------------------------------------------------- | |
130 | /* Returns true on a Yes.*/ | |
7db98ffc | 131 | bool YnPrompt(bool Default=true) |
a6568219 AL |
132 | { |
133 | if (_config->FindB("APT::Get::Assume-Yes",false) == true) | |
134 | { | |
10cda9fe | 135 | c1out << _("Y") << endl; |
a6568219 AL |
136 | return true; |
137 | } | |
10cda9fe AL |
138 | |
139 | char response[1024] = ""; | |
140 | cin.getline(response, sizeof(response)); | |
141 | ||
142 | if (!cin) | |
b2e465d6 | 143 | return false; |
10cda9fe AL |
144 | |
145 | if (strlen(response) == 0) | |
7db98ffc | 146 | return Default; |
10cda9fe AL |
147 | |
148 | regex_t Pattern; | |
149 | int Res; | |
150 | ||
151 | Res = regcomp(&Pattern, nl_langinfo(YESEXPR), | |
152 | REG_EXTENDED|REG_ICASE|REG_NOSUB); | |
153 | ||
154 | if (Res != 0) { | |
155 | char Error[300]; | |
156 | regerror(Res,&Pattern,Error,sizeof(Error)); | |
157 | return _error->Error(_("Regex compilation error - %s"),Error); | |
158 | } | |
a6568219 | 159 | |
10cda9fe AL |
160 | Res = regexec(&Pattern, response, 0, NULL, 0); |
161 | if (Res == 0) | |
162 | return true; | |
163 | return false; | |
a6568219 AL |
164 | } |
165 | /*}}}*/ | |
6f86c974 AL |
166 | // AnalPrompt - Annoying Yes No Prompt. /*{{{*/ |
167 | // --------------------------------------------------------------------- | |
168 | /* Returns true on a Yes.*/ | |
169 | bool AnalPrompt(const char *Text) | |
170 | { | |
171 | char Buf[1024]; | |
172 | cin.getline(Buf,sizeof(Buf)); | |
173 | if (strcmp(Buf,Text) == 0) | |
174 | return true; | |
175 | return false; | |
176 | } | |
177 | /*}}}*/ | |
0a8e3465 AL |
178 | // ShowList - Show a list /*{{{*/ |
179 | // --------------------------------------------------------------------- | |
b2e465d6 | 180 | /* This prints out a string of space separated words with a title and |
0a8e3465 | 181 | a two space indent line wraped to the current screen width. */ |
ac625538 | 182 | bool ShowList(ostream &out,string Title,string List,string VersionsList) |
0a8e3465 AL |
183 | { |
184 | if (List.empty() == true) | |
83d89a9f | 185 | return true; |
4968036c AL |
186 | // trim trailing space |
187 | int NonSpace = List.find_last_not_of(' '); | |
188 | if (NonSpace != -1) | |
189 | { | |
190 | List = List.erase(NonSpace + 1); | |
191 | if (List.empty() == true) | |
192 | return true; | |
193 | } | |
0a8e3465 AL |
194 | |
195 | // Acount for the leading space | |
196 | int ScreenWidth = ::ScreenWidth - 3; | |
197 | ||
198 | out << Title << endl; | |
199 | string::size_type Start = 0; | |
ac625538 | 200 | string::size_type VersionsStart = 0; |
0a8e3465 AL |
201 | while (Start < List.size()) |
202 | { | |
ac625538 AL |
203 | if(_config->FindB("APT::Get::Show-Versions",false) == true && |
204 | VersionsList.size() > 0) { | |
205 | string::size_type End; | |
206 | string::size_type VersionsEnd; | |
207 | ||
208 | End = List.find(' ',Start); | |
209 | VersionsEnd = VersionsList.find('\n', VersionsStart); | |
210 | ||
211 | out << " " << string(List,Start,End - Start) << " (" << | |
212 | string(VersionsList,VersionsStart,VersionsEnd - VersionsStart) << | |
213 | ")" << endl; | |
03b9be80 AL |
214 | |
215 | if (End == string::npos || End < Start) | |
216 | End = Start + ScreenWidth; | |
217 | ||
ac625538 AL |
218 | Start = End + 1; |
219 | VersionsStart = VersionsEnd + 1; | |
220 | } else { | |
221 | string::size_type End; | |
222 | ||
223 | if (Start + ScreenWidth >= List.size()) | |
224 | End = List.size(); | |
225 | else | |
226 | End = List.rfind(' ',Start+ScreenWidth); | |
227 | ||
228 | if (End == string::npos || End < Start) | |
229 | End = Start + ScreenWidth; | |
230 | out << " " << string(List,Start,End - Start) << endl; | |
231 | Start = End + 1; | |
232 | } | |
0a8e3465 | 233 | } |
ac625538 | 234 | |
83d89a9f | 235 | return false; |
0a8e3465 AL |
236 | } |
237 | /*}}}*/ | |
238 | // ShowBroken - Debugging aide /*{{{*/ | |
239 | // --------------------------------------------------------------------- | |
240 | /* This prints out the names of all the packages that are broken along | |
241 | with the name of each each broken dependency and a quite version | |
b2e465d6 AL |
242 | description. |
243 | ||
244 | The output looks like: | |
677cbcbc | 245 | The following packages have unmet dependencies: |
b2e465d6 AL |
246 | exim: Depends: libc6 (>= 2.1.94) but 2.1.3-10 is to be installed |
247 | Depends: libldap2 (>= 2.0.2-2) but it is not going to be installed | |
248 | Depends: libsasl7 but it is not going to be installed | |
249 | */ | |
421c8d10 | 250 | void ShowBroken(ostream &out,CacheFile &Cache,bool Now) |
0a8e3465 | 251 | { |
677cbcbc | 252 | out << _("The following packages have unmet dependencies:") << endl; |
1089ca89 | 253 | for (unsigned J = 0; J < Cache->Head().PackageCount; J++) |
0a8e3465 | 254 | { |
1089ca89 AL |
255 | pkgCache::PkgIterator I(Cache,Cache.List[J]); |
256 | ||
079a992d AL |
257 | if (Now == true) |
258 | { | |
259 | if (Cache[I].NowBroken() == false) | |
260 | continue; | |
261 | } | |
262 | else | |
263 | { | |
264 | if (Cache[I].InstBroken() == false) | |
265 | continue; | |
266 | } | |
267 | ||
303a1703 | 268 | // Print out each package and the failed dependencies |
75ce2062 DK |
269 | out << " " << I.FullName(true) << " :"; |
270 | unsigned const Indent = I.FullName(true).size() + 3; | |
303a1703 | 271 | bool First = true; |
079a992d AL |
272 | pkgCache::VerIterator Ver; |
273 | ||
274 | if (Now == true) | |
275 | Ver = I.CurrentVer(); | |
276 | else | |
277 | Ver = Cache[I].InstVerIter(Cache); | |
278 | ||
279 | if (Ver.end() == true) | |
0a8e3465 | 280 | { |
079a992d | 281 | out << endl; |
303a1703 AL |
282 | continue; |
283 | } | |
284 | ||
079a992d | 285 | for (pkgCache::DepIterator D = Ver.DependsList(); D.end() == false;) |
303a1703 | 286 | { |
30e1eab5 AL |
287 | // Compute a single dependency element (glob or) |
288 | pkgCache::DepIterator Start; | |
289 | pkgCache::DepIterator End; | |
d20333af | 290 | D.GlobOr(Start,End); // advances D |
76fbce56 | 291 | |
079a992d | 292 | if (Cache->IsImportantDep(End) == false) |
303a1703 | 293 | continue; |
079a992d AL |
294 | |
295 | if (Now == true) | |
296 | { | |
297 | if ((Cache[End] & pkgDepCache::DepGNow) == pkgDepCache::DepGNow) | |
298 | continue; | |
299 | } | |
300 | else | |
301 | { | |
302 | if ((Cache[End] & pkgDepCache::DepGInstall) == pkgDepCache::DepGInstall) | |
303 | continue; | |
304 | } | |
305 | ||
648e3cb4 AL |
306 | bool FirstOr = true; |
307 | while (1) | |
0a8e3465 | 308 | { |
648e3cb4 AL |
309 | if (First == false) |
310 | for (unsigned J = 0; J != Indent; J++) | |
311 | out << ' '; | |
312 | First = false; | |
313 | ||
314 | if (FirstOr == false) | |
315 | { | |
316 | for (unsigned J = 0; J != strlen(End.DepType()) + 3; J++) | |
317 | out << ' '; | |
318 | } | |
0a8e3465 | 319 | else |
648e3cb4 AL |
320 | out << ' ' << End.DepType() << ": "; |
321 | FirstOr = false; | |
322 | ||
75ce2062 | 323 | out << Start.TargetPkg().FullName(true); |
648e3cb4 AL |
324 | |
325 | // Show a quick summary of the version requirements | |
326 | if (Start.TargetVer() != 0) | |
b2e465d6 | 327 | out << " (" << Start.CompType() << " " << Start.TargetVer() << ")"; |
648e3cb4 AL |
328 | |
329 | /* Show a summary of the target package if possible. In the case | |
330 | of virtual packages we show nothing */ | |
331 | pkgCache::PkgIterator Targ = Start.TargetPkg(); | |
332 | if (Targ->ProvidesList == 0) | |
7e798dd7 | 333 | { |
b2e465d6 | 334 | out << ' '; |
648e3cb4 | 335 | pkgCache::VerIterator Ver = Cache[Targ].InstVerIter(Cache); |
f0ec51c2 AL |
336 | if (Now == true) |
337 | Ver = Targ.CurrentVer(); | |
079a992d | 338 | |
648e3cb4 | 339 | if (Ver.end() == false) |
b2e465d6 AL |
340 | { |
341 | if (Now == true) | |
342 | ioprintf(out,_("but %s is installed"),Ver.VerStr()); | |
343 | else | |
344 | ioprintf(out,_("but %s is to be installed"),Ver.VerStr()); | |
345 | } | |
648e3cb4 | 346 | else |
303a1703 | 347 | { |
648e3cb4 AL |
348 | if (Cache[Targ].CandidateVerIter(Cache).end() == true) |
349 | { | |
350 | if (Targ->ProvidesList == 0) | |
b2e465d6 | 351 | out << _("but it is not installable"); |
648e3cb4 | 352 | else |
b2e465d6 | 353 | out << _("but it is a virtual package"); |
648e3cb4 | 354 | } |
303a1703 | 355 | else |
b2e465d6 | 356 | out << (Now?_("but it is not installed"):_("but it is not going to be installed")); |
648e3cb4 AL |
357 | } |
358 | } | |
359 | ||
360 | if (Start != End) | |
b2e465d6 | 361 | out << _(" or"); |
648e3cb4 AL |
362 | out << endl; |
363 | ||
364 | if (Start == End) | |
365 | break; | |
366 | Start++; | |
367 | } | |
303a1703 | 368 | } |
0a8e3465 AL |
369 | } |
370 | } | |
371 | /*}}}*/ | |
372 | // ShowNew - Show packages to newly install /*{{{*/ | |
373 | // --------------------------------------------------------------------- | |
374 | /* */ | |
1089ca89 | 375 | void ShowNew(ostream &out,CacheFile &Cache) |
0a8e3465 | 376 | { |
89260e53 | 377 | /* Print out a list of packages that are going to be installed extra |
0a8e3465 | 378 | to what the user asked */ |
0a8e3465 | 379 | string List; |
ac625538 | 380 | string VersionsList; |
1089ca89 AL |
381 | for (unsigned J = 0; J < Cache->Head().PackageCount; J++) |
382 | { | |
383 | pkgCache::PkgIterator I(Cache,Cache.List[J]); | |
ac625538 | 384 | if (Cache[I].NewInstall() == true) { |
803ea2a8 DK |
385 | if (Cache[I].CandidateVerIter(Cache).Pseudo() == true) |
386 | continue; | |
75ce2062 | 387 | List += I.FullName(true) + " "; |
ac625538 AL |
388 | VersionsList += string(Cache[I].CandVersion) + "\n"; |
389 | } | |
1089ca89 AL |
390 | } |
391 | ||
ac625538 | 392 | ShowList(out,_("The following NEW packages will be installed:"),List,VersionsList); |
0a8e3465 AL |
393 | } |
394 | /*}}}*/ | |
395 | // ShowDel - Show packages to delete /*{{{*/ | |
396 | // --------------------------------------------------------------------- | |
397 | /* */ | |
1089ca89 | 398 | void ShowDel(ostream &out,CacheFile &Cache) |
0a8e3465 AL |
399 | { |
400 | /* Print out a list of packages that are going to be removed extra | |
401 | to what the user asked */ | |
0a8e3465 | 402 | string List; |
ac625538 | 403 | string VersionsList; |
1089ca89 | 404 | for (unsigned J = 0; J < Cache->Head().PackageCount; J++) |
fc4b5c9f | 405 | { |
1089ca89 AL |
406 | pkgCache::PkgIterator I(Cache,Cache.List[J]); |
407 | if (Cache[I].Delete() == true) | |
fc4b5c9f | 408 | { |
803ea2a8 DK |
409 | if (Cache[I].CandidateVerIter(Cache).Pseudo() == true) |
410 | continue; | |
1089ca89 | 411 | if ((Cache[I].iFlags & pkgDepCache::Purge) == pkgDepCache::Purge) |
75ce2062 | 412 | List += I.FullName(true) + "* "; |
fc4b5c9f | 413 | else |
75ce2062 | 414 | List += I.FullName(true) + " "; |
ac625538 AL |
415 | |
416 | VersionsList += string(Cache[I].CandVersion)+ "\n"; | |
fc4b5c9f AL |
417 | } |
418 | } | |
3d615484 | 419 | |
ac625538 | 420 | ShowList(out,_("The following packages will be REMOVED:"),List,VersionsList); |
0a8e3465 AL |
421 | } |
422 | /*}}}*/ | |
423 | // ShowKept - Show kept packages /*{{{*/ | |
424 | // --------------------------------------------------------------------- | |
425 | /* */ | |
f292686b | 426 | void ShowKept(ostream &out,CacheFile &Cache) |
0a8e3465 | 427 | { |
0a8e3465 | 428 | string List; |
ac625538 | 429 | string VersionsList; |
f292686b | 430 | for (unsigned J = 0; J < Cache->Head().PackageCount; J++) |
0a8e3465 | 431 | { |
f292686b AL |
432 | pkgCache::PkgIterator I(Cache,Cache.List[J]); |
433 | ||
0a8e3465 | 434 | // Not interesting |
f292686b AL |
435 | if (Cache[I].Upgrade() == true || Cache[I].Upgradable() == false || |
436 | I->CurrentVer == 0 || Cache[I].Delete() == true) | |
0a8e3465 AL |
437 | continue; |
438 | ||
75ce2062 | 439 | List += I.FullName(true) + " "; |
ac625538 | 440 | VersionsList += string(Cache[I].CurVersion) + " => " + Cache[I].CandVersion + "\n"; |
0a8e3465 | 441 | } |
aee7bceb | 442 | ShowList(out,_("The following packages have been kept back:"),List,VersionsList); |
0a8e3465 AL |
443 | } |
444 | /*}}}*/ | |
445 | // ShowUpgraded - Show upgraded packages /*{{{*/ | |
446 | // --------------------------------------------------------------------- | |
447 | /* */ | |
1089ca89 | 448 | void ShowUpgraded(ostream &out,CacheFile &Cache) |
0a8e3465 | 449 | { |
0a8e3465 | 450 | string List; |
ac625538 | 451 | string VersionsList; |
1089ca89 | 452 | for (unsigned J = 0; J < Cache->Head().PackageCount; J++) |
0a8e3465 | 453 | { |
1089ca89 AL |
454 | pkgCache::PkgIterator I(Cache,Cache.List[J]); |
455 | ||
0a8e3465 | 456 | // Not interesting |
1089ca89 | 457 | if (Cache[I].Upgrade() == false || Cache[I].NewInstall() == true) |
0a8e3465 | 458 | continue; |
803ea2a8 DK |
459 | if (Cache[I].CandidateVerIter(Cache).Pseudo() == true) |
460 | continue; | |
461 | ||
75ce2062 | 462 | List += I.FullName(true) + " "; |
ac625538 | 463 | VersionsList += string(Cache[I].CurVersion) + " => " + Cache[I].CandVersion + "\n"; |
0a8e3465 | 464 | } |
aee7bceb | 465 | ShowList(out,_("The following packages will be upgraded:"),List,VersionsList); |
b2e465d6 AL |
466 | } |
467 | /*}}}*/ | |
468 | // ShowDowngraded - Show downgraded packages /*{{{*/ | |
469 | // --------------------------------------------------------------------- | |
470 | /* */ | |
471 | bool ShowDowngraded(ostream &out,CacheFile &Cache) | |
472 | { | |
473 | string List; | |
ac625538 | 474 | string VersionsList; |
b2e465d6 AL |
475 | for (unsigned J = 0; J < Cache->Head().PackageCount; J++) |
476 | { | |
477 | pkgCache::PkgIterator I(Cache,Cache.List[J]); | |
478 | ||
479 | // Not interesting | |
480 | if (Cache[I].Downgrade() == false || Cache[I].NewInstall() == true) | |
481 | continue; | |
803ea2a8 DK |
482 | if (Cache[I].CandidateVerIter(Cache).Pseudo() == true) |
483 | continue; | |
484 | ||
75ce2062 | 485 | List += I.FullName(true) + " "; |
ac625538 | 486 | VersionsList += string(Cache[I].CurVersion) + " => " + Cache[I].CandVersion + "\n"; |
b2e465d6 | 487 | } |
aee7bceb | 488 | return ShowList(out,_("The following packages will be DOWNGRADED:"),List,VersionsList); |
0a8e3465 AL |
489 | } |
490 | /*}}}*/ | |
491 | // ShowHold - Show held but changed packages /*{{{*/ | |
492 | // --------------------------------------------------------------------- | |
493 | /* */ | |
1089ca89 | 494 | bool ShowHold(ostream &out,CacheFile &Cache) |
0a8e3465 | 495 | { |
0a8e3465 | 496 | string List; |
ac625538 | 497 | string VersionsList; |
1089ca89 | 498 | for (unsigned J = 0; J < Cache->Head().PackageCount; J++) |
0a8e3465 | 499 | { |
1089ca89 AL |
500 | pkgCache::PkgIterator I(Cache,Cache.List[J]); |
501 | if (Cache[I].InstallVer != (pkgCache::Version *)I.CurrentVer() && | |
ac625538 | 502 | I->SelectedState == pkgCache::State::Hold) { |
75ce2062 | 503 | List += I.FullName(true) + " "; |
ac625538 AL |
504 | VersionsList += string(Cache[I].CurVersion) + " => " + Cache[I].CandVersion + "\n"; |
505 | } | |
0a8e3465 AL |
506 | } |
507 | ||
ac625538 | 508 | return ShowList(out,_("The following held packages will be changed:"),List,VersionsList); |
0a8e3465 AL |
509 | } |
510 | /*}}}*/ | |
511 | // ShowEssential - Show an essential package warning /*{{{*/ | |
512 | // --------------------------------------------------------------------- | |
513 | /* This prints out a warning message that is not to be ignored. It shows | |
514 | all essential packages and their dependents that are to be removed. | |
515 | It is insanely risky to remove the dependents of an essential package! */ | |
1089ca89 | 516 | bool ShowEssential(ostream &out,CacheFile &Cache) |
0a8e3465 | 517 | { |
0a8e3465 | 518 | string List; |
ac625538 | 519 | string VersionsList; |
b2e465d6 AL |
520 | bool *Added = new bool[Cache->Head().PackageCount]; |
521 | for (unsigned int I = 0; I != Cache->Head().PackageCount; I++) | |
0a8e3465 AL |
522 | Added[I] = false; |
523 | ||
1089ca89 | 524 | for (unsigned J = 0; J < Cache->Head().PackageCount; J++) |
0a8e3465 | 525 | { |
1089ca89 | 526 | pkgCache::PkgIterator I(Cache,Cache.List[J]); |
b2e465d6 AL |
527 | if ((I->Flags & pkgCache::Flag::Essential) != pkgCache::Flag::Essential && |
528 | (I->Flags & pkgCache::Flag::Important) != pkgCache::Flag::Important) | |
0a8e3465 AL |
529 | continue; |
530 | ||
531 | // The essential package is being removed | |
1089ca89 | 532 | if (Cache[I].Delete() == true) |
0a8e3465 AL |
533 | { |
534 | if (Added[I->ID] == false) | |
535 | { | |
536 | Added[I->ID] = true; | |
75ce2062 | 537 | List += I.FullName(true) + " "; |
ac625538 | 538 | //VersionsList += string(Cache[I].CurVersion) + "\n"; ??? |
0a8e3465 AL |
539 | } |
540 | } | |
541 | ||
542 | if (I->CurrentVer == 0) | |
543 | continue; | |
544 | ||
545 | // Print out any essential package depenendents that are to be removed | |
b2e465d6 | 546 | for (pkgCache::DepIterator D = I.CurrentVer().DependsList(); D.end() == false; D++) |
0a8e3465 | 547 | { |
3e3221ba AL |
548 | // Skip everything but depends |
549 | if (D->Type != pkgCache::Dep::PreDepends && | |
550 | D->Type != pkgCache::Dep::Depends) | |
551 | continue; | |
552 | ||
0a8e3465 | 553 | pkgCache::PkgIterator P = D.SmartTargetPkg(); |
1089ca89 | 554 | if (Cache[P].Delete() == true) |
0a8e3465 AL |
555 | { |
556 | if (Added[P->ID] == true) | |
557 | continue; | |
558 | Added[P->ID] = true; | |
3e3221ba AL |
559 | |
560 | char S[300]; | |
75ce2062 | 561 | snprintf(S,sizeof(S),_("%s (due to %s) "),P.FullName(true).c_str(),I.FullName(true).c_str()); |
3e3221ba | 562 | List += S; |
ac625538 | 563 | //VersionsList += "\n"; ??? |
0a8e3465 AL |
564 | } |
565 | } | |
566 | } | |
567 | ||
83d89a9f | 568 | delete [] Added; |
080bf1be | 569 | return ShowList(out,_("WARNING: The following essential packages will be removed.\n" |
ac625538 | 570 | "This should NOT be done unless you know exactly what you are doing!"),List,VersionsList); |
0a8e3465 | 571 | } |
7db98ffc | 572 | |
0a8e3465 AL |
573 | /*}}}*/ |
574 | // Stats - Show some statistics /*{{{*/ | |
575 | // --------------------------------------------------------------------- | |
576 | /* */ | |
577 | void Stats(ostream &out,pkgDepCache &Dep) | |
578 | { | |
579 | unsigned long Upgrade = 0; | |
b2e465d6 | 580 | unsigned long Downgrade = 0; |
0a8e3465 | 581 | unsigned long Install = 0; |
d0c59649 | 582 | unsigned long ReInstall = 0; |
0a8e3465 AL |
583 | for (pkgCache::PkgIterator I = Dep.PkgBegin(); I.end() == false; I++) |
584 | { | |
42d71ab5 DK |
585 | if (pkgCache::VerIterator(Dep, Dep[I].CandidateVer).Pseudo() == true) |
586 | continue; | |
587 | ||
0a8e3465 AL |
588 | if (Dep[I].NewInstall() == true) |
589 | Install++; | |
590 | else | |
b2e465d6 | 591 | { |
0a8e3465 AL |
592 | if (Dep[I].Upgrade() == true) |
593 | Upgrade++; | |
b2e465d6 AL |
594 | else |
595 | if (Dep[I].Downgrade() == true) | |
596 | Downgrade++; | |
597 | } | |
598 | ||
d0c59649 AL |
599 | if (Dep[I].Delete() == false && (Dep[I].iFlags & pkgDepCache::ReInstall) == pkgDepCache::ReInstall) |
600 | ReInstall++; | |
0a8e3465 AL |
601 | } |
602 | ||
2adb5fda | 603 | ioprintf(out,_("%lu upgraded, %lu newly installed, "), |
b2e465d6 AL |
604 | Upgrade,Install); |
605 | ||
d0c59649 | 606 | if (ReInstall != 0) |
b2e465d6 AL |
607 | ioprintf(out,_("%lu reinstalled, "),ReInstall); |
608 | if (Downgrade != 0) | |
609 | ioprintf(out,_("%lu downgraded, "),Downgrade); | |
0a8e3465 | 610 | |
2d425135 | 611 | ioprintf(out,_("%lu to remove and %lu not upgraded.\n"), |
b2e465d6 AL |
612 | Dep.DelCount(),Dep.KeepCount()); |
613 | ||
0a8e3465 | 614 | if (Dep.BadCount() != 0) |
2adb5fda | 615 | ioprintf(out,_("%lu not fully installed or removed.\n"), |
b2e465d6 | 616 | Dep.BadCount()); |
0a8e3465 AL |
617 | } |
618 | /*}}}*/ | |
21d4c9f1 DK |
619 | // CacheSetHelperAPTGet - responsible for message telling from the CacheSets/*{{{*/ |
620 | class CacheSetHelperAPTGet : public APT::CacheSetHelper { | |
621 | /** \brief stream message should be printed to */ | |
622 | std::ostream &out; | |
623 | /** \brief were things like Task or RegEx used to select packages? */ | |
624 | bool explicitlyNamed; | |
625 | ||
626 | APT::PackageSet virtualPkgs; | |
627 | ||
628 | public: | |
629 | CacheSetHelperAPTGet(std::ostream &out) : APT::CacheSetHelper(true), out(out) { | |
630 | explicitlyNamed = true; | |
631 | } | |
632 | ||
633 | virtual void showTaskSelection(APT::PackageSet const &pkgset, string const &pattern) { | |
634 | for (APT::PackageSet::const_iterator Pkg = pkgset.begin(); Pkg != pkgset.end(); ++Pkg) | |
635 | ioprintf(out, _("Note, selecting '%s' for task '%s'\n"), | |
636 | Pkg.FullName(true).c_str(), pattern.c_str()); | |
637 | explicitlyNamed = false; | |
638 | } | |
639 | virtual void showRegExSelection(APT::PackageSet const &pkgset, string const &pattern) { | |
640 | for (APT::PackageSet::const_iterator Pkg = pkgset.begin(); Pkg != pkgset.end(); ++Pkg) | |
641 | ioprintf(out, _("Note, selecting '%s' for regex '%s'\n"), | |
642 | Pkg.FullName(true).c_str(), pattern.c_str()); | |
643 | explicitlyNamed = false; | |
644 | } | |
645 | virtual void showSelectedVersion(pkgCache::PkgIterator const &Pkg, pkgCache::VerIterator const Ver, | |
646 | string const &ver, bool const &verIsRel) { | |
647 | if (ver != Ver.VerStr()) | |
648 | ioprintf(out, _("Selected version '%s' (%s) for '%s'\n"), | |
649 | Ver.VerStr(), Ver.RelStr().c_str(), Pkg.FullName(true).c_str()); | |
650 | } | |
651 | ||
652 | bool showVirtualPackageErrors(pkgCacheFile &Cache) { | |
653 | if (virtualPkgs.empty() == true) | |
654 | return true; | |
655 | for (APT::PackageSet::const_iterator Pkg = virtualPkgs.begin(); | |
656 | Pkg != virtualPkgs.end(); ++Pkg) { | |
657 | if (Pkg->ProvidesList != 0) { | |
658 | ioprintf(c1out,_("Package %s is a virtual package provided by:\n"), | |
659 | Pkg.FullName(true).c_str()); | |
660 | ||
661 | pkgCache::PrvIterator I = Pkg.ProvidesList(); | |
662 | unsigned short provider = 0; | |
663 | for (; I.end() == false; ++I) { | |
664 | pkgCache::PkgIterator Pkg = I.OwnerPkg(); | |
665 | ||
666 | if (Cache[Pkg].CandidateVerIter(Cache) == I.OwnerVer()) { | |
667 | out << " " << Pkg.FullName(true) << " " << I.OwnerVer().VerStr(); | |
668 | if (Cache[Pkg].Install() == true && Cache[Pkg].NewInstall() == false) | |
669 | out << _(" [Installed]"); | |
670 | out << endl; | |
671 | ++provider; | |
672 | } | |
673 | } | |
674 | // if we found no candidate which provide this package, show non-candidates | |
675 | if (provider == 0) | |
676 | for (I = Pkg.ProvidesList(); I.end() == false; I++) | |
677 | out << " " << I.OwnerPkg().FullName(true) << " " << I.OwnerVer().VerStr() | |
678 | << _(" [Not candidate version]") << endl; | |
679 | else | |
680 | out << _("You should explicitly select one to install.") << endl; | |
681 | } else { | |
682 | ioprintf(out, | |
683 | _("Package %s is not available, but is referred to by another package.\n" | |
684 | "This may mean that the package is missing, has been obsoleted, or\n" | |
685 | "is only available from another source\n"),Pkg.FullName(true).c_str()); | |
686 | ||
687 | string List; | |
688 | string VersionsList; | |
689 | SPtrArray<bool> Seen = new bool[Cache.GetPkgCache()->Head().PackageCount]; | |
690 | memset(Seen,0,Cache.GetPkgCache()->Head().PackageCount*sizeof(*Seen)); | |
691 | for (pkgCache::DepIterator Dep = Pkg.RevDependsList(); | |
692 | Dep.end() == false; Dep++) { | |
693 | if (Dep->Type != pkgCache::Dep::Replaces) | |
694 | continue; | |
695 | if (Seen[Dep.ParentPkg()->ID] == true) | |
696 | continue; | |
697 | Seen[Dep.ParentPkg()->ID] = true; | |
698 | List += Dep.ParentPkg().FullName(true) + " "; | |
699 | //VersionsList += string(Dep.ParentPkg().CurVersion) + "\n"; ??? | |
700 | } | |
701 | ShowList(out,_("However the following packages replace it:"),List,VersionsList); | |
702 | } | |
703 | out << std::endl; | |
704 | } | |
705 | return false; | |
706 | } | |
707 | ||
708 | virtual pkgCache::VerIterator canNotFindCandidateVer(pkgCacheFile &Cache, pkgCache::PkgIterator const &Pkg) { | |
709 | APT::VersionSet const verset = tryVirtualPackage(Cache, Pkg, APT::VersionSet::CANDIDATE); | |
710 | if (verset.empty() == false) | |
711 | return *(verset.begin()); | |
712 | if (ShowError == true) { | |
713 | _error->Error(_("Package '%s' has no installation candidate"),Pkg.FullName(true).c_str()); | |
714 | virtualPkgs.insert(Pkg); | |
715 | } | |
716 | return pkgCache::VerIterator(Cache, 0); | |
717 | } | |
718 | ||
719 | virtual pkgCache::VerIterator canNotFindNewestVer(pkgCacheFile &Cache, pkgCache::PkgIterator const &Pkg) { | |
720 | APT::VersionSet const verset = tryVirtualPackage(Cache, Pkg, APT::VersionSet::NEWEST); | |
721 | if (verset.empty() == false) | |
722 | return *(verset.begin()); | |
723 | if (ShowError == true) | |
724 | ioprintf(out, _("Virtual packages like '%s' can't be removed\n"), Pkg.FullName(true).c_str()); | |
725 | return pkgCache::VerIterator(Cache, 0); | |
726 | } | |
727 | ||
728 | APT::VersionSet tryVirtualPackage(pkgCacheFile &Cache, pkgCache::PkgIterator const &Pkg, | |
729 | APT::VersionSet::Version const &select) { | |
730 | /* This is a pure virtual package and there is a single available | |
731 | candidate providing it. */ | |
732 | if (unlikely(Cache[Pkg].CandidateVer != 0) || Pkg->ProvidesList == 0) | |
733 | return APT::VersionSet(); | |
734 | ||
735 | pkgCache::PkgIterator Prov; | |
736 | bool found_one = false; | |
737 | for (pkgCache::PrvIterator P = Pkg.ProvidesList(); P; ++P) { | |
738 | pkgCache::VerIterator const PVer = P.OwnerVer(); | |
739 | pkgCache::PkgIterator const PPkg = PVer.ParentPkg(); | |
740 | ||
741 | /* Ignore versions that are not a candidate. */ | |
742 | if (Cache[PPkg].CandidateVer != PVer) | |
743 | continue; | |
744 | ||
745 | if (found_one == false) { | |
746 | Prov = PPkg; | |
747 | found_one = true; | |
748 | } else if (PPkg != Prov) { | |
749 | found_one = false; // we found at least two | |
750 | break; | |
751 | } | |
752 | } | |
753 | ||
754 | if (found_one == true) { | |
755 | ioprintf(out, _("Note, selecting '%s' instead of '%s'\n"), | |
756 | Prov.FullName(true).c_str(), Pkg.FullName(true).c_str()); | |
757 | return APT::VersionSet::FromPackage(Cache, Prov, select, *this); | |
758 | } | |
759 | return APT::VersionSet(); | |
760 | } | |
761 | ||
762 | inline bool allPkgNamedExplicitly() const { return explicitlyNamed; } | |
763 | ||
764 | }; | |
765 | /*}}}*/ | |
766 | // TryToInstall - Mark a package for installation /*{{{*/ | |
767 | struct TryToInstall { | |
768 | pkgCacheFile* Cache; | |
769 | pkgProblemResolver* Fix; | |
770 | bool FixBroken; | |
771 | unsigned long AutoMarkChanged; | |
6806db8a | 772 | APT::PackageSet doAutoInstallLater; |
21d4c9f1 DK |
773 | |
774 | TryToInstall(pkgCacheFile &Cache, pkgProblemResolver &PM, bool const &FixBroken) : Cache(&Cache), Fix(&PM), | |
775 | FixBroken(FixBroken), AutoMarkChanged(0) {}; | |
776 | ||
777 | void operator() (pkgCache::VerIterator const &Ver) { | |
778 | pkgCache::PkgIterator Pkg = Ver.ParentPkg(); | |
2fbfb111 | 779 | |
21d4c9f1 DK |
780 | Cache->GetDepCache()->SetCandidateVersion(Ver); |
781 | pkgDepCache::StateCache &State = (*Cache)[Pkg]; | |
782 | ||
783 | // Handle the no-upgrade case | |
784 | if (_config->FindB("APT::Get::upgrade",true) == false && Pkg->CurrentVer != 0) | |
785 | ioprintf(c1out,_("Skipping %s, it is already installed and upgrade is not set.\n"), | |
786 | Pkg.FullName(true).c_str()); | |
787 | // Ignore request for install if package would be new | |
788 | else if (_config->FindB("APT::Get::Only-Upgrade", false) == true && Pkg->CurrentVer == 0) | |
789 | ioprintf(c1out,_("Skipping %s, it is not installed and only upgrades are requested.\n"), | |
790 | Pkg.FullName(true).c_str()); | |
791 | else { | |
792 | Fix->Clear(Pkg); | |
793 | Fix->Protect(Pkg); | |
794 | Cache->GetDepCache()->MarkInstall(Pkg,false); | |
795 | ||
796 | if (State.Install() == false) { | |
797 | if (_config->FindB("APT::Get::ReInstall",false) == true) { | |
798 | if (Pkg->CurrentVer == 0 || Pkg.CurrentVer().Downloadable() == false) | |
799 | ioprintf(c1out,_("Reinstallation of %s is not possible, it cannot be downloaded.\n"), | |
800 | Pkg.FullName(true).c_str()); | |
801 | else | |
802 | Cache->GetDepCache()->SetReInstall(Pkg, true); | |
803 | } else | |
804 | ioprintf(c1out,_("%s is already the newest version.\n"), | |
805 | Pkg.FullName(true).c_str()); | |
806 | } | |
807 | ||
808 | // Install it with autoinstalling enabled (if we not respect the minial | |
809 | // required deps or the policy) | |
6806db8a DK |
810 | if (FixBroken == false) |
811 | doAutoInstallLater.insert(Pkg); | |
21d4c9f1 DK |
812 | } |
813 | ||
814 | // see if we need to fix the auto-mark flag | |
815 | // e.g. apt-get install foo | |
816 | // where foo is marked automatic | |
817 | if (State.Install() == false && | |
818 | (State.Flags & pkgCache::Flag::Auto) && | |
819 | _config->FindB("APT::Get::ReInstall",false) == false && | |
820 | _config->FindB("APT::Get::Only-Upgrade",false) == false && | |
821 | _config->FindB("APT::Get::Download-Only",false) == false) | |
822 | { | |
823 | ioprintf(c1out,_("%s set to manually installed.\n"), | |
824 | Pkg.FullName(true).c_str()); | |
825 | Cache->GetDepCache()->MarkAuto(Pkg,false); | |
826 | AutoMarkChanged++; | |
827 | } | |
828 | } | |
6806db8a DK |
829 | |
830 | void doAutoInstall() { | |
831 | for (APT::PackageSet::const_iterator P = doAutoInstallLater.begin(); | |
832 | P != doAutoInstallLater.end(); ++P) { | |
833 | pkgDepCache::StateCache &State = (*Cache)[P]; | |
834 | if (State.InstBroken() == false && State.InstPolicyBroken() == false) | |
835 | continue; | |
836 | Cache->GetDepCache()->MarkInstall(P, true); | |
837 | } | |
838 | doAutoInstallLater.clear(); | |
839 | } | |
21d4c9f1 DK |
840 | }; |
841 | /*}}}*/ | |
842 | // TryToRemove - Mark a package for removal /*{{{*/ | |
843 | struct TryToRemove { | |
844 | pkgCacheFile* Cache; | |
845 | pkgProblemResolver* Fix; | |
846 | bool FixBroken; | |
6cb1583a | 847 | bool PurgePkgs; |
21d4c9f1 DK |
848 | unsigned long AutoMarkChanged; |
849 | ||
6cb1583a DK |
850 | TryToRemove(pkgCacheFile &Cache, pkgProblemResolver &PM) : Cache(&Cache), Fix(&PM), |
851 | PurgePkgs(_config->FindB("APT::Get::Purge", false)) {}; | |
21d4c9f1 DK |
852 | |
853 | void operator() (pkgCache::VerIterator const &Ver) | |
854 | { | |
855 | pkgCache::PkgIterator Pkg = Ver.ParentPkg(); | |
856 | ||
857 | Fix->Clear(Pkg); | |
858 | Fix->Protect(Pkg); | |
859 | Fix->Remove(Pkg); | |
860 | ||
6cb1583a DK |
861 | if ((Pkg->CurrentVer == 0 && PurgePkgs == false) || |
862 | (PurgePkgs == true && Pkg->CurrentState == pkgCache::State::NotInstalled)) | |
21d4c9f1 DK |
863 | ioprintf(c1out,_("Package %s is not installed, so not removed\n"),Pkg.FullName(true).c_str()); |
864 | else | |
6cb1583a | 865 | Cache->GetDepCache()->MarkDelete(Pkg, PurgePkgs); |
21d4c9f1 DK |
866 | } |
867 | }; | |
868 | /*}}}*/ | |
1089ca89 | 869 | // CacheFile::NameComp - QSort compare by name /*{{{*/ |
0a8e3465 AL |
870 | // --------------------------------------------------------------------- |
871 | /* */ | |
1089ca89 AL |
872 | pkgCache *CacheFile::SortCache = 0; |
873 | int CacheFile::NameComp(const void *a,const void *b) | |
0a8e3465 | 874 | { |
8508b1df AL |
875 | if (*(pkgCache::Package **)a == 0 || *(pkgCache::Package **)b == 0) |
876 | return *(pkgCache::Package **)a - *(pkgCache::Package **)b; | |
0a8e3465 | 877 | |
1089ca89 AL |
878 | const pkgCache::Package &A = **(pkgCache::Package **)a; |
879 | const pkgCache::Package &B = **(pkgCache::Package **)b; | |
880 | ||
881 | return strcmp(SortCache->StrP + A.Name,SortCache->StrP + B.Name); | |
882 | } | |
883 | /*}}}*/ | |
884 | // CacheFile::Sort - Sort by name /*{{{*/ | |
885 | // --------------------------------------------------------------------- | |
886 | /* */ | |
887 | void CacheFile::Sort() | |
888 | { | |
889 | delete [] List; | |
890 | List = new pkgCache::Package *[Cache->Head().PackageCount]; | |
891 | memset(List,0,sizeof(*List)*Cache->Head().PackageCount); | |
892 | pkgCache::PkgIterator I = Cache->PkgBegin(); | |
893 | for (;I.end() != true; I++) | |
894 | List[I->ID] = I; | |
895 | ||
896 | SortCache = *this; | |
897 | qsort(List,Cache->Head().PackageCount,sizeof(*List),NameComp); | |
898 | } | |
0a8e3465 | 899 | /*}}}*/ |
b2e465d6 | 900 | // CacheFile::CheckDeps - Open the cache file /*{{{*/ |
0a8e3465 AL |
901 | // --------------------------------------------------------------------- |
902 | /* This routine generates the caches and then opens the dependency cache | |
903 | and verifies that the system is OK. */ | |
2d11135a | 904 | bool CacheFile::CheckDeps(bool AllowBroken) |
0a8e3465 | 905 | { |
4ef9a929 MV |
906 | bool FixBroken = _config->FindB("APT::Get::Fix-Broken",false); |
907 | ||
d38b7b3d AL |
908 | if (_error->PendingError() == true) |
909 | return false; | |
0a8e3465 | 910 | |
0a8e3465 | 911 | // Check that the system is OK |
b2e465d6 | 912 | if (DCache->DelCount() != 0 || DCache->InstCount() != 0) |
db0db9fe | 913 | return _error->Error("Internal error, non-zero counts"); |
0a8e3465 AL |
914 | |
915 | // Apply corrections for half-installed packages | |
b2e465d6 | 916 | if (pkgApplyStatus(*DCache) == false) |
0a8e3465 AL |
917 | return false; |
918 | ||
4ef9a929 MV |
919 | if (_config->FindB("APT::Get::Fix-Policy-Broken",false) == true) |
920 | { | |
921 | FixBroken = true; | |
922 | if ((DCache->PolicyBrokenCount() > 0)) | |
923 | { | |
924 | // upgrade all policy-broken packages with ForceImportantDeps=True | |
925 | for (pkgCache::PkgIterator I = Cache->PkgBegin(); !I.end(); I++) | |
926 | if ((*DCache)[I].NowPolicyBroken() == true) | |
7610bb3d | 927 | DCache->MarkInstall(I,true,0, false, true); |
4ef9a929 MV |
928 | } |
929 | } | |
930 | ||
0a8e3465 | 931 | // Nothing is broken |
b2e465d6 | 932 | if (DCache->BrokenCount() == 0 || AllowBroken == true) |
0a8e3465 AL |
933 | return true; |
934 | ||
935 | // Attempt to fix broken things | |
4ef9a929 | 936 | if (FixBroken == true) |
0a8e3465 | 937 | { |
b2e465d6 AL |
938 | c1out << _("Correcting dependencies...") << flush; |
939 | if (pkgFixBroken(*DCache) == false || DCache->BrokenCount() != 0) | |
0a8e3465 | 940 | { |
b2e465d6 | 941 | c1out << _(" failed.") << endl; |
421c8d10 | 942 | ShowBroken(c1out,*this,true); |
0a8e3465 | 943 | |
b2e465d6 | 944 | return _error->Error(_("Unable to correct dependencies")); |
0a8e3465 | 945 | } |
b2e465d6 AL |
946 | if (pkgMinimizeUpgrade(*DCache) == false) |
947 | return _error->Error(_("Unable to minimize the upgrade set")); | |
0a8e3465 | 948 | |
b2e465d6 | 949 | c1out << _(" Done") << endl; |
0a8e3465 AL |
950 | } |
951 | else | |
952 | { | |
b5647402 | 953 | c1out << _("You might want to run 'apt-get -f install' to correct these.") << endl; |
421c8d10 | 954 | ShowBroken(c1out,*this,true); |
0a8e3465 | 955 | |
b2e465d6 | 956 | return _error->Error(_("Unmet dependencies. Try using -f.")); |
0a8e3465 AL |
957 | } |
958 | ||
959 | return true; | |
960 | } | |
92fcbfc1 DK |
961 | /*}}}*/ |
962 | // CheckAuth - check if each download comes form a trusted source /*{{{*/ | |
963 | // --------------------------------------------------------------------- | |
964 | /* */ | |
7db98ffc MZ |
965 | static bool CheckAuth(pkgAcquire& Fetcher) |
966 | { | |
967 | string UntrustedList; | |
968 | for (pkgAcquire::ItemIterator I = Fetcher.ItemsBegin(); I < Fetcher.ItemsEnd(); ++I) | |
969 | { | |
970 | if (!(*I)->IsTrusted()) | |
971 | { | |
972 | UntrustedList += string((*I)->ShortDesc()) + " "; | |
973 | } | |
974 | } | |
975 | ||
976 | if (UntrustedList == "") | |
977 | { | |
978 | return true; | |
979 | } | |
980 | ||
981 | ShowList(c2out,_("WARNING: The following packages cannot be authenticated!"),UntrustedList,""); | |
982 | ||
983 | if (_config->FindB("APT::Get::AllowUnauthenticated",false) == true) | |
984 | { | |
2a7e07c7 | 985 | c2out << _("Authentication warning overridden.\n"); |
7db98ffc MZ |
986 | return true; |
987 | } | |
988 | ||
989 | if (_config->FindI("quiet",0) < 2 | |
990 | && _config->FindB("APT::Get::Assume-Yes",false) == false) | |
991 | { | |
db0db9fe | 992 | c2out << _("Install these packages without verification [y/N]? ") << flush; |
7db98ffc MZ |
993 | if (!YnPrompt(false)) |
994 | return _error->Error(_("Some packages could not be authenticated")); | |
995 | ||
996 | return true; | |
997 | } | |
998 | else if (_config->FindB("APT::Get::Force-Yes",false) == true) | |
999 | { | |
1000 | return true; | |
1001 | } | |
1002 | ||
1003 | return _error->Error(_("There are problems and -y was used without --force-yes")); | |
1004 | } | |
0a8e3465 | 1005 | /*}}}*/ |
0a8e3465 AL |
1006 | // InstallPackages - Actually download and install the packages /*{{{*/ |
1007 | // --------------------------------------------------------------------- | |
1008 | /* This displays the informative messages describing what is going to | |
1009 | happen and then calls the download routines */ | |
a3eaf954 | 1010 | bool InstallPackages(CacheFile &Cache,bool ShwKept,bool Ask = true, |
80fbda96 | 1011 | bool Safety = true) |
0a8e3465 | 1012 | { |
fc4b5c9f AL |
1013 | if (_config->FindB("APT::Get::Purge",false) == true) |
1014 | { | |
1015 | pkgCache::PkgIterator I = Cache->PkgBegin(); | |
1016 | for (; I.end() == false; I++) | |
d556d1a1 AL |
1017 | { |
1018 | if (I.Purge() == false && Cache[I].Mode == pkgDepCache::ModeDelete) | |
1019 | Cache->MarkDelete(I,true); | |
1020 | } | |
fc4b5c9f AL |
1021 | } |
1022 | ||
83d89a9f | 1023 | bool Fail = false; |
6f86c974 | 1024 | bool Essential = false; |
83d89a9f | 1025 | |
a6568219 | 1026 | // Show all the various warning indicators |
0a8e3465 AL |
1027 | ShowDel(c1out,Cache); |
1028 | ShowNew(c1out,Cache); | |
1029 | if (ShwKept == true) | |
1030 | ShowKept(c1out,Cache); | |
7a215bee | 1031 | Fail |= !ShowHold(c1out,Cache); |
906fbf88 | 1032 | if (_config->FindB("APT::Get::Show-Upgraded",true) == true) |
0a8e3465 | 1033 | ShowUpgraded(c1out,Cache); |
b2e465d6 | 1034 | Fail |= !ShowDowngraded(c1out,Cache); |
5d1d0738 AL |
1035 | if (_config->FindB("APT::Get::Download-Only",false) == false) |
1036 | Essential = !ShowEssential(c1out,Cache); | |
6f86c974 | 1037 | Fail |= Essential; |
0a8e3465 | 1038 | Stats(c1out,Cache); |
7db98ffc | 1039 | |
0a8e3465 | 1040 | // Sanity check |
d38b7b3d | 1041 | if (Cache->BrokenCount() != 0) |
0a8e3465 | 1042 | { |
421c8d10 | 1043 | ShowBroken(c1out,Cache,false); |
2a7e07c7 | 1044 | return _error->Error(_("Internal error, InstallPackages was called with broken packages!")); |
0a8e3465 AL |
1045 | } |
1046 | ||
d0c59649 | 1047 | if (Cache->DelCount() == 0 && Cache->InstCount() == 0 && |
d38b7b3d | 1048 | Cache->BadCount() == 0) |
c60d151b | 1049 | return true; |
03e39e59 | 1050 | |
d150b09d | 1051 | // No remove flag |
b2e465d6 | 1052 | if (Cache->DelCount() != 0 && _config->FindB("APT::Get::Remove",true) == false) |
db0db9fe | 1053 | return _error->Error(_("Packages need to be removed but remove is disabled.")); |
d150b09d | 1054 | |
03e39e59 AL |
1055 | // Run the simulator .. |
1056 | if (_config->FindB("APT::Get::Simulate") == true) | |
1057 | { | |
1058 | pkgSimulate PM(Cache); | |
2a7e07c7 MV |
1059 | int status_fd = _config->FindI("APT::Status-Fd",-1); |
1060 | pkgPackageManager::OrderResult Res = PM.DoInstall(status_fd); | |
281daf46 AL |
1061 | if (Res == pkgPackageManager::Failed) |
1062 | return false; | |
1063 | if (Res != pkgPackageManager::Completed) | |
2a7e07c7 | 1064 | return _error->Error(_("Internal error, Ordering didn't finish")); |
281daf46 | 1065 | return true; |
03e39e59 AL |
1066 | } |
1067 | ||
1068 | // Create the text record parser | |
1069 | pkgRecords Recs(Cache); | |
83d89a9f AL |
1070 | if (_error->PendingError() == true) |
1071 | return false; | |
1cd1c398 | 1072 | |
03e39e59 | 1073 | // Create the download object |
1cd1c398 | 1074 | pkgAcquire Fetcher; |
03e39e59 | 1075 | AcqTextStatus Stat(ScreenWidth,_config->FindI("quiet",0)); |
a722b2c5 DK |
1076 | if (_config->FindB("APT::Get::Print-URIs", false) == true) |
1077 | { | |
1078 | // force a hashsum for compatibility reasons | |
1079 | _config->CndSet("Acquire::ForceHash", "md5sum"); | |
1080 | if (Fetcher.Setup(&Stat, "") == false) | |
1081 | return false; | |
1082 | } | |
1083 | else if (Fetcher.Setup(&Stat, _config->FindDir("Dir::Cache::Archives")) == false) | |
1cd1c398 | 1084 | return false; |
03e39e59 AL |
1085 | |
1086 | // Read the source list | |
1bb8cd67 DK |
1087 | if (Cache.BuildSourceList() == false) |
1088 | return false; | |
1089 | pkgSourceList *List = Cache.GetSourceList(); | |
03e39e59 AL |
1090 | |
1091 | // Create the package manager and prepare to download | |
b2e465d6 | 1092 | SPtr<pkgPackageManager> PM= _system->CreatePM(Cache); |
1bb8cd67 | 1093 | if (PM->GetArchives(&Fetcher,List,&Recs) == false || |
424c3bc0 | 1094 | _error->PendingError() == true) |
03e39e59 AL |
1095 | return false; |
1096 | ||
7a1b1f8b | 1097 | // Display statistics |
3a882565 DK |
1098 | unsigned long long FetchBytes = Fetcher.FetchNeeded(); |
1099 | unsigned long long FetchPBytes = Fetcher.PartialPresent(); | |
1100 | unsigned long long DebBytes = Fetcher.TotalNeeded(); | |
d38b7b3d AL |
1101 | if (DebBytes != Cache->DebSize()) |
1102 | { | |
1103 | c0out << DebBytes << ',' << Cache->DebSize() << endl; | |
2a7e07c7 | 1104 | c0out << _("How odd.. The sizes didn't match, email apt@packages.debian.org") << endl; |
d38b7b3d | 1105 | } |
138d4b3d | 1106 | |
7a1b1f8b | 1107 | // Number of bytes |
a6568219 | 1108 | if (DebBytes != FetchBytes) |
4d8d8112 DK |
1109 | //TRANSLATOR: The required space between number and unit is already included |
1110 | // in the replacement strings, so %sB will be correctly translate in e.g. 1,5 MB | |
ac7fd99c | 1111 | ioprintf(c1out,_("Need to get %sB/%sB of archives.\n"), |
b2e465d6 | 1112 | SizeToStr(FetchBytes).c_str(),SizeToStr(DebBytes).c_str()); |
813603a0 | 1113 | else if (DebBytes != 0) |
4d8d8112 DK |
1114 | //TRANSLATOR: The required space between number and unit is already included |
1115 | // in the replacement string, so %sB will be correctly translate in e.g. 1,5 MB | |
ac7fd99c | 1116 | ioprintf(c1out,_("Need to get %sB of archives.\n"), |
b2e465d6 AL |
1117 | SizeToStr(DebBytes).c_str()); |
1118 | ||
10bb1f5f AL |
1119 | // Size delta |
1120 | if (Cache->UsrSize() >= 0) | |
4d8d8112 DK |
1121 | //TRANSLATOR: The required space between number and unit is already included |
1122 | // in the replacement string, so %sB will be correctly translate in e.g. 1,5 MB | |
813603a0 | 1123 | ioprintf(c1out,_("After this operation, %sB of additional disk space will be used.\n"), |
b2e465d6 | 1124 | SizeToStr(Cache->UsrSize()).c_str()); |
10bb1f5f | 1125 | else |
4d8d8112 DK |
1126 | //TRANSLATOR: The required space between number and unit is already included |
1127 | // in the replacement string, so %sB will be correctly translate in e.g. 1,5 MB | |
813603a0 | 1128 | ioprintf(c1out,_("After this operation, %sB disk space will be freed.\n"), |
b2e465d6 | 1129 | SizeToStr(-1*Cache->UsrSize()).c_str()); |
10bb1f5f AL |
1130 | |
1131 | if (_error->PendingError() == true) | |
1132 | return false; | |
31a0531d | 1133 | |
01b64152 AL |
1134 | /* Check for enough free space, but only if we are actually going to |
1135 | download */ | |
18e20d63 AL |
1136 | if (_config->FindB("APT::Get::Print-URIs") == false && |
1137 | _config->FindB("APT::Get::Download",true) == true) | |
01b64152 AL |
1138 | { |
1139 | struct statvfs Buf; | |
1140 | string OutputDir = _config->FindDir("Dir::Cache::Archives"); | |
c1ce032a DK |
1141 | if (statvfs(OutputDir.c_str(),&Buf) != 0) { |
1142 | if (errno == EOVERFLOW) | |
1143 | return _error->WarningE("statvfs",_("Couldn't determine free space in %s"), | |
1144 | OutputDir.c_str()); | |
1145 | else | |
1146 | return _error->Errno("statvfs",_("Couldn't determine free space in %s"), | |
1147 | OutputDir.c_str()); | |
1148 | } else if (unsigned(Buf.f_bfree) < (FetchBytes - FetchPBytes)/Buf.f_bsize) | |
885d204b OS |
1149 | { |
1150 | struct statfs Stat; | |
f64196e8 DK |
1151 | if (statfs(OutputDir.c_str(),&Stat) != 0 |
1152 | #if HAVE_STRUCT_STATFS_F_TYPE | |
1153 | || unsigned(Stat.f_type) != RAMFS_MAGIC | |
1154 | #endif | |
1155 | ) | |
885d204b OS |
1156 | return _error->Error(_("You don't have enough free space in %s."), |
1157 | OutputDir.c_str()); | |
1158 | } | |
01b64152 AL |
1159 | } |
1160 | ||
83d89a9f | 1161 | // Fail safe check |
0c95c765 AL |
1162 | if (_config->FindI("quiet",0) >= 2 || |
1163 | _config->FindB("APT::Get::Assume-Yes",false) == true) | |
83d89a9f AL |
1164 | { |
1165 | if (Fail == true && _config->FindB("APT::Get::Force-Yes",false) == false) | |
b2e465d6 | 1166 | return _error->Error(_("There are problems and -y was used without --force-yes")); |
83d89a9f | 1167 | } |
83d89a9f | 1168 | |
80fbda96 | 1169 | if (Essential == true && Safety == true) |
6f86c974 | 1170 | { |
d150b09d | 1171 | if (_config->FindB("APT::Get::Trivial-Only",false) == true) |
b2e465d6 | 1172 | return _error->Error(_("Trivial Only specified but this is not a trivial operation.")); |
d150b09d | 1173 | |
b2e465d6 AL |
1174 | const char *Prompt = _("Yes, do as I say!"); |
1175 | ioprintf(c2out, | |
080bf1be | 1176 | _("You are about to do something potentially harmful.\n" |
b2e465d6 AL |
1177 | "To continue type in the phrase '%s'\n" |
1178 | " ?] "),Prompt); | |
1179 | c2out << flush; | |
1180 | if (AnalPrompt(Prompt) == false) | |
6f86c974 | 1181 | { |
b2e465d6 | 1182 | c2out << _("Abort.") << endl; |
a6568219 | 1183 | exit(1); |
6f86c974 AL |
1184 | } |
1185 | } | |
1186 | else | |
d150b09d | 1187 | { |
6f86c974 | 1188 | // Prompt to continue |
38262e68 | 1189 | if (Ask == true || Fail == true) |
6f86c974 | 1190 | { |
d150b09d | 1191 | if (_config->FindB("APT::Get::Trivial-Only",false) == true) |
b2e465d6 | 1192 | return _error->Error(_("Trivial Only specified but this is not a trivial operation.")); |
d150b09d | 1193 | |
0c95c765 | 1194 | if (_config->FindI("quiet",0) < 2 && |
6f86c974 | 1195 | _config->FindB("APT::Get::Assume-Yes",false) == false) |
0c95c765 | 1196 | { |
db0db9fe | 1197 | c2out << _("Do you want to continue [Y/n]? ") << flush; |
6f86c974 | 1198 | |
0c95c765 AL |
1199 | if (YnPrompt() == false) |
1200 | { | |
b2e465d6 | 1201 | c2out << _("Abort.") << endl; |
0c95c765 AL |
1202 | exit(1); |
1203 | } | |
1204 | } | |
6f86c974 AL |
1205 | } |
1206 | } | |
1207 | ||
36375005 | 1208 | // Just print out the uris an exit if the --print-uris flag was used |
f7a08e33 AL |
1209 | if (_config->FindB("APT::Get::Print-URIs") == true) |
1210 | { | |
1211 | pkgAcquire::UriIterator I = Fetcher.UriBegin(); | |
1212 | for (; I != Fetcher.UriEnd(); I++) | |
1213 | cout << '\'' << I->URI << "' " << flNotDir(I->Owner->DestFile) << ' ' << | |
495e5cb2 | 1214 | I->Owner->FileSize << ' ' << I->Owner->HashSum() << endl; |
f7a08e33 AL |
1215 | return true; |
1216 | } | |
b2e465d6 | 1217 | |
7db98ffc MZ |
1218 | if (!CheckAuth(Fetcher)) |
1219 | return false; | |
1220 | ||
b2e465d6 AL |
1221 | /* Unlock the dpkg lock if we are not going to be doing an install |
1222 | after. */ | |
1223 | if (_config->FindB("APT::Get::Download-Only",false) == true) | |
1224 | _system->UnLock(); | |
83d89a9f | 1225 | |
03e39e59 | 1226 | // Run it |
281daf46 | 1227 | while (1) |
30e1eab5 | 1228 | { |
a3eaf954 | 1229 | bool Transient = false; |
b2e465d6 | 1230 | if (_config->FindB("APT::Get::Download",true) == false) |
a3eaf954 | 1231 | { |
076d01b0 | 1232 | for (pkgAcquire::ItemIterator I = Fetcher.ItemsBegin(); I < Fetcher.ItemsEnd();) |
a3eaf954 AL |
1233 | { |
1234 | if ((*I)->Local == true) | |
1235 | { | |
1236 | I++; | |
1237 | continue; | |
1238 | } | |
1239 | ||
1240 | // Close the item and check if it was found in cache | |
1241 | (*I)->Finished(); | |
1242 | if ((*I)->Complete == false) | |
1243 | Transient = true; | |
1244 | ||
1245 | // Clear it out of the fetch list | |
1246 | delete *I; | |
1247 | I = Fetcher.ItemsBegin(); | |
1248 | } | |
1249 | } | |
1250 | ||
1251 | if (Fetcher.Run() == pkgAcquire::Failed) | |
1252 | return false; | |
30e1eab5 | 1253 | |
281daf46 AL |
1254 | // Print out errors |
1255 | bool Failed = false; | |
076d01b0 | 1256 | for (pkgAcquire::ItemIterator I = Fetcher.ItemsBegin(); I != Fetcher.ItemsEnd(); I++) |
f01fe790 | 1257 | { |
281daf46 AL |
1258 | if ((*I)->Status == pkgAcquire::Item::StatDone && |
1259 | (*I)->Complete == true) | |
1260 | continue; | |
1261 | ||
281daf46 AL |
1262 | if ((*I)->Status == pkgAcquire::Item::StatIdle) |
1263 | { | |
1264 | Transient = true; | |
1265 | // Failed = true; | |
1266 | continue; | |
1267 | } | |
a3eaf954 | 1268 | |
b2e465d6 AL |
1269 | fprintf(stderr,_("Failed to fetch %s %s\n"),(*I)->DescURI().c_str(), |
1270 | (*I)->ErrorText.c_str()); | |
f01fe790 | 1271 | Failed = true; |
f01fe790 | 1272 | } |
5ec427c2 | 1273 | |
a3eaf954 | 1274 | /* If we are in no download mode and missing files and there were |
5ec427c2 AL |
1275 | 'failures' then the user must specify -m. Furthermore, there |
1276 | is no such thing as a transient error in no-download mode! */ | |
a3eaf954 | 1277 | if (Transient == true && |
b2e465d6 | 1278 | _config->FindB("APT::Get::Download",true) == false) |
5ec427c2 AL |
1279 | { |
1280 | Transient = false; | |
1281 | Failed = true; | |
1282 | } | |
f01fe790 | 1283 | |
281daf46 AL |
1284 | if (_config->FindB("APT::Get::Download-Only",false) == true) |
1285 | { | |
1286 | if (Failed == true && _config->FindB("APT::Get::Fix-Missing",false) == false) | |
b2e465d6 AL |
1287 | return _error->Error(_("Some files failed to download")); |
1288 | c1out << _("Download complete and in download only mode") << endl; | |
281daf46 AL |
1289 | return true; |
1290 | } | |
1291 | ||
8195ae46 | 1292 | if (Failed == true && _config->FindB("APT::Get::Fix-Missing",false) == false) |
f01fe790 | 1293 | { |
b2e465d6 | 1294 | return _error->Error(_("Unable to fetch some archives, maybe run apt-get update or try with --fix-missing?")); |
f01fe790 AL |
1295 | } |
1296 | ||
281daf46 | 1297 | if (Transient == true && Failed == true) |
b2e465d6 | 1298 | return _error->Error(_("--fix-missing and media swapping is not currently supported")); |
281daf46 AL |
1299 | |
1300 | // Try to deal with missing package files | |
b2e465d6 | 1301 | if (Failed == true && PM->FixMissing() == false) |
281daf46 | 1302 | { |
b2e465d6 | 1303 | cerr << _("Unable to correct missing packages.") << endl; |
db0db9fe | 1304 | return _error->Error(_("Aborting install.")); |
281daf46 | 1305 | } |
afb1e2e3 | 1306 | |
b2e465d6 | 1307 | _system->UnLock(); |
2a7e07c7 MV |
1308 | int status_fd = _config->FindI("APT::Status-Fd",-1); |
1309 | pkgPackageManager::OrderResult Res = PM->DoInstall(status_fd); | |
281daf46 AL |
1310 | if (Res == pkgPackageManager::Failed || _error->PendingError() == true) |
1311 | return false; | |
1312 | if (Res == pkgPackageManager::Completed) | |
642ebc1a | 1313 | break; |
281daf46 AL |
1314 | |
1315 | // Reload the fetcher object and loop again for media swapping | |
1316 | Fetcher.Shutdown(); | |
1bb8cd67 | 1317 | if (PM->GetArchives(&Fetcher,List,&Recs) == false) |
281daf46 | 1318 | return false; |
b2e465d6 AL |
1319 | |
1320 | _system->Lock(); | |
642ebc1a DK |
1321 | } |
1322 | ||
1323 | std::set<std::string> const disappearedPkgs = PM->GetDisappearedPackages(); | |
1324 | if (disappearedPkgs.empty() == true) | |
1325 | return true; | |
1326 | ||
1327 | string disappear; | |
1328 | for (std::set<std::string>::const_iterator d = disappearedPkgs.begin(); | |
1329 | d != disappearedPkgs.end(); ++d) | |
1330 | disappear.append(*d).append(" "); | |
1331 | ||
1332 | ShowList(c1out, P_("The following package disappeared from your system as\n" | |
1333 | "all files have been overwritten by other packages:", | |
1334 | "The following packages disappeared from your system as\n" | |
1335 | "all files have been overwritten by other packages:", disappearedPkgs.size()), disappear, ""); | |
1336 | c0out << _("Note: This is done automatic and on purpose by dpkg.") << std::endl; | |
1337 | ||
1338 | return true; | |
0a8e3465 AL |
1339 | } |
1340 | /*}}}*/ | |
b8ad5512 | 1341 | // TryToInstallBuildDep - Try to install a single package /*{{{*/ |
c373c37a AL |
1342 | // --------------------------------------------------------------------- |
1343 | /* This used to be inlined in DoInstall, but with the advent of regex package | |
1344 | name matching it was split out.. */ | |
21d4c9f1 | 1345 | bool TryToInstallBuildDep(pkgCache::PkgIterator Pkg,pkgCacheFile &Cache, |
c373c37a | 1346 | pkgProblemResolver &Fix,bool Remove,bool BrokenFix, |
70e706ad | 1347 | bool AllowFail = true) |
c373c37a | 1348 | { |
21d4c9f1 | 1349 | if (Cache[Pkg].CandidateVer == 0 && Pkg->ProvidesList != 0) |
c373c37a | 1350 | { |
21d4c9f1 DK |
1351 | CacheSetHelperAPTGet helper(c1out); |
1352 | helper.showErrors(AllowFail == false); | |
1353 | pkgCache::VerIterator Ver = helper.canNotFindNewestVer(Cache, Pkg); | |
1354 | if (Ver.end() == false) | |
1355 | Pkg = Ver.ParentPkg(); | |
1356 | else if (helper.showVirtualPackageErrors(Cache) == false) | |
1357 | return AllowFail; | |
c373c37a | 1358 | } |
61d6a8de | 1359 | |
c373c37a AL |
1360 | if (Remove == true) |
1361 | { | |
21d4c9f1 DK |
1362 | TryToRemove RemoveAction(Cache, Fix); |
1363 | RemoveAction(Pkg.VersionList()); | |
1364 | } else if (Cache[Pkg].CandidateVer != 0) { | |
1365 | TryToInstall InstallAction(Cache, Fix, BrokenFix); | |
1366 | InstallAction(Cache[Pkg].CandidateVerIter(Cache)); | |
6806db8a | 1367 | InstallAction.doAutoInstall(); |
21d4c9f1 DK |
1368 | } else |
1369 | return AllowFail; | |
60681f93 | 1370 | |
b2e465d6 AL |
1371 | return true; |
1372 | } | |
1373 | /*}}}*/ | |
1374 | // FindSrc - Find a source record /*{{{*/ | |
1375 | // --------------------------------------------------------------------- | |
1376 | /* */ | |
1377 | pkgSrcRecords::Parser *FindSrc(const char *Name,pkgRecords &Recs, | |
1378 | pkgSrcRecords &SrcRecs,string &Src, | |
1379 | pkgDepCache &Cache) | |
1380 | { | |
b2e465d6 | 1381 | string VerTag; |
fb3dc579 | 1382 | string DefRel = _config->Find("APT::Default-Release"); |
b2e465d6 | 1383 | string TmpSrc = Name; |
aca056a9 | 1384 | |
fb3dc579 MV |
1385 | // extract the version/release from the pkgname |
1386 | const size_t found = TmpSrc.find_last_of("/="); | |
1387 | if (found != string::npos) { | |
1388 | if (TmpSrc[found] == '/') | |
1389 | DefRel = TmpSrc.substr(found+1); | |
1390 | else | |
1391 | VerTag = TmpSrc.substr(found+1); | |
ebf6c42d DK |
1392 | TmpSrc = TmpSrc.substr(0,found); |
1393 | } | |
aca056a9 | 1394 | |
fb3dc579 MV |
1395 | /* Lookup the version of the package we would install if we were to |
1396 | install a version and determine the source package name, then look | |
1397 | in the archive for a source package of the same name. */ | |
1398 | bool MatchSrcOnly = _config->FindB("APT::Get::Only-Source"); | |
1399 | const pkgCache::PkgIterator Pkg = Cache.FindPkg(TmpSrc); | |
1400 | if (MatchSrcOnly == false && Pkg.end() == false) | |
aca056a9 | 1401 | { |
fb3dc579 | 1402 | if(VerTag.empty() == false || DefRel.empty() == false) |
aca056a9 | 1403 | { |
e84adb76 | 1404 | bool fuzzy = false; |
fb3dc579 MV |
1405 | // we have a default release, try to locate the pkg. we do it like |
1406 | // this because GetCandidateVer() will not "downgrade", that means | |
1407 | // "apt-get source -t stable apt" won't work on a unstable system | |
e84adb76 | 1408 | for (pkgCache::VerIterator Ver = Pkg.VersionList();; Ver++) |
aca056a9 | 1409 | { |
e84adb76 DK |
1410 | // try first only exact matches, later fuzzy matches |
1411 | if (Ver.end() == true) | |
1412 | { | |
1413 | if (fuzzy == true) | |
1414 | break; | |
1415 | fuzzy = true; | |
1416 | Ver = Pkg.VersionList(); | |
259f688a MV |
1417 | // exit right away from the Pkg.VersionList() loop if we |
1418 | // don't have any versions | |
1419 | if (Ver.end() == true) | |
1420 | break; | |
e84adb76 DK |
1421 | } |
1422 | // We match against a concrete version (or a part of this version) | |
1423 | if (VerTag.empty() == false && | |
1424 | (fuzzy == true || Cache.VS().CmpVersion(VerTag, Ver.VerStr()) != 0) && // exact match | |
1425 | (fuzzy == false || strncmp(VerTag.c_str(), Ver.VerStr(), VerTag.size()) != 0)) // fuzzy match | |
1426 | continue; | |
1427 | ||
fb3dc579 MV |
1428 | for (pkgCache::VerFileIterator VF = Ver.FileList(); |
1429 | VF.end() == false; VF++) | |
aca056a9 | 1430 | { |
fb3dc579 MV |
1431 | /* If this is the status file, and the current version is not the |
1432 | version in the status file (ie it is not installed, or somesuch) | |
1433 | then it is not a candidate for installation, ever. This weeds | |
1434 | out bogus entries that may be due to config-file states, or | |
1435 | other. */ | |
1436 | if ((VF.File()->Flags & pkgCache::Flag::NotSource) == | |
1437 | pkgCache::Flag::NotSource && Pkg.CurrentVer() != Ver) | |
1438 | continue; | |
1439 | ||
fb3dc579 MV |
1440 | // or we match against a release |
1441 | if(VerTag.empty() == false || | |
1442 | (VF.File().Archive() != 0 && VF.File().Archive() == DefRel) || | |
1443 | (VF.File().Codename() != 0 && VF.File().Codename() == DefRel)) | |
1444 | { | |
1445 | pkgRecords::Parser &Parse = Recs.Lookup(VF); | |
1446 | Src = Parse.SourcePkg(); | |
61690a7e MV |
1447 | // no SourcePkg name, so it is the "binary" name |
1448 | if (Src.empty() == true) | |
1449 | Src = TmpSrc; | |
e84adb76 DK |
1450 | // the Version we have is possibly fuzzy or includes binUploads, |
1451 | // so we use the Version of the SourcePkg (empty if same as package) | |
1452 | VerTag = Parse.SourceVer(); | |
61690a7e MV |
1453 | if (VerTag.empty() == true) |
1454 | VerTag = Ver.VerStr(); | |
fb3dc579 MV |
1455 | break; |
1456 | } | |
aca056a9 | 1457 | } |
61690a7e MV |
1458 | if (Src.empty() == false) |
1459 | break; | |
aca056a9 | 1460 | } |
fb3dc579 MV |
1461 | if (Src.empty() == true) |
1462 | { | |
61690a7e | 1463 | // Sources files have no codename information |
ddff663f MV |
1464 | if (VerTag.empty() == true && DefRel.empty() == false) |
1465 | { | |
1466 | _error->Error(_("Ignore unavailable target release '%s' of package '%s'"), DefRel.c_str(), TmpSrc.c_str()); | |
1467 | return 0; | |
1468 | } | |
fb3dc579 | 1469 | } |
026f60e2 | 1470 | } |
61690a7e | 1471 | if (Src.empty() == true) |
b2e465d6 | 1472 | { |
61690a7e MV |
1473 | // if we don't have found a fitting package yet so we will |
1474 | // choose a good candidate and proceed with that. | |
1475 | // Maybe we will find a source later on with the right VerTag | |
ce6162be | 1476 | pkgCache::VerIterator Ver = Cache.GetCandidateVer(Pkg); |
fb3dc579 | 1477 | if (Ver.end() == false) |
b2e465d6 AL |
1478 | { |
1479 | pkgRecords::Parser &Parse = Recs.Lookup(Ver.FileList()); | |
1480 | Src = Parse.SourcePkg(); | |
61690a7e MV |
1481 | if (VerTag.empty() == true) |
1482 | VerTag = Parse.SourceVer(); | |
b2e465d6 | 1483 | } |
fb3dc579 MV |
1484 | } |
1485 | } | |
1486 | ||
1487 | if (Src.empty() == true) | |
1488 | Src = TmpSrc; | |
1489 | else | |
1490 | { | |
1491 | /* if we have a source pkg name, make sure to only search | |
1492 | for srcpkg names, otherwise apt gets confused if there | |
1493 | is a binary package "pkg1" and a source package "pkg1" | |
1494 | with the same name but that comes from different packages */ | |
1495 | MatchSrcOnly = true; | |
1496 | if (Src != TmpSrc) | |
1497 | { | |
1498 | ioprintf(c1out, _("Picking '%s' as source package instead of '%s'\n"), Src.c_str(), TmpSrc.c_str()); | |
1499 | } | |
b2e465d6 | 1500 | } |
89ad8e7c | 1501 | |
b2e465d6 AL |
1502 | // The best hit |
1503 | pkgSrcRecords::Parser *Last = 0; | |
1504 | unsigned long Offset = 0; | |
1505 | string Version; | |
89ad8e7c | 1506 | |
b2e465d6 AL |
1507 | /* Iterate over all of the hits, which includes the resulting |
1508 | binary packages in the search */ | |
1509 | pkgSrcRecords::Parser *Parse; | |
fb3dc579 | 1510 | while (true) |
b2e465d6 | 1511 | { |
fb3dc579 MV |
1512 | SrcRecs.Restart(); |
1513 | while ((Parse = SrcRecs.Find(Src.c_str(), MatchSrcOnly)) != 0) | |
b2e465d6 | 1514 | { |
fb3dc579 MV |
1515 | const string Ver = Parse->Version(); |
1516 | ||
1517 | // Ignore all versions which doesn't fit | |
e84adb76 DK |
1518 | if (VerTag.empty() == false && |
1519 | Cache.VS().CmpVersion(VerTag, Ver) != 0) // exact match | |
b2e465d6 | 1520 | continue; |
fb3dc579 MV |
1521 | |
1522 | // Newer version or an exact match? Save the hit | |
1523 | if (Last == 0 || Cache.VS().CmpVersion(Version,Ver) < 0) { | |
1524 | Last = Parse; | |
1525 | Offset = Parse->Offset(); | |
1526 | Version = Ver; | |
1527 | } | |
1528 | ||
1529 | // was the version check above an exact match? If so, we don't need to look further | |
1530 | if (VerTag.empty() == false && VerTag.size() == Ver.size()) | |
1531 | break; | |
b2e465d6 | 1532 | } |
fb3dc579 MV |
1533 | if (Last != 0 || VerTag.empty() == true) |
1534 | break; | |
1535 | //if (VerTag.empty() == false && Last == 0) | |
ddff663f MV |
1536 | _error->Error(_("Ignore unavailable version '%s' of package '%s'"), VerTag.c_str(), TmpSrc.c_str()); |
1537 | return 0; | |
b2e465d6 | 1538 | } |
fb3dc579 | 1539 | |
ce6162be | 1540 | if (Last == 0 || Last->Jump(Offset) == false) |
b2e465d6 | 1541 | return 0; |
fb3dc579 | 1542 | |
b2e465d6 AL |
1543 | return Last; |
1544 | } | |
1545 | /*}}}*/ | |
0a8e3465 AL |
1546 | // DoUpdate - Update the package lists /*{{{*/ |
1547 | // --------------------------------------------------------------------- | |
1548 | /* */ | |
b2e465d6 | 1549 | bool DoUpdate(CommandLine &CmdL) |
0a8e3465 | 1550 | { |
b2e465d6 AL |
1551 | if (CmdL.FileSize() != 1) |
1552 | return _error->Error(_("The update command takes no arguments")); | |
1bb8cd67 DK |
1553 | |
1554 | CacheFile Cache; | |
1555 | ||
0919e3f9 | 1556 | // Get the source list |
1bb8cd67 | 1557 | if (Cache.BuildSourceList() == false) |
0919e3f9 | 1558 | return false; |
1bb8cd67 | 1559 | pkgSourceList *List = Cache.GetSourceList(); |
0919e3f9 | 1560 | |
89b70b5a | 1561 | // Create the progress |
0919e3f9 | 1562 | AcqTextStatus Stat(ScreenWidth,_config->FindI("quiet",0)); |
89b70b5a | 1563 | |
f0863b21 AL |
1564 | // Just print out the uris an exit if the --print-uris flag was used |
1565 | if (_config->FindB("APT::Get::Print-URIs") == true) | |
1566 | { | |
a722b2c5 DK |
1567 | // force a hashsum for compatibility reasons |
1568 | _config->CndSet("Acquire::ForceHash", "md5sum"); | |
1569 | ||
89b70b5a | 1570 | // get a fetcher |
1cd1c398 DK |
1571 | pkgAcquire Fetcher; |
1572 | if (Fetcher.Setup(&Stat) == false) | |
1573 | return false; | |
89b70b5a | 1574 | |
7db98ffc MZ |
1575 | // Populate it with the source selection and get all Indexes |
1576 | // (GetAll=true) | |
1bb8cd67 | 1577 | if (List->GetIndexes(&Fetcher,true) == false) |
7db98ffc MZ |
1578 | return false; |
1579 | ||
f0863b21 AL |
1580 | pkgAcquire::UriIterator I = Fetcher.UriBegin(); |
1581 | for (; I != Fetcher.UriEnd(); I++) | |
1582 | cout << '\'' << I->URI << "' " << flNotDir(I->Owner->DestFile) << ' ' << | |
495e5cb2 | 1583 | I->Owner->FileSize << ' ' << I->Owner->HashSum() << endl; |
f0863b21 AL |
1584 | return true; |
1585 | } | |
7db98ffc | 1586 | |
89b70b5a | 1587 | // do the work |
e88d983a | 1588 | if (_config->FindB("APT::Get::Download",true) == true) |
1bb8cd67 | 1589 | ListUpdate(Stat, *List); |
e88d983a | 1590 | |
89b70b5a | 1591 | // Rebuild the cache. |
0077d829 | 1592 | if (Cache.BuildCaches() == false) |
0919e3f9 AL |
1593 | return false; |
1594 | ||
1595 | return true; | |
afb1e2e3 MV |
1596 | } |
1597 | /*}}}*/ | |
1598 | // DoAutomaticRemove - Remove all automatic unused packages /*{{{*/ | |
1599 | // --------------------------------------------------------------------- | |
1600 | /* Remove unused automatic packages */ | |
1601 | bool DoAutomaticRemove(CacheFile &Cache) | |
1602 | { | |
9d2938d4 | 1603 | bool Debug = _config->FindI("Debug::pkgAutoRemove",false); |
b255ff1a | 1604 | bool doAutoRemove = _config->FindB("APT::Get::AutomaticRemove", false); |
7898bd97 | 1605 | bool hideAutoRemove = _config->FindB("APT::Get::HideAutoRemove"); |
afb1e2e3 | 1606 | |
03dbbc98 | 1607 | pkgDepCache::ActionGroup group(*Cache); |
9d2938d4 | 1608 | if(Debug) |
120365ce | 1609 | std::cout << "DoAutomaticRemove()" << std::endl; |
afb1e2e3 | 1610 | |
03dbbc98 DK |
1611 | // we don't want to autoremove and we don't want to see it, so why calculating? |
1612 | if (doAutoRemove == false && hideAutoRemove == true) | |
1613 | return true; | |
1614 | ||
1615 | if (doAutoRemove == true && | |
1616 | _config->FindB("APT::Get::Remove",true) == false) | |
afb1e2e3 | 1617 | { |
3d0de656 MV |
1618 | c1out << _("We are not supposed to delete stuff, can't start " |
1619 | "AutoRemover") << std::endl; | |
03dbbc98 | 1620 | return false; |
3d0de656 | 1621 | } |
74a05226 | 1622 | |
03dbbc98 DK |
1623 | bool purgePkgs = _config->FindB("APT::Get::Purge", false); |
1624 | bool smallList = (hideAutoRemove == false && | |
1625 | strcasecmp(_config->Find("APT::Get::HideAutoRemove","").c_str(),"small") == 0); | |
1626 | ||
9d2938d4 | 1627 | string autoremovelist, autoremoveversions; |
03dbbc98 | 1628 | unsigned long autoRemoveCount = 0; |
9d2938d4 MV |
1629 | // look over the cache to see what can be removed |
1630 | for (pkgCache::PkgIterator Pkg = Cache->PkgBegin(); ! Pkg.end(); ++Pkg) | |
afb1e2e3 | 1631 | { |
9d2938d4 MV |
1632 | if (Cache[Pkg].Garbage) |
1633 | { | |
1634 | if(Pkg.CurrentVer() != 0 || Cache[Pkg].Install()) | |
1635 | if(Debug) | |
75ce2062 | 1636 | std::cout << "We could delete %s" << Pkg.FullName(true).c_str() << std::endl; |
03dbbc98 | 1637 | |
3d0de656 | 1638 | if (doAutoRemove) |
9d2938d4 MV |
1639 | { |
1640 | if(Pkg.CurrentVer() != 0 && | |
1641 | Pkg->CurrentState != pkgCache::State::ConfigFiles) | |
03dbbc98 | 1642 | Cache->MarkDelete(Pkg, purgePkgs); |
9d2938d4 | 1643 | else |
74a05226 | 1644 | Cache->MarkKeep(Pkg, false, false); |
9d2938d4 | 1645 | } |
03dbbc98 DK |
1646 | else |
1647 | { | |
1648 | // only show stuff in the list that is not yet marked for removal | |
1649 | if(Cache[Pkg].Delete() == false) | |
1650 | { | |
f0f2f956 | 1651 | ++autoRemoveCount; |
03dbbc98 | 1652 | // we don't need to fill the strings if we don't need them |
f0f2f956 | 1653 | if (smallList == false) |
03dbbc98 | 1654 | { |
75ce2062 | 1655 | autoremovelist += Pkg.FullName(true) + " "; |
03dbbc98 DK |
1656 | autoremoveversions += string(Cache[Pkg].CandVersion) + "\n"; |
1657 | } | |
1658 | } | |
1659 | } | |
9d2938d4 | 1660 | } |
afb1e2e3 | 1661 | } |
03dbbc98 DK |
1662 | // if we don't remove them, we should show them! |
1663 | if (doAutoRemove == false && (autoremovelist.empty() == false || autoRemoveCount != 0)) | |
1664 | { | |
1665 | if (smallList == false) | |
d204fc7a | 1666 | ShowList(c1out, P_("The following package was automatically installed and is no longer required:", |
f0f2f956 DK |
1667 | "The following packages were automatically installed and are no longer required:", |
1668 | autoRemoveCount), autoremovelist, autoremoveversions); | |
03dbbc98 | 1669 | else |
f0f2f956 DK |
1670 | ioprintf(c1out, P_("%lu package was automatically installed and is no longer required.\n", |
1671 | "%lu packages were automatically installed and are no longer required.\n", autoRemoveCount), autoRemoveCount); | |
9d2938d4 | 1672 | c1out << _("Use 'apt-get autoremove' to remove them.") << std::endl; |
03dbbc98 DK |
1673 | } |
1674 | // Now see if we had destroyed anything (if we had done anything) | |
1675 | else if (Cache->BrokenCount() != 0) | |
afb1e2e3 MV |
1676 | { |
1677 | c1out << _("Hmm, seems like the AutoRemover destroyed something which really\n" | |
1678 | "shouldn't happen. Please file a bug report against apt.") << endl; | |
1679 | c1out << endl; | |
1680 | c1out << _("The following information may help to resolve the situation:") << endl; | |
1681 | c1out << endl; | |
1682 | ShowBroken(c1out,Cache,false); | |
1683 | ||
1684 | return _error->Error(_("Internal Error, AutoRemover broke stuff")); | |
1685 | } | |
1686 | return true; | |
db1e7193 | 1687 | } |
92fcbfc1 | 1688 | /*}}}*/ |
db1e7193 MV |
1689 | // DoUpgrade - Upgrade all packages /*{{{*/ |
1690 | // --------------------------------------------------------------------- | |
1691 | /* Upgrade all packages without installing new packages or erasing old | |
1692 | packages */ | |
1693 | bool DoUpgrade(CommandLine &CmdL) | |
1694 | { | |
1695 | CacheFile Cache; | |
1696 | if (Cache.OpenForInstall() == false || Cache.CheckDeps() == false) | |
1697 | return false; | |
1698 | ||
1699 | // Do the upgrade | |
1700 | if (pkgAllUpgrade(Cache) == false) | |
1701 | { | |
1702 | ShowBroken(c1out,Cache,false); | |
1703 | return _error->Error(_("Internal error, AllUpgrade broke stuff")); | |
1704 | } | |
1705 | ||
1706 | return InstallPackages(Cache,true); | |
afb1e2e3 MV |
1707 | } |
1708 | /*}}}*/ | |
0a8e3465 AL |
1709 | // DoInstall - Install packages from the command line /*{{{*/ |
1710 | // --------------------------------------------------------------------- | |
1711 | /* Install named packages */ | |
1712 | bool DoInstall(CommandLine &CmdL) | |
1713 | { | |
1714 | CacheFile Cache; | |
c37b9502 AL |
1715 | if (Cache.OpenForInstall() == false || |
1716 | Cache.CheckDeps(CmdL.FileSize() != 1) == false) | |
0a8e3465 AL |
1717 | return false; |
1718 | ||
7c57fe64 AL |
1719 | // Enter the special broken fixing mode if the user specified arguments |
1720 | bool BrokenFix = false; | |
1721 | if (Cache->BrokenCount() != 0) | |
1722 | BrokenFix = true; | |
1723 | ||
0a8e3465 | 1724 | pkgProblemResolver Fix(Cache); |
31367812 | 1725 | |
e67c0834 DK |
1726 | static const unsigned short MOD_REMOVE = 1; |
1727 | static const unsigned short MOD_INSTALL = 2; | |
1728 | ||
1729 | unsigned short fallback = MOD_INSTALL; | |
303a1703 | 1730 | if (strcasecmp(CmdL.FileList[0],"remove") == 0) |
e67c0834 | 1731 | fallback = MOD_REMOVE; |
e47c7d16 MV |
1732 | else if (strcasecmp(CmdL.FileList[0], "purge") == 0) |
1733 | { | |
1734 | _config->Set("APT::Get::Purge", true); | |
e67c0834 | 1735 | fallback = MOD_REMOVE; |
e47c7d16 | 1736 | } |
74a05226 | 1737 | else if (strcasecmp(CmdL.FileList[0], "autoremove") == 0) |
0a8e3465 | 1738 | { |
54668e4e | 1739 | _config->Set("APT::Get::AutomaticRemove", "true"); |
e67c0834 | 1740 | fallback = MOD_REMOVE; |
54668e4e | 1741 | } |
70e706ad DK |
1742 | |
1743 | std::list<APT::VersionSet::Modifier> mods; | |
e67c0834 | 1744 | mods.push_back(APT::VersionSet::Modifier(MOD_INSTALL, "+", |
b8ad5512 | 1745 | APT::VersionSet::Modifier::POSTFIX, APT::VersionSet::CANDIDATE)); |
e67c0834 | 1746 | mods.push_back(APT::VersionSet::Modifier(MOD_REMOVE, "-", |
b8ad5512 | 1747 | APT::VersionSet::Modifier::POSTFIX, APT::VersionSet::NEWEST)); |
70e706ad DK |
1748 | CacheSetHelperAPTGet helper(c0out); |
1749 | std::map<unsigned short, APT::VersionSet> verset = APT::VersionSet::GroupedFromCommandLine(Cache, | |
1750 | CmdL.FileList + 1, mods, fallback, helper); | |
31367812 | 1751 | |
70e706ad | 1752 | if (_error->PendingError() == true) |
b8ad5512 DK |
1753 | { |
1754 | helper.showVirtualPackageErrors(Cache); | |
70e706ad | 1755 | return false; |
b8ad5512 | 1756 | } |
31367812 | 1757 | |
e67c0834 DK |
1758 | unsigned short order[] = { 0, 0, 0 }; |
1759 | if (fallback == MOD_INSTALL) { | |
1760 | order[0] = MOD_INSTALL; | |
1761 | order[1] = MOD_REMOVE; | |
1762 | } else { | |
1763 | order[0] = MOD_REMOVE; | |
1764 | order[1] = MOD_INSTALL; | |
1765 | } | |
1766 | ||
b8ad5512 DK |
1767 | TryToInstall InstallAction(Cache, Fix, BrokenFix); |
1768 | TryToRemove RemoveAction(Cache, Fix); | |
1769 | ||
70e706ad DK |
1770 | // new scope for the ActionGroup |
1771 | { | |
1772 | pkgDepCache::ActionGroup group(Cache); | |
b8ad5512 | 1773 | |
e67c0834 | 1774 | for (unsigned short i = 0; order[i] != 0; ++i) |
31367812 | 1775 | { |
6806db8a | 1776 | if (order[i] == MOD_INSTALL) { |
b8ad5512 | 1777 | InstallAction = std::for_each(verset[MOD_INSTALL].begin(), verset[MOD_INSTALL].end(), InstallAction); |
6806db8a DK |
1778 | InstallAction.doAutoInstall(); |
1779 | } | |
e67c0834 | 1780 | else if (order[i] == MOD_REMOVE) |
b8ad5512 | 1781 | RemoveAction = std::for_each(verset[MOD_REMOVE].begin(), verset[MOD_REMOVE].end(), RemoveAction); |
54668e4e | 1782 | } |
0a8e3465 | 1783 | |
31367812 DK |
1784 | if (_error->PendingError() == true) |
1785 | return false; | |
1786 | ||
54668e4e MV |
1787 | /* If we are in the Broken fixing mode we do not attempt to fix the |
1788 | problems. This is if the user invoked install without -f and gave | |
1789 | packages */ | |
1790 | if (BrokenFix == true && Cache->BrokenCount() != 0) | |
1791 | { | |
b5647402 | 1792 | c1out << _("You might want to run 'apt-get -f install' to correct these:") << endl; |
54668e4e | 1793 | ShowBroken(c1out,Cache,false); |
7c57fe64 | 1794 | |
54668e4e MV |
1795 | return _error->Error(_("Unmet dependencies. Try 'apt-get -f install' with no packages (or specify a solution).")); |
1796 | } | |
7c57fe64 | 1797 | |
54668e4e MV |
1798 | // Call the scored problem resolver |
1799 | Fix.InstallProtect(); | |
1800 | if (Fix.Resolve(true) == false) | |
1801 | _error->Discard(); | |
0a8e3465 | 1802 | |
54668e4e MV |
1803 | // Now we check the state of the packages, |
1804 | if (Cache->BrokenCount() != 0) | |
303a1703 | 1805 | { |
b2e465d6 | 1806 | c1out << |
54668e4e MV |
1807 | _("Some packages could not be installed. This may mean that you have\n" |
1808 | "requested an impossible situation or if you are using the unstable\n" | |
1809 | "distribution that some required packages have not yet been created\n" | |
1810 | "or been moved out of Incoming.") << endl; | |
ecd414ef | 1811 | /* |
54668e4e MV |
1812 | if (Packages == 1) |
1813 | { | |
1814 | c1out << endl; | |
1815 | c1out << | |
1816 | _("Since you only requested a single operation it is extremely likely that\n" | |
1817 | "the package is simply not installable and a bug report against\n" | |
1818 | "that package should be filed.") << endl; | |
1819 | } | |
ecd414ef | 1820 | */ |
303a1703 | 1821 | |
54668e4e MV |
1822 | c1out << _("The following information may help to resolve the situation:") << endl; |
1823 | c1out << endl; | |
1824 | ShowBroken(c1out,Cache,false); | |
1825 | return _error->Error(_("Broken packages")); | |
1826 | } | |
120365ce | 1827 | } |
5a68ea79 MV |
1828 | if (!DoAutomaticRemove(Cache)) |
1829 | return false; | |
afb1e2e3 | 1830 | |
0a8e3465 AL |
1831 | /* Print out a list of packages that are going to be installed extra |
1832 | to what the user asked */ | |
e67c0834 | 1833 | if (Cache->InstCount() != verset[MOD_INSTALL].size()) |
0a8e3465 AL |
1834 | { |
1835 | string List; | |
ac625538 | 1836 | string VersionsList; |
1089ca89 | 1837 | for (unsigned J = 0; J < Cache->Head().PackageCount; J++) |
0a8e3465 | 1838 | { |
1089ca89 | 1839 | pkgCache::PkgIterator I(Cache,Cache.List[J]); |
0a8e3465 AL |
1840 | if ((*Cache)[I].Install() == false) |
1841 | continue; | |
1842 | ||
1843 | const char **J; | |
1844 | for (J = CmdL.FileList + 1; *J != 0; J++) | |
1845 | if (strcmp(*J,I.Name()) == 0) | |
1846 | break; | |
1847 | ||
ac625538 | 1848 | if (*J == 0) { |
75ce2062 | 1849 | List += I.FullName(true) + " "; |
80fa0d8a MV |
1850 | VersionsList += string(Cache[I].CandVersion) + "\n"; |
1851 | } | |
0a8e3465 AL |
1852 | } |
1853 | ||
ac625538 | 1854 | ShowList(c1out,_("The following extra packages will be installed:"),List,VersionsList); |
0a8e3465 AL |
1855 | } |
1856 | ||
a7e41689 AL |
1857 | /* Print out a list of suggested and recommended packages */ |
1858 | { | |
1859 | string SuggestsList, RecommendsList, List; | |
72122b62 | 1860 | string SuggestsVersions, RecommendsVersions; |
a7e41689 AL |
1861 | for (unsigned J = 0; J < Cache->Head().PackageCount; J++) |
1862 | { | |
29f37db8 | 1863 | pkgCache::PkgIterator Pkg(Cache,Cache.List[J]); |
a7e41689 AL |
1864 | |
1865 | /* Just look at the ones we want to install */ | |
29f37db8 | 1866 | if ((*Cache)[Pkg].Install() == false) |
a7e41689 AL |
1867 | continue; |
1868 | ||
29f37db8 MV |
1869 | // get the recommends/suggests for the candidate ver |
1870 | pkgCache::VerIterator CV = (*Cache)[Pkg].CandidateVerIter(*Cache); | |
1871 | for (pkgCache::DepIterator D = CV.DependsList(); D.end() == false; ) | |
1872 | { | |
1873 | pkgCache::DepIterator Start; | |
1874 | pkgCache::DepIterator End; | |
1875 | D.GlobOr(Start,End); // advances D | |
1876 | ||
cd33a786 MV |
1877 | // FIXME: we really should display a or-group as a or-group to the user |
1878 | // the problem is that ShowList is incapable of doing this | |
29f37db8 MV |
1879 | string RecommendsOrList,RecommendsOrVersions; |
1880 | string SuggestsOrList,SuggestsOrVersions; | |
1881 | bool foundInstalledInOrGroup = false; | |
1882 | for(;;) | |
1883 | { | |
1884 | /* Skip if package is installed already, or is about to be */ | |
75ce2062 | 1885 | string target = Start.TargetPkg().FullName(true) + " "; |
2d847a59 DK |
1886 | pkgCache::PkgIterator const TarPkg = Start.TargetPkg(); |
1887 | if (TarPkg->SelectedState == pkgCache::State::Install || | |
d1aa9162 | 1888 | TarPkg->SelectedState == pkgCache::State::Hold || |
2d847a59 | 1889 | Cache[Start.TargetPkg()].Install()) |
29f37db8 MV |
1890 | { |
1891 | foundInstalledInOrGroup=true; | |
1892 | break; | |
1893 | } | |
1894 | ||
1895 | /* Skip if we already saw it */ | |
1896 | if (int(SuggestsList.find(target)) != -1 || int(RecommendsList.find(target)) != -1) | |
1897 | { | |
1898 | foundInstalledInOrGroup=true; | |
1899 | break; | |
1900 | } | |
1901 | ||
1902 | // this is a dep on a virtual pkg, check if any package that provides it | |
1903 | // should be installed | |
1904 | if(Start.TargetPkg().ProvidesList() != 0) | |
1905 | { | |
1906 | pkgCache::PrvIterator I = Start.TargetPkg().ProvidesList(); | |
1907 | for (; I.end() == false; I++) | |
1908 | { | |
1909 | pkgCache::PkgIterator Pkg = I.OwnerPkg(); | |
1910 | if (Cache[Pkg].CandidateVerIter(Cache) == I.OwnerVer() && | |
1911 | Pkg.CurrentVer() != 0) | |
1912 | foundInstalledInOrGroup=true; | |
1913 | } | |
1914 | } | |
1915 | ||
1916 | if (Start->Type == pkgCache::Dep::Suggests) | |
1917 | { | |
1918 | SuggestsOrList += target; | |
1919 | SuggestsOrVersions += string(Cache[Start.TargetPkg()].CandVersion) + "\n"; | |
1920 | } | |
1921 | ||
1922 | if (Start->Type == pkgCache::Dep::Recommends) | |
1923 | { | |
1924 | RecommendsOrList += target; | |
1925 | RecommendsOrVersions += string(Cache[Start.TargetPkg()].CandVersion) + "\n"; | |
1926 | } | |
1927 | ||
1928 | if (Start >= End) | |
1929 | break; | |
1930 | Start++; | |
1931 | } | |
1932 | ||
1933 | if(foundInstalledInOrGroup == false) | |
1934 | { | |
1935 | RecommendsList += RecommendsOrList; | |
1936 | RecommendsVersions += RecommendsOrVersions; | |
1937 | SuggestsList += SuggestsOrList; | |
1938 | SuggestsVersions += SuggestsOrVersions; | |
1939 | } | |
1940 | ||
1941 | } | |
a7e41689 | 1942 | } |
29f37db8 | 1943 | |
72122b62 AL |
1944 | ShowList(c1out,_("Suggested packages:"),SuggestsList,SuggestsVersions); |
1945 | ShowList(c1out,_("Recommended packages:"),RecommendsList,RecommendsVersions); | |
a7e41689 AL |
1946 | |
1947 | } | |
1948 | ||
e4b74e4b MV |
1949 | // if nothing changed in the cache, but only the automark information |
1950 | // we write the StateFile here, otherwise it will be written in | |
1951 | // cache.commit() | |
b8ad5512 | 1952 | if (InstallAction.AutoMarkChanged > 0 && |
e4b74e4b | 1953 | Cache->DelCount() == 0 && Cache->InstCount() == 0 && |
9964a721 MV |
1954 | Cache->BadCount() == 0 && |
1955 | _config->FindB("APT::Get::Simulate",false) == false) | |
e4b74e4b MV |
1956 | Cache->writeStateFile(NULL); |
1957 | ||
03e39e59 | 1958 | // See if we need to prompt |
70e706ad | 1959 | // FIXME: check if really the packages in the set are going to be installed |
e67c0834 | 1960 | if (Cache->InstCount() == verset[MOD_INSTALL].size() && Cache->DelCount() == 0) |
2c3bc8bb | 1961 | return InstallPackages(Cache,false,false); |
13e8426f | 1962 | |
03e39e59 | 1963 | return InstallPackages(Cache,false); |
0a8e3465 | 1964 | } |
d63a1458 | 1965 | |
d63a1458 JAK |
1966 | /* mark packages as automatically/manually installed. */ |
1967 | bool DoMarkAuto(CommandLine &CmdL) | |
1968 | { | |
1969 | bool Action = true; | |
1970 | int AutoMarkChanged = 0; | |
1971 | OpTextProgress progress; | |
1972 | CacheFile Cache; | |
1973 | if (Cache.Open() == false) | |
1974 | return false; | |
1975 | ||
1976 | if (strcasecmp(CmdL.FileList[0],"markauto") == 0) | |
1977 | Action = true; | |
1978 | else if (strcasecmp(CmdL.FileList[0],"unmarkauto") == 0) | |
1979 | Action = false; | |
1980 | ||
1981 | for (const char **I = CmdL.FileList + 1; *I != 0; I++) | |
1982 | { | |
1983 | const char *S = *I; | |
1984 | // Locate the package | |
1985 | pkgCache::PkgIterator Pkg = Cache->FindPkg(S); | |
1986 | if (Pkg.end() == true) { | |
1987 | return _error->Error(_("Couldn't find package %s"),S); | |
1988 | } | |
1989 | else | |
1990 | { | |
1991 | if (!Action) | |
1992 | ioprintf(c1out,_("%s set to manually installed.\n"), Pkg.Name()); | |
1993 | else | |
1994 | ioprintf(c1out,_("%s set to automatically installed.\n"), | |
1995 | Pkg.Name()); | |
1996 | ||
1997 | Cache->MarkAuto(Pkg,Action); | |
1998 | AutoMarkChanged++; | |
1999 | } | |
2000 | } | |
2001 | if (AutoMarkChanged && ! _config->FindB("APT::Get::Simulate",false)) | |
2002 | return Cache->writeStateFile(NULL); | |
2003 | return false; | |
2004 | } | |
0a8e3465 AL |
2005 | /*}}}*/ |
2006 | // DoDistUpgrade - Automatic smart upgrader /*{{{*/ | |
2007 | // --------------------------------------------------------------------- | |
2008 | /* Intelligent upgrader that will install and remove packages at will */ | |
2009 | bool DoDistUpgrade(CommandLine &CmdL) | |
2010 | { | |
2011 | CacheFile Cache; | |
c37b9502 | 2012 | if (Cache.OpenForInstall() == false || Cache.CheckDeps() == false) |
0a8e3465 AL |
2013 | return false; |
2014 | ||
db0db9fe | 2015 | c0out << _("Calculating upgrade... ") << flush; |
0a8e3465 AL |
2016 | if (pkgDistUpgrade(*Cache) == false) |
2017 | { | |
b2e465d6 | 2018 | c0out << _("Failed") << endl; |
421c8d10 | 2019 | ShowBroken(c1out,Cache,false); |
0a8e3465 AL |
2020 | return false; |
2021 | } | |
2022 | ||
b2e465d6 | 2023 | c0out << _("Done") << endl; |
0a8e3465 AL |
2024 | |
2025 | return InstallPackages(Cache,true); | |
2026 | } | |
2027 | /*}}}*/ | |
2028 | // DoDSelectUpgrade - Do an upgrade by following dselects selections /*{{{*/ | |
2029 | // --------------------------------------------------------------------- | |
2030 | /* Follows dselect's selections */ | |
2031 | bool DoDSelectUpgrade(CommandLine &CmdL) | |
2032 | { | |
2033 | CacheFile Cache; | |
c37b9502 | 2034 | if (Cache.OpenForInstall() == false || Cache.CheckDeps() == false) |
0a8e3465 AL |
2035 | return false; |
2036 | ||
a4decc40 MV |
2037 | pkgDepCache::ActionGroup group(Cache); |
2038 | ||
0a8e3465 AL |
2039 | // Install everything with the install flag set |
2040 | pkgCache::PkgIterator I = Cache->PkgBegin(); | |
2041 | for (;I.end() != true; I++) | |
2042 | { | |
2043 | /* Install the package only if it is a new install, the autoupgrader | |
2044 | will deal with the rest */ | |
2045 | if (I->SelectedState == pkgCache::State::Install) | |
2046 | Cache->MarkInstall(I,false); | |
2047 | } | |
2048 | ||
2049 | /* Now install their deps too, if we do this above then order of | |
2050 | the status file is significant for | groups */ | |
2051 | for (I = Cache->PkgBegin();I.end() != true; I++) | |
2052 | { | |
2053 | /* Install the package only if it is a new install, the autoupgrader | |
2054 | will deal with the rest */ | |
2055 | if (I->SelectedState == pkgCache::State::Install) | |
2f45c76a | 2056 | Cache->MarkInstall(I,true); |
0a8e3465 AL |
2057 | } |
2058 | ||
2059 | // Apply erasures now, they override everything else. | |
2060 | for (I = Cache->PkgBegin();I.end() != true; I++) | |
2061 | { | |
2062 | // Remove packages | |
2063 | if (I->SelectedState == pkgCache::State::DeInstall || | |
2064 | I->SelectedState == pkgCache::State::Purge) | |
d556d1a1 | 2065 | Cache->MarkDelete(I,I->SelectedState == pkgCache::State::Purge); |
0a8e3465 AL |
2066 | } |
2067 | ||
2f45c76a AL |
2068 | /* Resolve any problems that dselect created, allupgrade cannot handle |
2069 | such things. We do so quite agressively too.. */ | |
2070 | if (Cache->BrokenCount() != 0) | |
2071 | { | |
2072 | pkgProblemResolver Fix(Cache); | |
2073 | ||
2074 | // Hold back held packages. | |
b2e465d6 | 2075 | if (_config->FindB("APT::Ignore-Hold",false) == false) |
2f45c76a AL |
2076 | { |
2077 | for (pkgCache::PkgIterator I = Cache->PkgBegin(); I.end() == false; I++) | |
2078 | { | |
2079 | if (I->SelectedState == pkgCache::State::Hold) | |
2080 | { | |
2081 | Fix.Protect(I); | |
2082 | Cache->MarkKeep(I); | |
2083 | } | |
2084 | } | |
2085 | } | |
2086 | ||
2087 | if (Fix.Resolve() == false) | |
2088 | { | |
421c8d10 | 2089 | ShowBroken(c1out,Cache,false); |
2a7e07c7 | 2090 | return _error->Error(_("Internal error, problem resolver broke stuff")); |
2f45c76a AL |
2091 | } |
2092 | } | |
2093 | ||
2094 | // Now upgrade everything | |
0a8e3465 AL |
2095 | if (pkgAllUpgrade(Cache) == false) |
2096 | { | |
421c8d10 | 2097 | ShowBroken(c1out,Cache,false); |
2a7e07c7 | 2098 | return _error->Error(_("Internal error, problem resolver broke stuff")); |
0a8e3465 AL |
2099 | } |
2100 | ||
2101 | return InstallPackages(Cache,false); | |
2102 | } | |
2103 | /*}}}*/ | |
2104 | // DoClean - Remove download archives /*{{{*/ | |
2105 | // --------------------------------------------------------------------- | |
2106 | /* */ | |
2107 | bool DoClean(CommandLine &CmdL) | |
2108 | { | |
8b067c22 AL |
2109 | if (_config->FindB("APT::Get::Simulate") == true) |
2110 | { | |
2111 | cout << "Del " << _config->FindDir("Dir::Cache::archives") << "* " << | |
2112 | _config->FindDir("Dir::Cache::archives") << "partial/*" << endl; | |
2113 | return true; | |
2114 | } | |
2115 | ||
1b6d659c AL |
2116 | // Lock the archive directory |
2117 | FileFd Lock; | |
2118 | if (_config->FindB("Debug::NoLocking",false) == false) | |
2119 | { | |
2120 | Lock.Fd(GetLock(_config->FindDir("Dir::Cache::Archives") + "lock")); | |
2121 | if (_error->PendingError() == true) | |
b2e465d6 | 2122 | return _error->Error(_("Unable to lock the download directory")); |
1b6d659c AL |
2123 | } |
2124 | ||
7a1b1f8b AL |
2125 | pkgAcquire Fetcher; |
2126 | Fetcher.Clean(_config->FindDir("Dir::Cache::archives")); | |
2127 | Fetcher.Clean(_config->FindDir("Dir::Cache::archives") + "partial/"); | |
0a8e3465 AL |
2128 | return true; |
2129 | } | |
2130 | /*}}}*/ | |
1bc849af AL |
2131 | // DoAutoClean - Smartly remove downloaded archives /*{{{*/ |
2132 | // --------------------------------------------------------------------- | |
2133 | /* This is similar to clean but it only purges things that cannot be | |
2134 | downloaded, that is old versions of cached packages. */ | |
65a1e968 AL |
2135 | class LogCleaner : public pkgArchiveCleaner |
2136 | { | |
2137 | protected: | |
2138 | virtual void Erase(const char *File,string Pkg,string Ver,struct stat &St) | |
2139 | { | |
4cc8bab0 | 2140 | c1out << "Del " << Pkg << " " << Ver << " [" << SizeToStr(St.st_size) << "B]" << endl; |
c1e78ee5 AL |
2141 | |
2142 | if (_config->FindB("APT::Get::Simulate") == false) | |
2143 | unlink(File); | |
65a1e968 AL |
2144 | }; |
2145 | }; | |
2146 | ||
1bc849af AL |
2147 | bool DoAutoClean(CommandLine &CmdL) |
2148 | { | |
1b6d659c AL |
2149 | // Lock the archive directory |
2150 | FileFd Lock; | |
2151 | if (_config->FindB("Debug::NoLocking",false) == false) | |
2152 | { | |
2153 | Lock.Fd(GetLock(_config->FindDir("Dir::Cache::Archives") + "lock")); | |
2154 | if (_error->PendingError() == true) | |
b2e465d6 | 2155 | return _error->Error(_("Unable to lock the download directory")); |
1b6d659c AL |
2156 | } |
2157 | ||
1bc849af | 2158 | CacheFile Cache; |
2d11135a | 2159 | if (Cache.Open() == false) |
1bc849af AL |
2160 | return false; |
2161 | ||
65a1e968 | 2162 | LogCleaner Cleaner; |
1bc849af AL |
2163 | |
2164 | return Cleaner.Go(_config->FindDir("Dir::Cache::archives"),*Cache) && | |
2165 | Cleaner.Go(_config->FindDir("Dir::Cache::archives") + "partial/",*Cache); | |
2166 | } | |
2167 | /*}}}*/ | |
0e3e112e MV |
2168 | // DoDownload - download a binary /*{{{*/ |
2169 | // --------------------------------------------------------------------- | |
2170 | bool DoDownload(CommandLine &CmdL) | |
2171 | { | |
2172 | CacheFile Cache; | |
2173 | if (Cache.ReadOnlyOpen() == false) | |
2174 | return false; | |
2175 | ||
2176 | APT::CacheSetHelper helper(c0out); | |
2177 | APT::VersionSet verset = APT::VersionSet::FromCommandLine(Cache, | |
2178 | CmdL.FileList + 1, APT::VersionSet::CANDIDATE, helper); | |
2179 | pkgAcquire Fetcher; | |
2180 | AcqTextStatus Stat(ScreenWidth, _config->FindI("quiet",0)); | |
2181 | Fetcher.Setup(&Stat); | |
2182 | ||
2183 | if (verset.empty() == true) | |
2184 | return false; | |
2185 | ||
0e3e112e MV |
2186 | pkgRecords Recs(Cache); |
2187 | pkgSourceList *SrcList = Cache.GetSourceList(); | |
2188 | for (APT::VersionSet::const_iterator Ver = verset.begin(); | |
2189 | Ver != verset.end(); | |
2190 | ++Ver) | |
2191 | { | |
2192 | string descr; | |
2193 | // get the right version | |
2194 | pkgCache::PkgIterator Pkg = Ver.ParentPkg(); | |
2195 | pkgRecords::Parser &rec=Recs.Lookup(Ver.FileList()); | |
2196 | pkgCache::VerFileIterator Vf = Ver.FileList(); | |
2197 | if (Vf.end() == true) | |
2198 | return _error->Error("Can not find VerFile"); | |
2199 | pkgCache::PkgFileIterator F = Vf.File(); | |
2200 | pkgIndexFile *index; | |
2201 | if(SrcList->FindIndex(F, index) == false) | |
2202 | return _error->Error("FindIndex failed"); | |
2203 | string uri = index->ArchiveURI(rec.FileName()); | |
2204 | strprintf(descr, _("Downloading %s %s"), Pkg.Name(), Ver.VerStr()); | |
2205 | // get the most appropriate hash | |
2206 | HashString hash; | |
2207 | if (rec.SHA256Hash() != "") | |
2208 | hash = HashString("sha256", rec.SHA256Hash()); | |
2209 | else if (rec.SHA1Hash() != "") | |
2210 | hash = HashString("sha1", rec.SHA1Hash()); | |
2211 | else if (rec.MD5Hash() != "") | |
2212 | hash = HashString("md5", rec.MD5Hash()); | |
2213 | // get the file | |
2214 | new pkgAcqFile(&Fetcher, uri, hash.toStr(), (*Ver)->Size, descr, Pkg.Name(), "."); | |
0e3e112e | 2215 | } |
3b1c02f7 | 2216 | bool result = (Fetcher.Run() == pkgAcquire::Continue); |
0e3e112e MV |
2217 | |
2218 | return result; | |
2219 | } | |
2220 | /*}}}*/ | |
0a8e3465 AL |
2221 | // DoCheck - Perform the check operation /*{{{*/ |
2222 | // --------------------------------------------------------------------- | |
2223 | /* Opening automatically checks the system, this command is mostly used | |
2224 | for debugging */ | |
2225 | bool DoCheck(CommandLine &CmdL) | |
2226 | { | |
2227 | CacheFile Cache; | |
2228 | Cache.Open(); | |
2d11135a | 2229 | Cache.CheckDeps(); |
0a8e3465 AL |
2230 | |
2231 | return true; | |
2232 | } | |
2233 | /*}}}*/ | |
36375005 AL |
2234 | // DoSource - Fetch a source archive /*{{{*/ |
2235 | // --------------------------------------------------------------------- | |
2d11135a | 2236 | /* Fetch souce packages */ |
fb0ee66e AL |
2237 | struct DscFile |
2238 | { | |
2239 | string Package; | |
2240 | string Version; | |
2241 | string Dsc; | |
2242 | }; | |
2243 | ||
36375005 AL |
2244 | bool DoSource(CommandLine &CmdL) |
2245 | { | |
2246 | CacheFile Cache; | |
2d11135a | 2247 | if (Cache.Open(false) == false) |
36375005 AL |
2248 | return false; |
2249 | ||
2d11135a | 2250 | if (CmdL.FileSize() <= 1) |
b2e465d6 | 2251 | return _error->Error(_("Must specify at least one package to fetch source for")); |
2d11135a | 2252 | |
36375005 | 2253 | // Read the source list |
1bb8cd67 DK |
2254 | if (Cache.BuildSourceList() == false) |
2255 | return false; | |
2256 | pkgSourceList *List = Cache.GetSourceList(); | |
36375005 AL |
2257 | |
2258 | // Create the text record parsers | |
2259 | pkgRecords Recs(Cache); | |
1bb8cd67 | 2260 | pkgSrcRecords SrcRecs(*List); |
36375005 AL |
2261 | if (_error->PendingError() == true) |
2262 | return false; | |
2263 | ||
2264 | // Create the download object | |
2265 | AcqTextStatus Stat(ScreenWidth,_config->FindI("quiet",0)); | |
1cd1c398 DK |
2266 | pkgAcquire Fetcher; |
2267 | if (Fetcher.Setup(&Stat) == false) | |
2268 | return false; | |
fb0ee66e AL |
2269 | |
2270 | DscFile *Dsc = new DscFile[CmdL.FileSize()]; | |
36375005 | 2271 | |
092ae175 MV |
2272 | // insert all downloaded uris into this set to avoid downloading them |
2273 | // twice | |
2274 | set<string> queued; | |
8545b536 DK |
2275 | |
2276 | // Diff only mode only fetches .diff files | |
2277 | bool const diffOnly = _config->FindB("APT::Get::Diff-Only", false); | |
2278 | // Tar only mode only fetches .tar files | |
2279 | bool const tarOnly = _config->FindB("APT::Get::Tar-Only", false); | |
2280 | // Dsc only mode only fetches .dsc files | |
2281 | bool const dscOnly = _config->FindB("APT::Get::Dsc-Only", false); | |
2282 | ||
36375005 | 2283 | // Load the requestd sources into the fetcher |
fb0ee66e AL |
2284 | unsigned J = 0; |
2285 | for (const char **I = CmdL.FileList + 1; *I != 0; I++, J++) | |
36375005 AL |
2286 | { |
2287 | string Src; | |
b2e465d6 | 2288 | pkgSrcRecords::Parser *Last = FindSrc(*I,Recs,SrcRecs,Src,*Cache); |
36375005 AL |
2289 | |
2290 | if (Last == 0) | |
b2e465d6 | 2291 | return _error->Error(_("Unable to find a source package for %s"),Src.c_str()); |
36375005 | 2292 | |
3238423f MV |
2293 | string srec = Last->AsStr(); |
2294 | string::size_type pos = srec.find("\nVcs-"); | |
774a6687 | 2295 | while (pos != string::npos) |
3238423f MV |
2296 | { |
2297 | pos += strlen("\nVcs-"); | |
2298 | string vcs = srec.substr(pos,srec.find(":",pos)-pos); | |
774a6687 MV |
2299 | if(vcs == "Browser") |
2300 | { | |
2301 | pos = srec.find("\nVcs-", pos); | |
2302 | continue; | |
2303 | } | |
3238423f MV |
2304 | pos += vcs.length()+2; |
2305 | string::size_type epos = srec.find("\n", pos); | |
2306 | string uri = srec.substr(pos,epos-pos).c_str(); | |
b799e134 | 2307 | ioprintf(c1out, _("NOTICE: '%s' packaging is maintained in " |
3238423f | 2308 | "the '%s' version control system at:\n" |
8756297c | 2309 | "%s\n"), |
3238423f MV |
2310 | Src.c_str(), vcs.c_str(), uri.c_str()); |
2311 | if(vcs == "Bzr") | |
927677f0 MV |
2312 | ioprintf(c1out,_("Please use:\n" |
2313 | "bzr get %s\n" | |
3d513bbd | 2314 | "to retrieve the latest (possibly unreleased) " |
b799e134 | 2315 | "updates to the package.\n"), |
3238423f | 2316 | uri.c_str()); |
b799e134 | 2317 | break; |
3238423f MV |
2318 | } |
2319 | ||
36375005 AL |
2320 | // Back track |
2321 | vector<pkgSrcRecords::File> Lst; | |
b2e465d6 | 2322 | if (Last->Files(Lst) == false) |
36375005 AL |
2323 | return false; |
2324 | ||
2325 | // Load them into the fetcher | |
2326 | for (vector<pkgSrcRecords::File>::const_iterator I = Lst.begin(); | |
2327 | I != Lst.end(); I++) | |
2328 | { | |
2329 | // Try to guess what sort of file it is we are getting. | |
b2e465d6 | 2330 | if (I->Type == "dsc") |
fb0ee66e | 2331 | { |
fb0ee66e AL |
2332 | Dsc[J].Package = Last->Package(); |
2333 | Dsc[J].Version = Last->Version(); | |
2334 | Dsc[J].Dsc = flNotDir(I->Path); | |
2335 | } | |
092ae175 | 2336 | |
8545b536 DK |
2337 | // Handle the only options so that multiple can be used at once |
2338 | if (diffOnly == true || tarOnly == true || dscOnly == true) | |
2339 | { | |
2340 | if ((diffOnly == true && I->Type == "diff") || | |
2341 | (tarOnly == true && I->Type == "tar") || | |
2342 | (dscOnly == true && I->Type == "dsc")) | |
2343 | ; // Fine, we want this file downloaded | |
2344 | else | |
2345 | continue; | |
2346 | } | |
1979e742 | 2347 | |
092ae175 MV |
2348 | // don't download the same uri twice (should this be moved to |
2349 | // the fetcher interface itself?) | |
2350 | if(queued.find(Last->Index().ArchiveURI(I->Path)) != queued.end()) | |
2351 | continue; | |
2352 | queued.insert(Last->Index().ArchiveURI(I->Path)); | |
2353 | ||
2354 | // check if we have a file with that md5 sum already localy | |
2355 | if(!I->MD5Hash.empty() && FileExists(flNotDir(I->Path))) | |
2356 | { | |
2357 | FileFd Fd(flNotDir(I->Path), FileFd::ReadOnly); | |
2358 | MD5Summation sum; | |
2359 | sum.AddFD(Fd.Fd(), Fd.Size()); | |
2360 | Fd.Close(); | |
2361 | if((string)sum.Result() == I->MD5Hash) | |
2362 | { | |
443cb67c | 2363 | ioprintf(c1out,_("Skipping already downloaded file '%s'\n"), |
092ae175 MV |
2364 | flNotDir(I->Path).c_str()); |
2365 | continue; | |
2366 | } | |
2367 | } | |
2368 | ||
b2e465d6 AL |
2369 | new pkgAcqFile(&Fetcher,Last->Index().ArchiveURI(I->Path), |
2370 | I->MD5Hash,I->Size, | |
2371 | Last->Index().SourceInfo(*Last,*I),Src); | |
36375005 AL |
2372 | } |
2373 | } | |
2374 | ||
2375 | // Display statistics | |
3a882565 DK |
2376 | unsigned long long FetchBytes = Fetcher.FetchNeeded(); |
2377 | unsigned long long FetchPBytes = Fetcher.PartialPresent(); | |
2378 | unsigned long long DebBytes = Fetcher.TotalNeeded(); | |
36375005 AL |
2379 | |
2380 | // Check for enough free space | |
f332b62b | 2381 | struct statvfs Buf; |
36375005 | 2382 | string OutputDir = "."; |
c1ce032a DK |
2383 | if (statvfs(OutputDir.c_str(),&Buf) != 0) { |
2384 | if (errno == EOVERFLOW) | |
2385 | return _error->WarningE("statvfs",_("Couldn't determine free space in %s"), | |
2386 | OutputDir.c_str()); | |
2387 | else | |
2388 | return _error->Errno("statvfs",_("Couldn't determine free space in %s"), | |
2389 | OutputDir.c_str()); | |
2390 | } else if (unsigned(Buf.f_bfree) < (FetchBytes - FetchPBytes)/Buf.f_bsize) | |
885d204b OS |
2391 | { |
2392 | struct statfs Stat; | |
f64196e8 DK |
2393 | if (statfs(OutputDir.c_str(),&Stat) != 0 |
2394 | #if HAVE_STRUCT_STATFS_F_TYPE | |
2395 | || unsigned(Stat.f_type) != RAMFS_MAGIC | |
2396 | #endif | |
2397 | ) | |
885d204b OS |
2398 | return _error->Error(_("You don't have enough free space in %s"), |
2399 | OutputDir.c_str()); | |
2400 | } | |
36375005 AL |
2401 | |
2402 | // Number of bytes | |
36375005 | 2403 | if (DebBytes != FetchBytes) |
4d8d8112 DK |
2404 | //TRANSLATOR: The required space between number and unit is already included |
2405 | // in the replacement strings, so %sB will be correctly translate in e.g. 1,5 MB | |
b2e465d6 AL |
2406 | ioprintf(c1out,_("Need to get %sB/%sB of source archives.\n"), |
2407 | SizeToStr(FetchBytes).c_str(),SizeToStr(DebBytes).c_str()); | |
36375005 | 2408 | else |
4d8d8112 DK |
2409 | //TRANSLATOR: The required space between number and unit is already included |
2410 | // in the replacement string, so %sB will be correctly translate in e.g. 1,5 MB | |
b2e465d6 AL |
2411 | ioprintf(c1out,_("Need to get %sB of source archives.\n"), |
2412 | SizeToStr(DebBytes).c_str()); | |
2413 | ||
2c0c53b3 AL |
2414 | if (_config->FindB("APT::Get::Simulate",false) == true) |
2415 | { | |
2416 | for (unsigned I = 0; I != J; I++) | |
db0db9fe | 2417 | ioprintf(cout,_("Fetch source %s\n"),Dsc[I].Package.c_str()); |
3a4477a4 | 2418 | delete[] Dsc; |
2c0c53b3 AL |
2419 | return true; |
2420 | } | |
2421 | ||
36375005 AL |
2422 | // Just print out the uris an exit if the --print-uris flag was used |
2423 | if (_config->FindB("APT::Get::Print-URIs") == true) | |
2424 | { | |
2425 | pkgAcquire::UriIterator I = Fetcher.UriBegin(); | |
2426 | for (; I != Fetcher.UriEnd(); I++) | |
2427 | cout << '\'' << I->URI << "' " << flNotDir(I->Owner->DestFile) << ' ' << | |
495e5cb2 | 2428 | I->Owner->FileSize << ' ' << I->Owner->HashSum() << endl; |
3a4477a4 | 2429 | delete[] Dsc; |
36375005 AL |
2430 | return true; |
2431 | } | |
2432 | ||
2433 | // Run it | |
024d1123 | 2434 | if (Fetcher.Run() == pkgAcquire::Failed) |
36375005 AL |
2435 | return false; |
2436 | ||
2437 | // Print error messages | |
fb0ee66e | 2438 | bool Failed = false; |
076d01b0 | 2439 | for (pkgAcquire::ItemIterator I = Fetcher.ItemsBegin(); I != Fetcher.ItemsEnd(); I++) |
36375005 AL |
2440 | { |
2441 | if ((*I)->Status == pkgAcquire::Item::StatDone && | |
2442 | (*I)->Complete == true) | |
2443 | continue; | |
2444 | ||
b2e465d6 AL |
2445 | fprintf(stderr,_("Failed to fetch %s %s\n"),(*I)->DescURI().c_str(), |
2446 | (*I)->ErrorText.c_str()); | |
fb0ee66e | 2447 | Failed = true; |
36375005 | 2448 | } |
fb0ee66e | 2449 | if (Failed == true) |
b2e465d6 | 2450 | return _error->Error(_("Failed to fetch some archives.")); |
fb0ee66e AL |
2451 | |
2452 | if (_config->FindB("APT::Get::Download-only",false) == true) | |
b2e465d6 AL |
2453 | { |
2454 | c1out << _("Download complete and in download only mode") << endl; | |
3a4477a4 | 2455 | delete[] Dsc; |
fb0ee66e | 2456 | return true; |
b2e465d6 AL |
2457 | } |
2458 | ||
fb0ee66e | 2459 | // Unpack the sources |
54676e1a AL |
2460 | pid_t Process = ExecFork(); |
2461 | ||
2462 | if (Process == 0) | |
fb0ee66e | 2463 | { |
827d04d3 | 2464 | bool const fixBroken = _config->FindB("APT::Get::Fix-Broken", false); |
54676e1a | 2465 | for (unsigned I = 0; I != J; I++) |
fb0ee66e | 2466 | { |
b2e465d6 | 2467 | string Dir = Dsc[I].Package + '-' + Cache->VS().UpstreamVersion(Dsc[I].Version.c_str()); |
fb0ee66e | 2468 | |
17c0e8e1 AL |
2469 | // Diff only mode only fetches .diff files |
2470 | if (_config->FindB("APT::Get::Diff-Only",false) == true || | |
a3eaf954 AL |
2471 | _config->FindB("APT::Get::Tar-Only",false) == true || |
2472 | Dsc[I].Dsc.empty() == true) | |
17c0e8e1 | 2473 | continue; |
a3eaf954 | 2474 | |
54676e1a AL |
2475 | // See if the package is already unpacked |
2476 | struct stat Stat; | |
827d04d3 | 2477 | if (fixBroken == false && stat(Dir.c_str(),&Stat) == 0 && |
54676e1a AL |
2478 | S_ISDIR(Stat.st_mode) != 0) |
2479 | { | |
b2e465d6 AL |
2480 | ioprintf(c0out ,_("Skipping unpack of already unpacked source in %s\n"), |
2481 | Dir.c_str()); | |
54676e1a AL |
2482 | } |
2483 | else | |
2484 | { | |
2485 | // Call dpkg-source | |
2486 | char S[500]; | |
2487 | snprintf(S,sizeof(S),"%s -x %s", | |
2488 | _config->Find("Dir::Bin::dpkg-source","dpkg-source").c_str(), | |
2489 | Dsc[I].Dsc.c_str()); | |
2490 | if (system(S) != 0) | |
2491 | { | |
b2e465d6 | 2492 | fprintf(stderr,_("Unpack command '%s' failed.\n"),S); |
14cd494a | 2493 | fprintf(stderr,_("Check if the 'dpkg-dev' package is installed.\n")); |
54676e1a AL |
2494 | _exit(1); |
2495 | } | |
2496 | } | |
2497 | ||
2498 | // Try to compile it with dpkg-buildpackage | |
2499 | if (_config->FindB("APT::Get::Compile",false) == true) | |
2500 | { | |
2501 | // Call dpkg-buildpackage | |
2502 | char S[500]; | |
2503 | snprintf(S,sizeof(S),"cd %s && %s %s", | |
2504 | Dir.c_str(), | |
2505 | _config->Find("Dir::Bin::dpkg-buildpackage","dpkg-buildpackage").c_str(), | |
2506 | _config->Find("DPkg::Build-Options","-b -uc").c_str()); | |
2507 | ||
2508 | if (system(S) != 0) | |
2509 | { | |
b2e465d6 | 2510 | fprintf(stderr,_("Build command '%s' failed.\n"),S); |
54676e1a AL |
2511 | _exit(1); |
2512 | } | |
2513 | } | |
2514 | } | |
2515 | ||
2516 | _exit(0); | |
2517 | } | |
3a4477a4 DK |
2518 | delete[] Dsc; |
2519 | ||
54676e1a AL |
2520 | // Wait for the subprocess |
2521 | int Status = 0; | |
2522 | while (waitpid(Process,&Status,0) != Process) | |
2523 | { | |
2524 | if (errno == EINTR) | |
2525 | continue; | |
2526 | return _error->Errno("waitpid","Couldn't wait for subprocess"); | |
2527 | } | |
2528 | ||
2529 | if (WIFEXITED(Status) == 0 || WEXITSTATUS(Status) != 0) | |
b2e465d6 AL |
2530 | return _error->Error(_("Child process failed")); |
2531 | ||
2532 | return true; | |
2533 | } | |
2534 | /*}}}*/ | |
2535 | // DoBuildDep - Install/removes packages to satisfy build dependencies /*{{{*/ | |
2536 | // --------------------------------------------------------------------- | |
2537 | /* This function will look at the build depends list of the given source | |
2538 | package and install the necessary packages to make it true, or fail. */ | |
2539 | bool DoBuildDep(CommandLine &CmdL) | |
2540 | { | |
2541 | CacheFile Cache; | |
2542 | if (Cache.Open(true) == false) | |
2543 | return false; | |
2544 | ||
2545 | if (CmdL.FileSize() <= 1) | |
2546 | return _error->Error(_("Must specify at least one package to check builddeps for")); | |
2547 | ||
2548 | // Read the source list | |
1bb8cd67 DK |
2549 | if (Cache.BuildSourceList() == false) |
2550 | return false; | |
2551 | pkgSourceList *List = Cache.GetSourceList(); | |
54676e1a | 2552 | |
b2e465d6 AL |
2553 | // Create the text record parsers |
2554 | pkgRecords Recs(Cache); | |
1bb8cd67 | 2555 | pkgSrcRecords SrcRecs(*List); |
b2e465d6 AL |
2556 | if (_error->PendingError() == true) |
2557 | return false; | |
2558 | ||
2559 | // Create the download object | |
2560 | AcqTextStatus Stat(ScreenWidth,_config->FindI("quiet",0)); | |
1cd1c398 DK |
2561 | pkgAcquire Fetcher; |
2562 | if (Fetcher.Setup(&Stat) == false) | |
2563 | return false; | |
b2e465d6 AL |
2564 | |
2565 | unsigned J = 0; | |
086bb6d7 | 2566 | bool const StripMultiArch = APT::Configuration::getArchitectures().size() <= 1; |
b2e465d6 AL |
2567 | for (const char **I = CmdL.FileList + 1; *I != 0; I++, J++) |
2568 | { | |
2569 | string Src; | |
2570 | pkgSrcRecords::Parser *Last = FindSrc(*I,Recs,SrcRecs,Src,*Cache); | |
2571 | if (Last == 0) | |
2572 | return _error->Error(_("Unable to find a source package for %s"),Src.c_str()); | |
2573 | ||
2574 | // Process the build-dependencies | |
2575 | vector<pkgSrcRecords::Parser::BuildDepRec> BuildDeps; | |
086bb6d7 | 2576 | if (Last->BuildDepends(BuildDeps, _config->FindB("APT::Get::Arch-Only", false), StripMultiArch) == false) |
b2e465d6 AL |
2577 | return _error->Error(_("Unable to get build-dependency information for %s"),Src.c_str()); |
2578 | ||
7d6f9f8f AL |
2579 | // Also ensure that build-essential packages are present |
2580 | Configuration::Item const *Opts = _config->Tree("APT::Build-Essential"); | |
2581 | if (Opts) | |
2582 | Opts = Opts->Child; | |
2583 | for (; Opts; Opts = Opts->Next) | |
2584 | { | |
2585 | if (Opts->Value.empty() == true) | |
2586 | continue; | |
2587 | ||
2588 | pkgSrcRecords::Parser::BuildDepRec rec; | |
2589 | rec.Package = Opts->Value; | |
2590 | rec.Type = pkgSrcRecords::Parser::BuildDependIndep; | |
2591 | rec.Op = 0; | |
58d76831 | 2592 | BuildDeps.push_back(rec); |
7d6f9f8f AL |
2593 | } |
2594 | ||
b2e465d6 AL |
2595 | if (BuildDeps.size() == 0) |
2596 | { | |
2597 | ioprintf(c1out,_("%s has no build depends.\n"),Src.c_str()); | |
2598 | continue; | |
2599 | } | |
2600 | ||
2601 | // Install the requested packages | |
b2e465d6 AL |
2602 | vector <pkgSrcRecords::Parser::BuildDepRec>::iterator D; |
2603 | pkgProblemResolver Fix(Cache); | |
58d76831 | 2604 | bool skipAlternatives = false; // skip remaining alternatives in an or group |
b2e465d6 AL |
2605 | for (D = BuildDeps.begin(); D != BuildDeps.end(); D++) |
2606 | { | |
58d76831 AL |
2607 | bool hasAlternatives = (((*D).Op & pkgCache::Dep::Or) == pkgCache::Dep::Or); |
2608 | ||
2609 | if (skipAlternatives == true) | |
2610 | { | |
2611 | if (!hasAlternatives) | |
2612 | skipAlternatives = false; // end of or group | |
2613 | continue; | |
2614 | } | |
2615 | ||
aa2d22be AL |
2616 | if ((*D).Type == pkgSrcRecords::Parser::BuildConflict || |
2617 | (*D).Type == pkgSrcRecords::Parser::BuildConflictIndep) | |
d3fc0061 | 2618 | { |
aa2d22be AL |
2619 | pkgCache::PkgIterator Pkg = Cache->FindPkg((*D).Package); |
2620 | // Build-conflicts on unknown packages are silently ignored | |
2621 | if (Pkg.end() == true) | |
2622 | continue; | |
2623 | ||
2624 | pkgCache::VerIterator IV = (*Cache)[Pkg].InstVerIter(*Cache); | |
2625 | ||
2626 | /* | |
2627 | * Remove if we have an installed version that satisfies the | |
2628 | * version criteria | |
2629 | */ | |
2630 | if (IV.end() == false && | |
2631 | Cache->VS().CheckDep(IV.VerStr(),(*D).Op,(*D).Version.c_str()) == true) | |
b8ad5512 | 2632 | TryToInstallBuildDep(Pkg,Cache,Fix,true,false); |
d3fc0061 | 2633 | } |
aa2d22be AL |
2634 | else // BuildDep || BuildDepIndep |
2635 | { | |
2636 | pkgCache::PkgIterator Pkg = Cache->FindPkg((*D).Package); | |
58d76831 AL |
2637 | if (_config->FindB("Debug::BuildDeps",false) == true) |
2638 | cout << "Looking for " << (*D).Package << "...\n"; | |
2639 | ||
aa2d22be AL |
2640 | if (Pkg.end() == true) |
2641 | { | |
58d76831 AL |
2642 | if (_config->FindB("Debug::BuildDeps",false) == true) |
2643 | cout << " (not found)" << (*D).Package << endl; | |
2644 | ||
2645 | if (hasAlternatives) | |
2646 | continue; | |
2647 | ||
2648 | return _error->Error(_("%s dependency for %s cannot be satisfied " | |
2649 | "because the package %s cannot be found"), | |
2650 | Last->BuildDepType((*D).Type),Src.c_str(), | |
2651 | (*D).Package.c_str()); | |
aa2d22be AL |
2652 | } |
2653 | ||
2654 | /* | |
2655 | * if there are alternatives, we've already picked one, so skip | |
2656 | * the rest | |
2657 | * | |
2658 | * TODO: this means that if there's a build-dep on A|B and B is | |
2659 | * installed, we'll still try to install A; more importantly, | |
2660 | * if A is currently broken, we cannot go back and try B. To fix | |
2661 | * this would require we do a Resolve cycle for each package we | |
2662 | * add to the install list. Ugh | |
2663 | */ | |
aa2d22be | 2664 | |
cfa5659c AL |
2665 | /* |
2666 | * If this is a virtual package, we need to check the list of | |
2667 | * packages that provide it and see if any of those are | |
2668 | * installed | |
2669 | */ | |
2670 | pkgCache::PrvIterator Prv = Pkg.ProvidesList(); | |
a8a0fdcf AL |
2671 | for (; Prv.end() != true; Prv++) |
2672 | { | |
58d76831 | 2673 | if (_config->FindB("Debug::BuildDeps",false) == true) |
75ce2062 | 2674 | cout << " Checking provider " << Prv.OwnerPkg().FullName() << endl; |
58d76831 | 2675 | |
cfa5659c AL |
2676 | if ((*Cache)[Prv.OwnerPkg()].InstVerIter(*Cache).end() == false) |
2677 | break; | |
cb99271c | 2678 | } |
e5002e30 AL |
2679 | |
2680 | // Get installed version and version we are going to install | |
2681 | pkgCache::VerIterator IV = (*Cache)[Pkg].InstVerIter(*Cache); | |
e5002e30 | 2682 | |
58d76831 AL |
2683 | if ((*D).Version[0] != '\0') { |
2684 | // Versioned dependency | |
cb99271c AL |
2685 | |
2686 | pkgCache::VerIterator CV = (*Cache)[Pkg].CandidateVerIter(*Cache); | |
2687 | ||
2688 | for (; CV.end() != true; CV++) | |
2689 | { | |
2690 | if (Cache->VS().CheckDep(CV.VerStr(),(*D).Op,(*D).Version.c_str()) == true) | |
2691 | break; | |
2692 | } | |
2693 | if (CV.end() == true) | |
085bedac | 2694 | { |
34e88622 AL |
2695 | if (hasAlternatives) |
2696 | { | |
2697 | continue; | |
2698 | } | |
2699 | else | |
2700 | { | |
cb99271c AL |
2701 | return _error->Error(_("%s dependency for %s cannot be satisfied " |
2702 | "because no available versions of package %s " | |
2703 | "can satisfy version requirements"), | |
2704 | Last->BuildDepType((*D).Type),Src.c_str(), | |
2705 | (*D).Package.c_str()); | |
34e88622 | 2706 | } |
085bedac | 2707 | } |
e5002e30 | 2708 | } |
58d76831 AL |
2709 | else |
2710 | { | |
2711 | // Only consider virtual packages if there is no versioned dependency | |
2712 | if (Prv.end() == false) | |
2713 | { | |
2714 | if (_config->FindB("Debug::BuildDeps",false) == true) | |
75ce2062 | 2715 | cout << " Is provided by installed package " << Prv.OwnerPkg().FullName() << endl; |
58d76831 AL |
2716 | skipAlternatives = hasAlternatives; |
2717 | continue; | |
2718 | } | |
2719 | } | |
cfa5659c | 2720 | |
58d76831 AL |
2721 | if (IV.end() == false) |
2722 | { | |
2723 | if (_config->FindB("Debug::BuildDeps",false) == true) | |
2724 | cout << " Is installed\n"; | |
2725 | ||
2726 | if (Cache->VS().CheckDep(IV.VerStr(),(*D).Op,(*D).Version.c_str()) == true) | |
2727 | { | |
2728 | skipAlternatives = hasAlternatives; | |
2729 | continue; | |
2730 | } | |
2731 | ||
2732 | if (_config->FindB("Debug::BuildDeps",false) == true) | |
2733 | cout << " ...but the installed version doesn't meet the version requirement\n"; | |
2734 | ||
2735 | if (((*D).Op & pkgCache::Dep::LessEq) == pkgCache::Dep::LessEq) | |
2736 | { | |
2737 | return _error->Error(_("Failed to satisfy %s dependency for %s: Installed package %s is too new"), | |
2738 | Last->BuildDepType((*D).Type), | |
2739 | Src.c_str(), | |
75ce2062 | 2740 | Pkg.FullName(true).c_str()); |
58d76831 AL |
2741 | } |
2742 | } | |
2743 | ||
2744 | ||
2745 | if (_config->FindB("Debug::BuildDeps",false) == true) | |
2746 | cout << " Trying to install " << (*D).Package << endl; | |
2747 | ||
b8ad5512 | 2748 | if (TryToInstallBuildDep(Pkg,Cache,Fix,false,false) == true) |
58d76831 AL |
2749 | { |
2750 | // We successfully installed something; skip remaining alternatives | |
2751 | skipAlternatives = hasAlternatives; | |
d59228b0 | 2752 | if(_config->FindB("APT::Get::Build-Dep-Automatic", false) == true) |
496a05c6 | 2753 | Cache->MarkAuto(Pkg, true); |
58d76831 AL |
2754 | continue; |
2755 | } | |
2756 | else if (hasAlternatives) | |
2757 | { | |
2758 | if (_config->FindB("Debug::BuildDeps",false) == true) | |
2759 | cout << " Unsatisfiable, trying alternatives\n"; | |
2760 | continue; | |
2761 | } | |
2762 | else | |
2763 | { | |
2764 | return _error->Error(_("Failed to satisfy %s dependency for %s: %s"), | |
2765 | Last->BuildDepType((*D).Type), | |
2766 | Src.c_str(), | |
2767 | (*D).Package.c_str()); | |
2768 | } | |
b2e465d6 AL |
2769 | } |
2770 | } | |
2771 | ||
2772 | Fix.InstallProtect(); | |
2773 | if (Fix.Resolve(true) == false) | |
2774 | _error->Discard(); | |
2775 | ||
2776 | // Now we check the state of the packages, | |
2777 | if (Cache->BrokenCount() != 0) | |
0dae8ac5 DK |
2778 | { |
2779 | ShowBroken(cout, Cache, false); | |
2780 | return _error->Error(_("Build-dependencies for %s could not be satisfied."),*I); | |
2781 | } | |
b2e465d6 AL |
2782 | } |
2783 | ||
2784 | if (InstallPackages(Cache, false, true) == false) | |
2785 | return _error->Error(_("Failed to process build dependencies")); | |
36375005 AL |
2786 | return true; |
2787 | } | |
2788 | /*}}}*/ | |
a53b07bb MV |
2789 | // GetChangelogPath - return a path pointing to a changelog file or dir /*{{{*/ |
2790 | // --------------------------------------------------------------------- | |
2791 | /* This returns a "path" string for the changelog url construction. | |
2792 | * Please note that its not complete, it either needs a "/changelog" | |
2793 | * appended (for the packages.debian.org/changelogs site) or a | |
2794 | * ".changelog" (for third party sites that store the changelog in the | |
2795 | * pool/ next to the deb itself) | |
2796 | * Example return: "pool/main/a/apt/apt_0.8.8ubuntu3" | |
2797 | */ | |
2798 | string GetChangelogPath(CacheFile &Cache, | |
2799 | pkgCache::PkgIterator Pkg, | |
2800 | pkgCache::VerIterator Ver) | |
2801 | { | |
2802 | string path; | |
2803 | ||
2804 | pkgRecords Recs(Cache); | |
2805 | pkgRecords::Parser &rec=Recs.Lookup(Ver.FileList()); | |
2806 | string srcpkg = rec.SourcePkg().empty() ? Pkg.Name() : rec.SourcePkg(); | |
c5d6a22c MV |
2807 | string ver = Ver.VerStr(); |
2808 | // if there is a source version it always wins | |
2809 | if (rec.SourceVer() != "") | |
2810 | ver = rec.SourceVer(); | |
a53b07bb | 2811 | path = flNotFile(rec.FileName()); |
c5d6a22c | 2812 | path += srcpkg + "_" + StripEpoch(ver); |
a53b07bb MV |
2813 | return path; |
2814 | } | |
2815 | /*}}}*/ | |
cdb9307c MV |
2816 | // GuessThirdPartyChangelogUri - return url /*{{{*/ |
2817 | // --------------------------------------------------------------------- | |
a53b07bb MV |
2818 | /* Contruct a changelog file path for third party sites that do not use |
2819 | * packages.debian.org/changelogs | |
2820 | * This simply uses the ArchiveURI() of the source pkg and looks for | |
2821 | * a .changelog file there, Example for "mediabuntu": | |
2822 | * apt-get changelog mplayer-doc: | |
2823 | * http://packages.medibuntu.org/pool/non-free/m/mplayer/mplayer_1.0~rc4~try1.dsfg1-1ubuntu1+medibuntu1.changelog | |
2824 | */ | |
cdb9307c MV |
2825 | bool GuessThirdPartyChangelogUri(CacheFile &Cache, |
2826 | pkgCache::PkgIterator Pkg, | |
2827 | pkgCache::VerIterator Ver, | |
2828 | string &out_uri) | |
2829 | { | |
cdb9307c | 2830 | // get the binary deb server path |
cdb9307c MV |
2831 | pkgCache::VerFileIterator Vf = Ver.FileList(); |
2832 | if (Vf.end() == true) | |
2833 | return false; | |
2834 | pkgCache::PkgFileIterator F = Vf.File(); | |
2835 | pkgIndexFile *index; | |
a53b07bb | 2836 | pkgSourceList *SrcList = Cache.GetSourceList(); |
cdb9307c MV |
2837 | if(SrcList->FindIndex(F, index) == false) |
2838 | return false; | |
a53b07bb | 2839 | |
cdb9307c | 2840 | // get archive uri for the binary deb |
a53b07bb MV |
2841 | string path_without_dot_changelog = GetChangelogPath(Cache, Pkg, Ver); |
2842 | out_uri = index->ArchiveURI(path_without_dot_changelog + ".changelog"); | |
cdb9307c MV |
2843 | |
2844 | // now strip away the filename and add srcpkg_srcver.changelog | |
cdb9307c MV |
2845 | return true; |
2846 | } | |
a4c40430 MV |
2847 | // DownloadChangelog - Download the changelog /*{{{*/ |
2848 | // --------------------------------------------------------------------- | |
a53b07bb MV |
2849 | bool DownloadChangelog(CacheFile &CacheFile, pkgAcquire &Fetcher, |
2850 | pkgCache::VerIterator Ver, string targetfile) | |
2851 | /* Download a changelog file for the given package version to | |
2852 | * targetfile. This will first try the server from Apt::Changelogs::Server | |
2853 | * (http://packages.debian.org/changelogs by default) and if that gives | |
2854 | * a 404 tries to get it from the archive directly (see | |
2855 | * GuessThirdPartyChangelogUri for details how) | |
2856 | */ | |
a4c40430 | 2857 | { |
a53b07bb | 2858 | string path; |
a4c40430 | 2859 | string descr; |
c2991635 | 2860 | string server; |
a53b07bb | 2861 | string changelog_uri; |
a4c40430 MV |
2862 | |
2863 | // data structures we need | |
a53b07bb | 2864 | pkgCache::PkgIterator Pkg = Ver.ParentPkg(); |
a4c40430 | 2865 | |
a53b07bb | 2866 | // make the server root configurable |
c2991635 | 2867 | server = _config->Find("Apt::Changelogs::Server", |
a53b07bb MV |
2868 | "http://packages.debian.org/changelogs"); |
2869 | path = GetChangelogPath(CacheFile, Pkg, Ver); | |
2870 | strprintf(changelog_uri, "%s/%s/changelog", server.c_str(), path.c_str()); | |
88573174 | 2871 | strprintf(descr, _("Changelog for %s (%s)"), Pkg.Name(), changelog_uri.c_str()); |
a53b07bb | 2872 | // queue it |
88573174 | 2873 | new pkgAcqFile(&Fetcher, changelog_uri, "", 0, descr, Pkg.Name(), "ignored", targetfile); |
d786352d | 2874 | |
cdb9307c MV |
2875 | // try downloading it, if that fails, they third-party-changelogs location |
2876 | // FIXME: res is "Continue" even if I get a 404?!? | |
a4c40430 | 2877 | int res = Fetcher.Run(); |
cdb9307c MV |
2878 | if (!FileExists(targetfile)) |
2879 | { | |
2880 | string third_party_uri; | |
a53b07bb | 2881 | if (GuessThirdPartyChangelogUri(CacheFile, Pkg, Ver, third_party_uri)) |
cdb9307c | 2882 | { |
88573174 MV |
2883 | strprintf(descr, _("Changelog for %s (%s)"), Pkg.Name(), third_party_uri.c_str()); |
2884 | new pkgAcqFile(&Fetcher, third_party_uri, "", 0, descr, Pkg.Name(), "ignored", targetfile); | |
cdb9307c MV |
2885 | res = Fetcher.Run(); |
2886 | } | |
2887 | } | |
4a6fe09c | 2888 | |
a4c40430 | 2889 | if (FileExists(targetfile)) |
18ae8b29 | 2890 | return true; |
a4c40430 MV |
2891 | |
2892 | // error | |
18ae8b29 | 2893 | return _error->Error("changelog download failed"); |
a4c40430 MV |
2894 | } |
2895 | /*}}}*/ | |
2896 | // DisplayFileInPager - Display File with pager /*{{{*/ | |
2897 | void DisplayFileInPager(string filename) | |
2898 | { | |
2899 | pid_t Process = ExecFork(); | |
2900 | if (Process == 0) | |
2901 | { | |
2902 | const char *Args[3]; | |
2903 | Args[0] = "/usr/bin/sensible-pager"; | |
2904 | Args[1] = filename.c_str(); | |
2905 | Args[2] = 0; | |
2906 | execvp(Args[0],(char **)Args); | |
2907 | exit(100); | |
2908 | } | |
2909 | ||
2910 | // Wait for the subprocess | |
2911 | ExecWait(Process, "sensible-pager", false); | |
2912 | } | |
2913 | /*}}}*/ | |
2914 | // DoChangelog - Get changelog from the command line /*{{{*/ | |
2915 | // --------------------------------------------------------------------- | |
2916 | bool DoChangelog(CommandLine &CmdL) | |
2917 | { | |
2918 | CacheFile Cache; | |
2919 | if (Cache.ReadOnlyOpen() == false) | |
2920 | return false; | |
2921 | ||
2922 | APT::CacheSetHelper helper(c0out); | |
2923 | APT::VersionSet verset = APT::VersionSet::FromCommandLine(Cache, | |
2924 | CmdL.FileList + 1, APT::VersionSet::CANDIDATE, helper); | |
2925 | pkgAcquire Fetcher; | |
8cc74fb1 MV |
2926 | AcqTextStatus Stat(ScreenWidth, _config->FindI("quiet",0)); |
2927 | Fetcher.Setup(&Stat); | |
a4c40430 MV |
2928 | |
2929 | if (verset.empty() == true) | |
2930 | return false; | |
64b4c03e | 2931 | char *tmpdir = mkdtemp(strdup("/tmp/apt-changelog-XXXXXX")); |
18ae8b29 MV |
2932 | if (tmpdir == NULL) { |
2933 | return _error->Errno("mkdtemp", "mkdtemp failed"); | |
2934 | } | |
2935 | ||
a4c40430 MV |
2936 | for (APT::VersionSet::const_iterator Ver = verset.begin(); |
2937 | Ver != verset.end(); | |
2938 | ++Ver) | |
2939 | { | |
18ae8b29 MV |
2940 | string changelogfile = string(tmpdir) + "changelog"; |
2941 | if (DownloadChangelog(Cache, Fetcher, Ver, changelogfile)) | |
a4c40430 | 2942 | DisplayFileInPager(changelogfile); |
18ae8b29 MV |
2943 | // cleanup temp file |
2944 | unlink(changelogfile.c_str()); | |
a4c40430 | 2945 | } |
18ae8b29 MV |
2946 | // clenaup tmp dir |
2947 | rmdir(tmpdir); | |
2948 | free(tmpdir); | |
4a6fe09c | 2949 | return true; |
a4c40430 MV |
2950 | } |
2951 | /*}}}*/ | |
b2e465d6 AL |
2952 | // DoMoo - Never Ask, Never Tell /*{{{*/ |
2953 | // --------------------------------------------------------------------- | |
2954 | /* */ | |
2955 | bool DoMoo(CommandLine &CmdL) | |
2956 | { | |
2957 | cout << | |
2958 | " (__) \n" | |
2959 | " (oo) \n" | |
2960 | " /------\\/ \n" | |
2961 | " / | || \n" | |
2962 | " * /\\---/\\ \n" | |
2963 | " ~~ ~~ \n" | |
2964 | "....\"Have you mooed today?\"...\n"; | |
2965 | ||
2966 | return true; | |
2967 | } | |
2968 | /*}}}*/ | |
0a8e3465 AL |
2969 | // ShowHelp - Show a help screen /*{{{*/ |
2970 | // --------------------------------------------------------------------- | |
2971 | /* */ | |
212ad54a | 2972 | bool ShowHelp(CommandLine &CmdL) |
0a8e3465 | 2973 | { |
5b28c804 OS |
2974 | ioprintf(cout,_("%s %s for %s compiled on %s %s\n"),PACKAGE,VERSION, |
2975 | COMMON_ARCH,__DATE__,__TIME__); | |
b2e465d6 | 2976 | |
04aa15a8 | 2977 | if (_config->FindB("version") == true) |
b2e465d6 | 2978 | { |
db0db9fe | 2979 | cout << _("Supported modules:") << endl; |
b2e465d6 AL |
2980 | |
2981 | for (unsigned I = 0; I != pkgVersioningSystem::GlobalListLen; I++) | |
2982 | { | |
2983 | pkgVersioningSystem *VS = pkgVersioningSystem::GlobalList[I]; | |
2984 | if (_system != 0 && _system->VS == VS) | |
2985 | cout << '*'; | |
2986 | else | |
2987 | cout << ' '; | |
2988 | cout << "Ver: " << VS->Label << endl; | |
2989 | ||
2990 | /* Print out all the packaging systems that will work with | |
2991 | this VS */ | |
2992 | for (unsigned J = 0; J != pkgSystem::GlobalListLen; J++) | |
2993 | { | |
2994 | pkgSystem *Sys = pkgSystem::GlobalList[J]; | |
2995 | if (_system == Sys) | |
2996 | cout << '*'; | |
2997 | else | |
2998 | cout << ' '; | |
2999 | if (Sys->VS->TestCompatibility(*VS) == true) | |
3000 | cout << "Pkg: " << Sys->Label << " (Priority " << Sys->Score(*_config) << ")" << endl; | |
3001 | } | |
3002 | } | |
3003 | ||
3004 | for (unsigned I = 0; I != pkgSourceList::Type::GlobalListLen; I++) | |
3005 | { | |
3006 | pkgSourceList::Type *Type = pkgSourceList::Type::GlobalList[I]; | |
3007 | cout << " S.L: '" << Type->Name << "' " << Type->Label << endl; | |
3008 | } | |
3009 | ||
3010 | for (unsigned I = 0; I != pkgIndexFile::Type::GlobalListLen; I++) | |
3011 | { | |
3012 | pkgIndexFile::Type *Type = pkgIndexFile::Type::GlobalList[I]; | |
3013 | cout << " Idx: " << Type->Label << endl; | |
3014 | } | |
3015 | ||
3016 | return true; | |
3017 | } | |
3018 | ||
3019 | cout << | |
3020 | _("Usage: apt-get [options] command\n" | |
3021 | " apt-get [options] install|remove pkg1 [pkg2 ...]\n" | |
3022 | " apt-get [options] source pkg1 [pkg2 ...]\n" | |
3023 | "\n" | |
3024 | "apt-get is a simple command line interface for downloading and\n" | |
3025 | "installing packages. The most frequently used commands are update\n" | |
3026 | "and install.\n" | |
3027 | "\n" | |
3028 | "Commands:\n" | |
3029 | " update - Retrieve new lists of packages\n" | |
3030 | " upgrade - Perform an upgrade\n" | |
3031 | " install - Install new packages (pkg is libc6 not libc6.deb)\n" | |
3032 | " remove - Remove packages\n" | |
12bffed7 | 3033 | " autoremove - Remove automatically all unused packages\n" |
73fc19d0 | 3034 | " purge - Remove packages and config files\n" |
b2e465d6 AL |
3035 | " source - Download source archives\n" |
3036 | " build-dep - Configure build-dependencies for source packages\n" | |
3037 | " dist-upgrade - Distribution upgrade, see apt-get(8)\n" | |
3038 | " dselect-upgrade - Follow dselect selections\n" | |
3039 | " clean - Erase downloaded archive files\n" | |
3040 | " autoclean - Erase old downloaded archive files\n" | |
3041 | " check - Verify that there are no broken dependencies\n" | |
d63a1458 JAK |
3042 | " markauto - Mark the given packages as automatically installed\n" |
3043 | " unmarkauto - Mark the given packages as manually installed\n" | |
5f967f2d MV |
3044 | " changelog - Download and display the changelog for the given package\n" |
3045 | " download - Download the binary package into the current directory\n" | |
b2e465d6 AL |
3046 | "\n" |
3047 | "Options:\n" | |
3048 | " -h This help text.\n" | |
3049 | " -q Loggable output - no progress indicator\n" | |
3050 | " -qq No output except for errors\n" | |
3051 | " -d Download only - do NOT install or unpack archives\n" | |
3052 | " -s No-act. Perform ordering simulation\n" | |
3053 | " -y Assume Yes to all queries and do not prompt\n" | |
0748d509 | 3054 | " -f Attempt to correct a system with broken dependencies in place\n" |
b2e465d6 AL |
3055 | " -m Attempt to continue if archives are unlocatable\n" |
3056 | " -u Show a list of upgraded packages as well\n" | |
3057 | " -b Build the source package after fetching it\n" | |
ac625538 | 3058 | " -V Show verbose version numbers\n" |
b2e465d6 | 3059 | " -c=? Read this configuration file\n" |
a2884e32 | 3060 | " -o=? Set an arbitrary configuration option, eg -o dir::cache=/tmp\n" |
b2e465d6 AL |
3061 | "See the apt-get(8), sources.list(5) and apt.conf(5) manual\n" |
3062 | "pages for more information and options.\n" | |
3063 | " This APT has Super Cow Powers.\n"); | |
3064 | return true; | |
0a8e3465 AL |
3065 | } |
3066 | /*}}}*/ | |
d7827aca AL |
3067 | // SigWinch - Window size change signal handler /*{{{*/ |
3068 | // --------------------------------------------------------------------- | |
3069 | /* */ | |
3070 | void SigWinch(int) | |
3071 | { | |
3072 | // Riped from GNU ls | |
3073 | #ifdef TIOCGWINSZ | |
3074 | struct winsize ws; | |
3075 | ||
3076 | if (ioctl(1, TIOCGWINSZ, &ws) != -1 && ws.ws_col >= 5) | |
3077 | ScreenWidth = ws.ws_col - 1; | |
3078 | #endif | |
3079 | } | |
3080 | /*}}}*/ | |
92fcbfc1 | 3081 | int main(int argc,const char *argv[]) /*{{{*/ |
0a8e3465 AL |
3082 | { |
3083 | CommandLine::Args Args[] = { | |
3084 | {'h',"help","help",0}, | |
04aa15a8 | 3085 | {'v',"version","version",0}, |
ac625538 | 3086 | {'V',"verbose-versions","APT::Get::Show-Versions",0}, |
0a8e3465 AL |
3087 | {'q',"quiet","quiet",CommandLine::IntLevel}, |
3088 | {'q',"silent","quiet",CommandLine::IntLevel}, | |
3089 | {'d',"download-only","APT::Get::Download-Only",0}, | |
fb0ee66e AL |
3090 | {'b',"compile","APT::Get::Compile",0}, |
3091 | {'b',"build","APT::Get::Compile",0}, | |
d150b09d AL |
3092 | {'s',"simulate","APT::Get::Simulate",0}, |
3093 | {'s',"just-print","APT::Get::Simulate",0}, | |
3094 | {'s',"recon","APT::Get::Simulate",0}, | |
6df23d2f | 3095 | {'s',"dry-run","APT::Get::Simulate",0}, |
d150b09d AL |
3096 | {'s',"no-act","APT::Get::Simulate",0}, |
3097 | {'y',"yes","APT::Get::Assume-Yes",0}, | |
0a8e3465 AL |
3098 | {'y',"assume-yes","APT::Get::Assume-Yes",0}, |
3099 | {'f',"fix-broken","APT::Get::Fix-Broken",0}, | |
3100 | {'u',"show-upgraded","APT::Get::Show-Upgraded",0}, | |
30e1eab5 | 3101 | {'m',"ignore-missing","APT::Get::Fix-Missing",0}, |
b2e465d6 AL |
3102 | {'t',"target-release","APT::Default-Release",CommandLine::HasArg}, |
3103 | {'t',"default-release","APT::Default-Release",CommandLine::HasArg}, | |
3104 | {0,"download","APT::Get::Download",0}, | |
30e1eab5 | 3105 | {0,"fix-missing","APT::Get::Fix-Missing",0}, |
b2e465d6 AL |
3106 | {0,"ignore-hold","APT::Ignore-Hold",0}, |
3107 | {0,"upgrade","APT::Get::upgrade",0}, | |
6cd9fbd7 | 3108 | {0,"only-upgrade","APT::Get::Only-Upgrade",0}, |
83d89a9f | 3109 | {0,"force-yes","APT::Get::force-yes",0}, |
f7a08e33 | 3110 | {0,"print-uris","APT::Get::Print-URIs",0}, |
5fafc0ef | 3111 | {0,"diff-only","APT::Get::Diff-Only",0}, |
a0895a74 | 3112 | {0,"debian-only","APT::Get::Diff-Only",0}, |
1979e742 MV |
3113 | {0,"tar-only","APT::Get::Tar-Only",0}, |
3114 | {0,"dsc-only","APT::Get::Dsc-Only",0}, | |
fc4b5c9f | 3115 | {0,"purge","APT::Get::Purge",0}, |
9df71a5b | 3116 | {0,"list-cleanup","APT::Get::List-Cleanup",0}, |
d0c59649 | 3117 | {0,"reinstall","APT::Get::ReInstall",0}, |
d150b09d | 3118 | {0,"trivial-only","APT::Get::Trivial-Only",0}, |
b2e465d6 AL |
3119 | {0,"remove","APT::Get::Remove",0}, |
3120 | {0,"only-source","APT::Get::Only-Source",0}, | |
45430cbf | 3121 | {0,"arch-only","APT::Get::Arch-Only",0}, |
f8ac1720 | 3122 | {0,"auto-remove","APT::Get::AutomaticRemove",0}, |
7db98ffc | 3123 | {0,"allow-unauthenticated","APT::Get::AllowUnauthenticated",0}, |
e9ae3677 | 3124 | {0,"install-recommends","APT::Install-Recommends",CommandLine::Boolean}, |
4ef9a929 | 3125 | {0,"fix-policy","APT::Get::Fix-Policy-Broken",0}, |
0a8e3465 AL |
3126 | {'c',"config-file",0,CommandLine::ConfigFile}, |
3127 | {'o',"option",0,CommandLine::ArbItem}, | |
3128 | {0,0,0,0}}; | |
83d89a9f AL |
3129 | CommandLine::Dispatch Cmds[] = {{"update",&DoUpdate}, |
3130 | {"upgrade",&DoUpgrade}, | |
3131 | {"install",&DoInstall}, | |
3132 | {"remove",&DoInstall}, | |
24401c09 | 3133 | {"purge",&DoInstall}, |
74a05226 | 3134 | {"autoremove",&DoInstall}, |
d63a1458 JAK |
3135 | {"markauto",&DoMarkAuto}, |
3136 | {"unmarkauto",&DoMarkAuto}, | |
83d89a9f AL |
3137 | {"dist-upgrade",&DoDistUpgrade}, |
3138 | {"dselect-upgrade",&DoDSelectUpgrade}, | |
b2e465d6 | 3139 | {"build-dep",&DoBuildDep}, |
83d89a9f | 3140 | {"clean",&DoClean}, |
1bc849af | 3141 | {"autoclean",&DoAutoClean}, |
83d89a9f | 3142 | {"check",&DoCheck}, |
67111687 | 3143 | {"source",&DoSource}, |
459b5f5d | 3144 | {"download",&DoDownload}, |
a4c40430 | 3145 | {"changelog",&DoChangelog}, |
b2e465d6 | 3146 | {"moo",&DoMoo}, |
67111687 | 3147 | {"help",&ShowHelp}, |
83d89a9f | 3148 | {0,0}}; |
67111687 AL |
3149 | |
3150 | // Set up gettext support | |
3151 | setlocale(LC_ALL,""); | |
3152 | textdomain(PACKAGE); | |
3153 | ||
0a8e3465 AL |
3154 | // Parse the command line and initialize the package library |
3155 | CommandLine CmdL(Args,_config); | |
b2e465d6 AL |
3156 | if (pkgInitConfig(*_config) == false || |
3157 | CmdL.Parse(argc,argv) == false || | |
3158 | pkgInitSystem(*_config,_system) == false) | |
0a8e3465 | 3159 | { |
b2e465d6 AL |
3160 | if (_config->FindB("version") == true) |
3161 | ShowHelp(CmdL); | |
3162 | ||
0a8e3465 AL |
3163 | _error->DumpErrors(); |
3164 | return 100; | |
3165 | } | |
3166 | ||
3167 | // See if the help should be shown | |
3168 | if (_config->FindB("help") == true || | |
04aa15a8 | 3169 | _config->FindB("version") == true || |
0a8e3465 | 3170 | CmdL.FileSize() == 0) |
b2e465d6 AL |
3171 | { |
3172 | ShowHelp(CmdL); | |
3173 | return 0; | |
3174 | } | |
55a5a46c MV |
3175 | |
3176 | // simulate user-friendly if apt-get has no root privileges | |
3177 | if (getuid() != 0 && _config->FindB("APT::Get::Simulate") == true) | |
3178 | { | |
ecf59bfc DK |
3179 | if (_config->FindB("APT::Get::Show-User-Simulation-Note",true) == true) |
3180 | cout << _("NOTE: This is only a simulation!\n" | |
3181 | " apt-get needs root privileges for real execution.\n" | |
3182 | " Keep also in mind that locking is deactivated,\n" | |
3183 | " so don't depend on the relevance to the real current situation!" | |
3184 | ) << std::endl; | |
55a5a46c MV |
3185 | _config->Set("Debug::NoLocking",true); |
3186 | } | |
3187 | ||
a9a5908d | 3188 | // Deal with stdout not being a tty |
c340d185 | 3189 | if (!isatty(STDOUT_FILENO) && _config->FindI("quiet", -1) == -1) |
a9a5908d | 3190 | _config->Set("quiet","1"); |
01b64152 | 3191 | |
0a8e3465 AL |
3192 | // Setup the output streams |
3193 | c0out.rdbuf(cout.rdbuf()); | |
3194 | c1out.rdbuf(cout.rdbuf()); | |
3195 | c2out.rdbuf(cout.rdbuf()); | |
3196 | if (_config->FindI("quiet",0) > 0) | |
3197 | c0out.rdbuf(devnull.rdbuf()); | |
3198 | if (_config->FindI("quiet",0) > 1) | |
3199 | c1out.rdbuf(devnull.rdbuf()); | |
d7827aca AL |
3200 | |
3201 | // Setup the signals | |
3202 | signal(SIGPIPE,SIG_IGN); | |
3203 | signal(SIGWINCH,SigWinch); | |
3204 | SigWinch(0); | |
b2e465d6 | 3205 | |
0a8e3465 | 3206 | // Match the operation |
83d89a9f | 3207 | CmdL.DispatchArg(Cmds); |
0a8e3465 AL |
3208 | |
3209 | // Print any errors or warnings found during parsing | |
65beb572 DK |
3210 | bool const Errors = _error->PendingError(); |
3211 | if (_config->FindI("quiet",0) > 0) | |
0a8e3465 | 3212 | _error->DumpErrors(); |
65beb572 DK |
3213 | else |
3214 | _error->DumpErrors(GlobalError::DEBUG); | |
3215 | return Errors == true ? 100 : 0; | |
0a8e3465 | 3216 | } |
92fcbfc1 | 3217 | /*}}}*/ |