]>
git.saurik.com Git - apt.git/blob - cmdline/apt-cache.cc
d73111b6a505b89f16ad41b2ca143e57ffe20b05
1 // -*- mode: cpp; mode: fold -*-
3 // $Id: apt-cache.cc,v 1.72 2004/04/30 04:34:03 mdz Exp $
4 /* ######################################################################
6 apt-cache - Manages the cache files
8 apt-cache provides some functions fo manipulating the cache files.
9 It uses the command line interface common to all the APT tools.
11 Returns 100 on failure, 0 on success.
13 ##################################################################### */
15 // Include Files /*{{{*/
16 #include <apt-pkg/error.h>
17 #include <apt-pkg/pkgcachegen.h>
18 #include <apt-pkg/init.h>
19 #include <apt-pkg/progress.h>
20 #include <apt-pkg/sourcelist.h>
21 #include <apt-pkg/cmndline.h>
22 #include <apt-pkg/strutl.h>
23 #include <apt-pkg/pkgrecords.h>
24 #include <apt-pkg/srcrecords.h>
25 #include <apt-pkg/version.h>
26 #include <apt-pkg/policy.h>
27 #include <apt-pkg/tagfile.h>
28 #include <apt-pkg/algorithms.h>
29 #include <apt-pkg/sptr.h>
47 pkgSourceList
*SrcList
= 0;
49 // LocalitySort - Sort a version list by package file locality /*{{{*/
50 // ---------------------------------------------------------------------
52 int LocalityCompare(const void *a
, const void *b
)
54 pkgCache::VerFile
*A
= *(pkgCache::VerFile
**)a
;
55 pkgCache::VerFile
*B
= *(pkgCache::VerFile
**)b
;
64 if (A
->File
== B
->File
)
65 return A
->Offset
- B
->Offset
;
66 return A
->File
- B
->File
;
69 void LocalitySort(pkgCache::VerFile
**begin
,
70 unsigned long Count
,size_t Size
)
72 qsort(begin
,Count
,Size
,LocalityCompare
);
75 void LocalitySort(pkgCache::DescFile
**begin
,
76 unsigned long Count
,size_t Size
)
78 qsort(begin
,Count
,Size
,LocalityCompare
);
81 // UnMet - Show unmet dependencies /*{{{*/
82 // ---------------------------------------------------------------------
84 bool UnMet(CommandLine
&CmdL
)
86 pkgCache
&Cache
= *GCache
;
87 bool Important
= _config
->FindB("APT::Cache::Important",false);
89 for (pkgCache::PkgIterator P
= Cache
.PkgBegin(); P
.end() == false; P
++)
91 for (pkgCache::VerIterator V
= P
.VersionList(); V
.end() == false; V
++)
94 for (pkgCache::DepIterator D
= V
.DependsList(); D
.end() == false;)
97 pkgCache::DepIterator Start
;
98 pkgCache::DepIterator End
;
101 // Skip conflicts and replaces
102 if (End
->Type
!= pkgCache::Dep::PreDepends
&&
103 End
->Type
!= pkgCache::Dep::Depends
&&
104 End
->Type
!= pkgCache::Dep::Suggests
&&
105 End
->Type
!= pkgCache::Dep::Recommends
)
108 // Important deps only
109 if (Important
== true)
110 if (End
->Type
!= pkgCache::Dep::PreDepends
&&
111 End
->Type
!= pkgCache::Dep::Depends
)
114 // Verify the or group
116 pkgCache::DepIterator RealStart
= Start
;
119 // See if this dep is Ok
120 pkgCache::Version
**VList
= Start
.AllTargets();
141 ioprintf(cout
,_("Package %s version %s has an unmet dep:\n"),
142 P
.Name(),V
.VerStr());
145 // Print out the dep type
146 cout
<< " " << End
.DepType() << ": ";
152 cout
<< Start
.TargetPkg().Name();
153 if (Start
.TargetVer() != 0)
154 cout
<< " (" << Start
.CompType() << " " << Start
.TargetVer() <<
170 // DumpPackage - Show a dump of a package record /*{{{*/
171 // ---------------------------------------------------------------------
173 bool DumpPackage(CommandLine
&CmdL
)
175 pkgCache
&Cache
= *GCache
;
176 for (const char **I
= CmdL
.FileList
+ 1; *I
!= 0; I
++)
178 pkgCache::PkgIterator Pkg
= Cache
.FindPkg(*I
);
179 if (Pkg
.end() == true)
181 _error
->Warning(_("Unable to locate package %s"),*I
);
185 cout
<< "Package: " << Pkg
.Name() << endl
;
186 cout
<< "Versions: " << endl
;
187 for (pkgCache::VerIterator Cur
= Pkg
.VersionList(); Cur
.end() != true; Cur
++)
189 cout
<< Cur
.VerStr();
190 for (pkgCache::VerFileIterator Vf
= Cur
.FileList(); Vf
.end() == false; Vf
++)
191 cout
<< " (" << Vf
.File().FileName() << ")";
193 for (pkgCache::DescIterator D
= Cur
.DescriptionList(); D
.end() == false; D
++)
195 cout
<< " Description Language: " << D
.LanguageCode() << endl
196 << " File: " << D
.FileList().File().FileName() << endl
197 << " MD5: " << D
.md5() << endl
;
204 cout
<< "Reverse Depends: " << endl
;
205 for (pkgCache::DepIterator D
= Pkg
.RevDependsList(); D
.end() != true; D
++)
207 cout
<< " " << D
.ParentPkg().Name() << ',' << D
.TargetPkg().Name();
209 cout
<< ' ' << DeNull(D
.TargetVer()) << endl
;
214 cout
<< "Dependencies: " << endl
;
215 for (pkgCache::VerIterator Cur
= Pkg
.VersionList(); Cur
.end() != true; Cur
++)
217 cout
<< Cur
.VerStr() << " - ";
218 for (pkgCache::DepIterator Dep
= Cur
.DependsList(); Dep
.end() != true; Dep
++)
219 cout
<< Dep
.TargetPkg().Name() << " (" << (int)Dep
->CompareOp
<< " " << DeNull(Dep
.TargetVer()) << ") ";
223 cout
<< "Provides: " << endl
;
224 for (pkgCache::VerIterator Cur
= Pkg
.VersionList(); Cur
.end() != true; Cur
++)
226 cout
<< Cur
.VerStr() << " - ";
227 for (pkgCache::PrvIterator Prv
= Cur
.ProvidesList(); Prv
.end() != true; Prv
++)
228 cout
<< Prv
.ParentPkg().Name() << " ";
231 cout
<< "Reverse Provides: " << endl
;
232 for (pkgCache::PrvIterator Prv
= Pkg
.ProvidesList(); Prv
.end() != true; Prv
++)
233 cout
<< Prv
.OwnerPkg().Name() << " " << Prv
.OwnerVer().VerStr() << endl
;
239 // Stats - Dump some nice statistics /*{{{*/
240 // ---------------------------------------------------------------------
242 bool Stats(CommandLine
&Cmd
)
244 pkgCache
&Cache
= *GCache
;
245 cout
<< _("Total package names: ") << Cache
.Head().PackageCount
<< " (" <<
246 SizeToStr(Cache
.Head().PackageCount
*Cache
.Head().PackageSz
) << ')' << endl
;
253 pkgCache::PkgIterator I
= Cache
.PkgBegin();
254 for (;I
.end() != true; I
++)
256 if (I
->VersionList
!= 0 && I
->ProvidesList
== 0)
262 if (I
->VersionList
!= 0 && I
->ProvidesList
!= 0)
268 if (I
->VersionList
== 0 && I
->ProvidesList
!= 0)
271 if (I
.ProvidesList()->NextProvides
== 0)
279 if (I
->VersionList
== 0 && I
->ProvidesList
== 0)
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
;
289 cout
<< _(" Missing: ") << Missing
<< endl
;
291 cout
<< _("Total distinct versions: ") << Cache
.Head().VersionCount
<< " (" <<
292 SizeToStr(Cache
.Head().VersionCount
*Cache
.Head().VersionSz
) << ')' << endl
;
293 cout
<< _("Total distinct descriptions: ") << Cache
.Head().DescriptionCount
<< " (" <<
294 SizeToStr(Cache
.Head().DescriptionCount
*Cache
.Head().DescriptionSz
) << ')' << endl
;
295 cout
<< _("Total dependencies: ") << Cache
.Head().DependsCount
<< " (" <<
296 SizeToStr(Cache
.Head().DependsCount
*Cache
.Head().DependencySz
) << ')' << endl
;
298 cout
<< _("Total ver/file relations: ") << Cache
.Head().VerFileCount
<< " (" <<
299 SizeToStr(Cache
.Head().VerFileCount
*Cache
.Head().VerFileSz
) << ')' << endl
;
300 cout
<< _("Total Desc/File relations: ") << Cache
.Head().DescFileCount
<< " (" <<
301 SizeToStr(Cache
.Head().DescFileCount
*Cache
.Head().DescFileSz
) << ')' << endl
;
302 cout
<< _("Total Provides mappings: ") << Cache
.Head().ProvidesCount
<< " (" <<
303 SizeToStr(Cache
.Head().ProvidesCount
*Cache
.Head().ProvidesSz
) << ')' << endl
;
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
)
312 Size
+= strlen(Cache
.StrP
+ I
->String
) + 1;
314 cout
<< _("Total globbed strings: ") << Count
<< " (" << SizeToStr(Size
) << ')' << endl
;
316 unsigned long DepVerSize
= 0;
317 for (pkgCache::PkgIterator P
= Cache
.PkgBegin(); P
.end() == false; P
++)
319 for (pkgCache::VerIterator V
= P
.VersionList(); V
.end() == false; V
++)
321 for (pkgCache::DepIterator D
= V
.DependsList(); D
.end() == false; D
++)
324 DepVerSize
+= strlen(D
.TargetVer()) + 1;
328 cout
<< _("Total dependency version space: ") << SizeToStr(DepVerSize
) << endl
;
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
;
333 cout
<< _("Total slack space: ") << SizeToStr(Slack
) << endl
;
335 unsigned long Total
= 0;
336 Total
= Slack
+ Size
+ Cache
.Head().DependsCount
*Cache
.Head().DependencySz
+
337 Cache
.Head().VersionCount
*Cache
.Head().VersionSz
+
338 Cache
.Head().PackageCount
*Cache
.Head().PackageSz
+
339 Cache
.Head().VerFileCount
*Cache
.Head().VerFileSz
+
340 Cache
.Head().ProvidesCount
*Cache
.Head().ProvidesSz
;
341 cout
<< _("Total space accounted for: ") << SizeToStr(Total
) << endl
;
346 // Dump - show everything /*{{{*/
347 // ---------------------------------------------------------------------
348 /* This is worthless except fer debugging things */
349 bool Dump(CommandLine
&Cmd
)
351 pkgCache
&Cache
= *GCache
;
352 cout
<< "Using Versioning System: " << Cache
.VS
->Label
<< endl
;
354 for (pkgCache::PkgIterator P
= Cache
.PkgBegin(); P
.end() == false; P
++)
356 cout
<< "Package: " << P
.Name() << endl
;
357 for (pkgCache::VerIterator V
= P
.VersionList(); V
.end() == false; V
++)
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
++)
362 cout
<< " Depends: " << D
.TargetPkg().Name() << ' ' <<
363 DeNull(D
.TargetVer()) << endl
;
364 for (pkgCache::DescIterator D
= V
.DescriptionList(); D
.end() == false; D
++)
366 cout
<< " Description Language: " << D
.LanguageCode() << endl
367 << " File: " << D
.FileList().File().FileName() << endl
368 << " MD5: " << D
.md5() << endl
;
373 for (pkgCache::PkgFileIterator F
= Cache
.FileBegin(); F
.end() == false; F
++)
375 cout
<< "File: " << F
.FileName() << endl
;
376 cout
<< " Type: " << F
.IndexType() << endl
;
377 cout
<< " Size: " << F
->Size
<< endl
;
378 cout
<< " ID: " << F
->ID
<< endl
;
379 cout
<< " Flags: " << F
->Flags
<< endl
;
380 cout
<< " Time: " << TimeRFC1123(F
->mtime
) << endl
;
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
;
393 // DumpAvail - Print out the available list /*{{{*/
394 // ---------------------------------------------------------------------
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.. */
397 bool DumpAvail(CommandLine
&Cmd
)
399 pkgCache
&Cache
= *GCache
;
401 pkgPolicy
Plcy(&Cache
);
402 if (ReadPinFile(Plcy
) == false)
405 unsigned long Count
= Cache
.HeaderP
->PackageCount
+1;
406 pkgCache::VerFile
**VFList
= new pkgCache::VerFile
*[Count
];
407 memset(VFList
,0,sizeof(*VFList
)*Count
);
409 // Map versions that we want to write out onto the VerList array.
410 for (pkgCache::PkgIterator P
= Cache
.PkgBegin(); P
.end() == false; P
++)
412 if (P
->VersionList
== 0)
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
);
421 if (P
->CurrentVer
== 0)
426 pkgCache::VerFileIterator VF
= V
.FileList();
427 for (; VF
.end() == false ; VF
++)
428 if ((VF
.File()->Flags
& pkgCache::Flag::NotSource
) == 0)
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)
441 for (pkgCache::VerIterator Cur
= P
.VersionList(); Cur
.end() != true; Cur
++)
443 for (VF
= Cur
.FileList(); VF
.end() == false; VF
++)
445 if ((VF
.File()->Flags
& pkgCache::Flag::NotSource
) == 0)
452 if (VF
.end() == false)
460 LocalitySort(VFList
,Count
,sizeof(*VFList
));
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;)
466 pkgCache::PkgFileIterator
File(Cache
,(*J
)->File
+ Cache
.PkgFileP
);
467 if (File
.IsOk() == false)
469 _error
->Error(_("Package file %s is out of sync."),File
.FileName());
473 FileFd
PkgF(File
.FileName(),FileFd::ReadOnly
);
474 if (_error
->PendingError() == true)
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;
485 if ((*J
)->File
+ Cache
.PkgFileP
!= File
)
488 const pkgCache::VerFile
&VF
= **J
;
490 // Read the record and then write it out again.
491 unsigned long Jitter
= VF
.Offset
- Pos
;
494 if (PkgF
.Seek(VF
.Offset
) == false)
499 if (PkgF
.Read(Buffer
,VF
.Size
+ Jitter
) == false)
501 Buffer
[VF
.Size
+ Jitter
] = '\n';
504 if ((File
->Flags
& pkgCache::Flag::NotSource
) == pkgCache::Flag::NotSource
)
507 TFRewriteData RW
[] = {{"Status",0},{"Config-Version",0},{}};
508 const char *Zero
= 0;
509 if (Tags
.Scan(Buffer
+Jitter
,VF
.Size
+1) == false ||
510 TFRewrite(stdout
,Tags
,&Zero
,RW
) == false)
512 _error
->Error("Internal Error, Unable to parse a package record");
519 if (fwrite(Buffer
+Jitter
,VF
.Size
+1,1,stdout
) != 1)
523 Pos
= VF
.Offset
+ VF
.Size
;
527 if (_error
->PendingError() == true)
533 return !_error
->PendingError();
536 // Depends - Print out a dependency tree /*{{{*/
537 // ---------------------------------------------------------------------
539 bool Depends(CommandLine
&CmdL
)
541 pkgCache
&Cache
= *GCache
;
542 SPtrArray
<unsigned> Colours
= new unsigned[Cache
.Head().PackageCount
];
543 memset(Colours
,0,sizeof(*Colours
)*Cache
.Head().PackageCount
);
545 for (const char **I
= CmdL
.FileList
+ 1; *I
!= 0; I
++)
547 pkgCache::PkgIterator Pkg
= Cache
.FindPkg(*I
);
548 if (Pkg
.end() == true)
550 _error
->Warning(_("Unable to locate package %s"),*I
);
553 Colours
[Pkg
->ID
] = 1;
556 bool Recurse
= _config
->FindB("APT::Cache::RecurseDepends",false);
557 bool Installed
= _config
->FindB("APT::Cache::Installed",false);
561 DidSomething
= false;
562 for (pkgCache::PkgIterator Pkg
= Cache
.PkgBegin(); Pkg
.end() == false; Pkg
++)
564 if (Colours
[Pkg
->ID
] != 1)
566 Colours
[Pkg
->ID
] = 2;
569 pkgCache::VerIterator Ver
= Pkg
.VersionList();
570 if (Ver
.end() == true)
572 cout
<< '<' << Pkg
.Name() << '>' << endl
;
576 cout
<< Pkg
.Name() << endl
;
578 for (pkgCache::DepIterator D
= Ver
.DependsList(); D
.end() == false; D
++)
581 pkgCache::PkgIterator Trg
= D
.TargetPkg();
583 if((Installed
&& Trg
->CurrentVer
!= 0) || !Installed
)
586 if ((D
->CompareOp
& pkgCache::Dep::Or
) == pkgCache::Dep::Or
)
592 if (Trg
->VersionList
== 0)
593 cout
<< D
.DepType() << ": <" << Trg
.Name() << ">" << endl
;
595 cout
<< D
.DepType() << ": " << Trg
.Name() << endl
;
598 Colours
[D
.TargetPkg()->ID
]++;
602 // Display all solutions
603 SPtrArray
<pkgCache::Version
*> List
= D
.AllTargets();
604 pkgPrioSortList(Cache
,List
);
605 for (pkgCache::Version
**I
= List
; *I
!= 0; I
++)
607 pkgCache::VerIterator
V(Cache
,*I
);
608 if (V
!= Cache
.VerP
+ V
.ParentPkg()->VersionList
||
609 V
->ParentPkg
== D
->Package
)
611 cout
<< " " << V
.ParentPkg().Name() << endl
;
614 Colours
[D
.ParentPkg()->ID
]++;
619 while (DidSomething
== true);
624 // RDepends - Print out a reverse dependency tree - mbc /*{{{*/
625 // ---------------------------------------------------------------------
627 bool RDepends(CommandLine
&CmdL
)
629 pkgCache
&Cache
= *GCache
;
630 SPtrArray
<unsigned> Colours
= new unsigned[Cache
.Head().PackageCount
];
631 memset(Colours
,0,sizeof(*Colours
)*Cache
.Head().PackageCount
);
633 for (const char **I
= CmdL
.FileList
+ 1; *I
!= 0; I
++)
635 pkgCache::PkgIterator Pkg
= Cache
.FindPkg(*I
);
636 if (Pkg
.end() == true)
638 _error
->Warning(_("Unable to locate package %s"),*I
);
641 Colours
[Pkg
->ID
] = 1;
644 bool Recurse
= _config
->FindB("APT::Cache::RecurseDepends",false);
645 bool Installed
= _config
->FindB("APT::Cache::Installed",false);
649 DidSomething
= false;
650 for (pkgCache::PkgIterator Pkg
= Cache
.PkgBegin(); Pkg
.end() == false; Pkg
++)
652 if (Colours
[Pkg
->ID
] != 1)
654 Colours
[Pkg
->ID
] = 2;
657 pkgCache::VerIterator Ver
= Pkg
.VersionList();
658 if (Ver
.end() == true)
660 cout
<< '<' << Pkg
.Name() << '>' << endl
;
664 cout
<< Pkg
.Name() << endl
;
666 cout
<< "Reverse Depends:" << endl
;
667 for (pkgCache::DepIterator D
= Pkg
.RevDependsList(); D
.end() == false; D
++)
670 pkgCache::PkgIterator Trg
= D
.ParentPkg();
672 if((Installed
&& Trg
->CurrentVer
!= 0) || !Installed
)
675 if ((D
->CompareOp
& pkgCache::Dep::Or
) == pkgCache::Dep::Or
)
680 if (Trg
->VersionList
== 0)
681 cout
<< D
.DepType() << ": <" << Trg
.Name() << ">" << endl
;
683 cout
<< Trg
.Name() << endl
;
686 Colours
[D
.ParentPkg()->ID
]++;
690 // Display all solutions
691 SPtrArray
<pkgCache::Version
*> List
= D
.AllTargets();
692 pkgPrioSortList(Cache
,List
);
693 for (pkgCache::Version
**I
= List
; *I
!= 0; I
++)
695 pkgCache::VerIterator
V(Cache
,*I
);
696 if (V
!= Cache
.VerP
+ V
.ParentPkg()->VersionList
||
697 V
->ParentPkg
== D
->Package
)
699 cout
<< " " << V
.ParentPkg().Name() << endl
;
702 Colours
[D
.ParentPkg()->ID
]++;
707 while (DidSomething
== true);
715 // xvcg - Generate a graph for xvcg /*{{{*/
716 // ---------------------------------------------------------------------
717 // Code contributed from Junichi Uekawa <dancer@debian.org> on 20 June 2002.
719 bool XVcg(CommandLine
&CmdL
)
721 pkgCache
&Cache
= *GCache
;
722 bool GivenOnly
= _config
->FindB("APT::Cache::GivenOnly",false);
724 /* Normal packages are boxes
725 Pure Provides are triangles
727 rhomb are missing packages*/
728 const char *Shapes
[] = {"ellipse","triangle","box","rhomb"};
730 /* Initialize the list of packages to show.
732 2 = To Show no recurse
733 3 = Emitted no recurse
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
];
742 // Show everything if no arguments given
743 if (CmdL
.FileList
[1] == 0)
744 for (unsigned long I
= 0; I
!= Cache
.Head().PackageCount
; I
++)
747 for (unsigned long I
= 0; I
!= Cache
.Head().PackageCount
; I
++)
749 memset(Flags
,0,sizeof(*Flags
)*Cache
.Head().PackageCount
);
752 for (pkgCache::PkgIterator Pkg
= Cache
.PkgBegin(); Pkg
.end() == false; Pkg
++)
754 if (Pkg
->VersionList
== 0)
757 if (Pkg
->ProvidesList
== 0)
758 ShapeMap
[Pkg
->ID
] = 0;
760 ShapeMap
[Pkg
->ID
] = 1;
765 if (Pkg
->ProvidesList
== 0)
766 ShapeMap
[Pkg
->ID
] = 2;
768 ShapeMap
[Pkg
->ID
] = 3;
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
++)
775 // Process per-package flags
780 if (P
.end()[-1] == '^')
786 if (P
.end()[-1] == ',')
790 // Locate the package
791 pkgCache::PkgIterator Pkg
= Cache
.FindPkg(P
);
792 if (Pkg
.end() == true)
794 _error
->Warning(_("Unable to locate package %s"),*I
);
797 Show
[Pkg
->ID
] = ToShow
;
800 Flags
[Pkg
->ID
] |= ForceNR
;
804 cout
<< "graph: { title: \"packages\"" << endl
<<
805 "xmax: 700 ymax: 700 x: 30 y: 30" << endl
<<
806 "layout_downfactor: 8" << endl
;
812 for (pkgCache::PkgIterator Pkg
= Cache
.PkgBegin(); Pkg
.end() == false; Pkg
++)
814 // See we need to show this package
815 if (Show
[Pkg
->ID
] == None
|| Show
[Pkg
->ID
] >= DoneNR
)
818 //printf ("node: { title: \"%s\" label: \"%s\" }\n", Pkg.Name(), Pkg.Name());
821 if (Show
[Pkg
->ID
] == ToShowNR
|| (Flags
[Pkg
->ID
] & ForceNR
) == ForceNR
)
823 // Pure Provides and missing packages have no deps!
824 if (ShapeMap
[Pkg
->ID
] == 0 || ShapeMap
[Pkg
->ID
] == 1)
825 Show
[Pkg
->ID
] = Done
;
827 Show
[Pkg
->ID
] = DoneNR
;
830 Show
[Pkg
->ID
] = Done
;
833 // No deps to map out
834 if (Pkg
->VersionList
== 0 || Show
[Pkg
->ID
] == DoneNR
)
837 pkgCache::VerIterator Ver
= Pkg
.VersionList();
838 for (pkgCache::DepIterator D
= Ver
.DependsList(); D
.end() == false; D
++)
840 // See if anything can meet this dep
841 // Walk along the actual package providing versions
843 pkgCache::PkgIterator DPkg
= D
.TargetPkg();
844 for (pkgCache::VerIterator I
= DPkg
.VersionList();
845 I
.end() == false && Hit
== false; I
++)
847 if (Cache
.VS
->CheckDep(I
.VerStr(),D
->CompareOp
,D
.TargetVer()) == true)
851 // Follow all provides
852 for (pkgCache::PrvIterator I
= DPkg
.ProvidesList();
853 I
.end() == false && Hit
== false; I
++)
855 if (Cache
.VS
->CheckDep(I
.ProvideVersion(),D
->CompareOp
,D
.TargetVer()) == false)
860 // Only graph critical deps
861 if (D
.IsCritical() == true)
863 printf ("edge: { sourcename: \"%s\" targetname: \"%s\" class: 2 ",Pkg
.Name(), D
.TargetPkg().Name() );
865 // Colour the node for recursion
866 if (Show
[D
.TargetPkg()->ID
] <= DoneNR
)
868 /* If a conflicts does not meet anything in the database
869 then show the relation but do not recurse */
871 (D
->Type
== pkgCache::Dep::Conflicts
||
872 D
->Type
== pkgCache::Dep::DpkgBreaks
||
873 D
->Type
== pkgCache::Dep::Obsoletes
))
875 if (Show
[D
.TargetPkg()->ID
] == None
&&
876 Show
[D
.TargetPkg()->ID
] != ToShow
)
877 Show
[D
.TargetPkg()->ID
] = ToShowNR
;
881 if (GivenOnly
== true && Show
[D
.TargetPkg()->ID
] != ToShow
)
882 Show
[D
.TargetPkg()->ID
] = ToShowNR
;
884 Show
[D
.TargetPkg()->ID
] = ToShow
;
891 case pkgCache::Dep::Conflicts
:
892 printf("label: \"conflicts\" color: lightgreen }\n");
894 case pkgCache::Dep::DpkgBreaks
:
895 printf("label: \"breaks\" color: lightgreen }\n");
897 case pkgCache::Dep::Obsoletes
:
898 printf("label: \"obsoletes\" color: lightgreen }\n");
901 case pkgCache::Dep::PreDepends
:
902 printf("label: \"predepends\" color: blue }\n");
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
++)
918 if (Show
[Pkg
->ID
] < DoneNR
)
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
]]);
925 printf("node: { title: \"%s\" label: \"%s\" shape: %s }\n", Pkg
.Name(), Pkg
.Name(),
926 Shapes
[ShapeMap
[Pkg
->ID
]]);
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
)
943 pkgCache
&Cache
= *GCache
;
944 bool GivenOnly
= _config
->FindB("APT::Cache::GivenOnly",false);
946 /* Normal packages are boxes
947 Pure Provides are triangles
949 Hexagons are missing packages*/
950 const char *Shapes
[] = {"hexagon","triangle","box","diamond"};
952 /* Initialize the list of packages to show.
954 2 = To Show no recurse
955 3 = Emitted no recurse
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
];
964 // Show everything if no arguments given
965 if (CmdL
.FileList
[1] == 0)
966 for (unsigned long I
= 0; I
!= Cache
.Head().PackageCount
; I
++)
969 for (unsigned long I
= 0; I
!= Cache
.Head().PackageCount
; I
++)
971 memset(Flags
,0,sizeof(*Flags
)*Cache
.Head().PackageCount
);
974 for (pkgCache::PkgIterator Pkg
= Cache
.PkgBegin(); Pkg
.end() == false; Pkg
++)
976 if (Pkg
->VersionList
== 0)
979 if (Pkg
->ProvidesList
== 0)
980 ShapeMap
[Pkg
->ID
] = 0;
982 ShapeMap
[Pkg
->ID
] = 1;
987 if (Pkg
->ProvidesList
== 0)
988 ShapeMap
[Pkg
->ID
] = 2;
990 ShapeMap
[Pkg
->ID
] = 3;
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
++)
997 // Process per-package flags
1002 if (P
.end()[-1] == '^')
1008 if (P
.end()[-1] == ',')
1012 // Locate the package
1013 pkgCache::PkgIterator Pkg
= Cache
.FindPkg(P
);
1014 if (Pkg
.end() == true)
1016 _error
->Warning(_("Unable to locate package %s"),*I
);
1019 Show
[Pkg
->ID
] = ToShow
;
1022 Flags
[Pkg
->ID
] |= ForceNR
;
1026 printf("digraph packages {\n");
1027 printf("concentrate=true;\n");
1028 printf("size=\"30,40\";\n");
1034 for (pkgCache::PkgIterator Pkg
= Cache
.PkgBegin(); Pkg
.end() == false; Pkg
++)
1036 // See we need to show this package
1037 if (Show
[Pkg
->ID
] == None
|| Show
[Pkg
->ID
] >= DoneNR
)
1041 if (Show
[Pkg
->ID
] == ToShowNR
|| (Flags
[Pkg
->ID
] & ForceNR
) == ForceNR
)
1043 // Pure Provides and missing packages have no deps!
1044 if (ShapeMap
[Pkg
->ID
] == 0 || ShapeMap
[Pkg
->ID
] == 1)
1045 Show
[Pkg
->ID
] = Done
;
1047 Show
[Pkg
->ID
] = DoneNR
;
1050 Show
[Pkg
->ID
] = Done
;
1053 // No deps to map out
1054 if (Pkg
->VersionList
== 0 || Show
[Pkg
->ID
] == DoneNR
)
1057 pkgCache::VerIterator Ver
= Pkg
.VersionList();
1058 for (pkgCache::DepIterator D
= Ver
.DependsList(); D
.end() == false; D
++)
1060 // See if anything can meet this dep
1061 // Walk along the actual package providing versions
1063 pkgCache::PkgIterator DPkg
= D
.TargetPkg();
1064 for (pkgCache::VerIterator I
= DPkg
.VersionList();
1065 I
.end() == false && Hit
== false; I
++)
1067 if (Cache
.VS
->CheckDep(I
.VerStr(),D
->CompareOp
,D
.TargetVer()) == true)
1071 // Follow all provides
1072 for (pkgCache::PrvIterator I
= DPkg
.ProvidesList();
1073 I
.end() == false && Hit
== false; I
++)
1075 if (Cache
.VS
->CheckDep(I
.ProvideVersion(),D
->CompareOp
,D
.TargetVer()) == false)
1079 // Only graph critical deps
1080 if (D
.IsCritical() == true)
1082 printf("\"%s\" -> \"%s\"",Pkg
.Name(),D
.TargetPkg().Name());
1084 // Colour the node for recursion
1085 if (Show
[D
.TargetPkg()->ID
] <= DoneNR
)
1087 /* If a conflicts does not meet anything in the database
1088 then show the relation but do not recurse */
1090 (D
->Type
== pkgCache::Dep::Conflicts
||
1091 D
->Type
== pkgCache::Dep::Obsoletes
))
1093 if (Show
[D
.TargetPkg()->ID
] == None
&&
1094 Show
[D
.TargetPkg()->ID
] != ToShow
)
1095 Show
[D
.TargetPkg()->ID
] = ToShowNR
;
1099 if (GivenOnly
== true && Show
[D
.TargetPkg()->ID
] != ToShow
)
1100 Show
[D
.TargetPkg()->ID
] = ToShowNR
;
1102 Show
[D
.TargetPkg()->ID
] = ToShow
;
1109 case pkgCache::Dep::Conflicts
:
1110 case pkgCache::Dep::Obsoletes
:
1111 printf("[color=springgreen];\n");
1114 case pkgCache::Dep::PreDepends
:
1115 printf("[color=blue];\n");
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
++)
1131 if (Show
[Pkg
->ID
] < DoneNR
)
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
]]);
1139 printf("\"%s\" [shape=%s];\n",Pkg
.Name(),
1140 Shapes
[ShapeMap
[Pkg
->ID
]]);
1147 // DoAdd - Perform an adding operation /*{{{*/
1148 // ---------------------------------------------------------------------
1150 bool DoAdd(CommandLine
&CmdL
)
1152 return _error
->Error("Unimplemented");
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");
1159 FileFd
CacheF(_config
->FindFile("Dir::Cache::pkgcache"),FileFd::WriteAny
);
1160 if (_error
->PendingError() == true)
1163 DynamicMMap
Map(CacheF
,MMap::Public
);
1164 if (_error
->PendingError() == true)
1167 OpTextProgress
Progress(*_config
);
1168 pkgCacheGenerator
Gen(Map
,Progress
);
1169 if (_error
->PendingError() == true)
1172 unsigned long Length
= CmdL
.FileSize() - 1;
1173 for (const char **I
= CmdL
.FileList
+ 1; *I
!= 0; I
++)
1175 Progress
.OverallProgress(I
- CmdL
.FileList
,Length
,1,"Generating cache");
1176 Progress
.SubProgress(Length
);
1179 FileFd
TagF(*I
,FileFd::ReadOnly
);
1180 debListParser
Parser(TagF
);
1181 if (_error
->PendingError() == true)
1182 return _error
->Error("Problem opening %s",*I
);
1184 if (Gen
.SelectFile(*I
,"") == false)
1185 return _error
->Error("Problem with SelectFile");
1187 if (Gen
.MergeList(Parser
) == false)
1188 return _error
->Error("Problem with MergeList");
1192 GCache
= &Gen
.GetCache();
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
)
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)
1210 if (Vf
.end() == true)
1213 // Check and load the package list file
1214 pkgCache::PkgFileIterator I
= Vf
.File();
1215 if (I
.IsOk() == false)
1216 return _error
->Error(_("Package file %s is out of sync."),I
.FileName());
1218 FileFd
PkgF(I
.FileName(),FileFd::ReadOnly
);
1219 if (_error
->PendingError() == true)
1223 unsigned char *Buffer
= new unsigned char[GCache
->HeaderP
->MaxVerFileSize
+1];
1224 Buffer
[V
.FileList()->Size
] = '\n';
1225 if (PkgF
.Seek(V
.FileList()->Offset
) == false ||
1226 PkgF
.Read(Buffer
,V
.FileList()->Size
) == false)
1232 // Get a pointer to start of Description field
1233 const unsigned char *DescP
= (unsigned char*)strstr((char*)Buffer
, "Description:");
1235 // Write all but Description
1236 if (fwrite(Buffer
,1,DescP
- Buffer
,stdout
) < (size_t)(DescP
- Buffer
))
1242 // Show the right description
1243 pkgRecords
Recs(*GCache
);
1244 pkgCache::DescIterator Desc
= V
.TranslatedDescription();
1245 pkgRecords::Parser
&P
= Recs
.Lookup(Desc
.FileList());
1246 cout
<< "Description" << ( (strcmp(Desc
.LanguageCode(),"") != 0) ? "-" : "" ) << Desc
.LanguageCode() << ": " << P
.LongDesc();
1248 // Find the first field after the description (if there is any)
1249 for(DescP
++;DescP
!= &Buffer
[V
.FileList()->Size
];DescP
++)
1251 if(*DescP
== '\n' && *(DescP
+1) != ' ')
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
))
1264 // write a final newline (after the description)
1271 // Search - Perform a search /*{{{*/
1272 // ---------------------------------------------------------------------
1273 /* This searches the package names and pacakge descriptions for a pattern */
1276 pkgCache::DescFile
*Df
;
1280 bool Search(CommandLine
&CmdL
)
1282 pkgCache
&Cache
= *GCache
;
1283 bool ShowFull
= _config
->FindB("APT::Cache::ShowFull",false);
1284 bool NamesOnly
= _config
->FindB("APT::Cache::NamesOnly",false);
1285 unsigned NumPatterns
= CmdL
.FileSize() -1;
1287 pkgDepCache::Policy Plcy
;
1289 // Make sure there is at least one argument
1290 if (NumPatterns
< 1)
1291 return _error
->Error(_("You must give exactly one pattern"));
1293 // Compile the regex pattern
1294 regex_t
*Patterns
= new regex_t
[NumPatterns
];
1295 memset(Patterns
,0,sizeof(*Patterns
)*NumPatterns
);
1296 for (unsigned I
= 0; I
!= NumPatterns
; I
++)
1298 if (regcomp(&Patterns
[I
],CmdL
.FileList
[I
+1],REG_EXTENDED
| REG_ICASE
|
1302 regfree(&Patterns
[I
]);
1303 return _error
->Error("Regex compilation error");
1307 // Create the text record parser
1308 pkgRecords
Recs(Cache
);
1309 if (_error
->PendingError() == true)
1311 for (unsigned I
= 0; I
!= NumPatterns
; I
++)
1312 regfree(&Patterns
[I
]);
1316 ExDescFile
*DFList
= new ExDescFile
[Cache
.HeaderP
->PackageCount
+1];
1317 memset(DFList
,0,sizeof(*DFList
)*Cache
.HeaderP
->PackageCount
+1);
1319 // Map versions that we want to write out onto the VerList array.
1320 for (pkgCache::PkgIterator P
= Cache
.PkgBegin(); P
.end() == false; P
++)
1322 DFList
[P
->ID
].NameMatch
= NumPatterns
!= 0;
1323 for (unsigned I
= 0; I
!= NumPatterns
; I
++)
1325 if (regexec(&Patterns
[I
],P
.Name(),0,0,0) == 0)
1326 DFList
[P
->ID
].NameMatch
&= true;
1328 DFList
[P
->ID
].NameMatch
= false;
1331 // Doing names only, drop any that dont match..
1332 if (NamesOnly
== true && DFList
[P
->ID
].NameMatch
== false)
1335 // Find the proper version to use.
1336 pkgCache::VerIterator V
= Plcy
.GetCandidateVer(P
);
1337 if (V
.end() == false)
1338 DFList
[P
->ID
].Df
= V
.DescriptionList().FileList();
1341 // Include all the packages that provide matching names too
1342 for (pkgCache::PkgIterator P
= Cache
.PkgBegin(); P
.end() == false; P
++)
1344 if (DFList
[P
->ID
].NameMatch
== false)
1347 for (pkgCache::PrvIterator Prv
= P
.ProvidesList() ; Prv
.end() == false; Prv
++)
1349 pkgCache::VerIterator V
= Plcy
.GetCandidateVer(Prv
.OwnerPkg());
1350 if (V
.end() == false)
1352 DFList
[Prv
.OwnerPkg()->ID
].Df
= V
.DescriptionList().FileList();
1353 DFList
[Prv
.OwnerPkg()->ID
].NameMatch
= true;
1358 LocalitySort(&DFList
->Df
,Cache
.HeaderP
->PackageCount
,sizeof(*DFList
));
1360 // Iterate over all the version records and check them
1361 for (ExDescFile
*J
= DFList
; J
->Df
!= 0; J
++)
1363 pkgRecords::Parser
&P
= Recs
.Lookup(pkgCache::DescFileIterator(Cache
,J
->Df
));
1366 if (J
->NameMatch
== false)
1368 string LongDesc
= P
.LongDesc();
1369 Match
= NumPatterns
!= 0;
1370 for (unsigned I
= 0; I
!= NumPatterns
; I
++)
1372 if (regexec(&Patterns
[I
],LongDesc
.c_str(),0,0,0) == 0)
1381 if (ShowFull
== true)
1385 P
.GetRec(Start
,End
);
1386 fwrite(Start
,End
-Start
,1,stdout
);
1390 printf("%s - %s\n",P
.Name().c_str(),P
.ShortDesc().c_str());
1395 for (unsigned I
= 0; I
!= NumPatterns
; I
++)
1396 regfree(&Patterns
[I
]);
1398 return _error
->Error("Write to stdout failed");
1402 // ShowPackage - Dump the package record to the screen /*{{{*/
1403 // ---------------------------------------------------------------------
1405 bool ShowPackage(CommandLine
&CmdL
)
1407 pkgCache
&Cache
= *GCache
;
1408 pkgDepCache::Policy Plcy
;
1412 for (const char **I
= CmdL
.FileList
+ 1; *I
!= 0; I
++)
1414 pkgCache::PkgIterator Pkg
= Cache
.FindPkg(*I
);
1415 if (Pkg
.end() == true)
1417 _error
->Warning(_("Unable to locate package %s"),*I
);
1423 // Find the proper version to use.
1424 if (_config
->FindB("APT::Cache::AllVersions","true") == true)
1426 pkgCache::VerIterator V
;
1427 for (V
= Pkg
.VersionList(); V
.end() == false; V
++)
1429 if (DisplayRecord(V
) == false)
1435 pkgCache::VerIterator V
= Plcy
.GetCandidateVer(Pkg
);
1436 if (V
.end() == true || V
.FileList().end() == true)
1438 if (DisplayRecord(V
) == false)
1445 return _error
->Error(_("No packages found"));
1448 // ShowPkgNames - Show package names /*{{{*/
1449 // ---------------------------------------------------------------------
1450 /* This does a prefix match on the first argument */
1451 bool ShowPkgNames(CommandLine
&CmdL
)
1453 pkgCache
&Cache
= *GCache
;
1454 pkgCache::PkgIterator I
= Cache
.PkgBegin();
1455 bool All
= _config
->FindB("APT::Cache::AllNames","false");
1457 if (CmdL
.FileList
[1] != 0)
1459 for (;I
.end() != true; I
++)
1461 if (All
== false && I
->VersionList
== 0)
1464 if (strncmp(I
.Name(),CmdL
.FileList
[1],strlen(CmdL
.FileList
[1])) == 0)
1465 cout
<< I
.Name() << endl
;
1472 for (;I
.end() != true; I
++)
1474 if (All
== false && I
->VersionList
== 0)
1476 cout
<< I
.Name() << endl
;
1482 // ShowSrcPackage - Show source package records /*{{{*/
1483 // ---------------------------------------------------------------------
1485 bool ShowSrcPackage(CommandLine
&CmdL
)
1488 List
.ReadMainList();
1490 // Create the text record parsers
1491 pkgSrcRecords
SrcRecs(List
);
1492 if (_error
->PendingError() == true)
1495 for (const char **I
= CmdL
.FileList
+ 1; *I
!= 0; I
++)
1499 pkgSrcRecords::Parser
*Parse
;
1500 while ((Parse
= SrcRecs
.Find(*I
,false)) != 0)
1501 cout
<< Parse
->AsStr() << endl
;;
1506 // Policy - Show the results of the preferences file /*{{{*/
1507 // ---------------------------------------------------------------------
1509 bool Policy(CommandLine
&CmdL
)
1512 return _error
->Error("Generate must be enabled for this function");
1514 pkgCache
&Cache
= *GCache
;
1515 pkgPolicy
Plcy(&Cache
);
1516 if (ReadPinFile(Plcy
) == false)
1519 // Print out all of the package files
1520 if (CmdL
.FileList
[1] == 0)
1522 cout
<< _("Package files:") << endl
;
1523 for (pkgCache::PkgFileIterator F
= Cache
.FileBegin(); F
.end() == false; F
++)
1525 // Locate the associated index files so we can derive a description
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());
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());
1541 // Show any packages have explicit pins
1542 cout
<< _("Pinned packages:") << endl
;
1543 pkgCache::PkgIterator I
= Cache
.PkgBegin();
1544 for (;I
.end() != true; I
++)
1546 if (Plcy
.GetPriority(I
) == 0)
1549 // Print the package name and the version we are forcing to
1550 cout
<< " " << I
.Name() << " -> ";
1552 pkgCache::VerIterator V
= Plcy
.GetMatch(I
);
1553 if (V
.end() == true)
1554 cout
<< _("(not found)") << endl
;
1556 cout
<< V
.VerStr() << endl
;
1562 // Print out detailed information for each package
1563 for (const char **I
= CmdL
.FileList
+ 1; *I
!= 0; I
++)
1565 pkgCache::PkgIterator Pkg
= Cache
.FindPkg(*I
);
1566 if (Pkg
.end() == true)
1568 _error
->Warning(_("Unable to locate package %s"),*I
);
1572 cout
<< Pkg
.Name() << ":" << endl
;
1574 // Installed version
1575 cout
<< _(" Installed: ");
1576 if (Pkg
->CurrentVer
== 0)
1577 cout
<< _("(none)") << endl
;
1579 cout
<< Pkg
.CurrentVer().VerStr() << endl
;
1581 // Candidate Version
1582 cout
<< _(" Candidate: ");
1583 pkgCache::VerIterator V
= Plcy
.GetCandidateVer(Pkg
);
1584 if (V
.end() == true)
1585 cout
<< _("(none)") << endl
;
1587 cout
<< V
.VerStr() << endl
;
1590 if (Plcy
.GetPriority(Pkg
) != 0)
1592 cout
<< _(" Package pin: ");
1593 V
= Plcy
.GetMatch(Pkg
);
1594 if (V
.end() == true)
1595 cout
<< _("(not found)") << endl
;
1597 cout
<< V
.VerStr() << endl
;
1600 // Show the priority tables
1601 cout
<< _(" Version table:") << endl
;
1602 for (V
= Pkg
.VersionList(); V
.end() == false; V
++)
1604 if (Pkg
.CurrentVer() == V
)
1605 cout
<< " *** " << V
.VerStr();
1607 cout
<< " " << V
.VerStr();
1608 cout
<< " " << Plcy
.GetPriority(Pkg
) << endl
;
1609 for (pkgCache::VerFileIterator VF
= V
.FileList(); VF
.end() == false; VF
++)
1611 // Locate the associated index files so we can derive a description
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());
1625 // Madison - Look a bit like katie's madison /*{{{*/
1626 // ---------------------------------------------------------------------
1628 bool Madison(CommandLine
&CmdL
)
1631 return _error
->Error("Generate must be enabled for this function");
1633 SrcList
->ReadMainList();
1635 pkgCache
&Cache
= *GCache
;
1637 // Create the src text record parsers and ignore errors about missing
1638 // deb-src lines that are generated from pkgSrcRecords::pkgSrcRecords
1639 pkgSrcRecords
SrcRecs(*SrcList
);
1640 if (_error
->PendingError() == true)
1643 for (const char **I
= CmdL
.FileList
+ 1; *I
!= 0; I
++)
1645 pkgCache::PkgIterator Pkg
= Cache
.FindPkg(*I
);
1647 if (Pkg
.end() == false)
1649 for (pkgCache::VerIterator V
= Pkg
.VersionList(); V
.end() == false; V
++)
1651 for (pkgCache::VerFileIterator VF
= V
.FileList(); VF
.end() == false; VF
++)
1653 // This might be nice, but wouldn't uniquely identify the source -mdz
1654 // if (VF.File().Archive() != 0)
1656 // cout << setw(10) << Pkg.Name() << " | " << setw(10) << V.VerStr() << " | "
1657 // << VF.File().Archive() << endl;
1660 // Locate the associated index files so we can derive a description
1661 for (pkgSourceList::const_iterator S
= SrcList
->begin(); S
!= SrcList
->end(); S
++)
1663 vector
<pkgIndexFile
*> *Indexes
= (*S
)->GetIndexFiles();
1664 for (vector
<pkgIndexFile
*>::const_iterator IF
= Indexes
->begin();
1665 IF
!= Indexes
->end(); IF
++)
1667 if ((*IF
)->FindInCache(*(VF
.File().Cache())) == VF
.File())
1669 cout
<< setw(10) << Pkg
.Name() << " | " << setw(10) << V
.VerStr() << " | "
1670 << (*IF
)->Describe(true) << endl
;
1680 pkgSrcRecords::Parser
*SrcParser
;
1681 while ((SrcParser
= SrcRecs
.Find(*I
,false)) != 0)
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
;
1694 // GenCaches - Call the main cache generator /*{{{*/
1695 // ---------------------------------------------------------------------
1697 bool GenCaches(CommandLine
&Cmd
)
1699 OpTextProgress
Progress(*_config
);
1702 if (List
.ReadMainList() == false)
1704 return pkgMakeStatusCache(List
,Progress
);
1707 // ShowHelp - Show a help screen /*{{{*/
1708 // ---------------------------------------------------------------------
1710 bool ShowHelp(CommandLine
&Cmd
)
1712 ioprintf(cout
,_("%s %s for %s compiled on %s %s\n"),PACKAGE
,VERSION
,
1713 COMMON_ARCH
,__DATE__
,__TIME__
);
1715 if (_config
->FindB("version") == true)
1719 _("Usage: apt-cache [options] command\n"
1720 " apt-cache [options] add file1 [file2 ...]\n"
1721 " apt-cache [options] showpkg pkg1 [pkg2 ...]\n"
1722 " apt-cache [options] showsrc pkg1 [pkg2 ...]\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"
1728 " add - Add a package file to the source cache\n"
1729 " gencaches - Build both the package and source cache\n"
1730 " showpkg - Show some general information for a single package\n"
1731 " showsrc - Show source records\n"
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"
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"
1739 " rdepends - Show reverse dependency information for a package\n"
1740 " pkgnames - List the names of all packages\n"
1741 " dotty - Generate package graphs for GraphVis\n"
1742 " xvcg - Generate package graphs for xvcg\n"
1743 " policy - Show policy settings\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"
1752 " -o=? Set an arbitrary configuration option, eg -o dir::cache=/tmp\n"
1753 "See the apt-cache(8) and apt.conf(5) manual pages for more information.\n");
1757 // CacheInitialize - Initialize things for apt-cache /*{{{*/
1758 // ---------------------------------------------------------------------
1760 void CacheInitialize()
1762 _config
->Set("quiet",0);
1763 _config
->Set("help",false);
1767 int main(int argc
,const char *argv
[])
1769 CommandLine::Args Args
[] = {
1770 {'h',"help","help",0},
1771 {'v',"version","version",0},
1772 {'p',"pkg-cache","Dir::Cache::pkgcache",CommandLine::HasArg
},
1773 {'s',"src-cache","Dir::Cache::srcpkgcache",CommandLine::HasArg
},
1774 {'q',"quiet","quiet",CommandLine::IntLevel
},
1775 {'i',"important","APT::Cache::Important",0},
1776 {'f',"full","APT::Cache::ShowFull",0},
1777 {'g',"generate","APT::Cache::Generate",0},
1778 {'a',"all-versions","APT::Cache::AllVersions",0},
1779 {'n',"names-only","APT::Cache::NamesOnly",0},
1780 {0,"all-names","APT::Cache::AllNames",0},
1781 {0,"recurse","APT::Cache::RecurseDepends",0},
1782 {'c',"config-file",0,CommandLine::ConfigFile
},
1783 {'o',"option",0,CommandLine::ArbItem
},
1784 {0,"installed","APT::Cache::Installed",0},
1786 CommandLine::Dispatch CmdsA
[] = {{"help",&ShowHelp
},
1788 {"gencaches",&GenCaches
},
1789 {"showsrc",&ShowSrcPackage
},
1791 CommandLine::Dispatch CmdsB
[] = {{"showpkg",&DumpPackage
},
1794 {"dumpavail",&DumpAvail
},
1797 {"depends",&Depends
},
1798 {"rdepends",&RDepends
},
1801 {"show",&ShowPackage
},
1802 {"pkgnames",&ShowPkgNames
},
1804 {"madison",&Madison
},
1809 // Set up gettext support
1810 setlocale(LC_ALL
,"");
1811 textdomain(PACKAGE
);
1813 // Parse the command line and initialize the package library
1814 CommandLine
CmdL(Args
,_config
);
1815 if (pkgInitConfig(*_config
) == false ||
1816 CmdL
.Parse(argc
,argv
) == false ||
1817 pkgInitSystem(*_config
,_system
) == false)
1819 _error
->DumpErrors();
1823 // See if the help should be shown
1824 if (_config
->FindB("help") == true ||
1825 CmdL
.FileSize() == 0)
1831 // Deal with stdout not being a tty
1832 if (isatty(STDOUT_FILENO
) && _config
->FindI("quiet",0) < 1)
1833 _config
->Set("quiet","1");
1835 if (CmdL
.DispatchArg(CmdsA
,false) == false && _error
->PendingError() == false)
1838 if (_config
->FindB("APT::Cache::Generate",true) == false)
1840 Map
= new MMap(*new FileFd(_config
->FindFile("Dir::Cache::pkgcache"),
1841 FileFd::ReadOnly
),MMap::Public
|MMap::ReadOnly
);
1845 // Open the cache file
1846 SrcList
= new pkgSourceList
;
1847 SrcList
->ReadMainList();
1849 // Generate it and map it
1851 pkgMakeStatusCache(*SrcList
,Prog
,&Map
,true);
1854 if (_error
->PendingError() == false)
1856 pkgCache
Cache(Map
);
1858 if (_error
->PendingError() == false)
1859 CmdL
.DispatchArg(CmdsB
);
1864 // Print any errors or warnings found during parsing
1865 if (_error
->empty() == false)
1867 bool Errors
= _error
->PendingError();
1868 _error
->DumpErrors();
1869 return Errors
== true?100:0;