]>
git.saurik.com Git - apt.git/blob - cmdline/apt-cache.cc
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>
18 #include <apt-pkg/pkgcachegen.h>
19 #include <apt-pkg/cachefile.h>
20 #include <apt-pkg/init.h>
21 #include <apt-pkg/progress.h>
22 #include <apt-pkg/sourcelist.h>
23 #include <apt-pkg/cmndline.h>
24 #include <apt-pkg/strutl.h>
25 #include <apt-pkg/pkgrecords.h>
26 #include <apt-pkg/srcrecords.h>
27 #include <apt-pkg/version.h>
28 #include <apt-pkg/policy.h>
29 #include <apt-pkg/tagfile.h>
30 #include <apt-pkg/algorithms.h>
31 #include <apt-pkg/sptr.h>
49 pkgSourceList
*SrcList
= 0;
51 // LocalitySort - Sort a version list by package file locality /*{{{*/
52 // ---------------------------------------------------------------------
54 int LocalityCompare(const void *a
, const void *b
)
56 pkgCache::VerFile
*A
= *(pkgCache::VerFile
**)a
;
57 pkgCache::VerFile
*B
= *(pkgCache::VerFile
**)b
;
66 if (A
->File
== B
->File
)
67 return A
->Offset
- B
->Offset
;
68 return A
->File
- B
->File
;
71 void LocalitySort(pkgCache::VerFile
**begin
,
72 unsigned long Count
,size_t Size
)
74 qsort(begin
,Count
,Size
,LocalityCompare
);
77 void LocalitySort(pkgCache::DescFile
**begin
,
78 unsigned long Count
,size_t Size
)
80 qsort(begin
,Count
,Size
,LocalityCompare
);
83 // UnMet - Show unmet dependencies /*{{{*/
84 // ---------------------------------------------------------------------
86 bool UnMet(CommandLine
&CmdL
)
88 pkgCache
&Cache
= *GCache
;
89 bool Important
= _config
->FindB("APT::Cache::Important",false);
91 for (pkgCache::PkgIterator P
= Cache
.PkgBegin(); P
.end() == false; P
++)
93 for (pkgCache::VerIterator V
= P
.VersionList(); V
.end() == false; V
++)
96 for (pkgCache::DepIterator D
= V
.DependsList(); D
.end() == false;)
99 pkgCache::DepIterator Start
;
100 pkgCache::DepIterator End
;
103 // Skip conflicts and replaces
104 if (End
->Type
!= pkgCache::Dep::PreDepends
&&
105 End
->Type
!= pkgCache::Dep::Depends
&&
106 End
->Type
!= pkgCache::Dep::Suggests
&&
107 End
->Type
!= pkgCache::Dep::Recommends
)
110 // Important deps only
111 if (Important
== true)
112 if (End
->Type
!= pkgCache::Dep::PreDepends
&&
113 End
->Type
!= pkgCache::Dep::Depends
)
116 // Verify the or group
118 pkgCache::DepIterator RealStart
= Start
;
121 // See if this dep is Ok
122 pkgCache::Version
**VList
= Start
.AllTargets();
143 ioprintf(cout
,_("Package %s version %s has an unmet dep:\n"),
144 P
.FullName(true).c_str(),V
.VerStr());
147 // Print out the dep type
148 cout
<< " " << End
.DepType() << ": ";
154 cout
<< Start
.TargetPkg().FullName(true);
155 if (Start
.TargetVer() != 0)
156 cout
<< " (" << Start
.CompType() << " " << Start
.TargetVer() <<
172 // DumpPackage - Show a dump of a package record /*{{{*/
173 // ---------------------------------------------------------------------
175 bool DumpPackage(CommandLine
&CmdL
)
177 pkgCache
&Cache
= *GCache
;
178 for (const char **I
= CmdL
.FileList
+ 1; *I
!= 0; I
++)
180 pkgCache::PkgIterator Pkg
= Cache
.FindPkg(*I
);
181 if (Pkg
.end() == true)
183 _error
->Warning(_("Unable to locate package %s"),*I
);
187 cout
<< "Package: " << Pkg
.FullName(true) << endl
;
188 cout
<< "Versions: " << endl
;
189 for (pkgCache::VerIterator Cur
= Pkg
.VersionList(); Cur
.end() != true; Cur
++)
191 cout
<< Cur
.VerStr();
192 for (pkgCache::VerFileIterator Vf
= Cur
.FileList(); Vf
.end() == false; Vf
++)
193 cout
<< " (" << Vf
.File().FileName() << ")";
195 for (pkgCache::DescIterator D
= Cur
.DescriptionList(); D
.end() == false; D
++)
197 cout
<< " Description Language: " << D
.LanguageCode() << endl
198 << " File: " << D
.FileList().File().FileName() << endl
199 << " MD5: " << D
.md5() << endl
;
206 cout
<< "Reverse Depends: " << endl
;
207 for (pkgCache::DepIterator D
= Pkg
.RevDependsList(); D
.end() != true; D
++)
209 cout
<< " " << D
.ParentPkg().FullName(true) << ',' << D
.TargetPkg().FullName(true);
211 cout
<< ' ' << DeNull(D
.TargetVer()) << endl
;
216 cout
<< "Dependencies: " << endl
;
217 for (pkgCache::VerIterator Cur
= Pkg
.VersionList(); Cur
.end() != true; Cur
++)
219 cout
<< Cur
.VerStr() << " - ";
220 for (pkgCache::DepIterator Dep
= Cur
.DependsList(); Dep
.end() != true; Dep
++)
221 cout
<< Dep
.TargetPkg().FullName(true) << " (" << (int)Dep
->CompareOp
<< " " << DeNull(Dep
.TargetVer()) << ") ";
225 cout
<< "Provides: " << endl
;
226 for (pkgCache::VerIterator Cur
= Pkg
.VersionList(); Cur
.end() != true; Cur
++)
228 cout
<< Cur
.VerStr() << " - ";
229 for (pkgCache::PrvIterator Prv
= Cur
.ProvidesList(); Prv
.end() != true; Prv
++)
230 cout
<< Prv
.ParentPkg().FullName(true) << " ";
233 cout
<< "Reverse Provides: " << endl
;
234 for (pkgCache::PrvIterator Prv
= Pkg
.ProvidesList(); Prv
.end() != true; Prv
++)
235 cout
<< Prv
.OwnerPkg().FullName(true) << " " << Prv
.OwnerVer().VerStr() << endl
;
241 // Stats - Dump some nice statistics /*{{{*/
242 // ---------------------------------------------------------------------
244 bool Stats(CommandLine
&Cmd
)
246 pkgCache
&Cache
= *GCache
;
247 cout
<< _("Total package names: ") << Cache
.Head().GroupCount
<< " (" <<
248 SizeToStr(Cache
.Head().GroupCount
*Cache
.Head().GroupSz
) << ')' << endl
249 << _("Total package structures: ") << Cache
.Head().PackageCount
<< " (" <<
250 SizeToStr(Cache
.Head().PackageCount
*Cache
.Head().PackageSz
) << ')' << endl
;
257 pkgCache::PkgIterator I
= Cache
.PkgBegin();
258 for (;I
.end() != true; I
++)
260 if (I
->VersionList
!= 0 && I
->ProvidesList
== 0)
266 if (I
->VersionList
!= 0 && I
->ProvidesList
!= 0)
272 if (I
->VersionList
== 0 && I
->ProvidesList
!= 0)
275 if (I
.ProvidesList()->NextProvides
== 0)
283 if (I
->VersionList
== 0 && I
->ProvidesList
== 0)
289 cout
<< _(" Normal packages: ") << Normal
<< endl
;
290 cout
<< _(" Pure virtual packages: ") << Virtual
<< endl
;
291 cout
<< _(" Single virtual packages: ") << DVirt
<< endl
;
292 cout
<< _(" Mixed virtual packages: ") << NVirt
<< endl
;
293 cout
<< _(" Missing: ") << Missing
<< endl
;
295 cout
<< _("Total distinct versions: ") << Cache
.Head().VersionCount
<< " (" <<
296 SizeToStr(Cache
.Head().VersionCount
*Cache
.Head().VersionSz
) << ')' << endl
;
297 cout
<< _("Total distinct descriptions: ") << Cache
.Head().DescriptionCount
<< " (" <<
298 SizeToStr(Cache
.Head().DescriptionCount
*Cache
.Head().DescriptionSz
) << ')' << endl
;
299 cout
<< _("Total dependencies: ") << Cache
.Head().DependsCount
<< " (" <<
300 SizeToStr(Cache
.Head().DependsCount
*Cache
.Head().DependencySz
) << ')' << endl
;
302 cout
<< _("Total ver/file relations: ") << Cache
.Head().VerFileCount
<< " (" <<
303 SizeToStr(Cache
.Head().VerFileCount
*Cache
.Head().VerFileSz
) << ')' << endl
;
304 cout
<< _("Total Desc/File relations: ") << Cache
.Head().DescFileCount
<< " (" <<
305 SizeToStr(Cache
.Head().DescFileCount
*Cache
.Head().DescFileSz
) << ')' << endl
;
306 cout
<< _("Total Provides mappings: ") << Cache
.Head().ProvidesCount
<< " (" <<
307 SizeToStr(Cache
.Head().ProvidesCount
*Cache
.Head().ProvidesSz
) << ')' << endl
;
310 unsigned long Size
= 0;
311 unsigned long Count
= 0;
312 for (pkgCache::StringItem
*I
= Cache
.StringItemP
+ Cache
.Head().StringList
;
313 I
!= Cache
.StringItemP
; I
= Cache
.StringItemP
+ I
->NextItem
)
316 Size
+= strlen(Cache
.StrP
+ I
->String
) + 1;
318 cout
<< _("Total globbed strings: ") << Count
<< " (" << SizeToStr(Size
) << ')' << endl
;
320 unsigned long DepVerSize
= 0;
321 for (pkgCache::PkgIterator P
= Cache
.PkgBegin(); P
.end() == false; P
++)
323 for (pkgCache::VerIterator V
= P
.VersionList(); V
.end() == false; V
++)
325 for (pkgCache::DepIterator D
= V
.DependsList(); D
.end() == false; D
++)
328 DepVerSize
+= strlen(D
.TargetVer()) + 1;
332 cout
<< _("Total dependency version space: ") << SizeToStr(DepVerSize
) << endl
;
334 unsigned long Slack
= 0;
335 for (int I
= 0; I
!= 7; I
++)
336 Slack
+= Cache
.Head().Pools
[I
].ItemSize
*Cache
.Head().Pools
[I
].Count
;
337 cout
<< _("Total slack space: ") << SizeToStr(Slack
) << endl
;
339 unsigned long Total
= 0;
340 Total
= Slack
+ Size
+ Cache
.Head().DependsCount
*Cache
.Head().DependencySz
+
341 Cache
.Head().VersionCount
*Cache
.Head().VersionSz
+
342 Cache
.Head().PackageCount
*Cache
.Head().PackageSz
+
343 Cache
.Head().VerFileCount
*Cache
.Head().VerFileSz
+
344 Cache
.Head().ProvidesCount
*Cache
.Head().ProvidesSz
;
345 cout
<< _("Total space accounted for: ") << SizeToStr(Total
) << endl
;
350 // Dump - show everything /*{{{*/
351 // ---------------------------------------------------------------------
352 /* This is worthless except fer debugging things */
353 bool Dump(CommandLine
&Cmd
)
355 pkgCache
&Cache
= *GCache
;
356 cout
<< "Using Versioning System: " << Cache
.VS
->Label
<< endl
;
358 for (pkgCache::PkgIterator P
= Cache
.PkgBegin(); P
.end() == false; P
++)
360 cout
<< "Package: " << P
.FullName(true) << endl
;
361 for (pkgCache::VerIterator V
= P
.VersionList(); V
.end() == false; V
++)
363 cout
<< " Version: " << V
.VerStr() << endl
;
364 cout
<< " File: " << V
.FileList().File().FileName() << endl
;
365 for (pkgCache::DepIterator D
= V
.DependsList(); D
.end() == false; D
++)
366 cout
<< " Depends: " << D
.TargetPkg().FullName(true) << ' ' <<
367 DeNull(D
.TargetVer()) << endl
;
368 for (pkgCache::DescIterator D
= V
.DescriptionList(); D
.end() == false; D
++)
370 cout
<< " Description Language: " << D
.LanguageCode() << endl
371 << " File: " << D
.FileList().File().FileName() << endl
372 << " MD5: " << D
.md5() << endl
;
377 for (pkgCache::PkgFileIterator F
= Cache
.FileBegin(); F
.end() == false; F
++)
379 cout
<< "File: " << F
.FileName() << endl
;
380 cout
<< " Type: " << F
.IndexType() << endl
;
381 cout
<< " Size: " << F
->Size
<< endl
;
382 cout
<< " ID: " << F
->ID
<< endl
;
383 cout
<< " Flags: " << F
->Flags
<< endl
;
384 cout
<< " Time: " << TimeRFC1123(F
->mtime
) << endl
;
385 cout
<< " Archive: " << DeNull(F
.Archive()) << endl
;
386 cout
<< " Component: " << DeNull(F
.Component()) << endl
;
387 cout
<< " Version: " << DeNull(F
.Version()) << endl
;
388 cout
<< " Origin: " << DeNull(F
.Origin()) << endl
;
389 cout
<< " Site: " << DeNull(F
.Site()) << endl
;
390 cout
<< " Label: " << DeNull(F
.Label()) << endl
;
391 cout
<< " Architecture: " << DeNull(F
.Architecture()) << endl
;
397 // DumpAvail - Print out the available list /*{{{*/
398 // ---------------------------------------------------------------------
399 /* This is needed to make dpkg --merge happy.. I spent a bit of time to
400 make this run really fast, perhaps I went a little overboard.. */
401 bool DumpAvail(CommandLine
&Cmd
)
403 pkgCache
&Cache
= *GCache
;
405 pkgPolicy
Plcy(&Cache
);
406 if (ReadPinFile(Plcy
) == false || ReadPinDir(Plcy
) == false)
409 unsigned long Count
= Cache
.HeaderP
->PackageCount
+1;
410 pkgCache::VerFile
**VFList
= new pkgCache::VerFile
*[Count
];
411 memset(VFList
,0,sizeof(*VFList
)*Count
);
413 // Map versions that we want to write out onto the VerList array.
414 for (pkgCache::PkgIterator P
= Cache
.PkgBegin(); P
.end() == false; P
++)
416 if (P
->VersionList
== 0)
419 /* Find the proper version to use. If the policy says there are no
420 possible selections we return the installed version, if available..
421 This prevents dselect from making it obsolete. */
422 pkgCache::VerIterator V
= Plcy
.GetCandidateVer(P
);
425 if (P
->CurrentVer
== 0)
430 pkgCache::VerFileIterator VF
= V
.FileList();
431 for (; VF
.end() == false ; VF
++)
432 if ((VF
.File()->Flags
& pkgCache::Flag::NotSource
) == 0)
435 /* Okay, here we have a bit of a problem.. The policy has selected the
436 currently installed package - however it only exists in the
437 status file.. We need to write out something or dselect will mark
438 the package as obsolete! Thus we emit the status file entry, but
439 below we remove the status line to make it valid for the
440 available file. However! We only do this if their do exist *any*
441 non-source versions of the package - that way the dselect obsolete
442 handling works OK. */
443 if (VF
.end() == true)
445 for (pkgCache::VerIterator Cur
= P
.VersionList(); Cur
.end() != true; Cur
++)
447 for (VF
= Cur
.FileList(); VF
.end() == false; VF
++)
449 if ((VF
.File()->Flags
& pkgCache::Flag::NotSource
) == 0)
456 if (VF
.end() == false)
464 LocalitySort(VFList
,Count
,sizeof(*VFList
));
466 // Iterate over all the package files and write them out.
467 char *Buffer
= new char[Cache
.HeaderP
->MaxVerFileSize
+10];
468 for (pkgCache::VerFile
**J
= VFList
; *J
!= 0;)
470 pkgCache::PkgFileIterator
File(Cache
,(*J
)->File
+ Cache
.PkgFileP
);
471 if (File
.IsOk() == false)
473 _error
->Error(_("Package file %s is out of sync."),File
.FileName());
477 FileFd
PkgF(File
.FileName(),FileFd::ReadOnly
);
478 if (_error
->PendingError() == true)
481 /* Write all of the records from this package file, since we
482 already did locality sorting we can now just seek through the
483 file in read order. We apply 1 more optimization here, since often
484 there will be < 1 byte gaps between records (for the \n) we read that
485 into the next buffer and offset a bit.. */
486 unsigned long Pos
= 0;
489 if ((*J
)->File
+ Cache
.PkgFileP
!= File
)
492 const pkgCache::VerFile
&VF
= **J
;
494 // Read the record and then write it out again.
495 unsigned long Jitter
= VF
.Offset
- Pos
;
498 if (PkgF
.Seek(VF
.Offset
) == false)
503 if (PkgF
.Read(Buffer
,VF
.Size
+ Jitter
) == false)
505 Buffer
[VF
.Size
+ Jitter
] = '\n';
508 if ((File
->Flags
& pkgCache::Flag::NotSource
) == pkgCache::Flag::NotSource
)
511 TFRewriteData RW
[] = {{"Status",0},{"Config-Version",0},{}};
512 const char *Zero
= 0;
513 if (Tags
.Scan(Buffer
+Jitter
,VF
.Size
+1) == false ||
514 TFRewrite(stdout
,Tags
,&Zero
,RW
) == false)
516 _error
->Error("Internal Error, Unable to parse a package record");
523 if (fwrite(Buffer
+Jitter
,VF
.Size
+1,1,stdout
) != 1)
527 Pos
= VF
.Offset
+ VF
.Size
;
531 if (_error
->PendingError() == true)
537 return !_error
->PendingError();
540 // Depends - Print out a dependency tree /*{{{*/
541 // ---------------------------------------------------------------------
543 bool Depends(CommandLine
&CmdL
)
545 pkgCache
&Cache
= *GCache
;
546 SPtrArray
<unsigned> Colours
= new unsigned[Cache
.Head().PackageCount
];
547 memset(Colours
,0,sizeof(*Colours
)*Cache
.Head().PackageCount
);
549 for (const char **I
= CmdL
.FileList
+ 1; *I
!= 0; I
++)
551 pkgCache::PkgIterator Pkg
= Cache
.FindPkg(*I
);
552 if (Pkg
.end() == true)
554 _error
->Warning(_("Unable to locate package %s"),*I
);
557 Colours
[Pkg
->ID
] = 1;
560 bool Recurse
= _config
->FindB("APT::Cache::RecurseDepends",false);
561 bool Installed
= _config
->FindB("APT::Cache::Installed",false);
562 bool Important
= _config
->FindB("APT::Cache::Important",false);
566 DidSomething
= false;
567 for (pkgCache::PkgIterator Pkg
= Cache
.PkgBegin(); Pkg
.end() == false; Pkg
++)
569 if (Colours
[Pkg
->ID
] != 1)
571 Colours
[Pkg
->ID
] = 2;
574 pkgCache::VerIterator Ver
= Pkg
.VersionList();
575 if (Ver
.end() == true)
577 cout
<< '<' << Pkg
.FullName(true) << '>' << endl
;
581 cout
<< Pkg
.FullName(true) << endl
;
583 for (pkgCache::DepIterator D
= Ver
.DependsList(); D
.end() == false; D
++)
585 // Important deps only
586 if (Important
== true)
587 if (D
->Type
!= pkgCache::Dep::PreDepends
&&
588 D
->Type
!= pkgCache::Dep::Depends
)
591 pkgCache::PkgIterator Trg
= D
.TargetPkg();
593 if((Installed
&& Trg
->CurrentVer
!= 0) || !Installed
)
596 if ((D
->CompareOp
& pkgCache::Dep::Or
) == pkgCache::Dep::Or
)
602 if (Trg
->VersionList
== 0)
603 cout
<< D
.DepType() << ": <" << Trg
.FullName(true) << ">" << endl
;
605 cout
<< D
.DepType() << ": " << Trg
.FullName(true) << endl
;
608 Colours
[D
.TargetPkg()->ID
]++;
612 // Display all solutions
613 SPtrArray
<pkgCache::Version
*> List
= D
.AllTargets();
614 pkgPrioSortList(Cache
,List
);
615 for (pkgCache::Version
**I
= List
; *I
!= 0; I
++)
617 pkgCache::VerIterator
V(Cache
,*I
);
618 if (V
!= Cache
.VerP
+ V
.ParentPkg()->VersionList
||
619 V
->ParentPkg
== D
->Package
)
621 cout
<< " " << V
.ParentPkg().FullName(true) << endl
;
624 Colours
[D
.ParentPkg()->ID
]++;
629 while (DidSomething
== true);
634 // RDepends - Print out a reverse dependency tree - mbc /*{{{*/
635 // ---------------------------------------------------------------------
637 bool RDepends(CommandLine
&CmdL
)
639 pkgCache
&Cache
= *GCache
;
640 SPtrArray
<unsigned> Colours
= new unsigned[Cache
.Head().PackageCount
];
641 memset(Colours
,0,sizeof(*Colours
)*Cache
.Head().PackageCount
);
643 for (const char **I
= CmdL
.FileList
+ 1; *I
!= 0; I
++)
645 pkgCache::PkgIterator Pkg
= Cache
.FindPkg(*I
);
646 if (Pkg
.end() == true)
648 _error
->Warning(_("Unable to locate package %s"),*I
);
651 Colours
[Pkg
->ID
] = 1;
654 bool Recurse
= _config
->FindB("APT::Cache::RecurseDepends",false);
655 bool Installed
= _config
->FindB("APT::Cache::Installed",false);
659 DidSomething
= false;
660 for (pkgCache::PkgIterator Pkg
= Cache
.PkgBegin(); Pkg
.end() == false; Pkg
++)
662 if (Colours
[Pkg
->ID
] != 1)
664 Colours
[Pkg
->ID
] = 2;
667 pkgCache::VerIterator Ver
= Pkg
.VersionList();
668 if (Ver
.end() == true)
670 cout
<< '<' << Pkg
.FullName(true) << '>' << endl
;
674 cout
<< Pkg
.FullName(true) << endl
;
676 cout
<< "Reverse Depends:" << endl
;
677 for (pkgCache::DepIterator D
= Pkg
.RevDependsList(); D
.end() == false; D
++)
680 pkgCache::PkgIterator Trg
= D
.ParentPkg();
682 if((Installed
&& Trg
->CurrentVer
!= 0) || !Installed
)
685 if ((D
->CompareOp
& pkgCache::Dep::Or
) == pkgCache::Dep::Or
)
690 if (Trg
->VersionList
== 0)
691 cout
<< D
.DepType() << ": <" << Trg
.FullName(true) << ">" << endl
;
693 cout
<< Trg
.FullName(true) << endl
;
696 Colours
[D
.ParentPkg()->ID
]++;
700 // Display all solutions
701 SPtrArray
<pkgCache::Version
*> List
= D
.AllTargets();
702 pkgPrioSortList(Cache
,List
);
703 for (pkgCache::Version
**I
= List
; *I
!= 0; I
++)
705 pkgCache::VerIterator
V(Cache
,*I
);
706 if (V
!= Cache
.VerP
+ V
.ParentPkg()->VersionList
||
707 V
->ParentPkg
== D
->Package
)
709 cout
<< " " << V
.ParentPkg().FullName(true) << endl
;
712 Colours
[D
.ParentPkg()->ID
]++;
717 while (DidSomething
== true);
722 // xvcg - Generate a graph for xvcg /*{{{*/
723 // ---------------------------------------------------------------------
724 // Code contributed from Junichi Uekawa <dancer@debian.org> on 20 June 2002.
726 bool XVcg(CommandLine
&CmdL
)
728 pkgCache
&Cache
= *GCache
;
729 bool GivenOnly
= _config
->FindB("APT::Cache::GivenOnly",false);
731 /* Normal packages are boxes
732 Pure Provides are triangles
734 rhomb are missing packages*/
735 const char *Shapes
[] = {"ellipse","triangle","box","rhomb"};
737 /* Initialize the list of packages to show.
739 2 = To Show no recurse
740 3 = Emitted no recurse
743 enum States
{None
=0, ToShow
, ToShowNR
, DoneNR
, Done
};
744 enum TheFlags
{ForceNR
=(1<<0)};
745 unsigned char *Show
= new unsigned char[Cache
.Head().PackageCount
];
746 unsigned char *Flags
= new unsigned char[Cache
.Head().PackageCount
];
747 unsigned char *ShapeMap
= new unsigned char[Cache
.Head().PackageCount
];
749 // Show everything if no arguments given
750 if (CmdL
.FileList
[1] == 0)
751 for (unsigned long I
= 0; I
!= Cache
.Head().PackageCount
; I
++)
754 for (unsigned long I
= 0; I
!= Cache
.Head().PackageCount
; I
++)
756 memset(Flags
,0,sizeof(*Flags
)*Cache
.Head().PackageCount
);
759 for (pkgCache::PkgIterator Pkg
= Cache
.PkgBegin(); Pkg
.end() == false; Pkg
++)
761 if (Pkg
->VersionList
== 0)
764 if (Pkg
->ProvidesList
== 0)
765 ShapeMap
[Pkg
->ID
] = 0;
767 ShapeMap
[Pkg
->ID
] = 1;
772 if (Pkg
->ProvidesList
== 0)
773 ShapeMap
[Pkg
->ID
] = 2;
775 ShapeMap
[Pkg
->ID
] = 3;
779 // Load the list of packages from the command line into the show list
780 for (const char **I
= CmdL
.FileList
+ 1; *I
!= 0; I
++)
782 // Process per-package flags
787 if (P
.end()[-1] == '^')
793 if (P
.end()[-1] == ',')
797 // Locate the package
798 pkgCache::PkgIterator Pkg
= Cache
.FindPkg(P
);
799 if (Pkg
.end() == true)
801 _error
->Warning(_("Unable to locate package %s"),*I
);
804 Show
[Pkg
->ID
] = ToShow
;
807 Flags
[Pkg
->ID
] |= ForceNR
;
811 cout
<< "graph: { title: \"packages\"" << endl
<<
812 "xmax: 700 ymax: 700 x: 30 y: 30" << endl
<<
813 "layout_downfactor: 8" << endl
;
819 for (pkgCache::PkgIterator Pkg
= Cache
.PkgBegin(); Pkg
.end() == false; Pkg
++)
821 // See we need to show this package
822 if (Show
[Pkg
->ID
] == None
|| Show
[Pkg
->ID
] >= DoneNR
)
825 //printf ("node: { title: \"%s\" label: \"%s\" }\n", Pkg.Name(), Pkg.Name());
828 if (Show
[Pkg
->ID
] == ToShowNR
|| (Flags
[Pkg
->ID
] & ForceNR
) == ForceNR
)
830 // Pure Provides and missing packages have no deps!
831 if (ShapeMap
[Pkg
->ID
] == 0 || ShapeMap
[Pkg
->ID
] == 1)
832 Show
[Pkg
->ID
] = Done
;
834 Show
[Pkg
->ID
] = DoneNR
;
837 Show
[Pkg
->ID
] = Done
;
840 // No deps to map out
841 if (Pkg
->VersionList
== 0 || Show
[Pkg
->ID
] == DoneNR
)
844 pkgCache::VerIterator Ver
= Pkg
.VersionList();
845 for (pkgCache::DepIterator D
= Ver
.DependsList(); D
.end() == false; D
++)
847 // See if anything can meet this dep
848 // Walk along the actual package providing versions
850 pkgCache::PkgIterator DPkg
= D
.TargetPkg();
851 for (pkgCache::VerIterator I
= DPkg
.VersionList();
852 I
.end() == false && Hit
== false; I
++)
854 if (Cache
.VS
->CheckDep(I
.VerStr(),D
->CompareOp
,D
.TargetVer()) == true)
858 // Follow all provides
859 for (pkgCache::PrvIterator I
= DPkg
.ProvidesList();
860 I
.end() == false && Hit
== false; I
++)
862 if (Cache
.VS
->CheckDep(I
.ProvideVersion(),D
->CompareOp
,D
.TargetVer()) == false)
867 // Only graph critical deps
868 if (D
.IsCritical() == true)
870 printf ("edge: { sourcename: \"%s\" targetname: \"%s\" class: 2 ",Pkg
.FullName(true).c_str(), D
.TargetPkg().FullName(true).c_str() );
872 // Colour the node for recursion
873 if (Show
[D
.TargetPkg()->ID
] <= DoneNR
)
875 /* If a conflicts does not meet anything in the database
876 then show the relation but do not recurse */
878 (D
->Type
== pkgCache::Dep::Conflicts
||
879 D
->Type
== pkgCache::Dep::DpkgBreaks
||
880 D
->Type
== pkgCache::Dep::Obsoletes
))
882 if (Show
[D
.TargetPkg()->ID
] == None
&&
883 Show
[D
.TargetPkg()->ID
] != ToShow
)
884 Show
[D
.TargetPkg()->ID
] = ToShowNR
;
888 if (GivenOnly
== true && Show
[D
.TargetPkg()->ID
] != ToShow
)
889 Show
[D
.TargetPkg()->ID
] = ToShowNR
;
891 Show
[D
.TargetPkg()->ID
] = ToShow
;
898 case pkgCache::Dep::Conflicts
:
899 printf("label: \"conflicts\" color: lightgreen }\n");
901 case pkgCache::Dep::DpkgBreaks
:
902 printf("label: \"breaks\" color: lightgreen }\n");
904 case pkgCache::Dep::Obsoletes
:
905 printf("label: \"obsoletes\" color: lightgreen }\n");
908 case pkgCache::Dep::PreDepends
:
909 printf("label: \"predepends\" color: blue }\n");
921 /* Draw the box colours after the fact since we can not tell what colour
922 they should be until everything is finished drawing */
923 for (pkgCache::PkgIterator Pkg
= Cache
.PkgBegin(); Pkg
.end() == false; Pkg
++)
925 if (Show
[Pkg
->ID
] < DoneNR
)
928 if (Show
[Pkg
->ID
] == DoneNR
)
929 printf("node: { title: \"%s\" label: \"%s\" color: orange shape: %s }\n", Pkg
.FullName(true).c_str(), Pkg
.FullName(true).c_str(),
930 Shapes
[ShapeMap
[Pkg
->ID
]]);
932 printf("node: { title: \"%s\" label: \"%s\" shape: %s }\n", Pkg
.FullName(true).c_str(), Pkg
.FullName(true).c_str(),
933 Shapes
[ShapeMap
[Pkg
->ID
]]);
945 // Dotty - Generate a graph for Dotty /*{{{*/
946 // ---------------------------------------------------------------------
947 /* Dotty is the graphvis program for generating graphs. It is a fairly
948 simple queuing algorithm that just writes dependencies and nodes.
949 http://www.research.att.com/sw/tools/graphviz/ */
950 bool Dotty(CommandLine
&CmdL
)
952 pkgCache
&Cache
= *GCache
;
953 bool GivenOnly
= _config
->FindB("APT::Cache::GivenOnly",false);
955 /* Normal packages are boxes
956 Pure Provides are triangles
958 Hexagons are missing packages*/
959 const char *Shapes
[] = {"hexagon","triangle","box","diamond"};
961 /* Initialize the list of packages to show.
963 2 = To Show no recurse
964 3 = Emitted no recurse
967 enum States
{None
=0, ToShow
, ToShowNR
, DoneNR
, Done
};
968 enum TheFlags
{ForceNR
=(1<<0)};
969 unsigned char *Show
= new unsigned char[Cache
.Head().PackageCount
];
970 unsigned char *Flags
= new unsigned char[Cache
.Head().PackageCount
];
971 unsigned char *ShapeMap
= new unsigned char[Cache
.Head().PackageCount
];
973 // Show everything if no arguments given
974 if (CmdL
.FileList
[1] == 0)
975 for (unsigned long I
= 0; I
!= Cache
.Head().PackageCount
; I
++)
978 for (unsigned long I
= 0; I
!= Cache
.Head().PackageCount
; I
++)
980 memset(Flags
,0,sizeof(*Flags
)*Cache
.Head().PackageCount
);
983 for (pkgCache::PkgIterator Pkg
= Cache
.PkgBegin(); Pkg
.end() == false; Pkg
++)
985 if (Pkg
->VersionList
== 0)
988 if (Pkg
->ProvidesList
== 0)
989 ShapeMap
[Pkg
->ID
] = 0;
991 ShapeMap
[Pkg
->ID
] = 1;
996 if (Pkg
->ProvidesList
== 0)
997 ShapeMap
[Pkg
->ID
] = 2;
999 ShapeMap
[Pkg
->ID
] = 3;
1003 // Load the list of packages from the command line into the show list
1004 for (const char **I
= CmdL
.FileList
+ 1; *I
!= 0; I
++)
1006 // Process per-package flags
1011 if (P
.end()[-1] == '^')
1017 if (P
.end()[-1] == ',')
1021 // Locate the package
1022 pkgCache::PkgIterator Pkg
= Cache
.FindPkg(P
);
1023 if (Pkg
.end() == true)
1025 _error
->Warning(_("Unable to locate package %s"),*I
);
1028 Show
[Pkg
->ID
] = ToShow
;
1031 Flags
[Pkg
->ID
] |= ForceNR
;
1035 printf("digraph packages {\n");
1036 printf("concentrate=true;\n");
1037 printf("size=\"30,40\";\n");
1043 for (pkgCache::PkgIterator Pkg
= Cache
.PkgBegin(); Pkg
.end() == false; Pkg
++)
1045 // See we need to show this package
1046 if (Show
[Pkg
->ID
] == None
|| Show
[Pkg
->ID
] >= DoneNR
)
1050 if (Show
[Pkg
->ID
] == ToShowNR
|| (Flags
[Pkg
->ID
] & ForceNR
) == ForceNR
)
1052 // Pure Provides and missing packages have no deps!
1053 if (ShapeMap
[Pkg
->ID
] == 0 || ShapeMap
[Pkg
->ID
] == 1)
1054 Show
[Pkg
->ID
] = Done
;
1056 Show
[Pkg
->ID
] = DoneNR
;
1059 Show
[Pkg
->ID
] = Done
;
1062 // No deps to map out
1063 if (Pkg
->VersionList
== 0 || Show
[Pkg
->ID
] == DoneNR
)
1066 pkgCache::VerIterator Ver
= Pkg
.VersionList();
1067 for (pkgCache::DepIterator D
= Ver
.DependsList(); D
.end() == false; D
++)
1069 // See if anything can meet this dep
1070 // Walk along the actual package providing versions
1072 pkgCache::PkgIterator DPkg
= D
.TargetPkg();
1073 for (pkgCache::VerIterator I
= DPkg
.VersionList();
1074 I
.end() == false && Hit
== false; I
++)
1076 if (Cache
.VS
->CheckDep(I
.VerStr(),D
->CompareOp
,D
.TargetVer()) == true)
1080 // Follow all provides
1081 for (pkgCache::PrvIterator I
= DPkg
.ProvidesList();
1082 I
.end() == false && Hit
== false; I
++)
1084 if (Cache
.VS
->CheckDep(I
.ProvideVersion(),D
->CompareOp
,D
.TargetVer()) == false)
1088 // Only graph critical deps
1089 if (D
.IsCritical() == true)
1091 printf("\"%s\" -> \"%s\"",Pkg
.FullName(true).c_str(),D
.TargetPkg().FullName(true).c_str());
1093 // Colour the node for recursion
1094 if (Show
[D
.TargetPkg()->ID
] <= DoneNR
)
1096 /* If a conflicts does not meet anything in the database
1097 then show the relation but do not recurse */
1099 (D
->Type
== pkgCache::Dep::Conflicts
||
1100 D
->Type
== pkgCache::Dep::Obsoletes
))
1102 if (Show
[D
.TargetPkg()->ID
] == None
&&
1103 Show
[D
.TargetPkg()->ID
] != ToShow
)
1104 Show
[D
.TargetPkg()->ID
] = ToShowNR
;
1108 if (GivenOnly
== true && Show
[D
.TargetPkg()->ID
] != ToShow
)
1109 Show
[D
.TargetPkg()->ID
] = ToShowNR
;
1111 Show
[D
.TargetPkg()->ID
] = ToShow
;
1118 case pkgCache::Dep::Conflicts
:
1119 case pkgCache::Dep::Obsoletes
:
1120 printf("[color=springgreen];\n");
1123 case pkgCache::Dep::PreDepends
:
1124 printf("[color=blue];\n");
1136 /* Draw the box colours after the fact since we can not tell what colour
1137 they should be until everything is finished drawing */
1138 for (pkgCache::PkgIterator Pkg
= Cache
.PkgBegin(); Pkg
.end() == false; Pkg
++)
1140 if (Show
[Pkg
->ID
] < DoneNR
)
1143 // Orange box for early recursion stoppage
1144 if (Show
[Pkg
->ID
] == DoneNR
)
1145 printf("\"%s\" [color=orange,shape=%s];\n",Pkg
.FullName(true).c_str(),
1146 Shapes
[ShapeMap
[Pkg
->ID
]]);
1148 printf("\"%s\" [shape=%s];\n",Pkg
.FullName(true).c_str(),
1149 Shapes
[ShapeMap
[Pkg
->ID
]]);
1156 // DoAdd - Perform an adding operation /*{{{*/
1157 // ---------------------------------------------------------------------
1159 bool DoAdd(CommandLine
&CmdL
)
1161 return _error
->Error("Unimplemented");
1163 // Make sure there is at least one argument
1164 if (CmdL
.FileSize() <= 1)
1165 return _error
->Error("You must give at least one file name");
1168 FileFd
CacheF(_config
->FindFile("Dir::Cache::pkgcache"),FileFd::WriteAny
);
1169 if (_error
->PendingError() == true)
1172 DynamicMMap
Map(CacheF
,MMap::Public
);
1173 if (_error
->PendingError() == true)
1176 OpTextProgress
Progress(*_config
);
1177 pkgCacheGenerator
Gen(Map
,Progress
);
1178 if (_error
->PendingError() == true)
1181 unsigned long Length
= CmdL
.FileSize() - 1;
1182 for (const char **I
= CmdL
.FileList
+ 1; *I
!= 0; I
++)
1184 Progress
.OverallProgress(I
- CmdL
.FileList
,Length
,1,"Generating cache");
1185 Progress
.SubProgress(Length
);
1188 FileFd
TagF(*I
,FileFd::ReadOnly
);
1189 debListParser
Parser(TagF
);
1190 if (_error
->PendingError() == true)
1191 return _error
->Error("Problem opening %s",*I
);
1193 if (Gen
.SelectFile(*I
,"") == false)
1194 return _error
->Error("Problem with SelectFile");
1196 if (Gen
.MergeList(Parser
) == false)
1197 return _error
->Error("Problem with MergeList");
1201 GCache
= &Gen
.GetCache();
1208 // DisplayRecord - Displays the complete record for the package /*{{{*/
1209 // ---------------------------------------------------------------------
1210 /* This displays the package record from the proper package index file.
1211 It is not used by DumpAvail for performance reasons. */
1212 bool DisplayRecord(pkgCache::VerIterator V
)
1214 // Find an appropriate file
1215 pkgCache::VerFileIterator Vf
= V
.FileList();
1216 for (; Vf
.end() == false; Vf
++)
1217 if ((Vf
.File()->Flags
& pkgCache::Flag::NotSource
) == 0)
1219 if (Vf
.end() == true)
1222 // Check and load the package list file
1223 pkgCache::PkgFileIterator I
= Vf
.File();
1224 if (I
.IsOk() == false)
1225 return _error
->Error(_("Package file %s is out of sync."),I
.FileName());
1227 FileFd
PkgF(I
.FileName(),FileFd::ReadOnly
);
1228 if (_error
->PendingError() == true)
1232 unsigned char *Buffer
= new unsigned char[GCache
->HeaderP
->MaxVerFileSize
+1];
1233 Buffer
[V
.FileList()->Size
] = '\n';
1234 if (PkgF
.Seek(V
.FileList()->Offset
) == false ||
1235 PkgF
.Read(Buffer
,V
.FileList()->Size
) == false)
1241 // Get a pointer to start of Description field
1242 const unsigned char *DescP
= (unsigned char*)strstr((char*)Buffer
, "Description:");
1244 // Write all but Description
1245 if (fwrite(Buffer
,1,DescP
- Buffer
,stdout
) < (size_t)(DescP
- Buffer
))
1251 // Show the right description
1252 pkgRecords
Recs(*GCache
);
1253 pkgCache::DescIterator Desc
= V
.TranslatedDescription();
1254 pkgRecords::Parser
&P
= Recs
.Lookup(Desc
.FileList());
1255 cout
<< "Description" << ( (strcmp(Desc
.LanguageCode(),"") != 0) ? "-" : "" ) << Desc
.LanguageCode() << ": " << P
.LongDesc();
1257 // Find the first field after the description (if there is any)
1258 for(DescP
++;DescP
!= &Buffer
[V
.FileList()->Size
];DescP
++)
1260 if(*DescP
== '\n' && *(DescP
+1) != ' ')
1262 // write the rest of the buffer
1263 const unsigned char *end
=&Buffer
[V
.FileList()->Size
];
1264 if (fwrite(DescP
,1,end
-DescP
,stdout
) < (size_t)(end
-DescP
))
1273 // write a final newline (after the description)
1283 pkgCache::DescFile
*Df
;
1287 // Search - Perform a search /*{{{*/
1288 // ---------------------------------------------------------------------
1289 /* This searches the package names and package descriptions for a pattern */
1290 bool Search(CommandLine
&CmdL
)
1292 pkgCache
&Cache
= *GCache
;
1293 bool ShowFull
= _config
->FindB("APT::Cache::ShowFull",false);
1294 bool NamesOnly
= _config
->FindB("APT::Cache::NamesOnly",false);
1295 unsigned NumPatterns
= CmdL
.FileSize() -1;
1297 pkgDepCache::Policy Plcy
;
1299 // Make sure there is at least one argument
1300 if (NumPatterns
< 1)
1301 return _error
->Error(_("You must give exactly one pattern"));
1303 // Compile the regex pattern
1304 regex_t
*Patterns
= new regex_t
[NumPatterns
];
1305 memset(Patterns
,0,sizeof(*Patterns
)*NumPatterns
);
1306 for (unsigned I
= 0; I
!= NumPatterns
; I
++)
1308 if (regcomp(&Patterns
[I
],CmdL
.FileList
[I
+1],REG_EXTENDED
| REG_ICASE
|
1312 regfree(&Patterns
[I
]);
1313 return _error
->Error("Regex compilation error");
1317 // Create the text record parser
1318 pkgRecords
Recs(Cache
);
1319 if (_error
->PendingError() == true)
1321 for (unsigned I
= 0; I
!= NumPatterns
; I
++)
1322 regfree(&Patterns
[I
]);
1326 ExDescFile
*DFList
= new ExDescFile
[Cache
.HeaderP
->PackageCount
+1];
1327 memset(DFList
,0,sizeof(*DFList
)*Cache
.HeaderP
->PackageCount
+1);
1329 // Map versions that we want to write out onto the VerList array.
1330 for (pkgCache::PkgIterator P
= Cache
.PkgBegin(); P
.end() == false; P
++)
1332 DFList
[P
->ID
].NameMatch
= NumPatterns
!= 0;
1333 for (unsigned I
= 0; I
!= NumPatterns
; I
++)
1335 if (regexec(&Patterns
[I
],P
.Name(),0,0,0) == 0)
1336 DFList
[P
->ID
].NameMatch
&= true;
1338 DFList
[P
->ID
].NameMatch
= false;
1341 // Doing names only, drop any that dont match..
1342 if (NamesOnly
== true && DFList
[P
->ID
].NameMatch
== false)
1345 // Find the proper version to use.
1346 pkgCache::VerIterator V
= Plcy
.GetCandidateVer(P
);
1347 if (V
.end() == false)
1348 DFList
[P
->ID
].Df
= V
.DescriptionList().FileList();
1351 // Include all the packages that provide matching names too
1352 for (pkgCache::PkgIterator P
= Cache
.PkgBegin(); P
.end() == false; P
++)
1354 if (DFList
[P
->ID
].NameMatch
== false)
1357 for (pkgCache::PrvIterator Prv
= P
.ProvidesList() ; Prv
.end() == false; Prv
++)
1359 pkgCache::VerIterator V
= Plcy
.GetCandidateVer(Prv
.OwnerPkg());
1360 if (V
.end() == false)
1362 DFList
[Prv
.OwnerPkg()->ID
].Df
= V
.DescriptionList().FileList();
1363 DFList
[Prv
.OwnerPkg()->ID
].NameMatch
= true;
1368 LocalitySort(&DFList
->Df
,Cache
.HeaderP
->PackageCount
,sizeof(*DFList
));
1370 // Iterate over all the version records and check them
1371 for (ExDescFile
*J
= DFList
; J
->Df
!= 0; J
++)
1373 pkgRecords::Parser
&P
= Recs
.Lookup(pkgCache::DescFileIterator(Cache
,J
->Df
));
1376 if (J
->NameMatch
== false)
1378 string LongDesc
= P
.LongDesc();
1379 Match
= NumPatterns
!= 0;
1380 for (unsigned I
= 0; I
!= NumPatterns
; I
++)
1382 if (regexec(&Patterns
[I
],LongDesc
.c_str(),0,0,0) == 0)
1391 if (ShowFull
== true)
1395 P
.GetRec(Start
,End
);
1396 fwrite(Start
,End
-Start
,1,stdout
);
1400 printf("%s - %s\n",P
.Name().c_str(),P
.ShortDesc().c_str());
1405 for (unsigned I
= 0; I
!= NumPatterns
; I
++)
1406 regfree(&Patterns
[I
]);
1408 return _error
->Error("Write to stdout failed");
1413 /* show automatically installed packages (sorted) */
1414 bool ShowAuto(CommandLine
&CmdL
)
1417 pkgDepCache
DepCache(GCache
);
1420 std::vector
<string
> packages
;
1421 packages
.reserve(GCache
->HeaderP
->PackageCount
/ 3);
1423 for (pkgCache::PkgIterator P
= GCache
->PkgBegin(); P
.end() == false; P
++)
1424 if (DepCache
[P
].Flags
& pkgCache::Flag::Auto
)
1425 packages
.push_back(P
.Name());
1427 std::sort(packages
.begin(), packages
.end());
1429 for (vector
<string
>::iterator I
= packages
.begin(); I
!= packages
.end(); I
++)
1435 // ShowPackage - Dump the package record to the screen /*{{{*/
1436 // ---------------------------------------------------------------------
1438 bool ShowPackage(CommandLine
&CmdL
)
1440 pkgCache
&Cache
= *GCache
;
1441 pkgDepCache::Policy Plcy
;
1445 for (const char **I
= CmdL
.FileList
+ 1; *I
!= 0; I
++)
1447 // FIXME: Handle the case in which pkgname name:arch is not found
1448 pkgCache::PkgIterator Pkg
= Cache
.FindPkg(*I
);
1449 if (Pkg
.end() == true)
1451 Pkg
= Cache
.FindPkg(*I
, "any");
1452 if (Pkg
.end() == true) {
1453 _error
->Warning(_("Unable to locate package %s"),*I
);
1460 // Find the proper version to use.
1461 if (_config
->FindB("APT::Cache::AllVersions","true") == true)
1463 pkgCache::VerIterator V
;
1464 for (V
= Pkg
.VersionList(); V
.end() == false; V
++)
1466 if (DisplayRecord(V
) == false)
1472 pkgCache::VerIterator V
= Plcy
.GetCandidateVer(Pkg
);
1473 if (V
.end() == true || V
.FileList().end() == true)
1475 if (DisplayRecord(V
) == false)
1482 return _error
->Error(_("No packages found"));
1485 // ShowPkgNames - Show package names /*{{{*/
1486 // ---------------------------------------------------------------------
1487 /* This does a prefix match on the first argument */
1488 bool ShowPkgNames(CommandLine
&CmdL
)
1490 pkgCache
&Cache
= *GCache
;
1491 pkgCache::GrpIterator I
= Cache
.GrpBegin();
1492 bool const All
= _config
->FindB("APT::Cache::AllNames","false");
1494 if (CmdL
.FileList
[1] != 0)
1496 for (;I
.end() != true; I
++)
1498 if (All
== false && I
->FirstPackage
== 0)
1500 if (I
.FindPkg("any")->VersionList
== 0)
1502 if (strncmp(I
.Name(),CmdL
.FileList
[1],strlen(CmdL
.FileList
[1])) == 0)
1503 cout
<< I
.Name() << endl
;
1510 for (;I
.end() != true; I
++)
1512 if (All
== false && I
->FirstPackage
== 0)
1514 if (I
.FindPkg("any")->VersionList
== 0)
1516 cout
<< I
.Name() << endl
;
1522 // ShowSrcPackage - Show source package records /*{{{*/
1523 // ---------------------------------------------------------------------
1525 bool ShowSrcPackage(CommandLine
&CmdL
)
1528 List
.ReadMainList();
1530 // Create the text record parsers
1531 pkgSrcRecords
SrcRecs(List
);
1532 if (_error
->PendingError() == true)
1536 for (const char **I
= CmdL
.FileList
+ 1; *I
!= 0; I
++)
1540 pkgSrcRecords::Parser
*Parse
;
1541 unsigned found_this
= 0;
1542 while ((Parse
= SrcRecs
.Find(*I
,false)) != 0) {
1543 cout
<< Parse
->AsStr() << endl
;;
1547 if (found_this
== 0) {
1548 _error
->Warning(_("Unable to locate package %s"),*I
);
1554 return _error
->Error(_("No packages found"));
1557 // Policy - Show the results of the preferences file /*{{{*/
1558 // ---------------------------------------------------------------------
1560 bool Policy(CommandLine
&CmdL
)
1563 return _error
->Error("Generate must be enabled for this function");
1565 pkgCache
&Cache
= *GCache
;
1566 pkgPolicy
Plcy(&Cache
);
1567 if (ReadPinFile(Plcy
) == false || ReadPinDir(Plcy
) == false)
1570 // Print out all of the package files
1571 if (CmdL
.FileList
[1] == 0)
1573 cout
<< _("Package files:") << endl
;
1574 for (pkgCache::PkgFileIterator F
= Cache
.FileBegin(); F
.end() == false; F
++)
1576 // Locate the associated index files so we can derive a description
1578 if (SrcList
->FindIndex(F
,Indx
) == false &&
1579 _system
->FindIndex(F
,Indx
) == false)
1580 return _error
->Error(_("Cache is out of sync, can't x-ref a package file"));
1583 Plcy
.GetPriority(F
),Indx
->Describe(true).c_str());
1585 // Print the reference information for the package
1586 string Str
= F
.RelStr();
1587 if (Str
.empty() == false)
1588 printf(" release %s\n",F
.RelStr().c_str());
1589 if (F
.Site() != 0 && F
.Site()[0] != 0)
1590 printf(" origin %s\n",F
.Site());
1593 // Show any packages have explicit pins
1594 cout
<< _("Pinned packages:") << endl
;
1595 pkgCache::PkgIterator I
= Cache
.PkgBegin();
1596 for (;I
.end() != true; I
++)
1598 if (Plcy
.GetPriority(I
) == 0)
1601 // Print the package name and the version we are forcing to
1602 cout
<< " " << I
.FullName(true) << " -> ";
1604 pkgCache::VerIterator V
= Plcy
.GetMatch(I
);
1605 if (V
.end() == true)
1606 cout
<< _("(not found)") << endl
;
1608 cout
<< V
.VerStr() << endl
;
1614 string
const myArch
= _config
->Find("APT::Architecture");
1615 char const * const msgInstalled
= _(" Installed: ");
1616 char const * const msgCandidate
= _(" Candidate: ");
1617 short const InstalledLessCandidate
=
1618 mbstowcs(NULL
, msgInstalled
, 0) - mbstowcs(NULL
, msgCandidate
, 0);
1619 short const deepInstalled
=
1620 (InstalledLessCandidate
< 0 ? (InstalledLessCandidate
*-1) : 0) - 1;
1621 short const deepCandidate
=
1622 (InstalledLessCandidate
> 0 ? (InstalledLessCandidate
) : 0) - 1;
1624 // Print out detailed information for each package
1625 for (const char **I
= CmdL
.FileList
+ 1; *I
!= 0; I
++)
1627 pkgCache::GrpIterator Grp
= Cache
.FindGrp(*I
);
1628 pkgCache::PkgIterator Pkg
= Grp
.FindPkg("any");
1629 if (Pkg
.end() == true)
1631 _error
->Warning(_("Unable to locate package %s"),*I
);
1635 for (; Pkg
.end() != true; Pkg
= Grp
.NextPkg(Pkg
)) {
1636 if (strcmp(Pkg
.Arch(),"all") == 0)
1639 cout
<< Pkg
.FullName(true) << ":" << endl
;
1641 // Installed version
1642 cout
<< msgInstalled
<< OutputInDepth(deepInstalled
, " ");
1643 if (Pkg
->CurrentVer
== 0)
1644 cout
<< _("(none)") << endl
;
1646 cout
<< Pkg
.CurrentVer().VerStr() << endl
;
1648 // Candidate Version
1649 cout
<< msgCandidate
<< OutputInDepth(deepCandidate
, " ");
1650 pkgCache::VerIterator V
= Plcy
.GetCandidateVer(Pkg
);
1651 if (V
.end() == true)
1652 cout
<< _("(none)") << endl
;
1654 cout
<< V
.VerStr() << endl
;
1657 if (Plcy
.GetPriority(Pkg
) != 0)
1659 cout
<< _(" Package pin: ");
1660 V
= Plcy
.GetMatch(Pkg
);
1661 if (V
.end() == true)
1662 cout
<< _("(not found)") << endl
;
1664 cout
<< V
.VerStr() << endl
;
1667 // Show the priority tables
1668 cout
<< _(" Version table:") << endl
;
1669 for (V
= Pkg
.VersionList(); V
.end() == false; V
++)
1671 if (Pkg
.CurrentVer() == V
)
1672 cout
<< " *** " << V
.VerStr();
1674 cout
<< " " << V
.VerStr();
1675 cout
<< " " << Plcy
.GetPriority(Pkg
) << endl
;
1676 for (pkgCache::VerFileIterator VF
= V
.FileList(); VF
.end() == false; VF
++)
1678 // Locate the associated index files so we can derive a description
1680 if (SrcList
->FindIndex(VF
.File(),Indx
) == false &&
1681 _system
->FindIndex(VF
.File(),Indx
) == false)
1682 return _error
->Error(_("Cache is out of sync, can't x-ref a package file"));
1683 printf(" %4i %s\n",Plcy
.GetPriority(VF
.File()),
1684 Indx
->Describe(true).c_str());
1693 // Madison - Look a bit like katie's madison /*{{{*/
1694 // ---------------------------------------------------------------------
1696 bool Madison(CommandLine
&CmdL
)
1699 return _error
->Error("Generate must be enabled for this function");
1701 SrcList
->ReadMainList();
1703 pkgCache
&Cache
= *GCache
;
1705 // Create the src text record parsers and ignore errors about missing
1706 // deb-src lines that are generated from pkgSrcRecords::pkgSrcRecords
1707 pkgSrcRecords
SrcRecs(*SrcList
);
1708 if (_error
->PendingError() == true)
1711 for (const char **I
= CmdL
.FileList
+ 1; *I
!= 0; I
++)
1713 pkgCache::PkgIterator Pkg
= Cache
.FindPkg(*I
);
1715 if (Pkg
.end() == false)
1717 for (pkgCache::VerIterator V
= Pkg
.VersionList(); V
.end() == false; V
++)
1719 for (pkgCache::VerFileIterator VF
= V
.FileList(); VF
.end() == false; VF
++)
1721 // This might be nice, but wouldn't uniquely identify the source -mdz
1722 // if (VF.File().Archive() != 0)
1724 // cout << setw(10) << Pkg.Name() << " | " << setw(10) << V.VerStr() << " | "
1725 // << VF.File().Archive() << endl;
1728 // Locate the associated index files so we can derive a description
1729 for (pkgSourceList::const_iterator S
= SrcList
->begin(); S
!= SrcList
->end(); S
++)
1731 vector
<pkgIndexFile
*> *Indexes
= (*S
)->GetIndexFiles();
1732 for (vector
<pkgIndexFile
*>::const_iterator IF
= Indexes
->begin();
1733 IF
!= Indexes
->end(); IF
++)
1735 if ((*IF
)->FindInCache(*(VF
.File().Cache())) == VF
.File())
1737 cout
<< setw(10) << Pkg
.FullName(true) << " | " << setw(10) << V
.VerStr() << " | "
1738 << (*IF
)->Describe(true) << endl
;
1748 pkgSrcRecords::Parser
*SrcParser
;
1749 while ((SrcParser
= SrcRecs
.Find(*I
,false)) != 0)
1751 // Maybe support Release info here too eventually
1752 cout
<< setw(10) << SrcParser
->Package() << " | "
1753 << setw(10) << SrcParser
->Version() << " | "
1754 << SrcParser
->Index().Describe(true) << endl
;
1761 // GenCaches - Call the main cache generator /*{{{*/
1762 // ---------------------------------------------------------------------
1764 bool GenCaches(CommandLine
&Cmd
)
1766 OpTextProgress
Progress(*_config
);
1769 if (List
.ReadMainList() == false)
1771 return pkgMakeStatusCache(List
,Progress
);
1774 // ShowHelp - Show a help screen /*{{{*/
1775 // ---------------------------------------------------------------------
1777 bool ShowHelp(CommandLine
&Cmd
)
1779 ioprintf(cout
,_("%s %s for %s compiled on %s %s\n"),PACKAGE
,VERSION
,
1780 COMMON_ARCH
,__DATE__
,__TIME__
);
1782 if (_config
->FindB("version") == true)
1786 _("Usage: apt-cache [options] command\n"
1787 " apt-cache [options] add file1 [file2 ...]\n"
1788 " apt-cache [options] showpkg pkg1 [pkg2 ...]\n"
1789 " apt-cache [options] showsrc pkg1 [pkg2 ...]\n"
1791 "apt-cache is a low-level tool used to manipulate APT's binary\n"
1792 "cache files, and query information from them\n"
1795 " add - Add a package file to the source cache\n"
1796 " gencaches - Build both the package and source cache\n"
1797 " showpkg - Show some general information for a single package\n"
1798 " showsrc - Show source records\n"
1799 " stats - Show some basic statistics\n"
1800 " dump - Show the entire file in a terse form\n"
1801 " dumpavail - Print an available file to stdout\n"
1802 " unmet - Show unmet dependencies\n"
1803 " search - Search the package list for a regex pattern\n"
1804 " show - Show a readable record for the package\n"
1805 " showauto - Display a list of automatically installed packages\n"
1806 " depends - Show raw dependency information for a package\n"
1807 " rdepends - Show reverse dependency information for a package\n"
1808 " pkgnames - List the names of all packages in the system\n"
1809 " dotty - Generate package graphs for GraphViz\n"
1810 " xvcg - Generate package graphs for xvcg\n"
1811 " policy - Show policy settings\n"
1814 " -h This help text.\n"
1815 " -p=? The package cache.\n"
1816 " -s=? The source cache.\n"
1817 " -q Disable progress indicator.\n"
1818 " -i Show only important deps for the unmet command.\n"
1819 " -c=? Read this configuration file\n"
1820 " -o=? Set an arbitrary configuration option, eg -o dir::cache=/tmp\n"
1821 "See the apt-cache(8) and apt.conf(5) manual pages for more information.\n");
1825 // CacheInitialize - Initialize things for apt-cache /*{{{*/
1826 // ---------------------------------------------------------------------
1828 void CacheInitialize()
1830 _config
->Set("quiet",0);
1831 _config
->Set("help",false);
1834 int main(int argc
,const char *argv
[]) /*{{{*/
1836 CommandLine::Args Args
[] = {
1837 {'h',"help","help",0},
1838 {'v',"version","version",0},
1839 {'p',"pkg-cache","Dir::Cache::pkgcache",CommandLine::HasArg
},
1840 {'s',"src-cache","Dir::Cache::srcpkgcache",CommandLine::HasArg
},
1841 {'q',"quiet","quiet",CommandLine::IntLevel
},
1842 {'i',"important","APT::Cache::Important",0},
1843 {'f',"full","APT::Cache::ShowFull",0},
1844 {'g',"generate","APT::Cache::Generate",0},
1845 {'a',"all-versions","APT::Cache::AllVersions",0},
1846 {'n',"names-only","APT::Cache::NamesOnly",0},
1847 {0,"all-names","APT::Cache::AllNames",0},
1848 {0,"recurse","APT::Cache::RecurseDepends",0},
1849 {'c',"config-file",0,CommandLine::ConfigFile
},
1850 {'o',"option",0,CommandLine::ArbItem
},
1851 {0,"installed","APT::Cache::Installed",0},
1853 CommandLine::Dispatch CmdsA
[] = {{"help",&ShowHelp
},
1855 {"gencaches",&GenCaches
},
1856 {"showsrc",&ShowSrcPackage
},
1858 CommandLine::Dispatch CmdsB
[] = {{"showpkg",&DumpPackage
},
1861 {"dumpavail",&DumpAvail
},
1864 {"depends",&Depends
},
1865 {"rdepends",&RDepends
},
1868 {"show",&ShowPackage
},
1869 {"pkgnames",&ShowPkgNames
},
1870 {"showauto",&ShowAuto
},
1872 {"madison",&Madison
},
1877 // Set up gettext support
1878 setlocale(LC_ALL
,"");
1879 textdomain(PACKAGE
);
1881 // Parse the command line and initialize the package library
1882 CommandLine
CmdL(Args
,_config
);
1883 if (pkgInitConfig(*_config
) == false ||
1884 CmdL
.Parse(argc
,argv
) == false ||
1885 pkgInitSystem(*_config
,_system
) == false)
1887 _error
->DumpErrors();
1891 // See if the help should be shown
1892 if (_config
->FindB("help") == true ||
1893 CmdL
.FileSize() == 0)
1899 // Deal with stdout not being a tty
1900 if (isatty(STDOUT_FILENO
) && _config
->FindI("quiet",0) < 1)
1901 _config
->Set("quiet","1");
1903 if (CmdL
.DispatchArg(CmdsA
,false) == false && _error
->PendingError() == false)
1906 if (_config
->FindB("APT::Cache::Generate",true) == false)
1908 Map
= new MMap(*new FileFd(_config
->FindFile("Dir::Cache::pkgcache"),
1909 FileFd::ReadOnly
),MMap::Public
|MMap::ReadOnly
);
1913 // Open the cache file
1914 SrcList
= new pkgSourceList
;
1915 SrcList
->ReadMainList();
1917 // Generate it and map it
1919 pkgMakeStatusCache(*SrcList
,Prog
,&Map
,true);
1922 if (_error
->PendingError() == false)
1924 pkgCache
Cache(Map
);
1926 if (_error
->PendingError() == false)
1927 CmdL
.DispatchArg(CmdsB
);
1932 // Print any errors or warnings found during parsing
1933 if (_error
->empty() == false)
1935 bool Errors
= _error
->PendingError();
1936 _error
->DumpErrors();
1937 return Errors
== true?100:0;