]>
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>
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 // UnMet - Show unmet dependencies /*{{{*/
76 // ---------------------------------------------------------------------
78 bool UnMet(CommandLine
&CmdL
)
80 pkgCache
&Cache
= *GCache
;
81 bool Important
= _config
->FindB("APT::Cache::Important",false);
83 for (pkgCache::PkgIterator P
= Cache
.PkgBegin(); P
.end() == false; P
++)
85 for (pkgCache::VerIterator V
= P
.VersionList(); V
.end() == false; V
++)
88 for (pkgCache::DepIterator D
= V
.DependsList(); D
.end() == false;)
91 pkgCache::DepIterator Start
;
92 pkgCache::DepIterator End
;
95 // Skip conflicts and replaces
96 if (End
->Type
!= pkgCache::Dep::PreDepends
&&
97 End
->Type
!= pkgCache::Dep::Depends
&&
98 End
->Type
!= pkgCache::Dep::Suggests
&&
99 End
->Type
!= pkgCache::Dep::Recommends
)
102 // Important deps only
103 if (Important
== true)
104 if (End
->Type
!= pkgCache::Dep::PreDepends
&&
105 End
->Type
!= pkgCache::Dep::Depends
)
108 // Verify the or group
110 pkgCache::DepIterator RealStart
= Start
;
113 // See if this dep is Ok
114 pkgCache::Version
**VList
= Start
.AllTargets();
135 ioprintf(cout
,_("Package %s version %s has an unmet dep:\n"),
136 P
.Name(),V
.VerStr());
139 // Print out the dep type
140 cout
<< " " << End
.DepType() << ": ";
146 cout
<< Start
.TargetPkg().Name();
147 if (Start
.TargetVer() != 0)
148 cout
<< " (" << Start
.CompType() << " " << Start
.TargetVer() <<
164 // DumpPackage - Show a dump of a package record /*{{{*/
165 // ---------------------------------------------------------------------
167 bool DumpPackage(CommandLine
&CmdL
)
169 pkgCache
&Cache
= *GCache
;
170 for (const char **I
= CmdL
.FileList
+ 1; *I
!= 0; I
++)
172 pkgCache::PkgIterator Pkg
= Cache
.FindPkg(*I
);
173 if (Pkg
.end() == true)
175 _error
->Warning(_("Unable to locate package %s"),*I
);
179 cout
<< "Package: " << Pkg
.Name() << endl
;
180 cout
<< "Versions: " << endl
;
181 for (pkgCache::VerIterator Cur
= Pkg
.VersionList(); Cur
.end() != true; Cur
++)
183 cout
<< Cur
.VerStr();
184 for (pkgCache::VerFileIterator Vf
= Cur
.FileList(); Vf
.end() == false; Vf
++)
185 cout
<< "(" << Vf
.File().FileName() << ")";
191 cout
<< "Reverse Depends: " << endl
;
192 for (pkgCache::DepIterator D
= Pkg
.RevDependsList(); D
.end() != true; D
++)
194 cout
<< " " << D
.ParentPkg().Name() << ',' << D
.TargetPkg().Name();
196 cout
<< ' ' << DeNull(D
.TargetVer()) << endl
;
201 cout
<< "Dependencies: " << endl
;
202 for (pkgCache::VerIterator Cur
= Pkg
.VersionList(); Cur
.end() != true; Cur
++)
204 cout
<< Cur
.VerStr() << " - ";
205 for (pkgCache::DepIterator Dep
= Cur
.DependsList(); Dep
.end() != true; Dep
++)
206 cout
<< Dep
.TargetPkg().Name() << " (" << (int)Dep
->CompareOp
<< " " << DeNull(Dep
.TargetVer()) << ") ";
210 cout
<< "Provides: " << endl
;
211 for (pkgCache::VerIterator Cur
= Pkg
.VersionList(); Cur
.end() != true; Cur
++)
213 cout
<< Cur
.VerStr() << " - ";
214 for (pkgCache::PrvIterator Prv
= Cur
.ProvidesList(); Prv
.end() != true; Prv
++)
215 cout
<< Prv
.ParentPkg().Name() << " ";
218 cout
<< "Reverse Provides: " << endl
;
219 for (pkgCache::PrvIterator Prv
= Pkg
.ProvidesList(); Prv
.end() != true; Prv
++)
220 cout
<< Prv
.OwnerPkg().Name() << " " << Prv
.OwnerVer().VerStr() << endl
;
226 // Stats - Dump some nice statistics /*{{{*/
227 // ---------------------------------------------------------------------
229 bool Stats(CommandLine
&Cmd
)
231 pkgCache
&Cache
= *GCache
;
232 cout
<< _("Total package names : ") << Cache
.Head().PackageCount
<< " (" <<
233 SizeToStr(Cache
.Head().PackageCount
*Cache
.Head().PackageSz
) << ')' << endl
;
240 pkgCache::PkgIterator I
= Cache
.PkgBegin();
241 for (;I
.end() != true; I
++)
243 if (I
->VersionList
!= 0 && I
->ProvidesList
== 0)
249 if (I
->VersionList
!= 0 && I
->ProvidesList
!= 0)
255 if (I
->VersionList
== 0 && I
->ProvidesList
!= 0)
258 if (I
.ProvidesList()->NextProvides
== 0)
266 if (I
->VersionList
== 0 && I
->ProvidesList
== 0)
272 cout
<< _(" Normal packages: ") << Normal
<< endl
;
273 cout
<< _(" Pure virtual packages: ") << Virtual
<< endl
;
274 cout
<< _(" Single virtual packages: ") << DVirt
<< endl
;
275 cout
<< _(" Mixed virtual packages: ") << NVirt
<< endl
;
276 cout
<< _(" Missing: ") << Missing
<< endl
;
278 cout
<< _("Total distinct versions: ") << Cache
.Head().VersionCount
<< " (" <<
279 SizeToStr(Cache
.Head().VersionCount
*Cache
.Head().VersionSz
) << ')' << endl
;
280 cout
<< _("Total dependencies: ") << Cache
.Head().DependsCount
<< " (" <<
281 SizeToStr(Cache
.Head().DependsCount
*Cache
.Head().DependencySz
) << ')' << endl
;
283 cout
<< _("Total ver/file relations: ") << Cache
.Head().VerFileCount
<< " (" <<
284 SizeToStr(Cache
.Head().VerFileCount
*Cache
.Head().VerFileSz
) << ')' << endl
;
285 cout
<< _("Total Provides mappings: ") << Cache
.Head().ProvidesCount
<< " (" <<
286 SizeToStr(Cache
.Head().ProvidesCount
*Cache
.Head().ProvidesSz
) << ')' << endl
;
289 unsigned long Size
= 0;
290 unsigned long Count
= 0;
291 for (pkgCache::StringItem
*I
= Cache
.StringItemP
+ Cache
.Head().StringList
;
292 I
!= Cache
.StringItemP
; I
= Cache
.StringItemP
+ I
->NextItem
)
295 Size
+= strlen(Cache
.StrP
+ I
->String
) + 1;
297 cout
<< _("Total globbed strings: ") << Count
<< " (" << SizeToStr(Size
) << ')' << endl
;
299 unsigned long DepVerSize
= 0;
300 for (pkgCache::PkgIterator P
= Cache
.PkgBegin(); P
.end() == false; P
++)
302 for (pkgCache::VerIterator V
= P
.VersionList(); V
.end() == false; V
++)
304 for (pkgCache::DepIterator D
= V
.DependsList(); D
.end() == false; D
++)
307 DepVerSize
+= strlen(D
.TargetVer()) + 1;
311 cout
<< _("Total dependency version space: ") << SizeToStr(DepVerSize
) << endl
;
313 unsigned long Slack
= 0;
314 for (int I
= 0; I
!= 7; I
++)
315 Slack
+= Cache
.Head().Pools
[I
].ItemSize
*Cache
.Head().Pools
[I
].Count
;
316 cout
<< _("Total slack space: ") << SizeToStr(Slack
) << endl
;
318 unsigned long Total
= 0;
319 Total
= Slack
+ Size
+ Cache
.Head().DependsCount
*Cache
.Head().DependencySz
+
320 Cache
.Head().VersionCount
*Cache
.Head().VersionSz
+
321 Cache
.Head().PackageCount
*Cache
.Head().PackageSz
+
322 Cache
.Head().VerFileCount
*Cache
.Head().VerFileSz
+
323 Cache
.Head().ProvidesCount
*Cache
.Head().ProvidesSz
;
324 cout
<< _("Total space accounted for: ") << SizeToStr(Total
) << endl
;
329 // Dump - show everything /*{{{*/
330 // ---------------------------------------------------------------------
331 /* This is worthless except fer debugging things */
332 bool Dump(CommandLine
&Cmd
)
334 pkgCache
&Cache
= *GCache
;
335 cout
<< "Using Versioning System: " << Cache
.VS
->Label
<< endl
;
337 for (pkgCache::PkgIterator P
= Cache
.PkgBegin(); P
.end() == false; P
++)
339 cout
<< "Package: " << P
.Name() << endl
;
340 for (pkgCache::VerIterator V
= P
.VersionList(); V
.end() == false; V
++)
342 cout
<< " Version: " << V
.VerStr() << endl
;
343 cout
<< " File: " << V
.FileList().File().FileName() << endl
;
344 for (pkgCache::DepIterator D
= V
.DependsList(); D
.end() == false; D
++)
345 cout
<< " Depends: " << D
.TargetPkg().Name() << ' ' <<
346 DeNull(D
.TargetVer()) << endl
;
350 for (pkgCache::PkgFileIterator F
= Cache
.FileBegin(); F
.end() == false; F
++)
352 cout
<< "File: " << F
.FileName() << endl
;
353 cout
<< " Type: " << F
.IndexType() << endl
;
354 cout
<< " Size: " << F
->Size
<< endl
;
355 cout
<< " ID: " << F
->ID
<< endl
;
356 cout
<< " Flags: " << F
->Flags
<< endl
;
357 cout
<< " Time: " << TimeRFC1123(F
->mtime
) << endl
;
358 cout
<< " Archive: " << DeNull(F
.Archive()) << endl
;
359 cout
<< " Component: " << DeNull(F
.Component()) << endl
;
360 cout
<< " Version: " << DeNull(F
.Version()) << endl
;
361 cout
<< " Origin: " << DeNull(F
.Origin()) << endl
;
362 cout
<< " Site: " << DeNull(F
.Site()) << endl
;
363 cout
<< " Label: " << DeNull(F
.Label()) << endl
;
364 cout
<< " Architecture: " << DeNull(F
.Architecture()) << endl
;
370 // DumpAvail - Print out the available list /*{{{*/
371 // ---------------------------------------------------------------------
372 /* This is needed to make dpkg --merge happy.. I spent a bit of time to
373 make this run really fast, perhaps I went a little overboard.. */
374 bool DumpAvail(CommandLine
&Cmd
)
376 pkgCache
&Cache
= *GCache
;
378 pkgPolicy
Plcy(&Cache
);
379 if (ReadPinFile(Plcy
) == false)
382 unsigned long Count
= Cache
.HeaderP
->PackageCount
+1;
383 pkgCache::VerFile
**VFList
= new pkgCache::VerFile
*[Count
];
384 memset(VFList
,0,sizeof(*VFList
)*Count
);
386 // Map versions that we want to write out onto the VerList array.
387 for (pkgCache::PkgIterator P
= Cache
.PkgBegin(); P
.end() == false; P
++)
389 if (P
->VersionList
== 0)
392 /* Find the proper version to use. If the policy says there are no
393 possible selections we return the installed version, if available..
394 This prevents dselect from making it obsolete. */
395 pkgCache::VerIterator V
= Plcy
.GetCandidateVer(P
);
398 if (P
->CurrentVer
== 0)
403 pkgCache::VerFileIterator VF
= V
.FileList();
404 for (; VF
.end() == false ; VF
++)
405 if ((VF
.File()->Flags
& pkgCache::Flag::NotSource
) == 0)
408 /* Okay, here we have a bit of a problem.. The policy has selected the
409 currently installed package - however it only exists in the
410 status file.. We need to write out something or dselect will mark
411 the package as obsolete! Thus we emit the status file entry, but
412 below we remove the status line to make it valid for the
413 available file. However! We only do this if their do exist *any*
414 non-source versions of the package - that way the dselect obsolete
415 handling works OK. */
416 if (VF
.end() == true)
418 for (pkgCache::VerIterator Cur
= P
.VersionList(); Cur
.end() != true; Cur
++)
420 for (VF
= Cur
.FileList(); VF
.end() == false; VF
++)
422 if ((VF
.File()->Flags
& pkgCache::Flag::NotSource
) == 0)
429 if (VF
.end() == false)
437 LocalitySort(VFList
,Count
,sizeof(*VFList
));
439 // Iterate over all the package files and write them out.
440 char *Buffer
= new char[Cache
.HeaderP
->MaxVerFileSize
+10];
441 for (pkgCache::VerFile
**J
= VFList
; *J
!= 0;)
443 pkgCache::PkgFileIterator
File(Cache
,(*J
)->File
+ Cache
.PkgFileP
);
444 if (File
.IsOk() == false)
446 _error
->Error(_("Package file %s is out of sync."),File
.FileName());
450 FileFd
PkgF(File
.FileName(),FileFd::ReadOnly
);
451 if (_error
->PendingError() == true)
454 /* Write all of the records from this package file, since we
455 already did locality sorting we can now just seek through the
456 file in read order. We apply 1 more optimization here, since often
457 there will be < 1 byte gaps between records (for the \n) we read that
458 into the next buffer and offset a bit.. */
459 unsigned long Pos
= 0;
462 if ((*J
)->File
+ Cache
.PkgFileP
!= File
)
465 const pkgCache::VerFile
&VF
= **J
;
467 // Read the record and then write it out again.
468 unsigned long Jitter
= VF
.Offset
- Pos
;
471 if (PkgF
.Seek(VF
.Offset
) == false)
476 if (PkgF
.Read(Buffer
,VF
.Size
+ Jitter
) == false)
478 Buffer
[VF
.Size
+ Jitter
] = '\n';
481 if ((File
->Flags
& pkgCache::Flag::NotSource
) == pkgCache::Flag::NotSource
)
484 TFRewriteData RW
[] = {{"Status",0},{"Config-Version",0},{}};
485 const char *Zero
= 0;
486 if (Tags
.Scan(Buffer
+Jitter
,VF
.Size
+1) == false ||
487 TFRewrite(stdout
,Tags
,&Zero
,RW
) == false)
489 _error
->Error("Internal Error, Unable to parse a package record");
496 if (fwrite(Buffer
+Jitter
,VF
.Size
+1,1,stdout
) != 1)
500 Pos
= VF
.Offset
+ VF
.Size
;
504 if (_error
->PendingError() == true)
510 return !_error
->PendingError();
513 // Depends - Print out a dependency tree /*{{{*/
514 // ---------------------------------------------------------------------
516 bool Depends(CommandLine
&CmdL
)
518 pkgCache
&Cache
= *GCache
;
519 SPtrArray
<unsigned> Colours
= new unsigned[Cache
.Head().PackageCount
];
520 memset(Colours
,0,sizeof(*Colours
)*Cache
.Head().PackageCount
);
522 for (const char **I
= CmdL
.FileList
+ 1; *I
!= 0; I
++)
524 pkgCache::PkgIterator Pkg
= Cache
.FindPkg(*I
);
525 if (Pkg
.end() == true)
527 _error
->Warning(_("Unable to locate package %s"),*I
);
530 Colours
[Pkg
->ID
] = 1;
533 bool Recurse
= _config
->FindB("APT::Cache::RecurseDepends",false);
534 bool Installed
= _config
->FindB("APT::Cache::Installed",false);
538 DidSomething
= false;
539 for (pkgCache::PkgIterator Pkg
= Cache
.PkgBegin(); Pkg
.end() == false; Pkg
++)
541 if (Colours
[Pkg
->ID
] != 1)
543 Colours
[Pkg
->ID
] = 2;
546 pkgCache::VerIterator Ver
= Pkg
.VersionList();
547 if (Ver
.end() == true)
549 cout
<< '<' << Pkg
.Name() << '>' << endl
;
553 cout
<< Pkg
.Name() << endl
;
555 for (pkgCache::DepIterator D
= Ver
.DependsList(); D
.end() == false; D
++)
558 pkgCache::PkgIterator Trg
= D
.TargetPkg();
560 if((Installed
&& Trg
->CurrentVer
!= 0) || !Installed
)
563 if ((D
->CompareOp
& pkgCache::Dep::Or
) == pkgCache::Dep::Or
)
569 if (Trg
->VersionList
== 0)
570 cout
<< D
.DepType() << ": <" << Trg
.Name() << ">" << endl
;
572 cout
<< D
.DepType() << ": " << Trg
.Name() << endl
;
575 Colours
[D
.TargetPkg()->ID
]++;
579 // Display all solutions
580 SPtrArray
<pkgCache::Version
*> List
= D
.AllTargets();
581 pkgPrioSortList(Cache
,List
);
582 for (pkgCache::Version
**I
= List
; *I
!= 0; I
++)
584 pkgCache::VerIterator
V(Cache
,*I
);
585 if (V
!= Cache
.VerP
+ V
.ParentPkg()->VersionList
||
586 V
->ParentPkg
== D
->Package
)
588 cout
<< " " << V
.ParentPkg().Name() << endl
;
591 Colours
[D
.ParentPkg()->ID
]++;
596 while (DidSomething
== true);
601 // RDepends - Print out a reverse dependency tree - mbc /*{{{*/
602 // ---------------------------------------------------------------------
604 bool RDepends(CommandLine
&CmdL
)
606 pkgCache
&Cache
= *GCache
;
607 SPtrArray
<unsigned> Colours
= new unsigned[Cache
.Head().PackageCount
];
608 memset(Colours
,0,sizeof(*Colours
)*Cache
.Head().PackageCount
);
610 for (const char **I
= CmdL
.FileList
+ 1; *I
!= 0; I
++)
612 pkgCache::PkgIterator Pkg
= Cache
.FindPkg(*I
);
613 if (Pkg
.end() == true)
615 _error
->Warning(_("Unable to locate package %s"),*I
);
618 Colours
[Pkg
->ID
] = 1;
621 bool Recurse
= _config
->FindB("APT::Cache::RecurseDepends",false);
622 bool Installed
= _config
->FindB("APT::Cache::Installed",false);
626 DidSomething
= false;
627 for (pkgCache::PkgIterator Pkg
= Cache
.PkgBegin(); Pkg
.end() == false; Pkg
++)
629 if (Colours
[Pkg
->ID
] != 1)
631 Colours
[Pkg
->ID
] = 2;
634 pkgCache::VerIterator Ver
= Pkg
.VersionList();
635 if (Ver
.end() == true)
637 cout
<< '<' << Pkg
.Name() << '>' << endl
;
641 cout
<< Pkg
.Name() << endl
;
643 cout
<< "Reverse Depends:" << endl
;
644 for (pkgCache::DepIterator D
= Pkg
.RevDependsList(); D
.end() == false; D
++)
647 pkgCache::PkgIterator Trg
= D
.ParentPkg();
649 if((Installed
&& Trg
->CurrentVer
!= 0) || !Installed
)
652 if ((D
->CompareOp
& pkgCache::Dep::Or
) == pkgCache::Dep::Or
)
657 if (Trg
->VersionList
== 0)
658 cout
<< D
.DepType() << ": <" << Trg
.Name() << ">" << endl
;
660 cout
<< Trg
.Name() << endl
;
663 Colours
[D
.ParentPkg()->ID
]++;
667 // Display all solutions
668 SPtrArray
<pkgCache::Version
*> List
= D
.AllTargets();
669 pkgPrioSortList(Cache
,List
);
670 for (pkgCache::Version
**I
= List
; *I
!= 0; I
++)
672 pkgCache::VerIterator
V(Cache
,*I
);
673 if (V
!= Cache
.VerP
+ V
.ParentPkg()->VersionList
||
674 V
->ParentPkg
== D
->Package
)
676 cout
<< " " << V
.ParentPkg().Name() << endl
;
679 Colours
[D
.ParentPkg()->ID
]++;
684 while (DidSomething
== true);
692 // xvcg - Generate a graph for xvcg /*{{{*/
693 // ---------------------------------------------------------------------
694 // Code contributed from Junichi Uekawa <dancer@debian.org> on 20 June 2002.
696 bool XVcg(CommandLine
&CmdL
)
698 pkgCache
&Cache
= *GCache
;
699 bool GivenOnly
= _config
->FindB("APT::Cache::GivenOnly",false);
701 /* Normal packages are boxes
702 Pure Provides are triangles
704 rhomb are missing packages*/
705 const char *Shapes
[] = {"ellipse","triangle","box","rhomb"};
707 /* Initialize the list of packages to show.
709 2 = To Show no recurse
710 3 = Emitted no recurse
713 enum States
{None
=0, ToShow
, ToShowNR
, DoneNR
, Done
};
714 enum TheFlags
{ForceNR
=(1<<0)};
715 unsigned char *Show
= new unsigned char[Cache
.Head().PackageCount
];
716 unsigned char *Flags
= new unsigned char[Cache
.Head().PackageCount
];
717 unsigned char *ShapeMap
= new unsigned char[Cache
.Head().PackageCount
];
719 // Show everything if no arguments given
720 if (CmdL
.FileList
[1] == 0)
721 for (unsigned long I
= 0; I
!= Cache
.Head().PackageCount
; I
++)
724 for (unsigned long I
= 0; I
!= Cache
.Head().PackageCount
; I
++)
726 memset(Flags
,0,sizeof(*Flags
)*Cache
.Head().PackageCount
);
729 for (pkgCache::PkgIterator Pkg
= Cache
.PkgBegin(); Pkg
.end() == false; Pkg
++)
731 if (Pkg
->VersionList
== 0)
734 if (Pkg
->ProvidesList
== 0)
735 ShapeMap
[Pkg
->ID
] = 0;
737 ShapeMap
[Pkg
->ID
] = 1;
742 if (Pkg
->ProvidesList
== 0)
743 ShapeMap
[Pkg
->ID
] = 2;
745 ShapeMap
[Pkg
->ID
] = 3;
749 // Load the list of packages from the command line into the show list
750 for (const char **I
= CmdL
.FileList
+ 1; *I
!= 0; I
++)
752 // Process per-package flags
757 if (P
.end()[-1] == '^')
763 if (P
.end()[-1] == ',')
767 // Locate the package
768 pkgCache::PkgIterator Pkg
= Cache
.FindPkg(P
);
769 if (Pkg
.end() == true)
771 _error
->Warning(_("Unable to locate package %s"),*I
);
774 Show
[Pkg
->ID
] = ToShow
;
777 Flags
[Pkg
->ID
] |= ForceNR
;
781 cout
<< "graph: { title: \"packages\"" << endl
<<
782 "xmax: 700 ymax: 700 x: 30 y: 30" << endl
<<
783 "layout_downfactor: 8" << endl
;
789 for (pkgCache::PkgIterator Pkg
= Cache
.PkgBegin(); Pkg
.end() == false; Pkg
++)
791 // See we need to show this package
792 if (Show
[Pkg
->ID
] == None
|| Show
[Pkg
->ID
] >= DoneNR
)
795 //printf ("node: { title: \"%s\" label: \"%s\" }\n", Pkg.Name(), Pkg.Name());
798 if (Show
[Pkg
->ID
] == ToShowNR
|| (Flags
[Pkg
->ID
] & ForceNR
) == ForceNR
)
800 // Pure Provides and missing packages have no deps!
801 if (ShapeMap
[Pkg
->ID
] == 0 || ShapeMap
[Pkg
->ID
] == 1)
802 Show
[Pkg
->ID
] = Done
;
804 Show
[Pkg
->ID
] = DoneNR
;
807 Show
[Pkg
->ID
] = Done
;
810 // No deps to map out
811 if (Pkg
->VersionList
== 0 || Show
[Pkg
->ID
] == DoneNR
)
814 pkgCache::VerIterator Ver
= Pkg
.VersionList();
815 for (pkgCache::DepIterator D
= Ver
.DependsList(); D
.end() == false; D
++)
817 // See if anything can meet this dep
818 // Walk along the actual package providing versions
820 pkgCache::PkgIterator DPkg
= D
.TargetPkg();
821 for (pkgCache::VerIterator I
= DPkg
.VersionList();
822 I
.end() == false && Hit
== false; I
++)
824 if (Cache
.VS
->CheckDep(I
.VerStr(),D
->CompareOp
,D
.TargetVer()) == true)
828 // Follow all provides
829 for (pkgCache::PrvIterator I
= DPkg
.ProvidesList();
830 I
.end() == false && Hit
== false; I
++)
832 if (Cache
.VS
->CheckDep(I
.ProvideVersion(),D
->CompareOp
,D
.TargetVer()) == false)
837 // Only graph critical deps
838 if (D
.IsCritical() == true)
840 printf ("edge: { sourcename: \"%s\" targetname: \"%s\" class: 2 ",Pkg
.Name(), D
.TargetPkg().Name() );
842 // Colour the node for recursion
843 if (Show
[D
.TargetPkg()->ID
] <= DoneNR
)
845 /* If a conflicts does not meet anything in the database
846 then show the relation but do not recurse */
848 (D
->Type
== pkgCache::Dep::Conflicts
||
849 D
->Type
== pkgCache::Dep::Obsoletes
))
851 if (Show
[D
.TargetPkg()->ID
] == None
&&
852 Show
[D
.TargetPkg()->ID
] != ToShow
)
853 Show
[D
.TargetPkg()->ID
] = ToShowNR
;
857 if (GivenOnly
== true && Show
[D
.TargetPkg()->ID
] != ToShow
)
858 Show
[D
.TargetPkg()->ID
] = ToShowNR
;
860 Show
[D
.TargetPkg()->ID
] = ToShow
;
867 case pkgCache::Dep::Conflicts
:
868 printf("label: \"conflicts\" color: lightgreen }\n");
870 case pkgCache::Dep::Obsoletes
:
871 printf("label: \"obsoletes\" color: lightgreen }\n");
874 case pkgCache::Dep::PreDepends
:
875 printf("label: \"predepends\" color: blue }\n");
887 /* Draw the box colours after the fact since we can not tell what colour
888 they should be until everything is finished drawing */
889 for (pkgCache::PkgIterator Pkg
= Cache
.PkgBegin(); Pkg
.end() == false; Pkg
++)
891 if (Show
[Pkg
->ID
] < DoneNR
)
894 if (Show
[Pkg
->ID
] == DoneNR
)
895 printf("node: { title: \"%s\" label: \"%s\" color: orange shape: %s }\n", Pkg
.Name(), Pkg
.Name(),
896 Shapes
[ShapeMap
[Pkg
->ID
]]);
898 printf("node: { title: \"%s\" label: \"%s\" shape: %s }\n", Pkg
.Name(), Pkg
.Name(),
899 Shapes
[ShapeMap
[Pkg
->ID
]]);
909 // Dotty - Generate a graph for Dotty /*{{{*/
910 // ---------------------------------------------------------------------
911 /* Dotty is the graphvis program for generating graphs. It is a fairly
912 simple queuing algorithm that just writes dependencies and nodes.
913 http://www.research.att.com/sw/tools/graphviz/ */
914 bool Dotty(CommandLine
&CmdL
)
916 pkgCache
&Cache
= *GCache
;
917 bool GivenOnly
= _config
->FindB("APT::Cache::GivenOnly",false);
919 /* Normal packages are boxes
920 Pure Provides are triangles
922 Hexagons are missing packages*/
923 const char *Shapes
[] = {"hexagon","triangle","box","diamond"};
925 /* Initialize the list of packages to show.
927 2 = To Show no recurse
928 3 = Emitted no recurse
931 enum States
{None
=0, ToShow
, ToShowNR
, DoneNR
, Done
};
932 enum TheFlags
{ForceNR
=(1<<0)};
933 unsigned char *Show
= new unsigned char[Cache
.Head().PackageCount
];
934 unsigned char *Flags
= new unsigned char[Cache
.Head().PackageCount
];
935 unsigned char *ShapeMap
= new unsigned char[Cache
.Head().PackageCount
];
937 // Show everything if no arguments given
938 if (CmdL
.FileList
[1] == 0)
939 for (unsigned long I
= 0; I
!= Cache
.Head().PackageCount
; I
++)
942 for (unsigned long I
= 0; I
!= Cache
.Head().PackageCount
; I
++)
944 memset(Flags
,0,sizeof(*Flags
)*Cache
.Head().PackageCount
);
947 for (pkgCache::PkgIterator Pkg
= Cache
.PkgBegin(); Pkg
.end() == false; Pkg
++)
949 if (Pkg
->VersionList
== 0)
952 if (Pkg
->ProvidesList
== 0)
953 ShapeMap
[Pkg
->ID
] = 0;
955 ShapeMap
[Pkg
->ID
] = 1;
960 if (Pkg
->ProvidesList
== 0)
961 ShapeMap
[Pkg
->ID
] = 2;
963 ShapeMap
[Pkg
->ID
] = 3;
967 // Load the list of packages from the command line into the show list
968 for (const char **I
= CmdL
.FileList
+ 1; *I
!= 0; I
++)
970 // Process per-package flags
975 if (P
.end()[-1] == '^')
981 if (P
.end()[-1] == ',')
985 // Locate the package
986 pkgCache::PkgIterator Pkg
= Cache
.FindPkg(P
);
987 if (Pkg
.end() == true)
989 _error
->Warning(_("Unable to locate package %s"),*I
);
992 Show
[Pkg
->ID
] = ToShow
;
995 Flags
[Pkg
->ID
] |= ForceNR
;
999 printf("digraph packages {\n");
1000 printf("concentrate=true;\n");
1001 printf("size=\"30,40\";\n");
1007 for (pkgCache::PkgIterator Pkg
= Cache
.PkgBegin(); Pkg
.end() == false; Pkg
++)
1009 // See we need to show this package
1010 if (Show
[Pkg
->ID
] == None
|| Show
[Pkg
->ID
] >= DoneNR
)
1014 if (Show
[Pkg
->ID
] == ToShowNR
|| (Flags
[Pkg
->ID
] & ForceNR
) == ForceNR
)
1016 // Pure Provides and missing packages have no deps!
1017 if (ShapeMap
[Pkg
->ID
] == 0 || ShapeMap
[Pkg
->ID
] == 1)
1018 Show
[Pkg
->ID
] = Done
;
1020 Show
[Pkg
->ID
] = DoneNR
;
1023 Show
[Pkg
->ID
] = Done
;
1026 // No deps to map out
1027 if (Pkg
->VersionList
== 0 || Show
[Pkg
->ID
] == DoneNR
)
1030 pkgCache::VerIterator Ver
= Pkg
.VersionList();
1031 for (pkgCache::DepIterator D
= Ver
.DependsList(); D
.end() == false; D
++)
1033 // See if anything can meet this dep
1034 // Walk along the actual package providing versions
1036 pkgCache::PkgIterator DPkg
= D
.TargetPkg();
1037 for (pkgCache::VerIterator I
= DPkg
.VersionList();
1038 I
.end() == false && Hit
== false; I
++)
1040 if (Cache
.VS
->CheckDep(I
.VerStr(),D
->CompareOp
,D
.TargetVer()) == true)
1044 // Follow all provides
1045 for (pkgCache::PrvIterator I
= DPkg
.ProvidesList();
1046 I
.end() == false && Hit
== false; I
++)
1048 if (Cache
.VS
->CheckDep(I
.ProvideVersion(),D
->CompareOp
,D
.TargetVer()) == false)
1052 // Only graph critical deps
1053 if (D
.IsCritical() == true)
1055 printf("\"%s\" -> \"%s\"",Pkg
.Name(),D
.TargetPkg().Name());
1057 // Colour the node for recursion
1058 if (Show
[D
.TargetPkg()->ID
] <= DoneNR
)
1060 /* If a conflicts does not meet anything in the database
1061 then show the relation but do not recurse */
1063 (D
->Type
== pkgCache::Dep::Conflicts
||
1064 D
->Type
== pkgCache::Dep::Obsoletes
))
1066 if (Show
[D
.TargetPkg()->ID
] == None
&&
1067 Show
[D
.TargetPkg()->ID
] != ToShow
)
1068 Show
[D
.TargetPkg()->ID
] = ToShowNR
;
1072 if (GivenOnly
== true && Show
[D
.TargetPkg()->ID
] != ToShow
)
1073 Show
[D
.TargetPkg()->ID
] = ToShowNR
;
1075 Show
[D
.TargetPkg()->ID
] = ToShow
;
1082 case pkgCache::Dep::Conflicts
:
1083 case pkgCache::Dep::Obsoletes
:
1084 printf("[color=springgreen];\n");
1087 case pkgCache::Dep::PreDepends
:
1088 printf("[color=blue];\n");
1100 /* Draw the box colours after the fact since we can not tell what colour
1101 they should be until everything is finished drawing */
1102 for (pkgCache::PkgIterator Pkg
= Cache
.PkgBegin(); Pkg
.end() == false; Pkg
++)
1104 if (Show
[Pkg
->ID
] < DoneNR
)
1107 // Orange box for early recursion stoppage
1108 if (Show
[Pkg
->ID
] == DoneNR
)
1109 printf("\"%s\" [color=orange,shape=%s];\n",Pkg
.Name(),
1110 Shapes
[ShapeMap
[Pkg
->ID
]]);
1112 printf("\"%s\" [shape=%s];\n",Pkg
.Name(),
1113 Shapes
[ShapeMap
[Pkg
->ID
]]);
1120 // DoAdd - Perform an adding operation /*{{{*/
1121 // ---------------------------------------------------------------------
1123 bool DoAdd(CommandLine
&CmdL
)
1125 return _error
->Error("Unimplemented");
1127 // Make sure there is at least one argument
1128 if (CmdL
.FileSize() <= 1)
1129 return _error
->Error("You must give at least one file name");
1132 FileFd
CacheF(_config
->FindFile("Dir::Cache::pkgcache"),FileFd::WriteAny
);
1133 if (_error
->PendingError() == true)
1136 DynamicMMap
Map(CacheF
,MMap::Public
);
1137 if (_error
->PendingError() == true)
1140 OpTextProgress
Progress(*_config
);
1141 pkgCacheGenerator
Gen(Map
,Progress
);
1142 if (_error
->PendingError() == true)
1145 unsigned long Length
= CmdL
.FileSize() - 1;
1146 for (const char **I
= CmdL
.FileList
+ 1; *I
!= 0; I
++)
1148 Progress
.OverallProgress(I
- CmdL
.FileList
,Length
,1,"Generating cache");
1149 Progress
.SubProgress(Length
);
1152 FileFd
TagF(*I
,FileFd::ReadOnly
);
1153 debListParser
Parser(TagF
);
1154 if (_error
->PendingError() == true)
1155 return _error
->Error("Problem opening %s",*I
);
1157 if (Gen
.SelectFile(*I
,"") == false)
1158 return _error
->Error("Problem with SelectFile");
1160 if (Gen
.MergeList(Parser
) == false)
1161 return _error
->Error("Problem with MergeList");
1165 GCache
= &Gen
.GetCache();
1172 // DisplayRecord - Displays the complete record for the package /*{{{*/
1173 // ---------------------------------------------------------------------
1174 /* This displays the package record from the proper package index file.
1175 It is not used by DumpAvail for performance reasons. */
1176 bool DisplayRecord(pkgCache::VerIterator V
)
1178 // Find an appropriate file
1179 pkgCache::VerFileIterator Vf
= V
.FileList();
1180 for (; Vf
.end() == false; Vf
++)
1181 if ((Vf
.File()->Flags
& pkgCache::Flag::NotSource
) == 0)
1183 if (Vf
.end() == true)
1186 // Check and load the package list file
1187 pkgCache::PkgFileIterator I
= Vf
.File();
1188 if (I
.IsOk() == false)
1189 return _error
->Error(_("Package file %s is out of sync."),I
.FileName());
1191 FileFd
PkgF(I
.FileName(),FileFd::ReadOnly
);
1192 if (_error
->PendingError() == true)
1195 // Read the record and then write it out again.
1196 unsigned char *Buffer
= new unsigned char[GCache
->HeaderP
->MaxVerFileSize
+1];
1197 Buffer
[V
.FileList()->Size
] = '\n';
1198 if (PkgF
.Seek(V
.FileList()->Offset
) == false ||
1199 PkgF
.Read(Buffer
,V
.FileList()->Size
) == false ||
1200 fwrite(Buffer
,1,V
.FileList()->Size
+1,stdout
) < (size_t)(V
.FileList()->Size
+1))
1211 // Search - Perform a search /*{{{*/
1212 // ---------------------------------------------------------------------
1213 /* This searches the package names and pacakge descriptions for a pattern */
1216 pkgCache::VerFile
*Vf
;
1220 bool Search(CommandLine
&CmdL
)
1222 pkgCache
&Cache
= *GCache
;
1223 bool ShowFull
= _config
->FindB("APT::Cache::ShowFull",false);
1224 bool NamesOnly
= _config
->FindB("APT::Cache::NamesOnly",false);
1225 unsigned NumPatterns
= CmdL
.FileSize() -1;
1227 pkgDepCache::Policy Plcy
;
1229 // Make sure there is at least one argument
1230 if (NumPatterns
< 1)
1231 return _error
->Error(_("You must give exactly one pattern"));
1233 // Compile the regex pattern
1234 regex_t
*Patterns
= new regex_t
[NumPatterns
];
1235 memset(Patterns
,0,sizeof(*Patterns
)*NumPatterns
);
1236 for (unsigned I
= 0; I
!= NumPatterns
; I
++)
1238 if (regcomp(&Patterns
[I
],CmdL
.FileList
[I
+1],REG_EXTENDED
| REG_ICASE
|
1242 regfree(&Patterns
[I
]);
1243 return _error
->Error("Regex compilation error");
1247 // Create the text record parser
1248 pkgRecords
Recs(Cache
);
1249 if (_error
->PendingError() == true)
1251 for (unsigned I
= 0; I
!= NumPatterns
; I
++)
1252 regfree(&Patterns
[I
]);
1256 ExVerFile
*VFList
= new ExVerFile
[Cache
.HeaderP
->PackageCount
+1];
1257 memset(VFList
,0,sizeof(*VFList
)*Cache
.HeaderP
->PackageCount
+1);
1259 // Map versions that we want to write out onto the VerList array.
1260 for (pkgCache::PkgIterator P
= Cache
.PkgBegin(); P
.end() == false; P
++)
1262 VFList
[P
->ID
].NameMatch
= NumPatterns
!= 0;
1263 for (unsigned I
= 0; I
!= NumPatterns
; I
++)
1265 if (regexec(&Patterns
[I
],P
.Name(),0,0,0) == 0)
1266 VFList
[P
->ID
].NameMatch
&= true;
1268 VFList
[P
->ID
].NameMatch
= false;
1271 // Doing names only, drop any that dont match..
1272 if (NamesOnly
== true && VFList
[P
->ID
].NameMatch
== false)
1275 // Find the proper version to use.
1276 pkgCache::VerIterator V
= Plcy
.GetCandidateVer(P
);
1277 if (V
.end() == false)
1278 VFList
[P
->ID
].Vf
= V
.FileList();
1281 // Include all the packages that provide matching names too
1282 for (pkgCache::PkgIterator P
= Cache
.PkgBegin(); P
.end() == false; P
++)
1284 if (VFList
[P
->ID
].NameMatch
== false)
1287 for (pkgCache::PrvIterator Prv
= P
.ProvidesList() ; Prv
.end() == false; Prv
++)
1289 pkgCache::VerIterator V
= Plcy
.GetCandidateVer(Prv
.OwnerPkg());
1290 if (V
.end() == false)
1292 VFList
[Prv
.OwnerPkg()->ID
].Vf
= V
.FileList();
1293 VFList
[Prv
.OwnerPkg()->ID
].NameMatch
= true;
1298 LocalitySort(&VFList
->Vf
,Cache
.HeaderP
->PackageCount
,sizeof(*VFList
));
1300 // Iterate over all the version records and check them
1301 for (ExVerFile
*J
= VFList
; J
->Vf
!= 0; J
++)
1303 pkgRecords::Parser
&P
= Recs
.Lookup(pkgCache::VerFileIterator(Cache
,J
->Vf
));
1306 if (J
->NameMatch
== false)
1308 string LongDesc
= P
.LongDesc();
1309 Match
= NumPatterns
!= 0;
1310 for (unsigned I
= 0; I
!= NumPatterns
; I
++)
1312 if (regexec(&Patterns
[I
],LongDesc
.c_str(),0,0,0) == 0)
1321 if (ShowFull
== true)
1325 P
.GetRec(Start
,End
);
1326 fwrite(Start
,End
-Start
,1,stdout
);
1330 printf("%s - %s\n",P
.Name().c_str(),P
.ShortDesc().c_str());
1335 for (unsigned I
= 0; I
!= NumPatterns
; I
++)
1336 regfree(&Patterns
[I
]);
1338 return _error
->Error("Write to stdout failed");
1342 // ShowPackage - Dump the package record to the screen /*{{{*/
1343 // ---------------------------------------------------------------------
1345 bool ShowPackage(CommandLine
&CmdL
)
1347 pkgCache
&Cache
= *GCache
;
1348 pkgDepCache::Policy Plcy
;
1352 for (const char **I
= CmdL
.FileList
+ 1; *I
!= 0; I
++)
1354 pkgCache::PkgIterator Pkg
= Cache
.FindPkg(*I
);
1355 if (Pkg
.end() == true)
1357 _error
->Warning(_("Unable to locate package %s"),*I
);
1363 // Find the proper version to use.
1364 if (_config
->FindB("APT::Cache::AllVersions","true") == true)
1366 pkgCache::VerIterator V
;
1367 for (V
= Pkg
.VersionList(); V
.end() == false; V
++)
1369 if (DisplayRecord(V
) == false)
1375 pkgCache::VerIterator V
= Plcy
.GetCandidateVer(Pkg
);
1376 if (V
.end() == true || V
.FileList().end() == true)
1378 if (DisplayRecord(V
) == false)
1385 return _error
->Error(_("No packages found"));
1388 // ShowPkgNames - Show package names /*{{{*/
1389 // ---------------------------------------------------------------------
1390 /* This does a prefix match on the first argument */
1391 bool ShowPkgNames(CommandLine
&CmdL
)
1393 pkgCache
&Cache
= *GCache
;
1394 pkgCache::PkgIterator I
= Cache
.PkgBegin();
1395 bool All
= _config
->FindB("APT::Cache::AllNames","false");
1397 if (CmdL
.FileList
[1] != 0)
1399 for (;I
.end() != true; I
++)
1401 if (All
== false && I
->VersionList
== 0)
1404 if (strncmp(I
.Name(),CmdL
.FileList
[1],strlen(CmdL
.FileList
[1])) == 0)
1405 cout
<< I
.Name() << endl
;
1412 for (;I
.end() != true; I
++)
1414 if (All
== false && I
->VersionList
== 0)
1416 cout
<< I
.Name() << endl
;
1422 // ShowSrcPackage - Show source package records /*{{{*/
1423 // ---------------------------------------------------------------------
1425 bool ShowSrcPackage(CommandLine
&CmdL
)
1428 List
.ReadMainList();
1430 // Create the text record parsers
1431 pkgSrcRecords
SrcRecs(List
);
1432 if (_error
->PendingError() == true)
1435 for (const char **I
= CmdL
.FileList
+ 1; *I
!= 0; I
++)
1439 pkgSrcRecords::Parser
*Parse
;
1440 while ((Parse
= SrcRecs
.Find(*I
,false)) != 0)
1441 cout
<< Parse
->AsStr() << endl
;;
1446 // Policy - Show the results of the preferences file /*{{{*/
1447 // ---------------------------------------------------------------------
1449 bool Policy(CommandLine
&CmdL
)
1452 return _error
->Error("Generate must be enabled for this function");
1454 pkgCache
&Cache
= *GCache
;
1455 pkgPolicy
Plcy(&Cache
);
1456 if (ReadPinFile(Plcy
) == false)
1459 // Print out all of the package files
1460 if (CmdL
.FileList
[1] == 0)
1462 cout
<< _("Package files:") << endl
;
1463 for (pkgCache::PkgFileIterator F
= Cache
.FileBegin(); F
.end() == false; F
++)
1465 // Locate the associated index files so we can derive a description
1467 if (SrcList
->FindIndex(F
,Indx
) == false &&
1468 _system
->FindIndex(F
,Indx
) == false)
1469 return _error
->Error(_("Cache is out of sync, can't x-ref a package file"));
1470 printf(_("%4i %s\n"),
1471 Plcy
.GetPriority(F
),Indx
->Describe(true).c_str());
1473 // Print the reference information for the package
1474 string Str
= F
.RelStr();
1475 if (Str
.empty() == false)
1476 printf(" release %s\n",F
.RelStr().c_str());
1477 if (F
.Site() != 0 && F
.Site()[0] != 0)
1478 printf(" origin %s\n",F
.Site());
1481 // Show any packages have explicit pins
1482 cout
<< _("Pinned packages:") << endl
;
1483 pkgCache::PkgIterator I
= Cache
.PkgBegin();
1484 for (;I
.end() != true; I
++)
1486 if (Plcy
.GetPriority(I
) == 0)
1489 // Print the package name and the version we are forcing to
1490 cout
<< " " << I
.Name() << " -> ";
1492 pkgCache::VerIterator V
= Plcy
.GetMatch(I
);
1493 if (V
.end() == true)
1494 cout
<< _("(not found)") << endl
;
1496 cout
<< V
.VerStr() << endl
;
1502 // Print out detailed information for each package
1503 for (const char **I
= CmdL
.FileList
+ 1; *I
!= 0; I
++)
1505 pkgCache::PkgIterator Pkg
= Cache
.FindPkg(*I
);
1506 if (Pkg
.end() == true)
1508 _error
->Warning(_("Unable to locate package %s"),*I
);
1512 cout
<< Pkg
.Name() << ":" << endl
;
1514 // Installed version
1515 cout
<< _(" Installed: ");
1516 if (Pkg
->CurrentVer
== 0)
1517 cout
<< _("(none)") << endl
;
1519 cout
<< Pkg
.CurrentVer().VerStr() << endl
;
1521 // Candidate Version
1522 cout
<< _(" Candidate: ");
1523 pkgCache::VerIterator V
= Plcy
.GetCandidateVer(Pkg
);
1524 if (V
.end() == true)
1525 cout
<< _("(none)") << endl
;
1527 cout
<< V
.VerStr() << endl
;
1530 if (Plcy
.GetPriority(Pkg
) != 0)
1532 cout
<< _(" Package pin: ");
1533 V
= Plcy
.GetMatch(Pkg
);
1534 if (V
.end() == true)
1535 cout
<< _("(not found)") << endl
;
1537 cout
<< V
.VerStr() << endl
;
1540 // Show the priority tables
1541 cout
<< _(" Version table:") << endl
;
1542 for (V
= Pkg
.VersionList(); V
.end() == false; V
++)
1544 if (Pkg
.CurrentVer() == V
)
1545 cout
<< " *** " << V
.VerStr();
1547 cout
<< " " << V
.VerStr();
1548 cout
<< " " << Plcy
.GetPriority(Pkg
) << endl
;
1549 for (pkgCache::VerFileIterator VF
= V
.FileList(); VF
.end() == false; VF
++)
1551 // Locate the associated index files so we can derive a description
1553 if (SrcList
->FindIndex(VF
.File(),Indx
) == false &&
1554 _system
->FindIndex(VF
.File(),Indx
) == false)
1555 return _error
->Error(_("Cache is out of sync, can't x-ref a package file"));
1556 printf(_(" %4i %s\n"),Plcy
.GetPriority(VF
.File()),
1557 Indx
->Describe(true).c_str());
1565 // Madison - Look a bit like katie's madison /*{{{*/
1566 // ---------------------------------------------------------------------
1568 bool Madison(CommandLine
&CmdL
)
1571 return _error
->Error("Generate must be enabled for this function");
1573 SrcList
->ReadMainList();
1575 pkgCache
&Cache
= *GCache
;
1577 // Create the src text record parsers and ignore errors about missing
1578 // deb-src lines that are generated from pkgSrcRecords::pkgSrcRecords
1579 pkgSrcRecords
SrcRecs(*SrcList
);
1580 if (_error
->PendingError() == true)
1583 for (const char **I
= CmdL
.FileList
+ 1; *I
!= 0; I
++)
1585 pkgCache::PkgIterator Pkg
= Cache
.FindPkg(*I
);
1587 if (Pkg
.end() == false)
1589 for (pkgCache::VerIterator V
= Pkg
.VersionList(); V
.end() == false; V
++)
1591 for (pkgCache::VerFileIterator VF
= V
.FileList(); VF
.end() == false; VF
++)
1593 // This might be nice, but wouldn't uniquely identify the source -mdz
1594 // if (VF.File().Archive() != 0)
1596 // cout << setw(10) << Pkg.Name() << " | " << setw(10) << V.VerStr() << " | "
1597 // << VF.File().Archive() << endl;
1600 // Locate the associated index files so we can derive a description
1601 for (pkgSourceList::const_iterator S
= SrcList
->begin(); S
!= SrcList
->end(); S
++)
1603 vector
<pkgIndexFile
*> *Indexes
= (*S
)->GetIndexFiles();
1604 for (vector
<pkgIndexFile
*>::const_iterator IF
= Indexes
->begin();
1605 IF
!= Indexes
->end(); IF
++)
1607 if ((*IF
)->FindInCache(*(VF
.File().Cache())) == VF
.File())
1609 cout
<< setw(10) << Pkg
.Name() << " | " << setw(10) << V
.VerStr() << " | "
1610 << (*IF
)->Describe(true) << endl
;
1620 pkgSrcRecords::Parser
*SrcParser
;
1621 while ((SrcParser
= SrcRecs
.Find(*I
,false)) != 0)
1623 // Maybe support Release info here too eventually
1624 cout
<< setw(10) << SrcParser
->Package() << " | "
1625 << setw(10) << SrcParser
->Version() << " | "
1626 << SrcParser
->Index().Describe(true) << endl
;
1634 // GenCaches - Call the main cache generator /*{{{*/
1635 // ---------------------------------------------------------------------
1637 bool GenCaches(CommandLine
&Cmd
)
1639 OpTextProgress
Progress(*_config
);
1642 if (List
.ReadMainList() == false)
1644 return pkgMakeStatusCache(List
,Progress
);
1647 // ShowHelp - Show a help screen /*{{{*/
1648 // ---------------------------------------------------------------------
1650 bool ShowHelp(CommandLine
&Cmd
)
1652 ioprintf(cout
,_("%s %s for %s %s compiled on %s %s\n"),PACKAGE
,VERSION
,
1653 COMMON_OS
,COMMON_CPU
,__DATE__
,__TIME__
);
1655 if (_config
->FindB("version") == true)
1659 _("Usage: apt-cache [options] command\n"
1660 " apt-cache [options] add file1 [file2 ...]\n"
1661 " apt-cache [options] showpkg pkg1 [pkg2 ...]\n"
1662 " apt-cache [options] showsrc pkg1 [pkg2 ...]\n"
1664 "apt-cache is a low-level tool used to manipulate APT's binary\n"
1665 "cache files, and query information from them\n"
1668 " add - Add a package file to the source cache\n"
1669 " gencaches - Build both the package and source cache\n"
1670 " showpkg - Show some general information for a single package\n"
1671 " showsrc - Show source records\n"
1672 " stats - Show some basic statistics\n"
1673 " dump - Show the entire file in a terse form\n"
1674 " dumpavail - Print an available file to stdout\n"
1675 " unmet - Show unmet dependencies\n"
1676 " search - Search the package list for a regex pattern\n"
1677 " show - Show a readable record for the package\n"
1678 " depends - Show raw dependency information for a package\n"
1679 " rdepends - Show reverse dependency information for a package\n"
1680 " pkgnames - List the names of all packages\n"
1681 " dotty - Generate package graphs for GraphVis\n"
1682 " xvcg - Generate package graphs for xvcg\n"
1683 " policy - Show policy settings\n"
1686 " -h This help text.\n"
1687 " -p=? The package cache.\n"
1688 " -s=? The source cache.\n"
1689 " -q Disable progress indicator.\n"
1690 " -i Show only important deps for the unmet command.\n"
1691 " -c=? Read this configuration file\n"
1692 " -o=? Set an arbitrary configuration option, eg -o dir::cache=/tmp\n"
1693 "See the apt-cache(8) and apt.conf(5) manual pages for more information.\n");
1697 // CacheInitialize - Initialize things for apt-cache /*{{{*/
1698 // ---------------------------------------------------------------------
1700 void CacheInitialize()
1702 _config
->Set("quiet",0);
1703 _config
->Set("help",false);
1707 int main(int argc
,const char *argv
[])
1709 CommandLine::Args Args
[] = {
1710 {'h',"help","help",0},
1711 {'v',"version","version",0},
1712 {'p',"pkg-cache","Dir::Cache::pkgcache",CommandLine::HasArg
},
1713 {'s',"src-cache","Dir::Cache::srcpkgcache",CommandLine::HasArg
},
1714 {'q',"quiet","quiet",CommandLine::IntLevel
},
1715 {'i',"important","APT::Cache::Important",0},
1716 {'f',"full","APT::Cache::ShowFull",0},
1717 {'g',"generate","APT::Cache::Generate",0},
1718 {'a',"all-versions","APT::Cache::AllVersions",0},
1719 {'n',"names-only","APT::Cache::NamesOnly",0},
1720 {0,"all-names","APT::Cache::AllNames",0},
1721 {0,"recurse","APT::Cache::RecurseDepends",0},
1722 {'c',"config-file",0,CommandLine::ConfigFile
},
1723 {'o',"option",0,CommandLine::ArbItem
},
1724 {0,"installed","APT::Cache::Installed",0},
1726 CommandLine::Dispatch CmdsA
[] = {{"help",&ShowHelp
},
1728 {"gencaches",&GenCaches
},
1729 {"showsrc",&ShowSrcPackage
},
1731 CommandLine::Dispatch CmdsB
[] = {{"showpkg",&DumpPackage
},
1734 {"dumpavail",&DumpAvail
},
1737 {"depends",&Depends
},
1738 {"rdepends",&RDepends
},
1741 {"show",&ShowPackage
},
1742 {"pkgnames",&ShowPkgNames
},
1744 {"madison",&Madison
},
1749 // Set up gettext support
1750 setlocale(LC_ALL
,"");
1751 textdomain(PACKAGE
);
1753 // Parse the command line and initialize the package library
1754 CommandLine
CmdL(Args
,_config
);
1755 if (pkgInitConfig(*_config
) == false ||
1756 CmdL
.Parse(argc
,argv
) == false ||
1757 pkgInitSystem(*_config
,_system
) == false)
1759 _error
->DumpErrors();
1763 // See if the help should be shown
1764 if (_config
->FindB("help") == true ||
1765 CmdL
.FileSize() == 0)
1771 // Deal with stdout not being a tty
1772 if (isatty(STDOUT_FILENO
) && _config
->FindI("quiet",0) < 1)
1773 _config
->Set("quiet","1");
1775 if (CmdL
.DispatchArg(CmdsA
,false) == false && _error
->PendingError() == false)
1778 if (_config
->FindB("APT::Cache::Generate",true) == false)
1780 Map
= new MMap(*new FileFd(_config
->FindFile("Dir::Cache::pkgcache"),
1781 FileFd::ReadOnly
),MMap::Public
|MMap::ReadOnly
);
1785 // Open the cache file
1786 SrcList
= new pkgSourceList
;
1787 SrcList
->ReadMainList();
1789 // Generate it and map it
1791 pkgMakeStatusCache(*SrcList
,Prog
,&Map
,true);
1794 if (_error
->PendingError() == false)
1796 pkgCache
Cache(Map
);
1798 if (_error
->PendingError() == false)
1799 CmdL
.DispatchArg(CmdsB
);
1804 // Print any errors or warnings found during parsing
1805 if (_error
->empty() == false)
1807 bool Errors
= _error
->PendingError();
1808 _error
->DumpErrors();
1809 return Errors
== true?100:0;