]>
Commit | Line | Data |
---|---|---|
1164783d AL |
1 | // -*- mode: cpp; mode: fold -*- |
2 | // Description /*{{{*/ | |
ea7f6363 | 3 | // $Id: apt-cache.cc,v 1.72 2004/04/30 04:34:03 mdz Exp $ |
1164783d AL |
4 | /* ###################################################################### |
5 | ||
e1b74f61 | 6 | apt-cache - Manages the cache files |
1164783d | 7 | |
e1b74f61 | 8 | apt-cache provides some functions fo manipulating the cache files. |
b2e465d6 | 9 | It uses the command line interface common to all the APT tools. |
1164783d AL |
10 | |
11 | Returns 100 on failure, 0 on success. | |
12 | ||
13 | ##################################################################### */ | |
14 | /*}}}*/ | |
15 | // Include Files /*{{{*/ | |
16 | #include <apt-pkg/error.h> | |
6007c1d4 | 17 | #include <cassert> |
1164783d | 18 | #include <apt-pkg/pkgcachegen.h> |
6007c1d4 | 19 | #include <apt-pkg/cachefile.h> |
8efa2a3b | 20 | #include <apt-pkg/init.h> |
404ec98e | 21 | #include <apt-pkg/progress.h> |
880e9be4 | 22 | #include <apt-pkg/sourcelist.h> |
08e8f724 | 23 | #include <apt-pkg/cmndline.h> |
cdcc6d34 | 24 | #include <apt-pkg/strutl.h> |
9dbb421f | 25 | #include <apt-pkg/pkgrecords.h> |
f8f410f5 | 26 | #include <apt-pkg/srcrecords.h> |
3e94da1b | 27 | #include <apt-pkg/version.h> |
b2e465d6 AL |
28 | #include <apt-pkg/policy.h> |
29 | #include <apt-pkg/tagfile.h> | |
30 | #include <apt-pkg/algorithms.h> | |
31 | #include <apt-pkg/sptr.h> | |
32 | ||
43981212 | 33 | #include <config.h> |
b2e465d6 | 34 | #include <apti18n.h> |
1164783d | 35 | |
233c2b66 | 36 | #include <locale.h> |
90f057fd | 37 | #include <iostream> |
cdb970c7 | 38 | #include <unistd.h> |
43981212 | 39 | #include <errno.h> |
9dbb421f | 40 | #include <regex.h> |
3e94da1b | 41 | #include <stdio.h> |
bd3d53ef AL |
42 | |
43 | #include <iomanip> | |
1164783d AL |
44 | /*}}}*/ |
45 | ||
8f312f45 AL |
46 | using namespace std; |
47 | ||
b0b4efb9 | 48 | pkgCache *GCache = 0; |
af87ab54 | 49 | pkgSourceList *SrcList = 0; |
b0b4efb9 | 50 | |
b2e465d6 AL |
51 | // LocalitySort - Sort a version list by package file locality /*{{{*/ |
52 | // --------------------------------------------------------------------- | |
53 | /* */ | |
54 | int LocalityCompare(const void *a, const void *b) | |
55 | { | |
56 | pkgCache::VerFile *A = *(pkgCache::VerFile **)a; | |
57 | pkgCache::VerFile *B = *(pkgCache::VerFile **)b; | |
58 | ||
59 | if (A == 0 && B == 0) | |
60 | return 0; | |
61 | if (A == 0) | |
62 | return 1; | |
63 | if (B == 0) | |
64 | return -1; | |
65 | ||
66 | if (A->File == B->File) | |
67 | return A->Offset - B->Offset; | |
68 | return A->File - B->File; | |
69 | } | |
70 | ||
71 | void LocalitySort(pkgCache::VerFile **begin, | |
72 | unsigned long Count,size_t Size) | |
73 | { | |
74 | qsort(begin,Count,Size,LocalityCompare); | |
75 | } | |
a52f938b OS |
76 | |
77 | void LocalitySort(pkgCache::DescFile **begin, | |
78 | unsigned long Count,size_t Size) | |
79 | { | |
80 | qsort(begin,Count,Size,LocalityCompare); | |
81 | } | |
b2e465d6 | 82 | /*}}}*/ |
cc718e9a AL |
83 | // UnMet - Show unmet dependencies /*{{{*/ |
84 | // --------------------------------------------------------------------- | |
85 | /* */ | |
b0b4efb9 | 86 | bool UnMet(CommandLine &CmdL) |
cc718e9a | 87 | { |
b0b4efb9 | 88 | pkgCache &Cache = *GCache; |
76fbce56 | 89 | bool Important = _config->FindB("APT::Cache::Important",false); |
018f1533 | 90 | |
cc718e9a AL |
91 | for (pkgCache::PkgIterator P = Cache.PkgBegin(); P.end() == false; P++) |
92 | { | |
93 | for (pkgCache::VerIterator V = P.VersionList(); V.end() == false; V++) | |
94 | { | |
95 | bool Header = false; | |
018f1533 | 96 | for (pkgCache::DepIterator D = V.DependsList(); D.end() == false;) |
cc718e9a AL |
97 | { |
98 | // Collect or groups | |
99 | pkgCache::DepIterator Start; | |
100 | pkgCache::DepIterator End; | |
101 | D.GlobOr(Start,End); | |
102 | ||
018f1533 | 103 | // Skip conflicts and replaces |
cc718e9a AL |
104 | if (End->Type != pkgCache::Dep::PreDepends && |
105 | End->Type != pkgCache::Dep::Depends && | |
106 | End->Type != pkgCache::Dep::Suggests && | |
7146a53c | 107 | End->Type != pkgCache::Dep::Recommends) |
cc718e9a AL |
108 | continue; |
109 | ||
018f1533 AL |
110 | // Important deps only |
111 | if (Important == true) | |
112 | if (End->Type != pkgCache::Dep::PreDepends && | |
7146a53c | 113 | End->Type != pkgCache::Dep::Depends) |
018f1533 AL |
114 | continue; |
115 | ||
cc718e9a AL |
116 | // Verify the or group |
117 | bool OK = false; | |
118 | pkgCache::DepIterator RealStart = Start; | |
119 | do | |
120 | { | |
121 | // See if this dep is Ok | |
122 | pkgCache::Version **VList = Start.AllTargets(); | |
123 | if (*VList != 0) | |
124 | { | |
125 | OK = true; | |
126 | delete [] VList; | |
127 | break; | |
128 | } | |
129 | delete [] VList; | |
130 | ||
131 | if (Start == End) | |
132 | break; | |
133 | Start++; | |
134 | } | |
135 | while (1); | |
136 | ||
137 | // The group is OK | |
138 | if (OK == true) | |
139 | continue; | |
140 | ||
141 | // Oops, it failed.. | |
142 | if (Header == false) | |
b2e465d6 | 143 | ioprintf(cout,_("Package %s version %s has an unmet dep:\n"), |
75ce2062 | 144 | P.FullName(true).c_str(),V.VerStr()); |
cc718e9a AL |
145 | Header = true; |
146 | ||
147 | // Print out the dep type | |
148 | cout << " " << End.DepType() << ": "; | |
149 | ||
150 | // Show the group | |
151 | Start = RealStart; | |
152 | do | |
153 | { | |
75ce2062 | 154 | cout << Start.TargetPkg().FullName(true); |
cc718e9a AL |
155 | if (Start.TargetVer() != 0) |
156 | cout << " (" << Start.CompType() << " " << Start.TargetVer() << | |
157 | ")"; | |
158 | if (Start == End) | |
159 | break; | |
160 | cout << " | "; | |
161 | Start++; | |
162 | } | |
163 | while (1); | |
164 | ||
165 | cout << endl; | |
166 | } | |
167 | } | |
168 | } | |
169 | return true; | |
170 | } | |
171 | /*}}}*/ | |
1164783d AL |
172 | // DumpPackage - Show a dump of a package record /*{{{*/ |
173 | // --------------------------------------------------------------------- | |
174 | /* */ | |
b0b4efb9 | 175 | bool DumpPackage(CommandLine &CmdL) |
ad00ae81 | 176 | { |
b0b4efb9 | 177 | pkgCache &Cache = *GCache; |
e1b74f61 | 178 | for (const char **I = CmdL.FileList + 1; *I != 0; I++) |
1164783d | 179 | { |
e1b74f61 | 180 | pkgCache::PkgIterator Pkg = Cache.FindPkg(*I); |
1164783d AL |
181 | if (Pkg.end() == true) |
182 | { | |
b2e465d6 | 183 | _error->Warning(_("Unable to locate package %s"),*I); |
1164783d AL |
184 | continue; |
185 | } | |
186 | ||
75ce2062 | 187 | cout << "Package: " << Pkg.FullName(true) << endl; |
b2e465d6 | 188 | cout << "Versions: " << endl; |
1164783d | 189 | for (pkgCache::VerIterator Cur = Pkg.VersionList(); Cur.end() != true; Cur++) |
03e39e59 AL |
190 | { |
191 | cout << Cur.VerStr(); | |
192 | for (pkgCache::VerFileIterator Vf = Cur.FileList(); Vf.end() == false; Vf++) | |
a52f938b OS |
193 | cout << " (" << Vf.File().FileName() << ")"; |
194 | cout << endl; | |
195 | for (pkgCache::DescIterator D = Cur.DescriptionList(); D.end() == false; D++) | |
196 | { | |
197 | cout << " Description Language: " << D.LanguageCode() << endl | |
198 | << " File: " << D.FileList().File().FileName() << endl | |
199 | << " MD5: " << D.md5() << endl; | |
200 | } | |
b2e465d6 | 201 | cout << endl; |
03e39e59 AL |
202 | } |
203 | ||
1164783d AL |
204 | cout << endl; |
205 | ||
206 | cout << "Reverse Depends: " << endl; | |
207 | for (pkgCache::DepIterator D = Pkg.RevDependsList(); D.end() != true; D++) | |
b2e465d6 | 208 | { |
75ce2062 | 209 | cout << " " << D.ParentPkg().FullName(true) << ',' << D.TargetPkg().FullName(true); |
b2e465d6 | 210 | if (D->Version != 0) |
b1b663d1 | 211 | cout << ' ' << DeNull(D.TargetVer()) << endl; |
b2e465d6 AL |
212 | else |
213 | cout << endl; | |
214 | } | |
215 | ||
1164783d AL |
216 | cout << "Dependencies: " << endl; |
217 | for (pkgCache::VerIterator Cur = Pkg.VersionList(); Cur.end() != true; Cur++) | |
218 | { | |
219 | cout << Cur.VerStr() << " - "; | |
220 | for (pkgCache::DepIterator Dep = Cur.DependsList(); Dep.end() != true; Dep++) | |
75ce2062 | 221 | cout << Dep.TargetPkg().FullName(true) << " (" << (int)Dep->CompareOp << " " << DeNull(Dep.TargetVer()) << ") "; |
1164783d AL |
222 | cout << endl; |
223 | } | |
224 | ||
225 | cout << "Provides: " << endl; | |
226 | for (pkgCache::VerIterator Cur = Pkg.VersionList(); Cur.end() != true; Cur++) | |
227 | { | |
228 | cout << Cur.VerStr() << " - "; | |
229 | for (pkgCache::PrvIterator Prv = Cur.ProvidesList(); Prv.end() != true; Prv++) | |
75ce2062 | 230 | cout << Prv.ParentPkg().FullName(true) << " "; |
1164783d | 231 | cout << endl; |
8efa2a3b AL |
232 | } |
233 | cout << "Reverse Provides: " << endl; | |
234 | for (pkgCache::PrvIterator Prv = Pkg.ProvidesList(); Prv.end() != true; Prv++) | |
75ce2062 | 235 | cout << Prv.OwnerPkg().FullName(true) << " " << Prv.OwnerVer().VerStr() << endl; |
1164783d AL |
236 | } |
237 | ||
238 | return true; | |
239 | } | |
240 | /*}}}*/ | |
241 | // Stats - Dump some nice statistics /*{{{*/ | |
242 | // --------------------------------------------------------------------- | |
243 | /* */ | |
b0b4efb9 | 244 | bool Stats(CommandLine &Cmd) |
1164783d | 245 | { |
b0b4efb9 | 246 | pkgCache &Cache = *GCache; |
173ae2a4 DK |
247 | cout << _("Total package names: ") << Cache.Head().GroupCount << " (" << |
248 | SizeToStr(Cache.Head().GroupCount*Cache.Head().GroupSz) << ')' << endl | |
249 | << _("Total package structures: ") << Cache.Head().PackageCount << " (" << | |
f826cfaa | 250 | SizeToStr(Cache.Head().PackageCount*Cache.Head().PackageSz) << ')' << endl; |
b2e465d6 | 251 | |
1164783d AL |
252 | int Normal = 0; |
253 | int Virtual = 0; | |
254 | int NVirt = 0; | |
255 | int DVirt = 0; | |
256 | int Missing = 0; | |
b2e465d6 | 257 | pkgCache::PkgIterator I = Cache.PkgBegin(); |
1164783d AL |
258 | for (;I.end() != true; I++) |
259 | { | |
260 | if (I->VersionList != 0 && I->ProvidesList == 0) | |
261 | { | |
262 | Normal++; | |
263 | continue; | |
264 | } | |
265 | ||
266 | if (I->VersionList != 0 && I->ProvidesList != 0) | |
267 | { | |
268 | NVirt++; | |
269 | continue; | |
270 | } | |
271 | ||
272 | if (I->VersionList == 0 && I->ProvidesList != 0) | |
273 | { | |
274 | // Only 1 provides | |
275 | if (I.ProvidesList()->NextProvides == 0) | |
276 | { | |
277 | DVirt++; | |
278 | } | |
279 | else | |
280 | Virtual++; | |
281 | continue; | |
282 | } | |
283 | if (I->VersionList == 0 && I->ProvidesList == 0) | |
284 | { | |
285 | Missing++; | |
286 | continue; | |
287 | } | |
288 | } | |
db0db9fe CP |
289 | cout << _(" Normal packages: ") << Normal << endl; |
290 | cout << _(" Pure virtual packages: ") << Virtual << endl; | |
291 | cout << _(" Single virtual packages: ") << DVirt << endl; | |
292 | cout << _(" Mixed virtual packages: ") << NVirt << endl; | |
b2e465d6 | 293 | cout << _(" Missing: ") << Missing << endl; |
1164783d | 294 | |
db0db9fe | 295 | cout << _("Total distinct versions: ") << Cache.Head().VersionCount << " (" << |
f826cfaa | 296 | SizeToStr(Cache.Head().VersionCount*Cache.Head().VersionSz) << ')' << endl; |
12bffed7 | 297 | cout << _("Total distinct descriptions: ") << Cache.Head().DescriptionCount << " (" << |
a52f938b | 298 | SizeToStr(Cache.Head().DescriptionCount*Cache.Head().DescriptionSz) << ')' << endl; |
db0db9fe | 299 | cout << _("Total dependencies: ") << Cache.Head().DependsCount << " (" << |
f826cfaa AL |
300 | SizeToStr(Cache.Head().DependsCount*Cache.Head().DependencySz) << ')' << endl; |
301 | ||
db0db9fe | 302 | cout << _("Total ver/file relations: ") << Cache.Head().VerFileCount << " (" << |
a7e66b17 | 303 | SizeToStr(Cache.Head().VerFileCount*Cache.Head().VerFileSz) << ')' << endl; |
a52f938b OS |
304 | cout << _("Total Desc/File relations: ") << Cache.Head().DescFileCount << " (" << |
305 | SizeToStr(Cache.Head().DescFileCount*Cache.Head().DescFileSz) << ')' << endl; | |
db0db9fe | 306 | cout << _("Total Provides mappings: ") << Cache.Head().ProvidesCount << " (" << |
a7e66b17 | 307 | SizeToStr(Cache.Head().ProvidesCount*Cache.Head().ProvidesSz) << ')' << endl; |
f826cfaa AL |
308 | |
309 | // String list stats | |
310 | unsigned long Size = 0; | |
311 | unsigned long Count = 0; | |
312 | for (pkgCache::StringItem *I = Cache.StringItemP + Cache.Head().StringList; | |
313 | I!= Cache.StringItemP; I = Cache.StringItemP + I->NextItem) | |
314 | { | |
315 | Count++; | |
b2e465d6 | 316 | Size += strlen(Cache.StrP + I->String) + 1; |
f826cfaa | 317 | } |
db0db9fe | 318 | cout << _("Total globbed strings: ") << Count << " (" << SizeToStr(Size) << ')' << endl; |
b2e465d6 AL |
319 | |
320 | unsigned long DepVerSize = 0; | |
321 | for (pkgCache::PkgIterator P = Cache.PkgBegin(); P.end() == false; P++) | |
322 | { | |
323 | for (pkgCache::VerIterator V = P.VersionList(); V.end() == false; V++) | |
324 | { | |
325 | for (pkgCache::DepIterator D = V.DependsList(); D.end() == false; D++) | |
326 | { | |
327 | if (D->Version != 0) | |
328 | DepVerSize += strlen(D.TargetVer()) + 1; | |
329 | } | |
330 | } | |
331 | } | |
db0db9fe | 332 | cout << _("Total dependency version space: ") << SizeToStr(DepVerSize) << endl; |
b2e465d6 | 333 | |
f826cfaa AL |
334 | unsigned long Slack = 0; |
335 | for (int I = 0; I != 7; I++) | |
336 | Slack += Cache.Head().Pools[I].ItemSize*Cache.Head().Pools[I].Count; | |
db0db9fe | 337 | cout << _("Total slack space: ") << SizeToStr(Slack) << endl; |
f826cfaa AL |
338 | |
339 | unsigned long Total = 0; | |
340 | Total = Slack + Size + Cache.Head().DependsCount*Cache.Head().DependencySz + | |
341 | Cache.Head().VersionCount*Cache.Head().VersionSz + | |
a7e66b17 AL |
342 | Cache.Head().PackageCount*Cache.Head().PackageSz + |
343 | Cache.Head().VerFileCount*Cache.Head().VerFileSz + | |
344 | Cache.Head().ProvidesCount*Cache.Head().ProvidesSz; | |
db0db9fe | 345 | cout << _("Total space accounted for: ") << SizeToStr(Total) << endl; |
f826cfaa | 346 | |
83d89a9f AL |
347 | return true; |
348 | } | |
349 | /*}}}*/ | |
1164783d AL |
350 | // Dump - show everything /*{{{*/ |
351 | // --------------------------------------------------------------------- | |
b2e465d6 | 352 | /* This is worthless except fer debugging things */ |
b0b4efb9 | 353 | bool Dump(CommandLine &Cmd) |
1164783d | 354 | { |
b0b4efb9 | 355 | pkgCache &Cache = *GCache; |
b2e465d6 AL |
356 | cout << "Using Versioning System: " << Cache.VS->Label << endl; |
357 | ||
1164783d AL |
358 | for (pkgCache::PkgIterator P = Cache.PkgBegin(); P.end() == false; P++) |
359 | { | |
75ce2062 | 360 | cout << "Package: " << P.FullName(true) << endl; |
1164783d AL |
361 | for (pkgCache::VerIterator V = P.VersionList(); V.end() == false; V++) |
362 | { | |
363 | cout << " Version: " << V.VerStr() << endl; | |
364 | cout << " File: " << V.FileList().File().FileName() << endl; | |
365 | for (pkgCache::DepIterator D = V.DependsList(); D.end() == false; D++) | |
75ce2062 | 366 | cout << " Depends: " << D.TargetPkg().FullName(true) << ' ' << |
076d01b0 | 367 | DeNull(D.TargetVer()) << endl; |
a52f938b OS |
368 | for (pkgCache::DescIterator D = V.DescriptionList(); D.end() == false; D++) |
369 | { | |
370 | cout << " Description Language: " << D.LanguageCode() << endl | |
371 | << " File: " << D.FileList().File().FileName() << endl | |
372 | << " MD5: " << D.md5() << endl; | |
373 | } | |
1164783d AL |
374 | } |
375 | } | |
376 | ||
b2e465d6 | 377 | for (pkgCache::PkgFileIterator F = Cache.FileBegin(); F.end() == false; F++) |
1164783d AL |
378 | { |
379 | cout << "File: " << F.FileName() << endl; | |
b2e465d6 | 380 | cout << " Type: " << F.IndexType() << endl; |
1164783d AL |
381 | cout << " Size: " << F->Size << endl; |
382 | cout << " ID: " << F->ID << endl; | |
383 | cout << " Flags: " << F->Flags << endl; | |
b0b4efb9 | 384 | cout << " Time: " << TimeRFC1123(F->mtime) << endl; |
076d01b0 AL |
385 | cout << " Archive: " << DeNull(F.Archive()) << endl; |
386 | cout << " Component: " << DeNull(F.Component()) << endl; | |
387 | cout << " Version: " << DeNull(F.Version()) << endl; | |
388 | cout << " Origin: " << DeNull(F.Origin()) << endl; | |
389 | cout << " Site: " << DeNull(F.Site()) << endl; | |
390 | cout << " Label: " << DeNull(F.Label()) << endl; | |
391 | cout << " Architecture: " << DeNull(F.Architecture()) << endl; | |
1164783d AL |
392 | } |
393 | ||
394 | return true; | |
395 | } | |
396 | /*}}}*/ | |
397 | // DumpAvail - Print out the available list /*{{{*/ | |
398 | // --------------------------------------------------------------------- | |
b2e465d6 AL |
399 | /* This is needed to make dpkg --merge happy.. I spent a bit of time to |
400 | make this run really fast, perhaps I went a little overboard.. */ | |
b0b4efb9 | 401 | bool DumpAvail(CommandLine &Cmd) |
1164783d | 402 | { |
b0b4efb9 | 403 | pkgCache &Cache = *GCache; |
1164783d | 404 | |
b2e465d6 | 405 | pkgPolicy Plcy(&Cache); |
e68ca100 | 406 | if (ReadPinFile(Plcy) == false || ReadPinDir(Plcy) == false) |
b2e465d6 AL |
407 | return false; |
408 | ||
fe648919 AL |
409 | unsigned long Count = Cache.HeaderP->PackageCount+1; |
410 | pkgCache::VerFile **VFList = new pkgCache::VerFile *[Count]; | |
411 | memset(VFList,0,sizeof(*VFList)*Count); | |
b2e465d6 AL |
412 | |
413 | // Map versions that we want to write out onto the VerList array. | |
414 | for (pkgCache::PkgIterator P = Cache.PkgBegin(); P.end() == false; P++) | |
415 | { | |
416 | if (P->VersionList == 0) | |
5b8c90bf AL |
417 | continue; |
418 | ||
b2e465d6 AL |
419 | /* Find the proper version to use. If the policy says there are no |
420 | possible selections we return the installed version, if available.. | |
421 | This prevents dselect from making it obsolete. */ | |
422 | pkgCache::VerIterator V = Plcy.GetCandidateVer(P); | |
423 | if (V.end() == true) | |
ad00ae81 | 424 | { |
b2e465d6 AL |
425 | if (P->CurrentVer == 0) |
426 | continue; | |
427 | V = P.CurrentVer(); | |
ad00ae81 | 428 | } |
1164783d | 429 | |
b2e465d6 AL |
430 | pkgCache::VerFileIterator VF = V.FileList(); |
431 | for (; VF.end() == false ; VF++) | |
432 | if ((VF.File()->Flags & pkgCache::Flag::NotSource) == 0) | |
433 | break; | |
434 | ||
435 | /* Okay, here we have a bit of a problem.. The policy has selected the | |
436 | currently installed package - however it only exists in the | |
437 | status file.. We need to write out something or dselect will mark | |
438 | the package as obsolete! Thus we emit the status file entry, but | |
439 | below we remove the status line to make it valid for the | |
440 | available file. However! We only do this if their do exist *any* | |
441 | non-source versions of the package - that way the dselect obsolete | |
442 | handling works OK. */ | |
443 | if (VF.end() == true) | |
1164783d | 444 | { |
b2e465d6 AL |
445 | for (pkgCache::VerIterator Cur = P.VersionList(); Cur.end() != true; Cur++) |
446 | { | |
447 | for (VF = Cur.FileList(); VF.end() == false; VF++) | |
448 | { | |
449 | if ((VF.File()->Flags & pkgCache::Flag::NotSource) == 0) | |
450 | { | |
451 | VF = V.FileList(); | |
452 | break; | |
453 | } | |
454 | } | |
455 | ||
456 | if (VF.end() == false) | |
457 | break; | |
458 | } | |
ad00ae81 | 459 | } |
b2e465d6 AL |
460 | |
461 | VFList[P->ID] = VF; | |
462 | } | |
463 | ||
fe648919 | 464 | LocalitySort(VFList,Count,sizeof(*VFList)); |
ad00ae81 | 465 | |
b2e465d6 AL |
466 | // Iterate over all the package files and write them out. |
467 | char *Buffer = new char[Cache.HeaderP->MaxVerFileSize+10]; | |
468 | for (pkgCache::VerFile **J = VFList; *J != 0;) | |
469 | { | |
470 | pkgCache::PkgFileIterator File(Cache,(*J)->File + Cache.PkgFileP); | |
471 | if (File.IsOk() == false) | |
ad00ae81 | 472 | { |
b2e465d6 AL |
473 | _error->Error(_("Package file %s is out of sync."),File.FileName()); |
474 | break; | |
475 | } | |
bd432be3 | 476 | |
b2e465d6 AL |
477 | FileFd PkgF(File.FileName(),FileFd::ReadOnly); |
478 | if (_error->PendingError() == true) | |
479 | break; | |
480 | ||
481 | /* Write all of the records from this package file, since we | |
482 | already did locality sorting we can now just seek through the | |
483 | file in read order. We apply 1 more optimization here, since often | |
484 | there will be < 1 byte gaps between records (for the \n) we read that | |
485 | into the next buffer and offset a bit.. */ | |
486 | unsigned long Pos = 0; | |
487 | for (; *J != 0; J++) | |
488 | { | |
489 | if ((*J)->File + Cache.PkgFileP != File) | |
490 | break; | |
bd432be3 | 491 | |
b2e465d6 AL |
492 | const pkgCache::VerFile &VF = **J; |
493 | ||
bd432be3 | 494 | // Read the record and then write it out again. |
b2e465d6 AL |
495 | unsigned long Jitter = VF.Offset - Pos; |
496 | if (Jitter > 8) | |
1164783d | 497 | { |
b2e465d6 AL |
498 | if (PkgF.Seek(VF.Offset) == false) |
499 | break; | |
500 | Jitter = 0; | |
501 | } | |
502 | ||
503 | if (PkgF.Read(Buffer,VF.Size + Jitter) == false) | |
504 | break; | |
505 | Buffer[VF.Size + Jitter] = '\n'; | |
506 | ||
507 | // See above.. | |
508 | if ((File->Flags & pkgCache::Flag::NotSource) == pkgCache::Flag::NotSource) | |
509 | { | |
510 | pkgTagSection Tags; | |
e8cbb49f | 511 | TFRewriteData RW[] = {{"Status",0},{"Config-Version",0},{}}; |
b2e465d6 AL |
512 | const char *Zero = 0; |
513 | if (Tags.Scan(Buffer+Jitter,VF.Size+1) == false || | |
514 | TFRewrite(stdout,Tags,&Zero,RW) == false) | |
515 | { | |
516 | _error->Error("Internal Error, Unable to parse a package record"); | |
517 | break; | |
518 | } | |
519 | fputc('\n',stdout); | |
520 | } | |
521 | else | |
522 | { | |
523 | if (fwrite(Buffer+Jitter,VF.Size+1,1,stdout) != 1) | |
524 | break; | |
525 | } | |
526 | ||
527 | Pos = VF.Offset + VF.Size; | |
1164783d | 528 | } |
b2e465d6 AL |
529 | |
530 | fflush(stdout); | |
531 | if (_error->PendingError() == true) | |
532 | break; | |
ad00ae81 AL |
533 | } |
534 | ||
b2e465d6 AL |
535 | delete [] Buffer; |
536 | delete [] VFList; | |
537 | return !_error->PendingError(); | |
349cd3b8 AL |
538 | } |
539 | /*}}}*/ | |
4b1b89c5 | 540 | // Depends - Print out a dependency tree /*{{{*/ |
349cd3b8 AL |
541 | // --------------------------------------------------------------------- |
542 | /* */ | |
543 | bool Depends(CommandLine &CmdL) | |
544 | { | |
545 | pkgCache &Cache = *GCache; | |
b2e465d6 AL |
546 | SPtrArray<unsigned> Colours = new unsigned[Cache.Head().PackageCount]; |
547 | memset(Colours,0,sizeof(*Colours)*Cache.Head().PackageCount); | |
349cd3b8 AL |
548 | |
549 | for (const char **I = CmdL.FileList + 1; *I != 0; I++) | |
550 | { | |
551 | pkgCache::PkgIterator Pkg = Cache.FindPkg(*I); | |
552 | if (Pkg.end() == true) | |
553 | { | |
b2e465d6 | 554 | _error->Warning(_("Unable to locate package %s"),*I); |
349cd3b8 AL |
555 | continue; |
556 | } | |
b2e465d6 AL |
557 | Colours[Pkg->ID] = 1; |
558 | } | |
559 | ||
560 | bool Recurse = _config->FindB("APT::Cache::RecurseDepends",false); | |
eba2b51d | 561 | bool Installed = _config->FindB("APT::Cache::Installed",false); |
5aa95c86 | 562 | bool Important = _config->FindB("APT::Cache::Important",false); |
b2e465d6 AL |
563 | bool DidSomething; |
564 | do | |
565 | { | |
566 | DidSomething = false; | |
567 | for (pkgCache::PkgIterator Pkg = Cache.PkgBegin(); Pkg.end() == false; Pkg++) | |
349cd3b8 | 568 | { |
b2e465d6 AL |
569 | if (Colours[Pkg->ID] != 1) |
570 | continue; | |
571 | Colours[Pkg->ID] = 2; | |
572 | DidSomething = true; | |
349cd3b8 | 573 | |
b2e465d6 AL |
574 | pkgCache::VerIterator Ver = Pkg.VersionList(); |
575 | if (Ver.end() == true) | |
349cd3b8 | 576 | { |
75ce2062 | 577 | cout << '<' << Pkg.FullName(true) << '>' << endl; |
b2e465d6 | 578 | continue; |
349cd3b8 | 579 | } |
b2e465d6 | 580 | |
75ce2062 | 581 | cout << Pkg.FullName(true) << endl; |
b2e465d6 AL |
582 | |
583 | for (pkgCache::DepIterator D = Ver.DependsList(); D.end() == false; D++) | |
584 | { | |
5aa95c86 MV |
585 | // Important deps only |
586 | if (Important == true) | |
587 | if (D->Type != pkgCache::Dep::PreDepends && | |
588 | D->Type != pkgCache::Dep::Depends) | |
589 | continue; | |
590 | ||
b2e465d6 | 591 | pkgCache::PkgIterator Trg = D.TargetPkg(); |
eba2b51d AL |
592 | |
593 | if((Installed && Trg->CurrentVer != 0) || !Installed) | |
594 | { | |
595 | ||
596 | if ((D->CompareOp & pkgCache::Dep::Or) == pkgCache::Dep::Or) | |
597 | cout << " |"; | |
598 | else | |
599 | cout << " "; | |
b2e465d6 | 600 | |
eba2b51d AL |
601 | // Show the package |
602 | if (Trg->VersionList == 0) | |
75ce2062 | 603 | cout << D.DepType() << ": <" << Trg.FullName(true) << ">" << endl; |
eba2b51d | 604 | else |
75ce2062 | 605 | cout << D.DepType() << ": " << Trg.FullName(true) << endl; |
eba2b51d AL |
606 | |
607 | if (Recurse == true) | |
608 | Colours[D.TargetPkg()->ID]++; | |
609 | ||
610 | } | |
b2e465d6 AL |
611 | |
612 | // Display all solutions | |
613 | SPtrArray<pkgCache::Version *> List = D.AllTargets(); | |
614 | pkgPrioSortList(Cache,List); | |
615 | for (pkgCache::Version **I = List; *I != 0; I++) | |
616 | { | |
617 | pkgCache::VerIterator V(Cache,*I); | |
618 | if (V != Cache.VerP + V.ParentPkg()->VersionList || | |
619 | V->ParentPkg == D->Package) | |
620 | continue; | |
75ce2062 | 621 | cout << " " << V.ParentPkg().FullName(true) << endl; |
b2e465d6 AL |
622 | |
623 | if (Recurse == true) | |
624 | Colours[D.ParentPkg()->ID]++; | |
625 | } | |
626 | } | |
627 | } | |
349cd3b8 | 628 | } |
b2e465d6 | 629 | while (DidSomething == true); |
349cd3b8 | 630 | |
3e94da1b AL |
631 | return true; |
632 | } | |
92fcbfc1 | 633 | /*}}}*/ |
eba2b51d AL |
634 | // RDepends - Print out a reverse dependency tree - mbc /*{{{*/ |
635 | // --------------------------------------------------------------------- | |
636 | /* */ | |
637 | bool RDepends(CommandLine &CmdL) | |
638 | { | |
639 | pkgCache &Cache = *GCache; | |
640 | SPtrArray<unsigned> Colours = new unsigned[Cache.Head().PackageCount]; | |
641 | memset(Colours,0,sizeof(*Colours)*Cache.Head().PackageCount); | |
642 | ||
643 | for (const char **I = CmdL.FileList + 1; *I != 0; I++) | |
644 | { | |
645 | pkgCache::PkgIterator Pkg = Cache.FindPkg(*I); | |
646 | if (Pkg.end() == true) | |
647 | { | |
648 | _error->Warning(_("Unable to locate package %s"),*I); | |
649 | continue; | |
650 | } | |
651 | Colours[Pkg->ID] = 1; | |
652 | } | |
653 | ||
654 | bool Recurse = _config->FindB("APT::Cache::RecurseDepends",false); | |
655 | bool Installed = _config->FindB("APT::Cache::Installed",false); | |
656 | bool DidSomething; | |
657 | do | |
658 | { | |
659 | DidSomething = false; | |
660 | for (pkgCache::PkgIterator Pkg = Cache.PkgBegin(); Pkg.end() == false; Pkg++) | |
661 | { | |
662 | if (Colours[Pkg->ID] != 1) | |
663 | continue; | |
664 | Colours[Pkg->ID] = 2; | |
665 | DidSomething = true; | |
666 | ||
667 | pkgCache::VerIterator Ver = Pkg.VersionList(); | |
668 | if (Ver.end() == true) | |
669 | { | |
75ce2062 | 670 | cout << '<' << Pkg.FullName(true) << '>' << endl; |
eba2b51d AL |
671 | continue; |
672 | } | |
673 | ||
75ce2062 | 674 | cout << Pkg.FullName(true) << endl; |
eba2b51d AL |
675 | |
676 | cout << "Reverse Depends:" << endl; | |
677 | for (pkgCache::DepIterator D = Pkg.RevDependsList(); D.end() == false; D++) | |
678 | { | |
679 | // Show the package | |
680 | pkgCache::PkgIterator Trg = D.ParentPkg(); | |
681 | ||
682 | if((Installed && Trg->CurrentVer != 0) || !Installed) | |
683 | { | |
684 | ||
685 | if ((D->CompareOp & pkgCache::Dep::Or) == pkgCache::Dep::Or) | |
686 | cout << " |"; | |
687 | else | |
688 | cout << " "; | |
689 | ||
690 | if (Trg->VersionList == 0) | |
75ce2062 | 691 | cout << D.DepType() << ": <" << Trg.FullName(true) << ">" << endl; |
eba2b51d | 692 | else |
75ce2062 | 693 | cout << Trg.FullName(true) << endl; |
eba2b51d AL |
694 | |
695 | if (Recurse == true) | |
696 | Colours[D.ParentPkg()->ID]++; | |
697 | ||
698 | } | |
699 | ||
700 | // Display all solutions | |
701 | SPtrArray<pkgCache::Version *> List = D.AllTargets(); | |
702 | pkgPrioSortList(Cache,List); | |
703 | for (pkgCache::Version **I = List; *I != 0; I++) | |
704 | { | |
705 | pkgCache::VerIterator V(Cache,*I); | |
706 | if (V != Cache.VerP + V.ParentPkg()->VersionList || | |
707 | V->ParentPkg == D->Package) | |
708 | continue; | |
75ce2062 | 709 | cout << " " << V.ParentPkg().FullName(true) << endl; |
eba2b51d AL |
710 | |
711 | if (Recurse == true) | |
712 | Colours[D.ParentPkg()->ID]++; | |
713 | } | |
714 | } | |
715 | } | |
716 | } | |
717 | while (DidSomething == true); | |
718 | ||
719 | return true; | |
720 | } | |
3e94da1b | 721 | /*}}}*/ |
fff4b7f3 AL |
722 | // xvcg - Generate a graph for xvcg /*{{{*/ |
723 | // --------------------------------------------------------------------- | |
724 | // Code contributed from Junichi Uekawa <dancer@debian.org> on 20 June 2002. | |
725 | ||
726 | bool XVcg(CommandLine &CmdL) | |
727 | { | |
728 | pkgCache &Cache = *GCache; | |
729 | bool GivenOnly = _config->FindB("APT::Cache::GivenOnly",false); | |
730 | ||
731 | /* Normal packages are boxes | |
732 | Pure Provides are triangles | |
733 | Mixed are diamonds | |
734 | rhomb are missing packages*/ | |
735 | const char *Shapes[] = {"ellipse","triangle","box","rhomb"}; | |
736 | ||
737 | /* Initialize the list of packages to show. | |
738 | 1 = To Show | |
739 | 2 = To Show no recurse | |
740 | 3 = Emitted no recurse | |
741 | 4 = Emitted | |
742 | 0 = None */ | |
743 | enum States {None=0, ToShow, ToShowNR, DoneNR, Done}; | |
744 | enum TheFlags {ForceNR=(1<<0)}; | |
745 | unsigned char *Show = new unsigned char[Cache.Head().PackageCount]; | |
746 | unsigned char *Flags = new unsigned char[Cache.Head().PackageCount]; | |
747 | unsigned char *ShapeMap = new unsigned char[Cache.Head().PackageCount]; | |
748 | ||
749 | // Show everything if no arguments given | |
750 | if (CmdL.FileList[1] == 0) | |
751 | for (unsigned long I = 0; I != Cache.Head().PackageCount; I++) | |
752 | Show[I] = ToShow; | |
753 | else | |
754 | for (unsigned long I = 0; I != Cache.Head().PackageCount; I++) | |
755 | Show[I] = None; | |
756 | memset(Flags,0,sizeof(*Flags)*Cache.Head().PackageCount); | |
757 | ||
758 | // Map the shapes | |
759 | for (pkgCache::PkgIterator Pkg = Cache.PkgBegin(); Pkg.end() == false; Pkg++) | |
760 | { | |
761 | if (Pkg->VersionList == 0) | |
762 | { | |
763 | // Missing | |
764 | if (Pkg->ProvidesList == 0) | |
765 | ShapeMap[Pkg->ID] = 0; | |
766 | else | |
767 | ShapeMap[Pkg->ID] = 1; | |
768 | } | |
769 | else | |
770 | { | |
771 | // Normal | |
772 | if (Pkg->ProvidesList == 0) | |
773 | ShapeMap[Pkg->ID] = 2; | |
774 | else | |
775 | ShapeMap[Pkg->ID] = 3; | |
776 | } | |
777 | } | |
778 | ||
779 | // Load the list of packages from the command line into the show list | |
780 | for (const char **I = CmdL.FileList + 1; *I != 0; I++) | |
781 | { | |
782 | // Process per-package flags | |
783 | string P = *I; | |
784 | bool Force = false; | |
785 | if (P.length() > 3) | |
786 | { | |
787 | if (P.end()[-1] == '^') | |
788 | { | |
789 | Force = true; | |
790 | P.erase(P.end()-1); | |
791 | } | |
792 | ||
793 | if (P.end()[-1] == ',') | |
794 | P.erase(P.end()-1); | |
795 | } | |
796 | ||
797 | // Locate the package | |
798 | pkgCache::PkgIterator Pkg = Cache.FindPkg(P); | |
799 | if (Pkg.end() == true) | |
800 | { | |
801 | _error->Warning(_("Unable to locate package %s"),*I); | |
802 | continue; | |
803 | } | |
804 | Show[Pkg->ID] = ToShow; | |
805 | ||
806 | if (Force == true) | |
807 | Flags[Pkg->ID] |= ForceNR; | |
808 | } | |
809 | ||
810 | // Little header | |
811 | cout << "graph: { title: \"packages\"" << endl << | |
812 | "xmax: 700 ymax: 700 x: 30 y: 30" << endl << | |
813 | "layout_downfactor: 8" << endl; | |
814 | ||
815 | bool Act = true; | |
816 | while (Act == true) | |
817 | { | |
818 | Act = false; | |
819 | for (pkgCache::PkgIterator Pkg = Cache.PkgBegin(); Pkg.end() == false; Pkg++) | |
820 | { | |
821 | // See we need to show this package | |
822 | if (Show[Pkg->ID] == None || Show[Pkg->ID] >= DoneNR) | |
823 | continue; | |
824 | ||
825 | //printf ("node: { title: \"%s\" label: \"%s\" }\n", Pkg.Name(), Pkg.Name()); | |
826 | ||
827 | // Colour as done | |
828 | if (Show[Pkg->ID] == ToShowNR || (Flags[Pkg->ID] & ForceNR) == ForceNR) | |
829 | { | |
830 | // Pure Provides and missing packages have no deps! | |
831 | if (ShapeMap[Pkg->ID] == 0 || ShapeMap[Pkg->ID] == 1) | |
832 | Show[Pkg->ID] = Done; | |
833 | else | |
834 | Show[Pkg->ID] = DoneNR; | |
835 | } | |
836 | else | |
837 | Show[Pkg->ID] = Done; | |
838 | Act = true; | |
839 | ||
840 | // No deps to map out | |
841 | if (Pkg->VersionList == 0 || Show[Pkg->ID] == DoneNR) | |
842 | continue; | |
843 | ||
844 | pkgCache::VerIterator Ver = Pkg.VersionList(); | |
845 | for (pkgCache::DepIterator D = Ver.DependsList(); D.end() == false; D++) | |
846 | { | |
847 | // See if anything can meet this dep | |
848 | // Walk along the actual package providing versions | |
849 | bool Hit = false; | |
850 | pkgCache::PkgIterator DPkg = D.TargetPkg(); | |
851 | for (pkgCache::VerIterator I = DPkg.VersionList(); | |
852 | I.end() == false && Hit == false; I++) | |
853 | { | |
854 | if (Cache.VS->CheckDep(I.VerStr(),D->CompareOp,D.TargetVer()) == true) | |
855 | Hit = true; | |
856 | } | |
857 | ||
858 | // Follow all provides | |
859 | for (pkgCache::PrvIterator I = DPkg.ProvidesList(); | |
860 | I.end() == false && Hit == false; I++) | |
861 | { | |
862 | if (Cache.VS->CheckDep(I.ProvideVersion(),D->CompareOp,D.TargetVer()) == false) | |
863 | Hit = true; | |
864 | } | |
865 | ||
866 | ||
867 | // Only graph critical deps | |
868 | if (D.IsCritical() == true) | |
869 | { | |
75ce2062 | 870 | printf ("edge: { sourcename: \"%s\" targetname: \"%s\" class: 2 ",Pkg.FullName(true).c_str(), D.TargetPkg().FullName(true).c_str() ); |
fff4b7f3 AL |
871 | |
872 | // Colour the node for recursion | |
873 | if (Show[D.TargetPkg()->ID] <= DoneNR) | |
874 | { | |
875 | /* If a conflicts does not meet anything in the database | |
876 | then show the relation but do not recurse */ | |
877 | if (Hit == false && | |
878 | (D->Type == pkgCache::Dep::Conflicts || | |
308c7d30 | 879 | D->Type == pkgCache::Dep::DpkgBreaks || |
fff4b7f3 AL |
880 | D->Type == pkgCache::Dep::Obsoletes)) |
881 | { | |
882 | if (Show[D.TargetPkg()->ID] == None && | |
883 | Show[D.TargetPkg()->ID] != ToShow) | |
884 | Show[D.TargetPkg()->ID] = ToShowNR; | |
885 | } | |
886 | else | |
887 | { | |
888 | if (GivenOnly == true && Show[D.TargetPkg()->ID] != ToShow) | |
889 | Show[D.TargetPkg()->ID] = ToShowNR; | |
890 | else | |
891 | Show[D.TargetPkg()->ID] = ToShow; | |
892 | } | |
893 | } | |
894 | ||
895 | // Edge colour | |
896 | switch(D->Type) | |
897 | { | |
898 | case pkgCache::Dep::Conflicts: | |
899 | printf("label: \"conflicts\" color: lightgreen }\n"); | |
900 | break; | |
308c7d30 IJ |
901 | case pkgCache::Dep::DpkgBreaks: |
902 | printf("label: \"breaks\" color: lightgreen }\n"); | |
903 | break; | |
fff4b7f3 AL |
904 | case pkgCache::Dep::Obsoletes: |
905 | printf("label: \"obsoletes\" color: lightgreen }\n"); | |
906 | break; | |
907 | ||
908 | case pkgCache::Dep::PreDepends: | |
909 | printf("label: \"predepends\" color: blue }\n"); | |
910 | break; | |
911 | ||
912 | default: | |
913 | printf("}\n"); | |
914 | break; | |
915 | } | |
916 | } | |
917 | } | |
918 | } | |
919 | } | |
920 | ||
921 | /* Draw the box colours after the fact since we can not tell what colour | |
922 | they should be until everything is finished drawing */ | |
923 | for (pkgCache::PkgIterator Pkg = Cache.PkgBegin(); Pkg.end() == false; Pkg++) | |
924 | { | |
925 | if (Show[Pkg->ID] < DoneNR) | |
926 | continue; | |
927 | ||
928 | if (Show[Pkg->ID] == DoneNR) | |
75ce2062 | 929 | printf("node: { title: \"%s\" label: \"%s\" color: orange shape: %s }\n", Pkg.FullName(true).c_str(), Pkg.FullName(true).c_str(), |
fff4b7f3 AL |
930 | Shapes[ShapeMap[Pkg->ID]]); |
931 | else | |
75ce2062 | 932 | printf("node: { title: \"%s\" label: \"%s\" shape: %s }\n", Pkg.FullName(true).c_str(), Pkg.FullName(true).c_str(), |
fff4b7f3 AL |
933 | Shapes[ShapeMap[Pkg->ID]]); |
934 | ||
935 | } | |
03496041 DK |
936 | |
937 | delete[] Show; | |
938 | delete[] Flags; | |
939 | delete[] ShapeMap; | |
940 | ||
fff4b7f3 AL |
941 | printf("}\n"); |
942 | return true; | |
943 | } | |
944 | /*}}}*/ | |
3e94da1b AL |
945 | // Dotty - Generate a graph for Dotty /*{{{*/ |
946 | // --------------------------------------------------------------------- | |
947 | /* Dotty is the graphvis program for generating graphs. It is a fairly | |
948 | simple queuing algorithm that just writes dependencies and nodes. | |
949 | http://www.research.att.com/sw/tools/graphviz/ */ | |
950 | bool Dotty(CommandLine &CmdL) | |
951 | { | |
952 | pkgCache &Cache = *GCache; | |
953 | bool GivenOnly = _config->FindB("APT::Cache::GivenOnly",false); | |
954 | ||
955 | /* Normal packages are boxes | |
956 | Pure Provides are triangles | |
957 | Mixed are diamonds | |
958 | Hexagons are missing packages*/ | |
959 | const char *Shapes[] = {"hexagon","triangle","box","diamond"}; | |
960 | ||
961 | /* Initialize the list of packages to show. | |
962 | 1 = To Show | |
963 | 2 = To Show no recurse | |
964 | 3 = Emitted no recurse | |
965 | 4 = Emitted | |
966 | 0 = None */ | |
967 | enum States {None=0, ToShow, ToShowNR, DoneNR, Done}; | |
968 | enum TheFlags {ForceNR=(1<<0)}; | |
969 | unsigned char *Show = new unsigned char[Cache.Head().PackageCount]; | |
970 | unsigned char *Flags = new unsigned char[Cache.Head().PackageCount]; | |
971 | unsigned char *ShapeMap = new unsigned char[Cache.Head().PackageCount]; | |
972 | ||
973 | // Show everything if no arguments given | |
974 | if (CmdL.FileList[1] == 0) | |
975 | for (unsigned long I = 0; I != Cache.Head().PackageCount; I++) | |
976 | Show[I] = ToShow; | |
977 | else | |
978 | for (unsigned long I = 0; I != Cache.Head().PackageCount; I++) | |
979 | Show[I] = None; | |
980 | memset(Flags,0,sizeof(*Flags)*Cache.Head().PackageCount); | |
981 | ||
982 | // Map the shapes | |
983 | for (pkgCache::PkgIterator Pkg = Cache.PkgBegin(); Pkg.end() == false; Pkg++) | |
984 | { | |
985 | if (Pkg->VersionList == 0) | |
986 | { | |
987 | // Missing | |
988 | if (Pkg->ProvidesList == 0) | |
989 | ShapeMap[Pkg->ID] = 0; | |
990 | else | |
991 | ShapeMap[Pkg->ID] = 1; | |
992 | } | |
993 | else | |
994 | { | |
995 | // Normal | |
996 | if (Pkg->ProvidesList == 0) | |
997 | ShapeMap[Pkg->ID] = 2; | |
998 | else | |
999 | ShapeMap[Pkg->ID] = 3; | |
1000 | } | |
1001 | } | |
1002 | ||
1003 | // Load the list of packages from the command line into the show list | |
1004 | for (const char **I = CmdL.FileList + 1; *I != 0; I++) | |
1005 | { | |
1006 | // Process per-package flags | |
1007 | string P = *I; | |
1008 | bool Force = false; | |
1009 | if (P.length() > 3) | |
1010 | { | |
1011 | if (P.end()[-1] == '^') | |
1012 | { | |
1013 | Force = true; | |
1014 | P.erase(P.end()-1); | |
1015 | } | |
1016 | ||
1017 | if (P.end()[-1] == ',') | |
1018 | P.erase(P.end()-1); | |
1019 | } | |
1020 | ||
1021 | // Locate the package | |
1022 | pkgCache::PkgIterator Pkg = Cache.FindPkg(P); | |
1023 | if (Pkg.end() == true) | |
1024 | { | |
b2e465d6 | 1025 | _error->Warning(_("Unable to locate package %s"),*I); |
3e94da1b AL |
1026 | continue; |
1027 | } | |
1028 | Show[Pkg->ID] = ToShow; | |
1029 | ||
1030 | if (Force == true) | |
1031 | Flags[Pkg->ID] |= ForceNR; | |
1032 | } | |
1033 | ||
1034 | // Little header | |
1035 | printf("digraph packages {\n"); | |
1036 | printf("concentrate=true;\n"); | |
1037 | printf("size=\"30,40\";\n"); | |
1038 | ||
1039 | bool Act = true; | |
1040 | while (Act == true) | |
1041 | { | |
1042 | Act = false; | |
1043 | for (pkgCache::PkgIterator Pkg = Cache.PkgBegin(); Pkg.end() == false; Pkg++) | |
1044 | { | |
1045 | // See we need to show this package | |
1046 | if (Show[Pkg->ID] == None || Show[Pkg->ID] >= DoneNR) | |
1047 | continue; | |
1048 | ||
1049 | // Colour as done | |
1050 | if (Show[Pkg->ID] == ToShowNR || (Flags[Pkg->ID] & ForceNR) == ForceNR) | |
1051 | { | |
1052 | // Pure Provides and missing packages have no deps! | |
1053 | if (ShapeMap[Pkg->ID] == 0 || ShapeMap[Pkg->ID] == 1) | |
1054 | Show[Pkg->ID] = Done; | |
1055 | else | |
1056 | Show[Pkg->ID] = DoneNR; | |
1057 | } | |
1058 | else | |
1059 | Show[Pkg->ID] = Done; | |
1060 | Act = true; | |
1061 | ||
1062 | // No deps to map out | |
1063 | if (Pkg->VersionList == 0 || Show[Pkg->ID] == DoneNR) | |
1064 | continue; | |
1065 | ||
1066 | pkgCache::VerIterator Ver = Pkg.VersionList(); | |
1067 | for (pkgCache::DepIterator D = Ver.DependsList(); D.end() == false; D++) | |
1068 | { | |
1069 | // See if anything can meet this dep | |
1070 | // Walk along the actual package providing versions | |
1071 | bool Hit = false; | |
1072 | pkgCache::PkgIterator DPkg = D.TargetPkg(); | |
1073 | for (pkgCache::VerIterator I = DPkg.VersionList(); | |
1074 | I.end() == false && Hit == false; I++) | |
1075 | { | |
b2e465d6 | 1076 | if (Cache.VS->CheckDep(I.VerStr(),D->CompareOp,D.TargetVer()) == true) |
3e94da1b AL |
1077 | Hit = true; |
1078 | } | |
1079 | ||
1080 | // Follow all provides | |
1081 | for (pkgCache::PrvIterator I = DPkg.ProvidesList(); | |
1082 | I.end() == false && Hit == false; I++) | |
1083 | { | |
b2e465d6 | 1084 | if (Cache.VS->CheckDep(I.ProvideVersion(),D->CompareOp,D.TargetVer()) == false) |
3e94da1b AL |
1085 | Hit = true; |
1086 | } | |
1087 | ||
1088 | // Only graph critical deps | |
1089 | if (D.IsCritical() == true) | |
1090 | { | |
75ce2062 | 1091 | printf("\"%s\" -> \"%s\"",Pkg.FullName(true).c_str(),D.TargetPkg().FullName(true).c_str()); |
3e94da1b AL |
1092 | |
1093 | // Colour the node for recursion | |
1094 | if (Show[D.TargetPkg()->ID] <= DoneNR) | |
1095 | { | |
1096 | /* If a conflicts does not meet anything in the database | |
1097 | then show the relation but do not recurse */ | |
b2e465d6 AL |
1098 | if (Hit == false && |
1099 | (D->Type == pkgCache::Dep::Conflicts || | |
1100 | D->Type == pkgCache::Dep::Obsoletes)) | |
3e94da1b AL |
1101 | { |
1102 | if (Show[D.TargetPkg()->ID] == None && | |
1103 | Show[D.TargetPkg()->ID] != ToShow) | |
1104 | Show[D.TargetPkg()->ID] = ToShowNR; | |
1105 | } | |
1106 | else | |
1107 | { | |
1108 | if (GivenOnly == true && Show[D.TargetPkg()->ID] != ToShow) | |
1109 | Show[D.TargetPkg()->ID] = ToShowNR; | |
1110 | else | |
1111 | Show[D.TargetPkg()->ID] = ToShow; | |
1112 | } | |
1113 | } | |
1114 | ||
1115 | // Edge colour | |
1116 | switch(D->Type) | |
1117 | { | |
1118 | case pkgCache::Dep::Conflicts: | |
b2e465d6 | 1119 | case pkgCache::Dep::Obsoletes: |
3e94da1b AL |
1120 | printf("[color=springgreen];\n"); |
1121 | break; | |
1122 | ||
1123 | case pkgCache::Dep::PreDepends: | |
1124 | printf("[color=blue];\n"); | |
1125 | break; | |
1126 | ||
1127 | default: | |
1128 | printf(";\n"); | |
1129 | break; | |
1130 | } | |
1131 | } | |
1132 | } | |
1133 | } | |
1134 | } | |
1135 | ||
1136 | /* Draw the box colours after the fact since we can not tell what colour | |
1137 | they should be until everything is finished drawing */ | |
1138 | for (pkgCache::PkgIterator Pkg = Cache.PkgBegin(); Pkg.end() == false; Pkg++) | |
1139 | { | |
1140 | if (Show[Pkg->ID] < DoneNR) | |
1141 | continue; | |
1142 | ||
1143 | // Orange box for early recursion stoppage | |
1144 | if (Show[Pkg->ID] == DoneNR) | |
75ce2062 | 1145 | printf("\"%s\" [color=orange,shape=%s];\n",Pkg.FullName(true).c_str(), |
3e94da1b AL |
1146 | Shapes[ShapeMap[Pkg->ID]]); |
1147 | else | |
75ce2062 | 1148 | printf("\"%s\" [shape=%s];\n",Pkg.FullName(true).c_str(), |
3e94da1b AL |
1149 | Shapes[ShapeMap[Pkg->ID]]); |
1150 | } | |
1151 | ||
1152 | printf("}\n"); | |
ad00ae81 AL |
1153 | return true; |
1154 | } | |
1155 | /*}}}*/ | |
1156 | // DoAdd - Perform an adding operation /*{{{*/ | |
1157 | // --------------------------------------------------------------------- | |
1158 | /* */ | |
e1b74f61 | 1159 | bool DoAdd(CommandLine &CmdL) |
ad00ae81 | 1160 | { |
b2e465d6 AL |
1161 | return _error->Error("Unimplemented"); |
1162 | #if 0 | |
e1b74f61 AL |
1163 | // Make sure there is at least one argument |
1164 | if (CmdL.FileSize() <= 1) | |
1165 | return _error->Error("You must give at least one file name"); | |
ad00ae81 AL |
1166 | |
1167 | // Open the cache | |
018f1533 | 1168 | FileFd CacheF(_config->FindFile("Dir::Cache::pkgcache"),FileFd::WriteAny); |
ad00ae81 AL |
1169 | if (_error->PendingError() == true) |
1170 | return false; | |
1171 | ||
1172 | DynamicMMap Map(CacheF,MMap::Public); | |
1173 | if (_error->PendingError() == true) | |
1174 | return false; | |
404ec98e | 1175 | |
0a8e3465 | 1176 | OpTextProgress Progress(*_config); |
404ec98e | 1177 | pkgCacheGenerator Gen(Map,Progress); |
ad00ae81 AL |
1178 | if (_error->PendingError() == true) |
1179 | return false; | |
1180 | ||
e1b74f61 AL |
1181 | unsigned long Length = CmdL.FileSize() - 1; |
1182 | for (const char **I = CmdL.FileList + 1; *I != 0; I++) | |
ad00ae81 | 1183 | { |
e1b74f61 | 1184 | Progress.OverallProgress(I - CmdL.FileList,Length,1,"Generating cache"); |
018f1533 AL |
1185 | Progress.SubProgress(Length); |
1186 | ||
ad00ae81 | 1187 | // Do the merge |
e1b74f61 | 1188 | FileFd TagF(*I,FileFd::ReadOnly); |
ad00ae81 AL |
1189 | debListParser Parser(TagF); |
1190 | if (_error->PendingError() == true) | |
e1b74f61 | 1191 | return _error->Error("Problem opening %s",*I); |
ad00ae81 | 1192 | |
b2e465d6 | 1193 | if (Gen.SelectFile(*I,"") == false) |
ad00ae81 AL |
1194 | return _error->Error("Problem with SelectFile"); |
1195 | ||
1196 | if (Gen.MergeList(Parser) == false) | |
1197 | return _error->Error("Problem with MergeList"); | |
1164783d | 1198 | } |
404ec98e AL |
1199 | |
1200 | Progress.Done(); | |
b0b4efb9 AL |
1201 | GCache = &Gen.GetCache(); |
1202 | Stats(CmdL); | |
ad00ae81 | 1203 | |
7e2e2d5d | 1204 | return true; |
b2e465d6 | 1205 | #endif |
7e2e2d5d AL |
1206 | } |
1207 | /*}}}*/ | |
1208 | // DisplayRecord - Displays the complete record for the package /*{{{*/ | |
1209 | // --------------------------------------------------------------------- | |
1210 | /* This displays the package record from the proper package index file. | |
1211 | It is not used by DumpAvail for performance reasons. */ | |
1212 | bool DisplayRecord(pkgCache::VerIterator V) | |
1213 | { | |
1214 | // Find an appropriate file | |
1215 | pkgCache::VerFileIterator Vf = V.FileList(); | |
1216 | for (; Vf.end() == false; Vf++) | |
1217 | if ((Vf.File()->Flags & pkgCache::Flag::NotSource) == 0) | |
1218 | break; | |
1219 | if (Vf.end() == true) | |
1220 | Vf = V.FileList(); | |
1221 | ||
1222 | // Check and load the package list file | |
1223 | pkgCache::PkgFileIterator I = Vf.File(); | |
1224 | if (I.IsOk() == false) | |
b2e465d6 | 1225 | return _error->Error(_("Package file %s is out of sync."),I.FileName()); |
7e2e2d5d AL |
1226 | |
1227 | FileFd PkgF(I.FileName(),FileFd::ReadOnly); | |
1228 | if (_error->PendingError() == true) | |
1229 | return false; | |
1230 | ||
a52f938b | 1231 | // Read the record |
b2e465d6 AL |
1232 | unsigned char *Buffer = new unsigned char[GCache->HeaderP->MaxVerFileSize+1]; |
1233 | Buffer[V.FileList()->Size] = '\n'; | |
7e2e2d5d | 1234 | if (PkgF.Seek(V.FileList()->Offset) == false || |
a52f938b | 1235 | PkgF.Read(Buffer,V.FileList()->Size) == false) |
7e2e2d5d AL |
1236 | { |
1237 | delete [] Buffer; | |
1238 | return false; | |
1239 | } | |
a52f938b | 1240 | |
e5e2d176 | 1241 | // Get a pointer to start of Description field |
e011829d | 1242 | const unsigned char *DescP = (unsigned char*)strstr((char*)Buffer, "Description:"); |
e5e2d176 MV |
1243 | |
1244 | // Write all but Description | |
487d7faa | 1245 | if (fwrite(Buffer,1,DescP - Buffer,stdout) < (size_t)(DescP - Buffer)) |
a52f938b OS |
1246 | { |
1247 | delete [] Buffer; | |
1248 | return false; | |
1249 | } | |
1250 | ||
a52f938b OS |
1251 | // Show the right description |
1252 | pkgRecords Recs(*GCache); | |
012b102a | 1253 | pkgCache::DescIterator Desc = V.TranslatedDescription(); |
a52f938b | 1254 | pkgRecords::Parser &P = Recs.Lookup(Desc.FileList()); |
e011829d | 1255 | cout << "Description" << ( (strcmp(Desc.LanguageCode(),"") != 0) ? "-" : "" ) << Desc.LanguageCode() << ": " << P.LongDesc(); |
a52f938b | 1256 | |
e011829d MV |
1257 | // Find the first field after the description (if there is any) |
1258 | for(DescP++;DescP != &Buffer[V.FileList()->Size];DescP++) | |
1259 | { | |
1260 | if(*DescP == '\n' && *(DescP+1) != ' ') | |
1261 | { | |
1262 | // write the rest of the buffer | |
1263 | const unsigned char *end=&Buffer[V.FileList()->Size]; | |
1264 | if (fwrite(DescP,1,end-DescP,stdout) < (size_t)(end-DescP)) | |
1265 | { | |
1266 | delete [] Buffer; | |
1267 | return false; | |
1268 | } | |
1269 | ||
1270 | break; | |
1271 | } | |
1272 | } | |
1273 | // write a final newline (after the description) | |
1274 | cout<<endl; | |
7e2e2d5d AL |
1275 | delete [] Buffer; |
1276 | ||
9dbb421f AL |
1277 | return true; |
1278 | } | |
1279 | /*}}}*/ | |
92fcbfc1 | 1280 | |
a52f938b | 1281 | struct ExDescFile |
b2e465d6 | 1282 | { |
a52f938b | 1283 | pkgCache::DescFile *Df; |
b2e465d6 AL |
1284 | bool NameMatch; |
1285 | }; | |
1286 | ||
92fcbfc1 DK |
1287 | // Search - Perform a search /*{{{*/ |
1288 | // --------------------------------------------------------------------- | |
1289 | /* This searches the package names and package descriptions for a pattern */ | |
9dbb421f AL |
1290 | bool Search(CommandLine &CmdL) |
1291 | { | |
1292 | pkgCache &Cache = *GCache; | |
7e2e2d5d AL |
1293 | bool ShowFull = _config->FindB("APT::Cache::ShowFull",false); |
1294 | bool NamesOnly = _config->FindB("APT::Cache::NamesOnly",false); | |
b2e465d6 AL |
1295 | unsigned NumPatterns = CmdL.FileSize() -1; |
1296 | ||
1297 | pkgDepCache::Policy Plcy; | |
9dbb421f AL |
1298 | |
1299 | // Make sure there is at least one argument | |
b2e465d6 AL |
1300 | if (NumPatterns < 1) |
1301 | return _error->Error(_("You must give exactly one pattern")); | |
9dbb421f AL |
1302 | |
1303 | // Compile the regex pattern | |
b2e465d6 AL |
1304 | regex_t *Patterns = new regex_t[NumPatterns]; |
1305 | memset(Patterns,0,sizeof(*Patterns)*NumPatterns); | |
1306 | for (unsigned I = 0; I != NumPatterns; I++) | |
1307 | { | |
1308 | if (regcomp(&Patterns[I],CmdL.FileList[I+1],REG_EXTENDED | REG_ICASE | | |
1309 | REG_NOSUB) != 0) | |
1310 | { | |
1311 | for (; I != 0; I--) | |
1312 | regfree(&Patterns[I]); | |
1313 | return _error->Error("Regex compilation error"); | |
1314 | } | |
1315 | } | |
9dbb421f AL |
1316 | |
1317 | // Create the text record parser | |
1318 | pkgRecords Recs(Cache); | |
1319 | if (_error->PendingError() == true) | |
b2e465d6 AL |
1320 | { |
1321 | for (unsigned I = 0; I != NumPatterns; I++) | |
1322 | regfree(&Patterns[I]); | |
9dbb421f | 1323 | return false; |
b2e465d6 | 1324 | } |
9dbb421f | 1325 | |
a52f938b OS |
1326 | ExDescFile *DFList = new ExDescFile[Cache.HeaderP->PackageCount+1]; |
1327 | memset(DFList,0,sizeof(*DFList)*Cache.HeaderP->PackageCount+1); | |
b2e465d6 AL |
1328 | |
1329 | // Map versions that we want to write out onto the VerList array. | |
1330 | for (pkgCache::PkgIterator P = Cache.PkgBegin(); P.end() == false; P++) | |
9dbb421f | 1331 | { |
a52f938b | 1332 | DFList[P->ID].NameMatch = NumPatterns != 0; |
b2e465d6 AL |
1333 | for (unsigned I = 0; I != NumPatterns; I++) |
1334 | { | |
1335 | if (regexec(&Patterns[I],P.Name(),0,0,0) == 0) | |
a52f938b | 1336 | DFList[P->ID].NameMatch &= true; |
0f2fa322 | 1337 | else |
a52f938b | 1338 | DFList[P->ID].NameMatch = false; |
b2e465d6 | 1339 | } |
c29652b0 | 1340 | |
b2e465d6 | 1341 | // Doing names only, drop any that dont match.. |
a52f938b | 1342 | if (NamesOnly == true && DFList[P->ID].NameMatch == false) |
b2e465d6 AL |
1343 | continue; |
1344 | ||
1345 | // Find the proper version to use. | |
1346 | pkgCache::VerIterator V = Plcy.GetCandidateVer(P); | |
c29652b0 | 1347 | if (V.end() == false) |
a52f938b | 1348 | DFList[P->ID].Df = V.DescriptionList().FileList(); |
c29652b0 AL |
1349 | } |
1350 | ||
1351 | // Include all the packages that provide matching names too | |
1352 | for (pkgCache::PkgIterator P = Cache.PkgBegin(); P.end() == false; P++) | |
1353 | { | |
a52f938b | 1354 | if (DFList[P->ID].NameMatch == false) |
7e2e2d5d | 1355 | continue; |
c29652b0 AL |
1356 | |
1357 | for (pkgCache::PrvIterator Prv = P.ProvidesList() ; Prv.end() == false; Prv++) | |
1358 | { | |
1359 | pkgCache::VerIterator V = Plcy.GetCandidateVer(Prv.OwnerPkg()); | |
1360 | if (V.end() == false) | |
1361 | { | |
a52f938b OS |
1362 | DFList[Prv.OwnerPkg()->ID].Df = V.DescriptionList().FileList(); |
1363 | DFList[Prv.OwnerPkg()->ID].NameMatch = true; | |
c29652b0 AL |
1364 | } |
1365 | } | |
b2e465d6 | 1366 | } |
a52f938b OS |
1367 | |
1368 | LocalitySort(&DFList->Df,Cache.HeaderP->PackageCount,sizeof(*DFList)); | |
7e2e2d5d | 1369 | |
b2e465d6 | 1370 | // Iterate over all the version records and check them |
a52f938b | 1371 | for (ExDescFile *J = DFList; J->Df != 0; J++) |
b2e465d6 | 1372 | { |
a52f938b | 1373 | pkgRecords::Parser &P = Recs.Lookup(pkgCache::DescFileIterator(Cache,J->Df)); |
0f2fa322 AL |
1374 | |
1375 | bool Match = true; | |
1376 | if (J->NameMatch == false) | |
1377 | { | |
1378 | string LongDesc = P.LongDesc(); | |
1379 | Match = NumPatterns != 0; | |
1380 | for (unsigned I = 0; I != NumPatterns; I++) | |
1381 | { | |
1382 | if (regexec(&Patterns[I],LongDesc.c_str(),0,0,0) == 0) | |
1383 | Match &= true; | |
1384 | else | |
1385 | Match = false; | |
1386 | } | |
1387 | } | |
b2e465d6 AL |
1388 | |
1389 | if (Match == true) | |
9dbb421f | 1390 | { |
7e2e2d5d | 1391 | if (ShowFull == true) |
b2e465d6 AL |
1392 | { |
1393 | const char *Start; | |
1394 | const char *End; | |
1395 | P.GetRec(Start,End); | |
1396 | fwrite(Start,End-Start,1,stdout); | |
1397 | putc('\n',stdout); | |
1398 | } | |
7e2e2d5d | 1399 | else |
b2e465d6 AL |
1400 | printf("%s - %s\n",P.Name().c_str(),P.ShortDesc().c_str()); |
1401 | } | |
9dbb421f AL |
1402 | } |
1403 | ||
a52f938b | 1404 | delete [] DFList; |
b2e465d6 AL |
1405 | for (unsigned I = 0; I != NumPatterns; I++) |
1406 | regfree(&Patterns[I]); | |
1407 | if (ferror(stdout)) | |
1408 | return _error->Error("Write to stdout failed"); | |
1164783d AL |
1409 | return true; |
1410 | } | |
6007c1d4 JAK |
1411 | |
1412 | ||
1413 | /* show automatically installed packages (sorted) */ | |
1414 | bool ShowAuto(CommandLine &CmdL) | |
1415 | { | |
1416 | OpProgress op; | |
1417 | pkgDepCache DepCache(GCache); | |
1418 | DepCache.Init(&op); | |
1419 | ||
1420 | std::vector<string> packages; | |
1421 | packages.reserve(GCache->HeaderP->PackageCount / 3); | |
1422 | ||
1423 | for (pkgCache::PkgIterator P = GCache->PkgBegin(); P.end() == false; P++) | |
1424 | if (DepCache[P].Flags & pkgCache::Flag::Auto) | |
1425 | packages.push_back(P.Name()); | |
1426 | ||
1427 | std::sort(packages.begin(), packages.end()); | |
1428 | ||
1429 | for (vector<string>::iterator I = packages.begin(); I != packages.end(); I++) | |
1430 | cout << *I << "\n"; | |
1431 | ||
1432 | return true; | |
1433 | } | |
1164783d | 1434 | /*}}}*/ |
7e2e2d5d AL |
1435 | // ShowPackage - Dump the package record to the screen /*{{{*/ |
1436 | // --------------------------------------------------------------------- | |
1437 | /* */ | |
1438 | bool ShowPackage(CommandLine &CmdL) | |
1439 | { | |
1440 | pkgCache &Cache = *GCache; | |
b2e465d6 | 1441 | pkgDepCache::Policy Plcy; |
9d366c89 AL |
1442 | |
1443 | unsigned found = 0; | |
b2e465d6 | 1444 | |
7e2e2d5d AL |
1445 | for (const char **I = CmdL.FileList + 1; *I != 0; I++) |
1446 | { | |
6293e04f | 1447 | // FIXME: Handle the case in which pkgname name:arch is not found |
7e2e2d5d AL |
1448 | pkgCache::PkgIterator Pkg = Cache.FindPkg(*I); |
1449 | if (Pkg.end() == true) | |
1450 | { | |
6293e04f DK |
1451 | Pkg = Cache.FindPkg(*I, "any"); |
1452 | if (Pkg.end() == true) { | |
1453 | _error->Warning(_("Unable to locate package %s"),*I); | |
1454 | continue; | |
1455 | } | |
7e2e2d5d | 1456 | } |
b2e465d6 | 1457 | |
9d366c89 AL |
1458 | ++found; |
1459 | ||
b2e465d6 | 1460 | // Find the proper version to use. |
648e3cb4 AL |
1461 | if (_config->FindB("APT::Cache::AllVersions","true") == true) |
1462 | { | |
1463 | pkgCache::VerIterator V; | |
1464 | for (V = Pkg.VersionList(); V.end() == false; V++) | |
1465 | { | |
1466 | if (DisplayRecord(V) == false) | |
1467 | return false; | |
1468 | } | |
1469 | } | |
1470 | else | |
1471 | { | |
b2e465d6 | 1472 | pkgCache::VerIterator V = Plcy.GetCandidateVer(Pkg); |
648e3cb4 AL |
1473 | if (V.end() == true || V.FileList().end() == true) |
1474 | continue; | |
1475 | if (DisplayRecord(V) == false) | |
1476 | return false; | |
1477 | } | |
7e2e2d5d | 1478 | } |
9d366c89 AL |
1479 | |
1480 | if (found > 0) | |
1481 | return true; | |
1482 | return _error->Error(_("No packages found")); | |
7c1133fe AL |
1483 | } |
1484 | /*}}}*/ | |
1485 | // ShowPkgNames - Show package names /*{{{*/ | |
1486 | // --------------------------------------------------------------------- | |
1487 | /* This does a prefix match on the first argument */ | |
1488 | bool ShowPkgNames(CommandLine &CmdL) | |
1489 | { | |
1490 | pkgCache &Cache = *GCache; | |
6293e04f DK |
1491 | pkgCache::GrpIterator I = Cache.GrpBegin(); |
1492 | bool const All = _config->FindB("APT::Cache::AllNames","false"); | |
1493 | ||
7c1133fe AL |
1494 | if (CmdL.FileList[1] != 0) |
1495 | { | |
1496 | for (;I.end() != true; I++) | |
1497 | { | |
6293e04f DK |
1498 | if (All == false && I->FirstPackage == 0) |
1499 | continue; | |
1500 | if (I.FindPkg("any")->VersionList == 0) | |
7c1133fe | 1501 | continue; |
7c1133fe AL |
1502 | if (strncmp(I.Name(),CmdL.FileList[1],strlen(CmdL.FileList[1])) == 0) |
1503 | cout << I.Name() << endl; | |
1504 | } | |
1505 | ||
1506 | return true; | |
1507 | } | |
1508 | ||
1509 | // Show all pkgs | |
1510 | for (;I.end() != true; I++) | |
1511 | { | |
6293e04f DK |
1512 | if (All == false && I->FirstPackage == 0) |
1513 | continue; | |
1514 | if (I.FindPkg("any")->VersionList == 0) | |
7c1133fe AL |
1515 | continue; |
1516 | cout << I.Name() << endl; | |
1517 | } | |
1518 | ||
7e2e2d5d AL |
1519 | return true; |
1520 | } | |
1521 | /*}}}*/ | |
f8f410f5 AL |
1522 | // ShowSrcPackage - Show source package records /*{{{*/ |
1523 | // --------------------------------------------------------------------- | |
1524 | /* */ | |
1525 | bool ShowSrcPackage(CommandLine &CmdL) | |
1526 | { | |
1527 | pkgSourceList List; | |
1528 | List.ReadMainList(); | |
1529 | ||
1530 | // Create the text record parsers | |
1531 | pkgSrcRecords SrcRecs(List); | |
1532 | if (_error->PendingError() == true) | |
1533 | return false; | |
1534 | ||
0458a811 | 1535 | unsigned found = 0; |
f8f410f5 AL |
1536 | for (const char **I = CmdL.FileList + 1; *I != 0; I++) |
1537 | { | |
aaee8293 AL |
1538 | SrcRecs.Restart(); |
1539 | ||
f8f410f5 | 1540 | pkgSrcRecords::Parser *Parse; |
0458a811 JAK |
1541 | unsigned found_this = 0; |
1542 | while ((Parse = SrcRecs.Find(*I,false)) != 0) { | |
1543 | cout << Parse->AsStr() << endl;; | |
1544 | found++; | |
1545 | found_this++; | |
1546 | } | |
1547 | if (found_this == 0) { | |
1548 | _error->Warning(_("Unable to locate package %s"),*I); | |
1549 | continue; | |
1550 | } | |
f8f410f5 | 1551 | } |
0458a811 JAK |
1552 | if (found > 0) |
1553 | return true; | |
1554 | return _error->Error(_("No packages found")); | |
af87ab54 AL |
1555 | } |
1556 | /*}}}*/ | |
1557 | // Policy - Show the results of the preferences file /*{{{*/ | |
1558 | // --------------------------------------------------------------------- | |
1559 | /* */ | |
1560 | bool Policy(CommandLine &CmdL) | |
1561 | { | |
1562 | if (SrcList == 0) | |
1563 | return _error->Error("Generate must be enabled for this function"); | |
1564 | ||
1565 | pkgCache &Cache = *GCache; | |
1566 | pkgPolicy Plcy(&Cache); | |
e68ca100 | 1567 | if (ReadPinFile(Plcy) == false || ReadPinDir(Plcy) == false) |
af87ab54 AL |
1568 | return false; |
1569 | ||
1570 | // Print out all of the package files | |
1571 | if (CmdL.FileList[1] == 0) | |
1572 | { | |
db0db9fe | 1573 | cout << _("Package files:") << endl; |
af87ab54 AL |
1574 | for (pkgCache::PkgFileIterator F = Cache.FileBegin(); F.end() == false; F++) |
1575 | { | |
1576 | // Locate the associated index files so we can derive a description | |
1577 | pkgIndexFile *Indx; | |
1578 | if (SrcList->FindIndex(F,Indx) == false && | |
1579 | _system->FindIndex(F,Indx) == false) | |
1580 | return _error->Error(_("Cache is out of sync, can't x-ref a package file")); | |
78acd650 MV |
1581 | |
1582 | printf("%4i %s\n", | |
af87ab54 AL |
1583 | Plcy.GetPriority(F),Indx->Describe(true).c_str()); |
1584 | ||
1585 | // Print the reference information for the package | |
1586 | string Str = F.RelStr(); | |
1587 | if (Str.empty() == false) | |
1588 | printf(" release %s\n",F.RelStr().c_str()); | |
1589 | if (F.Site() != 0 && F.Site()[0] != 0) | |
1590 | printf(" origin %s\n",F.Site()); | |
1591 | } | |
1592 | ||
1593 | // Show any packages have explicit pins | |
db0db9fe | 1594 | cout << _("Pinned packages:") << endl; |
af87ab54 AL |
1595 | pkgCache::PkgIterator I = Cache.PkgBegin(); |
1596 | for (;I.end() != true; I++) | |
1597 | { | |
1598 | if (Plcy.GetPriority(I) == 0) | |
1599 | continue; | |
1600 | ||
1601 | // Print the package name and the version we are forcing to | |
75ce2062 | 1602 | cout << " " << I.FullName(true) << " -> "; |
af87ab54 AL |
1603 | |
1604 | pkgCache::VerIterator V = Plcy.GetMatch(I); | |
1605 | if (V.end() == true) | |
1606 | cout << _("(not found)") << endl; | |
1607 | else | |
1608 | cout << V.VerStr() << endl; | |
1609 | } | |
1610 | ||
1611 | return true; | |
1612 | } | |
6293e04f DK |
1613 | |
1614 | string const myArch = _config->Find("APT::Architecture"); | |
ca964703 DK |
1615 | char const * const msgInstalled = _(" Installed: "); |
1616 | char const * const msgCandidate = _(" Candidate: "); | |
1617 | short const InstalledLessCandidate = | |
1618 | mbstowcs(NULL, msgInstalled, 0) - mbstowcs(NULL, msgCandidate, 0); | |
1619 | short const deepInstalled = | |
1620 | (InstalledLessCandidate < 0 ? (InstalledLessCandidate*-1) : 0) - 1; | |
1621 | short const deepCandidate = | |
1622 | (InstalledLessCandidate > 0 ? (InstalledLessCandidate) : 0) - 1; | |
6293e04f | 1623 | |
af87ab54 AL |
1624 | // Print out detailed information for each package |
1625 | for (const char **I = CmdL.FileList + 1; *I != 0; I++) | |
1626 | { | |
6293e04f DK |
1627 | pkgCache::GrpIterator Grp = Cache.FindGrp(*I); |
1628 | pkgCache::PkgIterator Pkg = Grp.FindPkg("any"); | |
af87ab54 AL |
1629 | if (Pkg.end() == true) |
1630 | { | |
1631 | _error->Warning(_("Unable to locate package %s"),*I); | |
1632 | continue; | |
1633 | } | |
6293e04f DK |
1634 | |
1635 | for (; Pkg.end() != true; Pkg = Grp.NextPkg(Pkg)) { | |
803ea2a8 DK |
1636 | if (strcmp(Pkg.Arch(),"all") == 0) |
1637 | continue; | |
6293e04f | 1638 | |
75ce2062 | 1639 | cout << Pkg.FullName(true) << ":" << endl; |
6293e04f | 1640 | |
af87ab54 | 1641 | // Installed version |
ca964703 | 1642 | cout << msgInstalled << OutputInDepth(deepInstalled, " "); |
af87ab54 AL |
1643 | if (Pkg->CurrentVer == 0) |
1644 | cout << _("(none)") << endl; | |
1645 | else | |
1646 | cout << Pkg.CurrentVer().VerStr() << endl; | |
1647 | ||
1648 | // Candidate Version | |
ca964703 | 1649 | cout << msgCandidate << OutputInDepth(deepCandidate, " "); |
af87ab54 AL |
1650 | pkgCache::VerIterator V = Plcy.GetCandidateVer(Pkg); |
1651 | if (V.end() == true) | |
1652 | cout << _("(none)") << endl; | |
1653 | else | |
1654 | cout << V.VerStr() << endl; | |
1655 | ||
1656 | // Pinned version | |
1657 | if (Plcy.GetPriority(Pkg) != 0) | |
1658 | { | |
db0db9fe | 1659 | cout << _(" Package pin: "); |
af87ab54 AL |
1660 | V = Plcy.GetMatch(Pkg); |
1661 | if (V.end() == true) | |
1662 | cout << _("(not found)") << endl; | |
1663 | else | |
1664 | cout << V.VerStr() << endl; | |
1665 | } | |
1666 | ||
1667 | // Show the priority tables | |
db0db9fe | 1668 | cout << _(" Version table:") << endl; |
af87ab54 AL |
1669 | for (V = Pkg.VersionList(); V.end() == false; V++) |
1670 | { | |
1671 | if (Pkg.CurrentVer() == V) | |
1672 | cout << " *** " << V.VerStr(); | |
1673 | else | |
1674 | cout << " " << V.VerStr(); | |
1675 | cout << " " << Plcy.GetPriority(Pkg) << endl; | |
1676 | for (pkgCache::VerFileIterator VF = V.FileList(); VF.end() == false; VF++) | |
1677 | { | |
1678 | // Locate the associated index files so we can derive a description | |
1679 | pkgIndexFile *Indx; | |
1680 | if (SrcList->FindIndex(VF.File(),Indx) == false && | |
1681 | _system->FindIndex(VF.File(),Indx) == false) | |
1682 | return _error->Error(_("Cache is out of sync, can't x-ref a package file")); | |
46e39c8e | 1683 | printf(" %4i %s\n",Plcy.GetPriority(VF.File()), |
af87ab54 | 1684 | Indx->Describe(true).c_str()); |
6293e04f DK |
1685 | } |
1686 | } | |
1687 | } | |
af87ab54 AL |
1688 | } |
1689 | ||
f8f410f5 AL |
1690 | return true; |
1691 | } | |
bd3d53ef AL |
1692 | /*}}}*/ |
1693 | // Madison - Look a bit like katie's madison /*{{{*/ | |
1694 | // --------------------------------------------------------------------- | |
1695 | /* */ | |
1696 | bool Madison(CommandLine &CmdL) | |
1697 | { | |
1698 | if (SrcList == 0) | |
1699 | return _error->Error("Generate must be enabled for this function"); | |
1700 | ||
1701 | SrcList->ReadMainList(); | |
1702 | ||
1703 | pkgCache &Cache = *GCache; | |
1704 | ||
03cd434b MV |
1705 | // Create the src text record parsers and ignore errors about missing |
1706 | // deb-src lines that are generated from pkgSrcRecords::pkgSrcRecords | |
bd3d53ef AL |
1707 | pkgSrcRecords SrcRecs(*SrcList); |
1708 | if (_error->PendingError() == true) | |
03cd434b | 1709 | _error->Discard(); |
bd3d53ef AL |
1710 | |
1711 | for (const char **I = CmdL.FileList + 1; *I != 0; I++) | |
1712 | { | |
1713 | pkgCache::PkgIterator Pkg = Cache.FindPkg(*I); | |
1714 | ||
1715 | if (Pkg.end() == false) | |
1716 | { | |
1717 | for (pkgCache::VerIterator V = Pkg.VersionList(); V.end() == false; V++) | |
1718 | { | |
1719 | for (pkgCache::VerFileIterator VF = V.FileList(); VF.end() == false; VF++) | |
1720 | { | |
a0e710af AL |
1721 | // This might be nice, but wouldn't uniquely identify the source -mdz |
1722 | // if (VF.File().Archive() != 0) | |
1723 | // { | |
1724 | // cout << setw(10) << Pkg.Name() << " | " << setw(10) << V.VerStr() << " | " | |
1725 | // << VF.File().Archive() << endl; | |
1726 | // } | |
1727 | ||
1728 | // Locate the associated index files so we can derive a description | |
1729 | for (pkgSourceList::const_iterator S = SrcList->begin(); S != SrcList->end(); S++) | |
bd3d53ef | 1730 | { |
7db98ffc MZ |
1731 | vector<pkgIndexFile *> *Indexes = (*S)->GetIndexFiles(); |
1732 | for (vector<pkgIndexFile *>::const_iterator IF = Indexes->begin(); | |
1733 | IF != Indexes->end(); IF++) | |
1734 | { | |
1735 | if ((*IF)->FindInCache(*(VF.File().Cache())) == VF.File()) | |
1736 | { | |
75ce2062 | 1737 | cout << setw(10) << Pkg.FullName(true) << " | " << setw(10) << V.VerStr() << " | " |
7db98ffc MZ |
1738 | << (*IF)->Describe(true) << endl; |
1739 | } | |
1740 | } | |
bd3d53ef AL |
1741 | } |
1742 | } | |
1743 | } | |
1744 | } | |
1745 | ||
1746 | ||
1747 | SrcRecs.Restart(); | |
1748 | pkgSrcRecords::Parser *SrcParser; | |
1749 | while ((SrcParser = SrcRecs.Find(*I,false)) != 0) | |
1750 | { | |
1751 | // Maybe support Release info here too eventually | |
1752 | cout << setw(10) << SrcParser->Package() << " | " | |
1753 | << setw(10) << SrcParser->Version() << " | " | |
1754 | << SrcParser->Index().Describe(true) << endl; | |
1755 | } | |
1756 | } | |
1757 | ||
1758 | return true; | |
1759 | } | |
f8f410f5 | 1760 | /*}}}*/ |
880e9be4 AL |
1761 | // GenCaches - Call the main cache generator /*{{{*/ |
1762 | // --------------------------------------------------------------------- | |
1763 | /* */ | |
b0b4efb9 | 1764 | bool GenCaches(CommandLine &Cmd) |
880e9be4 | 1765 | { |
0a8e3465 AL |
1766 | OpTextProgress Progress(*_config); |
1767 | ||
880e9be4 | 1768 | pkgSourceList List; |
b2e465d6 AL |
1769 | if (List.ReadMainList() == false) |
1770 | return false; | |
0a8e3465 | 1771 | return pkgMakeStatusCache(List,Progress); |
880e9be4 AL |
1772 | } |
1773 | /*}}}*/ | |
e1b74f61 AL |
1774 | // ShowHelp - Show a help screen /*{{{*/ |
1775 | // --------------------------------------------------------------------- | |
1776 | /* */ | |
b0b4efb9 | 1777 | bool ShowHelp(CommandLine &Cmd) |
e1b74f61 | 1778 | { |
5b28c804 OS |
1779 | ioprintf(cout,_("%s %s for %s compiled on %s %s\n"),PACKAGE,VERSION, |
1780 | COMMON_ARCH,__DATE__,__TIME__); | |
e1b74f61 | 1781 | |
b13af988 AL |
1782 | if (_config->FindB("version") == true) |
1783 | return true; | |
1784 | ||
b2e465d6 AL |
1785 | cout << |
1786 | _("Usage: apt-cache [options] command\n" | |
b9d2ece3 | 1787 | " apt-cache [options] add file1 [file2 ...]\n" |
b2e465d6 | 1788 | " apt-cache [options] showpkg pkg1 [pkg2 ...]\n" |
2d425135 | 1789 | " apt-cache [options] showsrc pkg1 [pkg2 ...]\n" |
b2e465d6 AL |
1790 | "\n" |
1791 | "apt-cache is a low-level tool used to manipulate APT's binary\n" | |
1792 | "cache files, and query information from them\n" | |
1793 | "\n" | |
1794 | "Commands:\n" | |
bac2e715 | 1795 | " add - Add a package file to the source cache\n" |
b2e465d6 AL |
1796 | " gencaches - Build both the package and source cache\n" |
1797 | " showpkg - Show some general information for a single package\n" | |
2d425135 | 1798 | " showsrc - Show source records\n" |
b2e465d6 AL |
1799 | " stats - Show some basic statistics\n" |
1800 | " dump - Show the entire file in a terse form\n" | |
1801 | " dumpavail - Print an available file to stdout\n" | |
1802 | " unmet - Show unmet dependencies\n" | |
b2e465d6 AL |
1803 | " search - Search the package list for a regex pattern\n" |
1804 | " show - Show a readable record for the package\n" | |
6007c1d4 | 1805 | " showauto - Display a list of automatically installed packages\n" |
b2e465d6 | 1806 | " depends - Show raw dependency information for a package\n" |
eba2b51d | 1807 | " rdepends - Show reverse dependency information for a package\n" |
2c120e24 EL |
1808 | " pkgnames - List the names of all packages in the system\n" |
1809 | " dotty - Generate package graphs for GraphViz\n" | |
fff4b7f3 | 1810 | " xvcg - Generate package graphs for xvcg\n" |
eba05d54 | 1811 | " policy - Show policy settings\n" |
b2e465d6 AL |
1812 | "\n" |
1813 | "Options:\n" | |
1814 | " -h This help text.\n" | |
1815 | " -p=? The package cache.\n" | |
1816 | " -s=? The source cache.\n" | |
1817 | " -q Disable progress indicator.\n" | |
1818 | " -i Show only important deps for the unmet command.\n" | |
1819 | " -c=? Read this configuration file\n" | |
a2884e32 | 1820 | " -o=? Set an arbitrary configuration option, eg -o dir::cache=/tmp\n" |
b2e465d6 AL |
1821 | "See the apt-cache(8) and apt.conf(5) manual pages for more information.\n"); |
1822 | return true; | |
e1b74f61 AL |
1823 | } |
1824 | /*}}}*/ | |
0a8e3465 AL |
1825 | // CacheInitialize - Initialize things for apt-cache /*{{{*/ |
1826 | // --------------------------------------------------------------------- | |
1827 | /* */ | |
1828 | void CacheInitialize() | |
1829 | { | |
1830 | _config->Set("quiet",0); | |
1831 | _config->Set("help",false); | |
1832 | } | |
1833 | /*}}}*/ | |
92fcbfc1 | 1834 | int main(int argc,const char *argv[]) /*{{{*/ |
1164783d | 1835 | { |
08e8f724 AL |
1836 | CommandLine::Args Args[] = { |
1837 | {'h',"help","help",0}, | |
04aa15a8 | 1838 | {'v',"version","version",0}, |
e1b74f61 AL |
1839 | {'p',"pkg-cache","Dir::Cache::pkgcache",CommandLine::HasArg}, |
1840 | {'s',"src-cache","Dir::Cache::srcpkgcache",CommandLine::HasArg}, | |
1841 | {'q',"quiet","quiet",CommandLine::IntLevel}, | |
76fbce56 | 1842 | {'i',"important","APT::Cache::Important",0}, |
7e2e2d5d | 1843 | {'f',"full","APT::Cache::ShowFull",0}, |
b2e465d6 | 1844 | {'g',"generate","APT::Cache::Generate",0}, |
648e3cb4 | 1845 | {'a',"all-versions","APT::Cache::AllVersions",0}, |
fe6fc1c2 AL |
1846 | {'n',"names-only","APT::Cache::NamesOnly",0}, |
1847 | {0,"all-names","APT::Cache::AllNames",0}, | |
b2e465d6 | 1848 | {0,"recurse","APT::Cache::RecurseDepends",0}, |
e1b74f61 AL |
1849 | {'c',"config-file",0,CommandLine::ConfigFile}, |
1850 | {'o',"option",0,CommandLine::ArbItem}, | |
fe6fc1c2 | 1851 | {0,"installed","APT::Cache::Installed",0}, |
08e8f724 | 1852 | {0,0,0,0}}; |
b0b4efb9 AL |
1853 | CommandLine::Dispatch CmdsA[] = {{"help",&ShowHelp}, |
1854 | {"add",&DoAdd}, | |
1855 | {"gencaches",&GenCaches}, | |
f8f410f5 | 1856 | {"showsrc",&ShowSrcPackage}, |
b0b4efb9 AL |
1857 | {0,0}}; |
1858 | CommandLine::Dispatch CmdsB[] = {{"showpkg",&DumpPackage}, | |
1859 | {"stats",&Stats}, | |
1860 | {"dump",&Dump}, | |
1861 | {"dumpavail",&DumpAvail}, | |
1862 | {"unmet",&UnMet}, | |
9dbb421f | 1863 | {"search",&Search}, |
349cd3b8 | 1864 | {"depends",&Depends}, |
eba2b51d | 1865 | {"rdepends",&RDepends}, |
3e94da1b | 1866 | {"dotty",&Dotty}, |
fff4b7f3 | 1867 | {"xvcg",&XVcg}, |
7e2e2d5d | 1868 | {"show",&ShowPackage}, |
7c1133fe | 1869 | {"pkgnames",&ShowPkgNames}, |
6007c1d4 | 1870 | {"showauto",&ShowAuto}, |
af87ab54 | 1871 | {"policy",&Policy}, |
bd3d53ef | 1872 | {"madison",&Madison}, |
b0b4efb9 | 1873 | {0,0}}; |
0a8e3465 AL |
1874 | |
1875 | CacheInitialize(); | |
67111687 AL |
1876 | |
1877 | // Set up gettext support | |
1878 | setlocale(LC_ALL,""); | |
1879 | textdomain(PACKAGE); | |
1880 | ||
e1b74f61 AL |
1881 | // Parse the command line and initialize the package library |
1882 | CommandLine CmdL(Args,_config); | |
b2e465d6 AL |
1883 | if (pkgInitConfig(*_config) == false || |
1884 | CmdL.Parse(argc,argv) == false || | |
1885 | pkgInitSystem(*_config,_system) == false) | |
08e8f724 AL |
1886 | { |
1887 | _error->DumpErrors(); | |
1888 | return 100; | |
1164783d | 1889 | } |
8efa2a3b | 1890 | |
e1b74f61 AL |
1891 | // See if the help should be shown |
1892 | if (_config->FindB("help") == true || | |
1893 | CmdL.FileSize() == 0) | |
b2e465d6 AL |
1894 | { |
1895 | ShowHelp(CmdL); | |
1896 | return 0; | |
1897 | } | |
1898 | ||
a9a5908d | 1899 | // Deal with stdout not being a tty |
a3f6ea20 | 1900 | if (isatty(STDOUT_FILENO) && _config->FindI("quiet",0) < 1) |
a9a5908d AL |
1901 | _config->Set("quiet","1"); |
1902 | ||
b0b4efb9 | 1903 | if (CmdL.DispatchArg(CmdsA,false) == false && _error->PendingError() == false) |
4b1b89c5 | 1904 | { |
2a3f3893 | 1905 | MMap *Map = 0; |
b2e465d6 | 1906 | if (_config->FindB("APT::Cache::Generate",true) == false) |
4b1b89c5 AL |
1907 | { |
1908 | Map = new MMap(*new FileFd(_config->FindFile("Dir::Cache::pkgcache"), | |
1909 | FileFd::ReadOnly),MMap::Public|MMap::ReadOnly); | |
1910 | } | |
1911 | else | |
1912 | { | |
1913 | // Open the cache file | |
af87ab54 AL |
1914 | SrcList = new pkgSourceList; |
1915 | SrcList->ReadMainList(); | |
f8f410f5 | 1916 | |
4b1b89c5 AL |
1917 | // Generate it and map it |
1918 | OpProgress Prog; | |
af87ab54 | 1919 | pkgMakeStatusCache(*SrcList,Prog,&Map,true); |
4b1b89c5 AL |
1920 | } |
1921 | ||
b0b4efb9 | 1922 | if (_error->PendingError() == false) |
1164783d | 1923 | { |
b2e465d6 | 1924 | pkgCache Cache(Map); |
b0b4efb9 AL |
1925 | GCache = &Cache; |
1926 | if (_error->PendingError() == false) | |
1927 | CmdL.DispatchArg(CmdsB); | |
803fafcb AL |
1928 | } |
1929 | delete Map; | |
1164783d AL |
1930 | } |
1931 | ||
1932 | // Print any errors or warnings found during parsing | |
1933 | if (_error->empty() == false) | |
1934 | { | |
0a8e3465 | 1935 | bool Errors = _error->PendingError(); |
1164783d | 1936 | _error->DumpErrors(); |
0a8e3465 | 1937 | return Errors == true?100:0; |
1164783d AL |
1938 | } |
1939 | ||
1940 | return 0; | |
1941 | } | |
92fcbfc1 | 1942 | /*}}}*/ |