]>
git.saurik.com Git - apt.git/blob - cmdline/apt-cache.cc
1 // -*- mode: cpp; mode: fold -*-
3 // $Id: apt-cache.cc,v 1.64 2003/05/15 09:39:38 piefel 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>
45 pkgSourceList
*SrcList
= 0;
47 // LocalitySort - Sort a version list by package file locality /*{{{*/
48 // ---------------------------------------------------------------------
50 int LocalityCompare(const void *a
, const void *b
)
52 pkgCache::VerFile
*A
= *(pkgCache::VerFile
**)a
;
53 pkgCache::VerFile
*B
= *(pkgCache::VerFile
**)b
;
62 if (A
->File
== B
->File
)
63 return A
->Offset
- B
->Offset
;
64 return A
->File
- B
->File
;
67 void LocalitySort(pkgCache::VerFile
**begin
,
68 unsigned long Count
,size_t Size
)
70 qsort(begin
,Count
,Size
,LocalityCompare
);
73 // UnMet - Show unmet dependencies /*{{{*/
74 // ---------------------------------------------------------------------
76 bool UnMet(CommandLine
&CmdL
)
78 pkgCache
&Cache
= *GCache
;
79 bool Important
= _config
->FindB("APT::Cache::Important",false);
81 for (pkgCache::PkgIterator P
= Cache
.PkgBegin(); P
.end() == false; P
++)
83 for (pkgCache::VerIterator V
= P
.VersionList(); V
.end() == false; V
++)
86 for (pkgCache::DepIterator D
= V
.DependsList(); D
.end() == false;)
89 pkgCache::DepIterator Start
;
90 pkgCache::DepIterator End
;
93 // Skip conflicts and replaces
94 if (End
->Type
!= pkgCache::Dep::PreDepends
&&
95 End
->Type
!= pkgCache::Dep::Depends
&&
96 End
->Type
!= pkgCache::Dep::Suggests
&&
97 End
->Type
!= pkgCache::Dep::Recommends
)
100 // Important deps only
101 if (Important
== true)
102 if (End
->Type
!= pkgCache::Dep::PreDepends
&&
103 End
->Type
!= pkgCache::Dep::Depends
)
106 // Verify the or group
108 pkgCache::DepIterator RealStart
= Start
;
111 // See if this dep is Ok
112 pkgCache::Version
**VList
= Start
.AllTargets();
133 ioprintf(cout
,_("Package %s version %s has an unmet dep:\n"),
134 P
.Name(),V
.VerStr());
137 // Print out the dep type
138 cout
<< " " << End
.DepType() << ": ";
144 cout
<< Start
.TargetPkg().Name();
145 if (Start
.TargetVer() != 0)
146 cout
<< " (" << Start
.CompType() << " " << Start
.TargetVer() <<
162 // DumpPackage - Show a dump of a package record /*{{{*/
163 // ---------------------------------------------------------------------
165 bool DumpPackage(CommandLine
&CmdL
)
167 pkgCache
&Cache
= *GCache
;
168 for (const char **I
= CmdL
.FileList
+ 1; *I
!= 0; I
++)
170 pkgCache::PkgIterator Pkg
= Cache
.FindPkg(*I
);
171 if (Pkg
.end() == true)
173 _error
->Warning(_("Unable to locate package %s"),*I
);
177 cout
<< "Package: " << Pkg
.Name() << endl
;
178 cout
<< "Versions: " << endl
;
179 for (pkgCache::VerIterator Cur
= Pkg
.VersionList(); Cur
.end() != true; Cur
++)
181 cout
<< Cur
.VerStr();
182 for (pkgCache::VerFileIterator Vf
= Cur
.FileList(); Vf
.end() == false; Vf
++)
183 cout
<< "(" << Vf
.File().FileName() << ")";
189 cout
<< "Reverse Depends: " << endl
;
190 for (pkgCache::DepIterator D
= Pkg
.RevDependsList(); D
.end() != true; D
++)
192 cout
<< " " << D
.ParentPkg().Name() << ',' << D
.TargetPkg().Name();
194 cout
<< ' ' << DeNull(D
.TargetVer()) << endl
;
199 cout
<< "Dependencies: " << endl
;
200 for (pkgCache::VerIterator Cur
= Pkg
.VersionList(); Cur
.end() != true; Cur
++)
202 cout
<< Cur
.VerStr() << " - ";
203 for (pkgCache::DepIterator Dep
= Cur
.DependsList(); Dep
.end() != true; Dep
++)
204 cout
<< Dep
.TargetPkg().Name() << " (" << (int)Dep
->CompareOp
<< " " << DeNull(Dep
.TargetVer()) << ") ";
208 cout
<< "Provides: " << endl
;
209 for (pkgCache::VerIterator Cur
= Pkg
.VersionList(); Cur
.end() != true; Cur
++)
211 cout
<< Cur
.VerStr() << " - ";
212 for (pkgCache::PrvIterator Prv
= Cur
.ProvidesList(); Prv
.end() != true; Prv
++)
213 cout
<< Prv
.ParentPkg().Name() << " ";
216 cout
<< "Reverse Provides: " << endl
;
217 for (pkgCache::PrvIterator Prv
= Pkg
.ProvidesList(); Prv
.end() != true; Prv
++)
218 cout
<< Prv
.OwnerPkg().Name() << " " << Prv
.OwnerVer().VerStr() << endl
;
224 // Stats - Dump some nice statistics /*{{{*/
225 // ---------------------------------------------------------------------
227 bool Stats(CommandLine
&Cmd
)
229 pkgCache
&Cache
= *GCache
;
230 cout
<< _("Total Package Names : ") << Cache
.Head().PackageCount
<< " (" <<
231 SizeToStr(Cache
.Head().PackageCount
*Cache
.Head().PackageSz
) << ')' << endl
;
238 pkgCache::PkgIterator I
= Cache
.PkgBegin();
239 for (;I
.end() != true; I
++)
241 if (I
->VersionList
!= 0 && I
->ProvidesList
== 0)
247 if (I
->VersionList
!= 0 && I
->ProvidesList
!= 0)
253 if (I
->VersionList
== 0 && I
->ProvidesList
!= 0)
256 if (I
.ProvidesList()->NextProvides
== 0)
264 if (I
->VersionList
== 0 && I
->ProvidesList
== 0)
270 cout
<< _(" Normal Packages: ") << Normal
<< endl
;
271 cout
<< _(" Pure Virtual Packages: ") << Virtual
<< endl
;
272 cout
<< _(" Single Virtual Packages: ") << DVirt
<< endl
;
273 cout
<< _(" Mixed Virtual Packages: ") << NVirt
<< endl
;
274 cout
<< _(" Missing: ") << Missing
<< endl
;
276 cout
<< _("Total Distinct Versions: ") << Cache
.Head().VersionCount
<< " (" <<
277 SizeToStr(Cache
.Head().VersionCount
*Cache
.Head().VersionSz
) << ')' << endl
;
278 cout
<< _("Total Dependencies: ") << Cache
.Head().DependsCount
<< " (" <<
279 SizeToStr(Cache
.Head().DependsCount
*Cache
.Head().DependencySz
) << ')' << endl
;
281 cout
<< _("Total Ver/File relations: ") << Cache
.Head().VerFileCount
<< " (" <<
282 SizeToStr(Cache
.Head().VerFileCount
*Cache
.Head().VerFileSz
) << ')' << endl
;
283 cout
<< _("Total Provides Mappings: ") << Cache
.Head().ProvidesCount
<< " (" <<
284 SizeToStr(Cache
.Head().ProvidesCount
*Cache
.Head().ProvidesSz
) << ')' << endl
;
287 unsigned long Size
= 0;
288 unsigned long Count
= 0;
289 for (pkgCache::StringItem
*I
= Cache
.StringItemP
+ Cache
.Head().StringList
;
290 I
!= Cache
.StringItemP
; I
= Cache
.StringItemP
+ I
->NextItem
)
293 Size
+= strlen(Cache
.StrP
+ I
->String
) + 1;
295 cout
<< _("Total Globbed Strings: ") << Count
<< " (" << SizeToStr(Size
) << ')' << endl
;
297 unsigned long DepVerSize
= 0;
298 for (pkgCache::PkgIterator P
= Cache
.PkgBegin(); P
.end() == false; P
++)
300 for (pkgCache::VerIterator V
= P
.VersionList(); V
.end() == false; V
++)
302 for (pkgCache::DepIterator D
= V
.DependsList(); D
.end() == false; D
++)
305 DepVerSize
+= strlen(D
.TargetVer()) + 1;
309 cout
<< _("Total Dependency Version space: ") << SizeToStr(DepVerSize
) << endl
;
311 unsigned long Slack
= 0;
312 for (int I
= 0; I
!= 7; I
++)
313 Slack
+= Cache
.Head().Pools
[I
].ItemSize
*Cache
.Head().Pools
[I
].Count
;
314 cout
<< _("Total Slack space: ") << SizeToStr(Slack
) << endl
;
316 unsigned long Total
= 0;
317 Total
= Slack
+ Size
+ Cache
.Head().DependsCount
*Cache
.Head().DependencySz
+
318 Cache
.Head().VersionCount
*Cache
.Head().VersionSz
+
319 Cache
.Head().PackageCount
*Cache
.Head().PackageSz
+
320 Cache
.Head().VerFileCount
*Cache
.Head().VerFileSz
+
321 Cache
.Head().ProvidesCount
*Cache
.Head().ProvidesSz
;
322 cout
<< _("Total Space Accounted for: ") << SizeToStr(Total
) << endl
;
327 // Dump - show everything /*{{{*/
328 // ---------------------------------------------------------------------
329 /* This is worthless except fer debugging things */
330 bool Dump(CommandLine
&Cmd
)
332 pkgCache
&Cache
= *GCache
;
333 cout
<< "Using Versioning System: " << Cache
.VS
->Label
<< endl
;
335 for (pkgCache::PkgIterator P
= Cache
.PkgBegin(); P
.end() == false; P
++)
337 cout
<< "Package: " << P
.Name() << endl
;
338 for (pkgCache::VerIterator V
= P
.VersionList(); V
.end() == false; V
++)
340 cout
<< " Version: " << V
.VerStr() << endl
;
341 cout
<< " File: " << V
.FileList().File().FileName() << endl
;
342 for (pkgCache::DepIterator D
= V
.DependsList(); D
.end() == false; D
++)
343 cout
<< " Depends: " << D
.TargetPkg().Name() << ' ' <<
344 DeNull(D
.TargetVer()) << endl
;
348 for (pkgCache::PkgFileIterator F
= Cache
.FileBegin(); F
.end() == false; F
++)
350 cout
<< "File: " << F
.FileName() << endl
;
351 cout
<< " Type: " << F
.IndexType() << endl
;
352 cout
<< " Size: " << F
->Size
<< endl
;
353 cout
<< " ID: " << F
->ID
<< endl
;
354 cout
<< " Flags: " << F
->Flags
<< endl
;
355 cout
<< " Time: " << TimeRFC1123(F
->mtime
) << endl
;
356 cout
<< " Archive: " << DeNull(F
.Archive()) << endl
;
357 cout
<< " Component: " << DeNull(F
.Component()) << endl
;
358 cout
<< " Version: " << DeNull(F
.Version()) << endl
;
359 cout
<< " Origin: " << DeNull(F
.Origin()) << endl
;
360 cout
<< " Site: " << DeNull(F
.Site()) << endl
;
361 cout
<< " Label: " << DeNull(F
.Label()) << endl
;
362 cout
<< " Architecture: " << DeNull(F
.Architecture()) << endl
;
368 // DumpAvail - Print out the available list /*{{{*/
369 // ---------------------------------------------------------------------
370 /* This is needed to make dpkg --merge happy.. I spent a bit of time to
371 make this run really fast, perhaps I went a little overboard.. */
372 bool DumpAvail(CommandLine
&Cmd
)
374 pkgCache
&Cache
= *GCache
;
376 pkgPolicy
Plcy(&Cache
);
377 if (ReadPinFile(Plcy
) == false)
380 unsigned long Count
= Cache
.HeaderP
->PackageCount
+1;
381 pkgCache::VerFile
**VFList
= new pkgCache::VerFile
*[Count
];
382 memset(VFList
,0,sizeof(*VFList
)*Count
);
384 // Map versions that we want to write out onto the VerList array.
385 for (pkgCache::PkgIterator P
= Cache
.PkgBegin(); P
.end() == false; P
++)
387 if (P
->VersionList
== 0)
390 /* Find the proper version to use. If the policy says there are no
391 possible selections we return the installed version, if available..
392 This prevents dselect from making it obsolete. */
393 pkgCache::VerIterator V
= Plcy
.GetCandidateVer(P
);
396 if (P
->CurrentVer
== 0)
401 pkgCache::VerFileIterator VF
= V
.FileList();
402 for (; VF
.end() == false ; VF
++)
403 if ((VF
.File()->Flags
& pkgCache::Flag::NotSource
) == 0)
406 /* Okay, here we have a bit of a problem.. The policy has selected the
407 currently installed package - however it only exists in the
408 status file.. We need to write out something or dselect will mark
409 the package as obsolete! Thus we emit the status file entry, but
410 below we remove the status line to make it valid for the
411 available file. However! We only do this if their do exist *any*
412 non-source versions of the package - that way the dselect obsolete
413 handling works OK. */
414 if (VF
.end() == true)
416 for (pkgCache::VerIterator Cur
= P
.VersionList(); Cur
.end() != true; Cur
++)
418 for (VF
= Cur
.FileList(); VF
.end() == false; VF
++)
420 if ((VF
.File()->Flags
& pkgCache::Flag::NotSource
) == 0)
427 if (VF
.end() == false)
435 LocalitySort(VFList
,Count
,sizeof(*VFList
));
437 // Iterate over all the package files and write them out.
438 char *Buffer
= new char[Cache
.HeaderP
->MaxVerFileSize
+10];
439 for (pkgCache::VerFile
**J
= VFList
; *J
!= 0;)
441 pkgCache::PkgFileIterator
File(Cache
,(*J
)->File
+ Cache
.PkgFileP
);
442 if (File
.IsOk() == false)
444 _error
->Error(_("Package file %s is out of sync."),File
.FileName());
448 FileFd
PkgF(File
.FileName(),FileFd::ReadOnly
);
449 if (_error
->PendingError() == true)
452 /* Write all of the records from this package file, since we
453 already did locality sorting we can now just seek through the
454 file in read order. We apply 1 more optimization here, since often
455 there will be < 1 byte gaps between records (for the \n) we read that
456 into the next buffer and offset a bit.. */
457 unsigned long Pos
= 0;
460 if ((*J
)->File
+ Cache
.PkgFileP
!= File
)
463 const pkgCache::VerFile
&VF
= **J
;
465 // Read the record and then write it out again.
466 unsigned long Jitter
= VF
.Offset
- Pos
;
469 if (PkgF
.Seek(VF
.Offset
) == false)
474 if (PkgF
.Read(Buffer
,VF
.Size
+ Jitter
) == false)
476 Buffer
[VF
.Size
+ Jitter
] = '\n';
479 if ((File
->Flags
& pkgCache::Flag::NotSource
) == pkgCache::Flag::NotSource
)
482 TFRewriteData RW
[] = {{"Status",0},{"Config-Version",0},{}};
483 const char *Zero
= 0;
484 if (Tags
.Scan(Buffer
+Jitter
,VF
.Size
+1) == false ||
485 TFRewrite(stdout
,Tags
,&Zero
,RW
) == false)
487 _error
->Error("Internal Error, Unable to parse a package record");
494 if (fwrite(Buffer
+Jitter
,VF
.Size
+1,1,stdout
) != 1)
498 Pos
= VF
.Offset
+ VF
.Size
;
502 if (_error
->PendingError() == true)
508 return !_error
->PendingError();
511 // Depends - Print out a dependency tree /*{{{*/
512 // ---------------------------------------------------------------------
514 bool Depends(CommandLine
&CmdL
)
516 pkgCache
&Cache
= *GCache
;
517 SPtrArray
<unsigned> Colours
= new unsigned[Cache
.Head().PackageCount
];
518 memset(Colours
,0,sizeof(*Colours
)*Cache
.Head().PackageCount
);
520 for (const char **I
= CmdL
.FileList
+ 1; *I
!= 0; I
++)
522 pkgCache::PkgIterator Pkg
= Cache
.FindPkg(*I
);
523 if (Pkg
.end() == true)
525 _error
->Warning(_("Unable to locate package %s"),*I
);
528 Colours
[Pkg
->ID
] = 1;
531 bool Recurse
= _config
->FindB("APT::Cache::RecurseDepends",false);
532 bool Installed
= _config
->FindB("APT::Cache::Installed",false);
536 DidSomething
= false;
537 for (pkgCache::PkgIterator Pkg
= Cache
.PkgBegin(); Pkg
.end() == false; Pkg
++)
539 if (Colours
[Pkg
->ID
] != 1)
541 Colours
[Pkg
->ID
] = 2;
544 pkgCache::VerIterator Ver
= Pkg
.VersionList();
545 if (Ver
.end() == true)
547 cout
<< '<' << Pkg
.Name() << '>' << endl
;
551 cout
<< Pkg
.Name() << endl
;
553 for (pkgCache::DepIterator D
= Ver
.DependsList(); D
.end() == false; D
++)
556 pkgCache::PkgIterator Trg
= D
.TargetPkg();
558 if((Installed
&& Trg
->CurrentVer
!= 0) || !Installed
)
561 if ((D
->CompareOp
& pkgCache::Dep::Or
) == pkgCache::Dep::Or
)
567 if (Trg
->VersionList
== 0)
568 cout
<< D
.DepType() << ": <" << Trg
.Name() << ">" << endl
;
570 cout
<< D
.DepType() << ": " << Trg
.Name() << endl
;
573 Colours
[D
.TargetPkg()->ID
]++;
577 // Display all solutions
578 SPtrArray
<pkgCache::Version
*> List
= D
.AllTargets();
579 pkgPrioSortList(Cache
,List
);
580 for (pkgCache::Version
**I
= List
; *I
!= 0; I
++)
582 pkgCache::VerIterator
V(Cache
,*I
);
583 if (V
!= Cache
.VerP
+ V
.ParentPkg()->VersionList
||
584 V
->ParentPkg
== D
->Package
)
586 cout
<< " " << V
.ParentPkg().Name() << endl
;
589 Colours
[D
.ParentPkg()->ID
]++;
594 while (DidSomething
== true);
599 // RDepends - Print out a reverse dependency tree - mbc /*{{{*/
600 // ---------------------------------------------------------------------
602 bool RDepends(CommandLine
&CmdL
)
604 pkgCache
&Cache
= *GCache
;
605 SPtrArray
<unsigned> Colours
= new unsigned[Cache
.Head().PackageCount
];
606 memset(Colours
,0,sizeof(*Colours
)*Cache
.Head().PackageCount
);
608 for (const char **I
= CmdL
.FileList
+ 1; *I
!= 0; I
++)
610 pkgCache::PkgIterator Pkg
= Cache
.FindPkg(*I
);
611 if (Pkg
.end() == true)
613 _error
->Warning(_("Unable to locate package %s"),*I
);
616 Colours
[Pkg
->ID
] = 1;
619 bool Recurse
= _config
->FindB("APT::Cache::RecurseDepends",false);
620 bool Installed
= _config
->FindB("APT::Cache::Installed",false);
624 DidSomething
= false;
625 for (pkgCache::PkgIterator Pkg
= Cache
.PkgBegin(); Pkg
.end() == false; Pkg
++)
627 if (Colours
[Pkg
->ID
] != 1)
629 Colours
[Pkg
->ID
] = 2;
632 pkgCache::VerIterator Ver
= Pkg
.VersionList();
633 if (Ver
.end() == true)
635 cout
<< '<' << Pkg
.Name() << '>' << endl
;
639 cout
<< Pkg
.Name() << endl
;
641 cout
<< "Reverse Depends:" << endl
;
642 for (pkgCache::DepIterator D
= Pkg
.RevDependsList(); D
.end() == false; D
++)
645 pkgCache::PkgIterator Trg
= D
.ParentPkg();
647 if((Installed
&& Trg
->CurrentVer
!= 0) || !Installed
)
650 if ((D
->CompareOp
& pkgCache::Dep::Or
) == pkgCache::Dep::Or
)
655 if (Trg
->VersionList
== 0)
656 cout
<< D
.DepType() << ": <" << Trg
.Name() << ">" << endl
;
658 cout
<< Trg
.Name() << endl
;
661 Colours
[D
.ParentPkg()->ID
]++;
665 // Display all solutions
666 SPtrArray
<pkgCache::Version
*> List
= D
.AllTargets();
667 pkgPrioSortList(Cache
,List
);
668 for (pkgCache::Version
**I
= List
; *I
!= 0; I
++)
670 pkgCache::VerIterator
V(Cache
,*I
);
671 if (V
!= Cache
.VerP
+ V
.ParentPkg()->VersionList
||
672 V
->ParentPkg
== D
->Package
)
674 cout
<< " " << V
.ParentPkg().Name() << endl
;
677 Colours
[D
.ParentPkg()->ID
]++;
682 while (DidSomething
== true);
690 // xvcg - Generate a graph for xvcg /*{{{*/
691 // ---------------------------------------------------------------------
692 // Code contributed from Junichi Uekawa <dancer@debian.org> on 20 June 2002.
694 bool XVcg(CommandLine
&CmdL
)
696 pkgCache
&Cache
= *GCache
;
697 bool GivenOnly
= _config
->FindB("APT::Cache::GivenOnly",false);
699 /* Normal packages are boxes
700 Pure Provides are triangles
702 rhomb are missing packages*/
703 const char *Shapes
[] = {"ellipse","triangle","box","rhomb"};
705 /* Initialize the list of packages to show.
707 2 = To Show no recurse
708 3 = Emitted no recurse
711 enum States
{None
=0, ToShow
, ToShowNR
, DoneNR
, Done
};
712 enum TheFlags
{ForceNR
=(1<<0)};
713 unsigned char *Show
= new unsigned char[Cache
.Head().PackageCount
];
714 unsigned char *Flags
= new unsigned char[Cache
.Head().PackageCount
];
715 unsigned char *ShapeMap
= new unsigned char[Cache
.Head().PackageCount
];
717 // Show everything if no arguments given
718 if (CmdL
.FileList
[1] == 0)
719 for (unsigned long I
= 0; I
!= Cache
.Head().PackageCount
; I
++)
722 for (unsigned long I
= 0; I
!= Cache
.Head().PackageCount
; I
++)
724 memset(Flags
,0,sizeof(*Flags
)*Cache
.Head().PackageCount
);
727 for (pkgCache::PkgIterator Pkg
= Cache
.PkgBegin(); Pkg
.end() == false; Pkg
++)
729 if (Pkg
->VersionList
== 0)
732 if (Pkg
->ProvidesList
== 0)
733 ShapeMap
[Pkg
->ID
] = 0;
735 ShapeMap
[Pkg
->ID
] = 1;
740 if (Pkg
->ProvidesList
== 0)
741 ShapeMap
[Pkg
->ID
] = 2;
743 ShapeMap
[Pkg
->ID
] = 3;
747 // Load the list of packages from the command line into the show list
748 for (const char **I
= CmdL
.FileList
+ 1; *I
!= 0; I
++)
750 // Process per-package flags
755 if (P
.end()[-1] == '^')
761 if (P
.end()[-1] == ',')
765 // Locate the package
766 pkgCache::PkgIterator Pkg
= Cache
.FindPkg(P
);
767 if (Pkg
.end() == true)
769 _error
->Warning(_("Unable to locate package %s"),*I
);
772 Show
[Pkg
->ID
] = ToShow
;
775 Flags
[Pkg
->ID
] |= ForceNR
;
779 cout
<< "graph: { title: \"packages\"" << endl
<<
780 "xmax: 700 ymax: 700 x: 30 y: 30" << endl
<<
781 "layout_downfactor: 8" << endl
;
787 for (pkgCache::PkgIterator Pkg
= Cache
.PkgBegin(); Pkg
.end() == false; Pkg
++)
789 // See we need to show this package
790 if (Show
[Pkg
->ID
] == None
|| Show
[Pkg
->ID
] >= DoneNR
)
793 //printf ("node: { title: \"%s\" label: \"%s\" }\n", Pkg.Name(), Pkg.Name());
796 if (Show
[Pkg
->ID
] == ToShowNR
|| (Flags
[Pkg
->ID
] & ForceNR
) == ForceNR
)
798 // Pure Provides and missing packages have no deps!
799 if (ShapeMap
[Pkg
->ID
] == 0 || ShapeMap
[Pkg
->ID
] == 1)
800 Show
[Pkg
->ID
] = Done
;
802 Show
[Pkg
->ID
] = DoneNR
;
805 Show
[Pkg
->ID
] = Done
;
808 // No deps to map out
809 if (Pkg
->VersionList
== 0 || Show
[Pkg
->ID
] == DoneNR
)
812 pkgCache::VerIterator Ver
= Pkg
.VersionList();
813 for (pkgCache::DepIterator D
= Ver
.DependsList(); D
.end() == false; D
++)
815 // See if anything can meet this dep
816 // Walk along the actual package providing versions
818 pkgCache::PkgIterator DPkg
= D
.TargetPkg();
819 for (pkgCache::VerIterator I
= DPkg
.VersionList();
820 I
.end() == false && Hit
== false; I
++)
822 if (Cache
.VS
->CheckDep(I
.VerStr(),D
->CompareOp
,D
.TargetVer()) == true)
826 // Follow all provides
827 for (pkgCache::PrvIterator I
= DPkg
.ProvidesList();
828 I
.end() == false && Hit
== false; I
++)
830 if (Cache
.VS
->CheckDep(I
.ProvideVersion(),D
->CompareOp
,D
.TargetVer()) == false)
835 // Only graph critical deps
836 if (D
.IsCritical() == true)
838 printf ("edge: { sourcename: \"%s\" targetname: \"%s\" class: 2 ",Pkg
.Name(), D
.TargetPkg().Name() );
840 // Colour the node for recursion
841 if (Show
[D
.TargetPkg()->ID
] <= DoneNR
)
843 /* If a conflicts does not meet anything in the database
844 then show the relation but do not recurse */
846 (D
->Type
== pkgCache::Dep::Conflicts
||
847 D
->Type
== pkgCache::Dep::Obsoletes
))
849 if (Show
[D
.TargetPkg()->ID
] == None
&&
850 Show
[D
.TargetPkg()->ID
] != ToShow
)
851 Show
[D
.TargetPkg()->ID
] = ToShowNR
;
855 if (GivenOnly
== true && Show
[D
.TargetPkg()->ID
] != ToShow
)
856 Show
[D
.TargetPkg()->ID
] = ToShowNR
;
858 Show
[D
.TargetPkg()->ID
] = ToShow
;
865 case pkgCache::Dep::Conflicts
:
866 printf("label: \"conflicts\" color: lightgreen }\n");
868 case pkgCache::Dep::Obsoletes
:
869 printf("label: \"obsoletes\" color: lightgreen }\n");
872 case pkgCache::Dep::PreDepends
:
873 printf("label: \"predepends\" color: blue }\n");
885 /* Draw the box colours after the fact since we can not tell what colour
886 they should be until everything is finished drawing */
887 for (pkgCache::PkgIterator Pkg
= Cache
.PkgBegin(); Pkg
.end() == false; Pkg
++)
889 if (Show
[Pkg
->ID
] < DoneNR
)
892 if (Show
[Pkg
->ID
] == DoneNR
)
893 printf("node: { title: \"%s\" label: \"%s\" color: orange shape: %s }\n", Pkg
.Name(), Pkg
.Name(),
894 Shapes
[ShapeMap
[Pkg
->ID
]]);
896 printf("node: { title: \"%s\" label: \"%s\" shape: %s }\n", Pkg
.Name(), Pkg
.Name(),
897 Shapes
[ShapeMap
[Pkg
->ID
]]);
907 // Dotty - Generate a graph for Dotty /*{{{*/
908 // ---------------------------------------------------------------------
909 /* Dotty is the graphvis program for generating graphs. It is a fairly
910 simple queuing algorithm that just writes dependencies and nodes.
911 http://www.research.att.com/sw/tools/graphviz/ */
912 bool Dotty(CommandLine
&CmdL
)
914 pkgCache
&Cache
= *GCache
;
915 bool GivenOnly
= _config
->FindB("APT::Cache::GivenOnly",false);
917 /* Normal packages are boxes
918 Pure Provides are triangles
920 Hexagons are missing packages*/
921 const char *Shapes
[] = {"hexagon","triangle","box","diamond"};
923 /* Initialize the list of packages to show.
925 2 = To Show no recurse
926 3 = Emitted no recurse
929 enum States
{None
=0, ToShow
, ToShowNR
, DoneNR
, Done
};
930 enum TheFlags
{ForceNR
=(1<<0)};
931 unsigned char *Show
= new unsigned char[Cache
.Head().PackageCount
];
932 unsigned char *Flags
= new unsigned char[Cache
.Head().PackageCount
];
933 unsigned char *ShapeMap
= new unsigned char[Cache
.Head().PackageCount
];
935 // Show everything if no arguments given
936 if (CmdL
.FileList
[1] == 0)
937 for (unsigned long I
= 0; I
!= Cache
.Head().PackageCount
; I
++)
940 for (unsigned long I
= 0; I
!= Cache
.Head().PackageCount
; I
++)
942 memset(Flags
,0,sizeof(*Flags
)*Cache
.Head().PackageCount
);
945 for (pkgCache::PkgIterator Pkg
= Cache
.PkgBegin(); Pkg
.end() == false; Pkg
++)
947 if (Pkg
->VersionList
== 0)
950 if (Pkg
->ProvidesList
== 0)
951 ShapeMap
[Pkg
->ID
] = 0;
953 ShapeMap
[Pkg
->ID
] = 1;
958 if (Pkg
->ProvidesList
== 0)
959 ShapeMap
[Pkg
->ID
] = 2;
961 ShapeMap
[Pkg
->ID
] = 3;
965 // Load the list of packages from the command line into the show list
966 for (const char **I
= CmdL
.FileList
+ 1; *I
!= 0; I
++)
968 // Process per-package flags
973 if (P
.end()[-1] == '^')
979 if (P
.end()[-1] == ',')
983 // Locate the package
984 pkgCache::PkgIterator Pkg
= Cache
.FindPkg(P
);
985 if (Pkg
.end() == true)
987 _error
->Warning(_("Unable to locate package %s"),*I
);
990 Show
[Pkg
->ID
] = ToShow
;
993 Flags
[Pkg
->ID
] |= ForceNR
;
997 printf("digraph packages {\n");
998 printf("concentrate=true;\n");
999 printf("size=\"30,40\";\n");
1005 for (pkgCache::PkgIterator Pkg
= Cache
.PkgBegin(); Pkg
.end() == false; Pkg
++)
1007 // See we need to show this package
1008 if (Show
[Pkg
->ID
] == None
|| Show
[Pkg
->ID
] >= DoneNR
)
1012 if (Show
[Pkg
->ID
] == ToShowNR
|| (Flags
[Pkg
->ID
] & ForceNR
) == ForceNR
)
1014 // Pure Provides and missing packages have no deps!
1015 if (ShapeMap
[Pkg
->ID
] == 0 || ShapeMap
[Pkg
->ID
] == 1)
1016 Show
[Pkg
->ID
] = Done
;
1018 Show
[Pkg
->ID
] = DoneNR
;
1021 Show
[Pkg
->ID
] = Done
;
1024 // No deps to map out
1025 if (Pkg
->VersionList
== 0 || Show
[Pkg
->ID
] == DoneNR
)
1028 pkgCache::VerIterator Ver
= Pkg
.VersionList();
1029 for (pkgCache::DepIterator D
= Ver
.DependsList(); D
.end() == false; D
++)
1031 // See if anything can meet this dep
1032 // Walk along the actual package providing versions
1034 pkgCache::PkgIterator DPkg
= D
.TargetPkg();
1035 for (pkgCache::VerIterator I
= DPkg
.VersionList();
1036 I
.end() == false && Hit
== false; I
++)
1038 if (Cache
.VS
->CheckDep(I
.VerStr(),D
->CompareOp
,D
.TargetVer()) == true)
1042 // Follow all provides
1043 for (pkgCache::PrvIterator I
= DPkg
.ProvidesList();
1044 I
.end() == false && Hit
== false; I
++)
1046 if (Cache
.VS
->CheckDep(I
.ProvideVersion(),D
->CompareOp
,D
.TargetVer()) == false)
1050 // Only graph critical deps
1051 if (D
.IsCritical() == true)
1053 printf("\"%s\" -> \"%s\"",Pkg
.Name(),D
.TargetPkg().Name());
1055 // Colour the node for recursion
1056 if (Show
[D
.TargetPkg()->ID
] <= DoneNR
)
1058 /* If a conflicts does not meet anything in the database
1059 then show the relation but do not recurse */
1061 (D
->Type
== pkgCache::Dep::Conflicts
||
1062 D
->Type
== pkgCache::Dep::Obsoletes
))
1064 if (Show
[D
.TargetPkg()->ID
] == None
&&
1065 Show
[D
.TargetPkg()->ID
] != ToShow
)
1066 Show
[D
.TargetPkg()->ID
] = ToShowNR
;
1070 if (GivenOnly
== true && Show
[D
.TargetPkg()->ID
] != ToShow
)
1071 Show
[D
.TargetPkg()->ID
] = ToShowNR
;
1073 Show
[D
.TargetPkg()->ID
] = ToShow
;
1080 case pkgCache::Dep::Conflicts
:
1081 case pkgCache::Dep::Obsoletes
:
1082 printf("[color=springgreen];\n");
1085 case pkgCache::Dep::PreDepends
:
1086 printf("[color=blue];\n");
1098 /* Draw the box colours after the fact since we can not tell what colour
1099 they should be until everything is finished drawing */
1100 for (pkgCache::PkgIterator Pkg
= Cache
.PkgBegin(); Pkg
.end() == false; Pkg
++)
1102 if (Show
[Pkg
->ID
] < DoneNR
)
1105 // Orange box for early recursion stoppage
1106 if (Show
[Pkg
->ID
] == DoneNR
)
1107 printf("\"%s\" [color=orange,shape=%s];\n",Pkg
.Name(),
1108 Shapes
[ShapeMap
[Pkg
->ID
]]);
1110 printf("\"%s\" [shape=%s];\n",Pkg
.Name(),
1111 Shapes
[ShapeMap
[Pkg
->ID
]]);
1118 // DoAdd - Perform an adding operation /*{{{*/
1119 // ---------------------------------------------------------------------
1121 bool DoAdd(CommandLine
&CmdL
)
1123 return _error
->Error("Unimplemented");
1125 // Make sure there is at least one argument
1126 if (CmdL
.FileSize() <= 1)
1127 return _error
->Error("You must give at least one file name");
1130 FileFd
CacheF(_config
->FindFile("Dir::Cache::pkgcache"),FileFd::WriteAny
);
1131 if (_error
->PendingError() == true)
1134 DynamicMMap
Map(CacheF
,MMap::Public
);
1135 if (_error
->PendingError() == true)
1138 OpTextProgress
Progress(*_config
);
1139 pkgCacheGenerator
Gen(Map
,Progress
);
1140 if (_error
->PendingError() == true)
1143 unsigned long Length
= CmdL
.FileSize() - 1;
1144 for (const char **I
= CmdL
.FileList
+ 1; *I
!= 0; I
++)
1146 Progress
.OverallProgress(I
- CmdL
.FileList
,Length
,1,"Generating cache");
1147 Progress
.SubProgress(Length
);
1150 FileFd
TagF(*I
,FileFd::ReadOnly
);
1151 debListParser
Parser(TagF
);
1152 if (_error
->PendingError() == true)
1153 return _error
->Error("Problem opening %s",*I
);
1155 if (Gen
.SelectFile(*I
,"") == false)
1156 return _error
->Error("Problem with SelectFile");
1158 if (Gen
.MergeList(Parser
) == false)
1159 return _error
->Error("Problem with MergeList");
1163 GCache
= &Gen
.GetCache();
1170 // DisplayRecord - Displays the complete record for the package /*{{{*/
1171 // ---------------------------------------------------------------------
1172 /* This displays the package record from the proper package index file.
1173 It is not used by DumpAvail for performance reasons. */
1174 bool DisplayRecord(pkgCache::VerIterator V
)
1176 // Find an appropriate file
1177 pkgCache::VerFileIterator Vf
= V
.FileList();
1178 for (; Vf
.end() == false; Vf
++)
1179 if ((Vf
.File()->Flags
& pkgCache::Flag::NotSource
) == 0)
1181 if (Vf
.end() == true)
1184 // Check and load the package list file
1185 pkgCache::PkgFileIterator I
= Vf
.File();
1186 if (I
.IsOk() == false)
1187 return _error
->Error(_("Package file %s is out of sync."),I
.FileName());
1189 FileFd
PkgF(I
.FileName(),FileFd::ReadOnly
);
1190 if (_error
->PendingError() == true)
1193 // Read the record and then write it out again.
1194 unsigned char *Buffer
= new unsigned char[GCache
->HeaderP
->MaxVerFileSize
+1];
1195 Buffer
[V
.FileList()->Size
] = '\n';
1196 if (PkgF
.Seek(V
.FileList()->Offset
) == false ||
1197 PkgF
.Read(Buffer
,V
.FileList()->Size
) == false ||
1198 write(STDOUT_FILENO
,Buffer
,V
.FileList()->Size
+1) != V
.FileList()->Size
+1)
1209 // Search - Perform a search /*{{{*/
1210 // ---------------------------------------------------------------------
1211 /* This searches the package names and pacakge descriptions for a pattern */
1214 pkgCache::VerFile
*Vf
;
1218 bool Search(CommandLine
&CmdL
)
1220 pkgCache
&Cache
= *GCache
;
1221 bool ShowFull
= _config
->FindB("APT::Cache::ShowFull",false);
1222 bool NamesOnly
= _config
->FindB("APT::Cache::NamesOnly",false);
1223 unsigned NumPatterns
= CmdL
.FileSize() -1;
1225 pkgDepCache::Policy Plcy
;
1227 // Make sure there is at least one argument
1228 if (NumPatterns
< 1)
1229 return _error
->Error(_("You must give exactly one pattern"));
1231 // Compile the regex pattern
1232 regex_t
*Patterns
= new regex_t
[NumPatterns
];
1233 memset(Patterns
,0,sizeof(*Patterns
)*NumPatterns
);
1234 for (unsigned I
= 0; I
!= NumPatterns
; I
++)
1236 if (regcomp(&Patterns
[I
],CmdL
.FileList
[I
+1],REG_EXTENDED
| REG_ICASE
|
1240 regfree(&Patterns
[I
]);
1241 return _error
->Error("Regex compilation error");
1245 // Create the text record parser
1246 pkgRecords
Recs(Cache
);
1247 if (_error
->PendingError() == true)
1249 for (unsigned I
= 0; I
!= NumPatterns
; I
++)
1250 regfree(&Patterns
[I
]);
1254 ExVerFile
*VFList
= new ExVerFile
[Cache
.HeaderP
->PackageCount
+1];
1255 memset(VFList
,0,sizeof(*VFList
)*Cache
.HeaderP
->PackageCount
+1);
1257 // Map versions that we want to write out onto the VerList array.
1258 for (pkgCache::PkgIterator P
= Cache
.PkgBegin(); P
.end() == false; P
++)
1260 VFList
[P
->ID
].NameMatch
= NumPatterns
!= 0;
1261 for (unsigned I
= 0; I
!= NumPatterns
; I
++)
1263 if (regexec(&Patterns
[I
],P
.Name(),0,0,0) == 0)
1264 VFList
[P
->ID
].NameMatch
&= true;
1266 VFList
[P
->ID
].NameMatch
= false;
1269 // Doing names only, drop any that dont match..
1270 if (NamesOnly
== true && VFList
[P
->ID
].NameMatch
== false)
1273 // Find the proper version to use.
1274 pkgCache::VerIterator V
= Plcy
.GetCandidateVer(P
);
1275 if (V
.end() == false)
1276 VFList
[P
->ID
].Vf
= V
.FileList();
1279 // Include all the packages that provide matching names too
1280 for (pkgCache::PkgIterator P
= Cache
.PkgBegin(); P
.end() == false; P
++)
1282 if (VFList
[P
->ID
].NameMatch
== false)
1285 for (pkgCache::PrvIterator Prv
= P
.ProvidesList() ; Prv
.end() == false; Prv
++)
1287 pkgCache::VerIterator V
= Plcy
.GetCandidateVer(Prv
.OwnerPkg());
1288 if (V
.end() == false)
1290 VFList
[Prv
.OwnerPkg()->ID
].Vf
= V
.FileList();
1291 VFList
[Prv
.OwnerPkg()->ID
].NameMatch
= true;
1296 LocalitySort(&VFList
->Vf
,Cache
.HeaderP
->PackageCount
,sizeof(*VFList
));
1298 // Iterate over all the version records and check them
1299 for (ExVerFile
*J
= VFList
; J
->Vf
!= 0; J
++)
1301 pkgRecords::Parser
&P
= Recs
.Lookup(pkgCache::VerFileIterator(Cache
,J
->Vf
));
1304 if (J
->NameMatch
== false)
1306 string LongDesc
= P
.LongDesc();
1307 Match
= NumPatterns
!= 0;
1308 for (unsigned I
= 0; I
!= NumPatterns
; I
++)
1310 if (regexec(&Patterns
[I
],LongDesc
.c_str(),0,0,0) == 0)
1319 if (ShowFull
== true)
1323 P
.GetRec(Start
,End
);
1324 fwrite(Start
,End
-Start
,1,stdout
);
1328 printf("%s - %s\n",P
.Name().c_str(),P
.ShortDesc().c_str());
1333 for (unsigned I
= 0; I
!= NumPatterns
; I
++)
1334 regfree(&Patterns
[I
]);
1336 return _error
->Error("Write to stdout failed");
1340 // ShowPackage - Dump the package record to the screen /*{{{*/
1341 // ---------------------------------------------------------------------
1343 bool ShowPackage(CommandLine
&CmdL
)
1345 pkgCache
&Cache
= *GCache
;
1346 pkgDepCache::Policy Plcy
;
1348 for (const char **I
= CmdL
.FileList
+ 1; *I
!= 0; I
++)
1350 pkgCache::PkgIterator Pkg
= Cache
.FindPkg(*I
);
1351 if (Pkg
.end() == true)
1353 _error
->Warning(_("Unable to locate package %s"),*I
);
1357 // Find the proper version to use.
1358 if (_config
->FindB("APT::Cache::AllVersions","true") == true)
1360 pkgCache::VerIterator V
;
1361 for (V
= Pkg
.VersionList(); V
.end() == false; V
++)
1363 if (DisplayRecord(V
) == false)
1369 pkgCache::VerIterator V
= Plcy
.GetCandidateVer(Pkg
);
1370 if (V
.end() == true || V
.FileList().end() == true)
1372 if (DisplayRecord(V
) == false)
1379 // ShowPkgNames - Show package names /*{{{*/
1380 // ---------------------------------------------------------------------
1381 /* This does a prefix match on the first argument */
1382 bool ShowPkgNames(CommandLine
&CmdL
)
1384 pkgCache
&Cache
= *GCache
;
1385 pkgCache::PkgIterator I
= Cache
.PkgBegin();
1386 bool All
= _config
->FindB("APT::Cache::AllNames","false");
1388 if (CmdL
.FileList
[1] != 0)
1390 for (;I
.end() != true; I
++)
1392 if (All
== false && I
->VersionList
== 0)
1395 if (strncmp(I
.Name(),CmdL
.FileList
[1],strlen(CmdL
.FileList
[1])) == 0)
1396 cout
<< I
.Name() << endl
;
1403 for (;I
.end() != true; I
++)
1405 if (All
== false && I
->VersionList
== 0)
1407 cout
<< I
.Name() << endl
;
1413 // ShowSrcPackage - Show source package records /*{{{*/
1414 // ---------------------------------------------------------------------
1416 bool ShowSrcPackage(CommandLine
&CmdL
)
1419 List
.ReadMainList();
1421 // Create the text record parsers
1422 pkgSrcRecords
SrcRecs(List
);
1423 if (_error
->PendingError() == true)
1426 for (const char **I
= CmdL
.FileList
+ 1; *I
!= 0; I
++)
1430 pkgSrcRecords::Parser
*Parse
;
1431 while ((Parse
= SrcRecs
.Find(*I
,false)) != 0)
1432 cout
<< Parse
->AsStr() << endl
;;
1437 // Policy - Show the results of the preferences file /*{{{*/
1438 // ---------------------------------------------------------------------
1440 bool Policy(CommandLine
&CmdL
)
1443 return _error
->Error("Generate must be enabled for this function");
1445 pkgCache
&Cache
= *GCache
;
1446 pkgPolicy
Plcy(&Cache
);
1447 if (ReadPinFile(Plcy
) == false)
1450 // Print out all of the package files
1451 if (CmdL
.FileList
[1] == 0)
1453 cout
<< _("Package Files:") << endl
;
1454 for (pkgCache::PkgFileIterator F
= Cache
.FileBegin(); F
.end() == false; F
++)
1456 // Locate the associated index files so we can derive a description
1458 if (SrcList
->FindIndex(F
,Indx
) == false &&
1459 _system
->FindIndex(F
,Indx
) == false)
1460 return _error
->Error(_("Cache is out of sync, can't x-ref a package file"));
1461 printf(_("%4i %s\n"),
1462 Plcy
.GetPriority(F
),Indx
->Describe(true).c_str());
1464 // Print the reference information for the package
1465 string Str
= F
.RelStr();
1466 if (Str
.empty() == false)
1467 printf(" release %s\n",F
.RelStr().c_str());
1468 if (F
.Site() != 0 && F
.Site()[0] != 0)
1469 printf(" origin %s\n",F
.Site());
1472 // Show any packages have explicit pins
1473 cout
<< _("Pinned Packages:") << endl
;
1474 pkgCache::PkgIterator I
= Cache
.PkgBegin();
1475 for (;I
.end() != true; I
++)
1477 if (Plcy
.GetPriority(I
) == 0)
1480 // Print the package name and the version we are forcing to
1481 cout
<< " " << I
.Name() << " -> ";
1483 pkgCache::VerIterator V
= Plcy
.GetMatch(I
);
1484 if (V
.end() == true)
1485 cout
<< _("(not found)") << endl
;
1487 cout
<< V
.VerStr() << endl
;
1493 // Print out detailed information for each package
1494 for (const char **I
= CmdL
.FileList
+ 1; *I
!= 0; I
++)
1496 pkgCache::PkgIterator Pkg
= Cache
.FindPkg(*I
);
1497 if (Pkg
.end() == true)
1499 _error
->Warning(_("Unable to locate package %s"),*I
);
1503 cout
<< Pkg
.Name() << ":" << endl
;
1505 // Installed version
1506 cout
<< _(" Installed: ");
1507 if (Pkg
->CurrentVer
== 0)
1508 cout
<< _("(none)") << endl
;
1510 cout
<< Pkg
.CurrentVer().VerStr() << endl
;
1512 // Candidate Version
1513 cout
<< _(" Candidate: ");
1514 pkgCache::VerIterator V
= Plcy
.GetCandidateVer(Pkg
);
1515 if (V
.end() == true)
1516 cout
<< _("(none)") << endl
;
1518 cout
<< V
.VerStr() << endl
;
1521 if (Plcy
.GetPriority(Pkg
) != 0)
1523 cout
<< _(" Package Pin: ");
1524 V
= Plcy
.GetMatch(Pkg
);
1525 if (V
.end() == true)
1526 cout
<< _("(not found)") << endl
;
1528 cout
<< V
.VerStr() << endl
;
1531 // Show the priority tables
1532 cout
<< _(" Version Table:") << endl
;
1533 for (V
= Pkg
.VersionList(); V
.end() == false; V
++)
1535 if (Pkg
.CurrentVer() == V
)
1536 cout
<< " *** " << V
.VerStr();
1538 cout
<< " " << V
.VerStr();
1539 cout
<< " " << Plcy
.GetPriority(Pkg
) << endl
;
1540 for (pkgCache::VerFileIterator VF
= V
.FileList(); VF
.end() == false; VF
++)
1542 // Locate the associated index files so we can derive a description
1544 if (SrcList
->FindIndex(VF
.File(),Indx
) == false &&
1545 _system
->FindIndex(VF
.File(),Indx
) == false)
1546 return _error
->Error(_("Cache is out of sync, can't x-ref a package file"));
1547 printf(_(" %4i %s\n"),Plcy
.GetPriority(VF
.File()),
1548 Indx
->Describe(true).c_str());
1556 // GenCaches - Call the main cache generator /*{{{*/
1557 // ---------------------------------------------------------------------
1559 bool GenCaches(CommandLine
&Cmd
)
1561 OpTextProgress
Progress(*_config
);
1564 if (List
.ReadMainList() == false)
1566 return pkgMakeStatusCache(List
,Progress
);
1569 // ShowHelp - Show a help screen /*{{{*/
1570 // ---------------------------------------------------------------------
1572 bool ShowHelp(CommandLine
&Cmd
)
1574 ioprintf(cout
,_("%s %s for %s %s compiled on %s %s\n"),PACKAGE
,VERSION
,
1575 COMMON_OS
,COMMON_CPU
,__DATE__
,__TIME__
);
1578 _("Usage: apt-cache [options] command\n"
1579 " apt-cache [options] add file1 [file2 ...]\n"
1580 " apt-cache [options] showpkg pkg1 [pkg2 ...]\n"
1581 " apt-cache [options] showsrc pkg1 [pkg2 ...]\n"
1583 "apt-cache is a low-level tool used to manipulate APT's binary\n"
1584 "cache files, and query information from them\n"
1587 " add - Add a package file to the source cache\n"
1588 " gencaches - Build both the package and source cache\n"
1589 " showpkg - Show some general information for a single package\n"
1590 " showsrc - Show source records\n"
1591 " stats - Show some basic statistics\n"
1592 " dump - Show the entire file in a terse form\n"
1593 " dumpavail - Print an available file to stdout\n"
1594 " unmet - Show unmet dependencies\n"
1595 " search - Search the package list for a regex pattern\n"
1596 " show - Show a readable record for the package\n"
1597 " depends - Show raw dependency information for a package\n"
1598 " rdepends - Show reverse dependency information for a package\n"
1599 " pkgnames - List the names of all packages\n"
1600 " dotty - Generate package graphs for GraphVis\n"
1601 " xvcg - Generate package graphs for xvcg\n"
1602 " policy - Show policy settings\n"
1605 " -h This help text.\n"
1606 " -p=? The package cache.\n"
1607 " -s=? The source cache.\n"
1608 " -q Disable progress indicator.\n"
1609 " -i Show only important deps for the unmet command.\n"
1610 " -c=? Read this configuration file\n"
1611 " -o=? Set an arbitary configuration option, eg -o dir::cache=/tmp\n"
1612 "See the apt-cache(8) and apt.conf(5) manual pages for more information.\n");
1616 // CacheInitialize - Initialize things for apt-cache /*{{{*/
1617 // ---------------------------------------------------------------------
1619 void CacheInitialize()
1621 _config
->Set("quiet",0);
1622 _config
->Set("help",false);
1626 int main(int argc
,const char *argv
[])
1628 CommandLine::Args Args
[] = {
1629 {'h',"help","help",0},
1630 {'v',"version","version",0},
1631 {'p',"pkg-cache","Dir::Cache::pkgcache",CommandLine::HasArg
},
1632 {'s',"src-cache","Dir::Cache::srcpkgcache",CommandLine::HasArg
},
1633 {'q',"quiet","quiet",CommandLine::IntLevel
},
1634 {'i',"important","APT::Cache::Important",0},
1635 {'f',"full","APT::Cache::ShowFull",0},
1636 {'g',"generate","APT::Cache::Generate",0},
1637 {'a',"all-versions","APT::Cache::AllVersions",0},
1638 {0,"names-only","APT::Cache::NamesOnly",0},
1639 {'n',"all-names","APT::Cache::AllNames",0},
1640 {0,"recurse","APT::Cache::RecurseDepends",0},
1641 {'c',"config-file",0,CommandLine::ConfigFile
},
1642 {'o',"option",0,CommandLine::ArbItem
},
1643 {'n',"installed","APT::Cache::Installed",0},
1645 CommandLine::Dispatch CmdsA
[] = {{"help",&ShowHelp
},
1647 {"gencaches",&GenCaches
},
1648 {"showsrc",&ShowSrcPackage
},
1650 CommandLine::Dispatch CmdsB
[] = {{"showpkg",&DumpPackage
},
1653 {"dumpavail",&DumpAvail
},
1656 {"depends",&Depends
},
1657 {"rdepends",&RDepends
},
1660 {"show",&ShowPackage
},
1661 {"pkgnames",&ShowPkgNames
},
1667 // Set up gettext support
1668 setlocale(LC_ALL
,"");
1669 textdomain(PACKAGE
);
1671 // Parse the command line and initialize the package library
1672 CommandLine
CmdL(Args
,_config
);
1673 if (pkgInitConfig(*_config
) == false ||
1674 CmdL
.Parse(argc
,argv
) == false ||
1675 pkgInitSystem(*_config
,_system
) == false)
1677 _error
->DumpErrors();
1681 // See if the help should be shown
1682 if (_config
->FindB("help") == true ||
1683 CmdL
.FileSize() == 0)
1689 // Deal with stdout not being a tty
1690 if (ttyname(STDOUT_FILENO
) == 0 && _config
->FindI("quiet",0) < 1)
1691 _config
->Set("quiet","1");
1693 if (CmdL
.DispatchArg(CmdsA
,false) == false && _error
->PendingError() == false)
1696 if (_config
->FindB("APT::Cache::Generate",true) == false)
1698 Map
= new MMap(*new FileFd(_config
->FindFile("Dir::Cache::pkgcache"),
1699 FileFd::ReadOnly
),MMap::Public
|MMap::ReadOnly
);
1703 // Open the cache file
1704 SrcList
= new pkgSourceList
;
1705 SrcList
->ReadMainList();
1707 // Generate it and map it
1709 pkgMakeStatusCache(*SrcList
,Prog
,&Map
,true);
1712 if (_error
->PendingError() == false)
1714 pkgCache
Cache(Map
);
1716 if (_error
->PendingError() == false)
1717 CmdL
.DispatchArg(CmdsB
);
1722 // Print any errors or warnings found during parsing
1723 if (_error
->empty() == false)
1725 bool Errors
= _error
->PendingError();
1726 _error
->DumpErrors();
1727 return Errors
== true?100:0;