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