]>
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 void LocalitySort(pkgCache::DescFile
**begin
,
76 unsigned long Count
,size_t Size
)
78 qsort(begin
,Count
,Size
,LocalityCompare
);
81 // UnMet - Show unmet dependencies /*{{{*/
82 // ---------------------------------------------------------------------
84 bool UnMet(CommandLine
&CmdL
)
86 pkgCache
&Cache
= *GCache
;
87 bool Important
= _config
->FindB("APT::Cache::Important",false);
89 for (pkgCache::PkgIterator P
= Cache
.PkgBegin(); P
.end() == false; P
++)
91 for (pkgCache::VerIterator V
= P
.VersionList(); V
.end() == false; V
++)
94 for (pkgCache::DepIterator D
= V
.DependsList(); D
.end() == false;)
97 pkgCache::DepIterator Start
;
98 pkgCache::DepIterator End
;
101 // Skip conflicts and replaces
102 if (End
->Type
!= pkgCache::Dep::PreDepends
&&
103 End
->Type
!= pkgCache::Dep::Depends
&&
104 End
->Type
!= pkgCache::Dep::Suggests
&&
105 End
->Type
!= pkgCache::Dep::Recommends
)
108 // Important deps only
109 if (Important
== true)
110 if (End
->Type
!= pkgCache::Dep::PreDepends
&&
111 End
->Type
!= pkgCache::Dep::Depends
)
114 // Verify the or group
116 pkgCache::DepIterator RealStart
= Start
;
119 // See if this dep is Ok
120 pkgCache::Version
**VList
= Start
.AllTargets();
141 ioprintf(cout
,_("Package %s version %s has an unmet dep:\n"),
142 P
.Name(),V
.VerStr());
145 // Print out the dep type
146 cout
<< " " << End
.DepType() << ": ";
152 cout
<< Start
.TargetPkg().Name();
153 if (Start
.TargetVer() != 0)
154 cout
<< " (" << Start
.CompType() << " " << Start
.TargetVer() <<
170 // DumpPackage - Show a dump of a package record /*{{{*/
171 // ---------------------------------------------------------------------
173 bool DumpPackage(CommandLine
&CmdL
)
175 pkgCache
&Cache
= *GCache
;
176 for (const char **I
= CmdL
.FileList
+ 1; *I
!= 0; I
++)
178 pkgCache::PkgIterator Pkg
= Cache
.FindPkg(*I
);
179 if (Pkg
.end() == true)
181 _error
->Warning(_("Unable to locate package %s"),*I
);
185 cout
<< "Package: " << Pkg
.Name() << endl
;
186 cout
<< "Versions: " << endl
;
187 for (pkgCache::VerIterator Cur
= Pkg
.VersionList(); Cur
.end() != true; Cur
++)
189 cout
<< Cur
.VerStr();
190 for (pkgCache::VerFileIterator Vf
= Cur
.FileList(); Vf
.end() == false; Vf
++)
191 cout
<< " (" << Vf
.File().FileName() << ")";
193 for (pkgCache::DescIterator D
= Cur
.DescriptionList(); D
.end() == false; D
++)
195 cout
<< " Description Language: " << D
.LanguageCode() << endl
196 << " File: " << D
.FileList().File().FileName() << endl
197 << " MD5: " << D
.md5() << endl
;
204 cout
<< "Reverse Depends: " << endl
;
205 for (pkgCache::DepIterator D
= Pkg
.RevDependsList(); D
.end() != true; D
++)
207 cout
<< " " << D
.ParentPkg().Name() << ',' << D
.TargetPkg().Name();
209 cout
<< ' ' << DeNull(D
.TargetVer()) << endl
;
214 cout
<< "Dependencies: " << endl
;
215 for (pkgCache::VerIterator Cur
= Pkg
.VersionList(); Cur
.end() != true; Cur
++)
217 cout
<< Cur
.VerStr() << " - ";
218 for (pkgCache::DepIterator Dep
= Cur
.DependsList(); Dep
.end() != true; Dep
++)
219 cout
<< Dep
.TargetPkg().Name() << " (" << (int)Dep
->CompareOp
<< " " << DeNull(Dep
.TargetVer()) << ") ";
223 cout
<< "Provides: " << endl
;
224 for (pkgCache::VerIterator Cur
= Pkg
.VersionList(); Cur
.end() != true; Cur
++)
226 cout
<< Cur
.VerStr() << " - ";
227 for (pkgCache::PrvIterator Prv
= Cur
.ProvidesList(); Prv
.end() != true; Prv
++)
228 cout
<< Prv
.ParentPkg().Name() << " ";
231 cout
<< "Reverse Provides: " << endl
;
232 for (pkgCache::PrvIterator Prv
= Pkg
.ProvidesList(); Prv
.end() != true; Prv
++)
233 cout
<< Prv
.OwnerPkg().Name() << " " << Prv
.OwnerVer().VerStr() << endl
;
239 // Stats - Dump some nice statistics /*{{{*/
240 // ---------------------------------------------------------------------
242 bool Stats(CommandLine
&Cmd
)
244 pkgCache
&Cache
= *GCache
;
245 cout
<< _("Total package names: ") << Cache
.Head().PackageCount
<< " (" <<
246 SizeToStr(Cache
.Head().PackageCount
*Cache
.Head().PackageSz
) << ')' << endl
;
253 pkgCache::PkgIterator I
= Cache
.PkgBegin();
254 for (;I
.end() != true; I
++)
256 if (I
->VersionList
!= 0 && I
->ProvidesList
== 0)
262 if (I
->VersionList
!= 0 && I
->ProvidesList
!= 0)
268 if (I
->VersionList
== 0 && I
->ProvidesList
!= 0)
271 if (I
.ProvidesList()->NextProvides
== 0)
279 if (I
->VersionList
== 0 && I
->ProvidesList
== 0)
285 cout
<< _(" Normal packages: ") << Normal
<< endl
;
286 cout
<< _(" Pure virtual packages: ") << Virtual
<< endl
;
287 cout
<< _(" Single virtual packages: ") << DVirt
<< endl
;
288 cout
<< _(" Mixed virtual packages: ") << NVirt
<< endl
;
289 cout
<< _(" Missing: ") << Missing
<< endl
;
291 cout
<< _("Total distinct versions: ") << Cache
.Head().VersionCount
<< " (" <<
292 SizeToStr(Cache
.Head().VersionCount
*Cache
.Head().VersionSz
) << ')' << endl
;
293 cout
<< _("Total distinct descriptions: ") << Cache
.Head().DescriptionCount
<< " (" <<
294 SizeToStr(Cache
.Head().DescriptionCount
*Cache
.Head().DescriptionSz
) << ')' << endl
;
295 cout
<< _("Total dependencies: ") << Cache
.Head().DependsCount
<< " (" <<
296 SizeToStr(Cache
.Head().DependsCount
*Cache
.Head().DependencySz
) << ')' << endl
;
298 cout
<< _("Total ver/file relations: ") << Cache
.Head().VerFileCount
<< " (" <<
299 SizeToStr(Cache
.Head().VerFileCount
*Cache
.Head().VerFileSz
) << ')' << endl
;
300 cout
<< _("Total Desc/File relations: ") << Cache
.Head().DescFileCount
<< " (" <<
301 SizeToStr(Cache
.Head().DescFileCount
*Cache
.Head().DescFileSz
) << ')' << endl
;
302 cout
<< _("Total Provides mappings: ") << Cache
.Head().ProvidesCount
<< " (" <<
303 SizeToStr(Cache
.Head().ProvidesCount
*Cache
.Head().ProvidesSz
) << ')' << endl
;
306 unsigned long Size
= 0;
307 unsigned long Count
= 0;
308 for (pkgCache::StringItem
*I
= Cache
.StringItemP
+ Cache
.Head().StringList
;
309 I
!= Cache
.StringItemP
; I
= Cache
.StringItemP
+ I
->NextItem
)
312 Size
+= strlen(Cache
.StrP
+ I
->String
) + 1;
314 cout
<< _("Total globbed strings: ") << Count
<< " (" << SizeToStr(Size
) << ')' << endl
;
316 unsigned long DepVerSize
= 0;
317 for (pkgCache::PkgIterator P
= Cache
.PkgBegin(); P
.end() == false; P
++)
319 for (pkgCache::VerIterator V
= P
.VersionList(); V
.end() == false; V
++)
321 for (pkgCache::DepIterator D
= V
.DependsList(); D
.end() == false; D
++)
324 DepVerSize
+= strlen(D
.TargetVer()) + 1;
328 cout
<< _("Total dependency version space: ") << SizeToStr(DepVerSize
) << endl
;
330 unsigned long Slack
= 0;
331 for (int I
= 0; I
!= 7; I
++)
332 Slack
+= Cache
.Head().Pools
[I
].ItemSize
*Cache
.Head().Pools
[I
].Count
;
333 cout
<< _("Total slack space: ") << SizeToStr(Slack
) << endl
;
335 unsigned long Total
= 0;
336 Total
= Slack
+ Size
+ Cache
.Head().DependsCount
*Cache
.Head().DependencySz
+
337 Cache
.Head().VersionCount
*Cache
.Head().VersionSz
+
338 Cache
.Head().PackageCount
*Cache
.Head().PackageSz
+
339 Cache
.Head().VerFileCount
*Cache
.Head().VerFileSz
+
340 Cache
.Head().ProvidesCount
*Cache
.Head().ProvidesSz
;
341 cout
<< _("Total space accounted for: ") << SizeToStr(Total
) << endl
;
346 // Dump - show everything /*{{{*/
347 // ---------------------------------------------------------------------
348 /* This is worthless except fer debugging things */
349 bool Dump(CommandLine
&Cmd
)
351 pkgCache
&Cache
= *GCache
;
352 cout
<< "Using Versioning System: " << Cache
.VS
->Label
<< endl
;
354 for (pkgCache::PkgIterator P
= Cache
.PkgBegin(); P
.end() == false; P
++)
356 cout
<< "Package: " << P
.Name() << endl
;
357 for (pkgCache::VerIterator V
= P
.VersionList(); V
.end() == false; V
++)
359 cout
<< " Version: " << V
.VerStr() << endl
;
360 cout
<< " File: " << V
.FileList().File().FileName() << endl
;
361 for (pkgCache::DepIterator D
= V
.DependsList(); D
.end() == false; D
++)
362 cout
<< " Depends: " << D
.TargetPkg().Name() << ' ' <<
363 DeNull(D
.TargetVer()) << endl
;
364 for (pkgCache::DescIterator D
= V
.DescriptionList(); D
.end() == false; D
++)
366 cout
<< " Description Language: " << D
.LanguageCode() << endl
367 << " File: " << D
.FileList().File().FileName() << endl
368 << " MD5: " << D
.md5() << endl
;
373 for (pkgCache::PkgFileIterator F
= Cache
.FileBegin(); F
.end() == false; F
++)
375 cout
<< "File: " << F
.FileName() << endl
;
376 cout
<< " Type: " << F
.IndexType() << endl
;
377 cout
<< " Size: " << F
->Size
<< endl
;
378 cout
<< " ID: " << F
->ID
<< endl
;
379 cout
<< " Flags: " << F
->Flags
<< endl
;
380 cout
<< " Time: " << TimeRFC1123(F
->mtime
) << endl
;
381 cout
<< " Archive: " << DeNull(F
.Archive()) << endl
;
382 cout
<< " Component: " << DeNull(F
.Component()) << endl
;
383 cout
<< " Version: " << DeNull(F
.Version()) << endl
;
384 cout
<< " Origin: " << DeNull(F
.Origin()) << endl
;
385 cout
<< " Site: " << DeNull(F
.Site()) << endl
;
386 cout
<< " Label: " << DeNull(F
.Label()) << endl
;
387 cout
<< " Architecture: " << DeNull(F
.Architecture()) << endl
;
393 // DumpAvail - Print out the available list /*{{{*/
394 // ---------------------------------------------------------------------
395 /* This is needed to make dpkg --merge happy.. I spent a bit of time to
396 make this run really fast, perhaps I went a little overboard.. */
397 bool DumpAvail(CommandLine
&Cmd
)
399 pkgCache
&Cache
= *GCache
;
401 pkgPolicy
Plcy(&Cache
);
402 if (ReadPinFile(Plcy
) == false || ReadPinDir(Plcy
) == false)
405 unsigned long Count
= Cache
.HeaderP
->PackageCount
+1;
406 pkgCache::VerFile
**VFList
= new pkgCache::VerFile
*[Count
];
407 memset(VFList
,0,sizeof(*VFList
)*Count
);
409 // Map versions that we want to write out onto the VerList array.
410 for (pkgCache::PkgIterator P
= Cache
.PkgBegin(); P
.end() == false; P
++)
412 if (P
->VersionList
== 0)
415 /* Find the proper version to use. If the policy says there are no
416 possible selections we return the installed version, if available..
417 This prevents dselect from making it obsolete. */
418 pkgCache::VerIterator V
= Plcy
.GetCandidateVer(P
);
421 if (P
->CurrentVer
== 0)
426 pkgCache::VerFileIterator VF
= V
.FileList();
427 for (; VF
.end() == false ; VF
++)
428 if ((VF
.File()->Flags
& pkgCache::Flag::NotSource
) == 0)
431 /* Okay, here we have a bit of a problem.. The policy has selected the
432 currently installed package - however it only exists in the
433 status file.. We need to write out something or dselect will mark
434 the package as obsolete! Thus we emit the status file entry, but
435 below we remove the status line to make it valid for the
436 available file. However! We only do this if their do exist *any*
437 non-source versions of the package - that way the dselect obsolete
438 handling works OK. */
439 if (VF
.end() == true)
441 for (pkgCache::VerIterator Cur
= P
.VersionList(); Cur
.end() != true; Cur
++)
443 for (VF
= Cur
.FileList(); VF
.end() == false; VF
++)
445 if ((VF
.File()->Flags
& pkgCache::Flag::NotSource
) == 0)
452 if (VF
.end() == false)
460 LocalitySort(VFList
,Count
,sizeof(*VFList
));
462 // Iterate over all the package files and write them out.
463 char *Buffer
= new char[Cache
.HeaderP
->MaxVerFileSize
+10];
464 for (pkgCache::VerFile
**J
= VFList
; *J
!= 0;)
466 pkgCache::PkgFileIterator
File(Cache
,(*J
)->File
+ Cache
.PkgFileP
);
467 if (File
.IsOk() == false)
469 _error
->Error(_("Package file %s is out of sync."),File
.FileName());
473 FileFd
PkgF(File
.FileName(),FileFd::ReadOnly
);
474 if (_error
->PendingError() == true)
477 /* Write all of the records from this package file, since we
478 already did locality sorting we can now just seek through the
479 file in read order. We apply 1 more optimization here, since often
480 there will be < 1 byte gaps between records (for the \n) we read that
481 into the next buffer and offset a bit.. */
482 unsigned long Pos
= 0;
485 if ((*J
)->File
+ Cache
.PkgFileP
!= File
)
488 const pkgCache::VerFile
&VF
= **J
;
490 // Read the record and then write it out again.
491 unsigned long Jitter
= VF
.Offset
- Pos
;
494 if (PkgF
.Seek(VF
.Offset
) == false)
499 if (PkgF
.Read(Buffer
,VF
.Size
+ Jitter
) == false)
501 Buffer
[VF
.Size
+ Jitter
] = '\n';
504 if ((File
->Flags
& pkgCache::Flag::NotSource
) == pkgCache::Flag::NotSource
)
507 TFRewriteData RW
[] = {{"Status",0},{"Config-Version",0},{}};
508 const char *Zero
= 0;
509 if (Tags
.Scan(Buffer
+Jitter
,VF
.Size
+1) == false ||
510 TFRewrite(stdout
,Tags
,&Zero
,RW
) == false)
512 _error
->Error("Internal Error, Unable to parse a package record");
519 if (fwrite(Buffer
+Jitter
,VF
.Size
+1,1,stdout
) != 1)
523 Pos
= VF
.Offset
+ VF
.Size
;
527 if (_error
->PendingError() == true)
533 return !_error
->PendingError();
536 // Depends - Print out a dependency tree /*{{{*/
537 // ---------------------------------------------------------------------
539 bool Depends(CommandLine
&CmdL
)
541 pkgCache
&Cache
= *GCache
;
542 SPtrArray
<unsigned> Colours
= new unsigned[Cache
.Head().PackageCount
];
543 memset(Colours
,0,sizeof(*Colours
)*Cache
.Head().PackageCount
);
545 for (const char **I
= CmdL
.FileList
+ 1; *I
!= 0; I
++)
547 pkgCache::PkgIterator Pkg
= Cache
.FindPkg(*I
);
548 if (Pkg
.end() == true)
550 _error
->Warning(_("Unable to locate package %s"),*I
);
553 Colours
[Pkg
->ID
] = 1;
556 bool Recurse
= _config
->FindB("APT::Cache::RecurseDepends",false);
557 bool Installed
= _config
->FindB("APT::Cache::Installed",false);
558 bool Important
= _config
->FindB("APT::Cache::Important",false);
562 DidSomething
= false;
563 for (pkgCache::PkgIterator Pkg
= Cache
.PkgBegin(); Pkg
.end() == false; Pkg
++)
565 if (Colours
[Pkg
->ID
] != 1)
567 Colours
[Pkg
->ID
] = 2;
570 pkgCache::VerIterator Ver
= Pkg
.VersionList();
571 if (Ver
.end() == true)
573 cout
<< '<' << Pkg
.Name() << '>' << endl
;
577 cout
<< Pkg
.Name() << endl
;
579 for (pkgCache::DepIterator D
= Ver
.DependsList(); D
.end() == false; D
++)
581 // Important deps only
582 if (Important
== true)
583 if (D
->Type
!= pkgCache::Dep::PreDepends
&&
584 D
->Type
!= pkgCache::Dep::Depends
)
587 pkgCache::PkgIterator Trg
= D
.TargetPkg();
589 if((Installed
&& Trg
->CurrentVer
!= 0) || !Installed
)
592 if ((D
->CompareOp
& pkgCache::Dep::Or
) == pkgCache::Dep::Or
)
598 if (Trg
->VersionList
== 0)
599 cout
<< D
.DepType() << ": <" << Trg
.Name() << ">" << endl
;
601 cout
<< D
.DepType() << ": " << Trg
.Name() << endl
;
604 Colours
[D
.TargetPkg()->ID
]++;
608 // Display all solutions
609 SPtrArray
<pkgCache::Version
*> List
= D
.AllTargets();
610 pkgPrioSortList(Cache
,List
);
611 for (pkgCache::Version
**I
= List
; *I
!= 0; I
++)
613 pkgCache::VerIterator
V(Cache
,*I
);
614 if (V
!= Cache
.VerP
+ V
.ParentPkg()->VersionList
||
615 V
->ParentPkg
== D
->Package
)
617 cout
<< " " << V
.ParentPkg().Name() << endl
;
620 Colours
[D
.ParentPkg()->ID
]++;
625 while (DidSomething
== true);
630 // RDepends - Print out a reverse dependency tree - mbc /*{{{*/
631 // ---------------------------------------------------------------------
633 bool RDepends(CommandLine
&CmdL
)
635 pkgCache
&Cache
= *GCache
;
636 SPtrArray
<unsigned> Colours
= new unsigned[Cache
.Head().PackageCount
];
637 memset(Colours
,0,sizeof(*Colours
)*Cache
.Head().PackageCount
);
639 for (const char **I
= CmdL
.FileList
+ 1; *I
!= 0; I
++)
641 pkgCache::PkgIterator Pkg
= Cache
.FindPkg(*I
);
642 if (Pkg
.end() == true)
644 _error
->Warning(_("Unable to locate package %s"),*I
);
647 Colours
[Pkg
->ID
] = 1;
650 bool Recurse
= _config
->FindB("APT::Cache::RecurseDepends",false);
651 bool Installed
= _config
->FindB("APT::Cache::Installed",false);
655 DidSomething
= false;
656 for (pkgCache::PkgIterator Pkg
= Cache
.PkgBegin(); Pkg
.end() == false; Pkg
++)
658 if (Colours
[Pkg
->ID
] != 1)
660 Colours
[Pkg
->ID
] = 2;
663 pkgCache::VerIterator Ver
= Pkg
.VersionList();
664 if (Ver
.end() == true)
666 cout
<< '<' << Pkg
.Name() << '>' << endl
;
670 cout
<< Pkg
.Name() << endl
;
672 cout
<< "Reverse Depends:" << endl
;
673 for (pkgCache::DepIterator D
= Pkg
.RevDependsList(); D
.end() == false; D
++)
676 pkgCache::PkgIterator Trg
= D
.ParentPkg();
678 if((Installed
&& Trg
->CurrentVer
!= 0) || !Installed
)
681 if ((D
->CompareOp
& pkgCache::Dep::Or
) == pkgCache::Dep::Or
)
686 if (Trg
->VersionList
== 0)
687 cout
<< D
.DepType() << ": <" << Trg
.Name() << ">" << endl
;
689 cout
<< Trg
.Name() << endl
;
692 Colours
[D
.ParentPkg()->ID
]++;
696 // Display all solutions
697 SPtrArray
<pkgCache::Version
*> List
= D
.AllTargets();
698 pkgPrioSortList(Cache
,List
);
699 for (pkgCache::Version
**I
= List
; *I
!= 0; I
++)
701 pkgCache::VerIterator
V(Cache
,*I
);
702 if (V
!= Cache
.VerP
+ V
.ParentPkg()->VersionList
||
703 V
->ParentPkg
== D
->Package
)
705 cout
<< " " << V
.ParentPkg().Name() << endl
;
708 Colours
[D
.ParentPkg()->ID
]++;
713 while (DidSomething
== true);
718 // xvcg - Generate a graph for xvcg /*{{{*/
719 // ---------------------------------------------------------------------
720 // Code contributed from Junichi Uekawa <dancer@debian.org> on 20 June 2002.
722 bool XVcg(CommandLine
&CmdL
)
724 pkgCache
&Cache
= *GCache
;
725 bool GivenOnly
= _config
->FindB("APT::Cache::GivenOnly",false);
727 /* Normal packages are boxes
728 Pure Provides are triangles
730 rhomb are missing packages*/
731 const char *Shapes
[] = {"ellipse","triangle","box","rhomb"};
733 /* Initialize the list of packages to show.
735 2 = To Show no recurse
736 3 = Emitted no recurse
739 enum States
{None
=0, ToShow
, ToShowNR
, DoneNR
, Done
};
740 enum TheFlags
{ForceNR
=(1<<0)};
741 unsigned char *Show
= new unsigned char[Cache
.Head().PackageCount
];
742 unsigned char *Flags
= new unsigned char[Cache
.Head().PackageCount
];
743 unsigned char *ShapeMap
= new unsigned char[Cache
.Head().PackageCount
];
745 // Show everything if no arguments given
746 if (CmdL
.FileList
[1] == 0)
747 for (unsigned long I
= 0; I
!= Cache
.Head().PackageCount
; I
++)
750 for (unsigned long I
= 0; I
!= Cache
.Head().PackageCount
; I
++)
752 memset(Flags
,0,sizeof(*Flags
)*Cache
.Head().PackageCount
);
755 for (pkgCache::PkgIterator Pkg
= Cache
.PkgBegin(); Pkg
.end() == false; Pkg
++)
757 if (Pkg
->VersionList
== 0)
760 if (Pkg
->ProvidesList
== 0)
761 ShapeMap
[Pkg
->ID
] = 0;
763 ShapeMap
[Pkg
->ID
] = 1;
768 if (Pkg
->ProvidesList
== 0)
769 ShapeMap
[Pkg
->ID
] = 2;
771 ShapeMap
[Pkg
->ID
] = 3;
775 // Load the list of packages from the command line into the show list
776 for (const char **I
= CmdL
.FileList
+ 1; *I
!= 0; I
++)
778 // Process per-package flags
783 if (P
.end()[-1] == '^')
789 if (P
.end()[-1] == ',')
793 // Locate the package
794 pkgCache::PkgIterator Pkg
= Cache
.FindPkg(P
);
795 if (Pkg
.end() == true)
797 _error
->Warning(_("Unable to locate package %s"),*I
);
800 Show
[Pkg
->ID
] = ToShow
;
803 Flags
[Pkg
->ID
] |= ForceNR
;
807 cout
<< "graph: { title: \"packages\"" << endl
<<
808 "xmax: 700 ymax: 700 x: 30 y: 30" << endl
<<
809 "layout_downfactor: 8" << endl
;
815 for (pkgCache::PkgIterator Pkg
= Cache
.PkgBegin(); Pkg
.end() == false; Pkg
++)
817 // See we need to show this package
818 if (Show
[Pkg
->ID
] == None
|| Show
[Pkg
->ID
] >= DoneNR
)
821 //printf ("node: { title: \"%s\" label: \"%s\" }\n", Pkg.Name(), Pkg.Name());
824 if (Show
[Pkg
->ID
] == ToShowNR
|| (Flags
[Pkg
->ID
] & ForceNR
) == ForceNR
)
826 // Pure Provides and missing packages have no deps!
827 if (ShapeMap
[Pkg
->ID
] == 0 || ShapeMap
[Pkg
->ID
] == 1)
828 Show
[Pkg
->ID
] = Done
;
830 Show
[Pkg
->ID
] = DoneNR
;
833 Show
[Pkg
->ID
] = Done
;
836 // No deps to map out
837 if (Pkg
->VersionList
== 0 || Show
[Pkg
->ID
] == DoneNR
)
840 pkgCache::VerIterator Ver
= Pkg
.VersionList();
841 for (pkgCache::DepIterator D
= Ver
.DependsList(); D
.end() == false; D
++)
843 // See if anything can meet this dep
844 // Walk along the actual package providing versions
846 pkgCache::PkgIterator DPkg
= D
.TargetPkg();
847 for (pkgCache::VerIterator I
= DPkg
.VersionList();
848 I
.end() == false && Hit
== false; I
++)
850 if (Cache
.VS
->CheckDep(I
.VerStr(),D
->CompareOp
,D
.TargetVer()) == true)
854 // Follow all provides
855 for (pkgCache::PrvIterator I
= DPkg
.ProvidesList();
856 I
.end() == false && Hit
== false; I
++)
858 if (Cache
.VS
->CheckDep(I
.ProvideVersion(),D
->CompareOp
,D
.TargetVer()) == false)
863 // Only graph critical deps
864 if (D
.IsCritical() == true)
866 printf ("edge: { sourcename: \"%s\" targetname: \"%s\" class: 2 ",Pkg
.Name(), D
.TargetPkg().Name() );
868 // Colour the node for recursion
869 if (Show
[D
.TargetPkg()->ID
] <= DoneNR
)
871 /* If a conflicts does not meet anything in the database
872 then show the relation but do not recurse */
874 (D
->Type
== pkgCache::Dep::Conflicts
||
875 D
->Type
== pkgCache::Dep::DpkgBreaks
||
876 D
->Type
== pkgCache::Dep::Obsoletes
))
878 if (Show
[D
.TargetPkg()->ID
] == None
&&
879 Show
[D
.TargetPkg()->ID
] != ToShow
)
880 Show
[D
.TargetPkg()->ID
] = ToShowNR
;
884 if (GivenOnly
== true && Show
[D
.TargetPkg()->ID
] != ToShow
)
885 Show
[D
.TargetPkg()->ID
] = ToShowNR
;
887 Show
[D
.TargetPkg()->ID
] = ToShow
;
894 case pkgCache::Dep::Conflicts
:
895 printf("label: \"conflicts\" color: lightgreen }\n");
897 case pkgCache::Dep::DpkgBreaks
:
898 printf("label: \"breaks\" color: lightgreen }\n");
900 case pkgCache::Dep::Obsoletes
:
901 printf("label: \"obsoletes\" color: lightgreen }\n");
904 case pkgCache::Dep::PreDepends
:
905 printf("label: \"predepends\" color: blue }\n");
917 /* Draw the box colours after the fact since we can not tell what colour
918 they should be until everything is finished drawing */
919 for (pkgCache::PkgIterator Pkg
= Cache
.PkgBegin(); Pkg
.end() == false; Pkg
++)
921 if (Show
[Pkg
->ID
] < DoneNR
)
924 if (Show
[Pkg
->ID
] == DoneNR
)
925 printf("node: { title: \"%s\" label: \"%s\" color: orange shape: %s }\n", Pkg
.Name(), Pkg
.Name(),
926 Shapes
[ShapeMap
[Pkg
->ID
]]);
928 printf("node: { title: \"%s\" label: \"%s\" shape: %s }\n", Pkg
.Name(), Pkg
.Name(),
929 Shapes
[ShapeMap
[Pkg
->ID
]]);
937 // Dotty - Generate a graph for Dotty /*{{{*/
938 // ---------------------------------------------------------------------
939 /* Dotty is the graphvis program for generating graphs. It is a fairly
940 simple queuing algorithm that just writes dependencies and nodes.
941 http://www.research.att.com/sw/tools/graphviz/ */
942 bool Dotty(CommandLine
&CmdL
)
944 pkgCache
&Cache
= *GCache
;
945 bool GivenOnly
= _config
->FindB("APT::Cache::GivenOnly",false);
947 /* Normal packages are boxes
948 Pure Provides are triangles
950 Hexagons are missing packages*/
951 const char *Shapes
[] = {"hexagon","triangle","box","diamond"};
953 /* Initialize the list of packages to show.
955 2 = To Show no recurse
956 3 = Emitted no recurse
959 enum States
{None
=0, ToShow
, ToShowNR
, DoneNR
, Done
};
960 enum TheFlags
{ForceNR
=(1<<0)};
961 unsigned char *Show
= new unsigned char[Cache
.Head().PackageCount
];
962 unsigned char *Flags
= new unsigned char[Cache
.Head().PackageCount
];
963 unsigned char *ShapeMap
= new unsigned char[Cache
.Head().PackageCount
];
965 // Show everything if no arguments given
966 if (CmdL
.FileList
[1] == 0)
967 for (unsigned long I
= 0; I
!= Cache
.Head().PackageCount
; I
++)
970 for (unsigned long I
= 0; I
!= Cache
.Head().PackageCount
; I
++)
972 memset(Flags
,0,sizeof(*Flags
)*Cache
.Head().PackageCount
);
975 for (pkgCache::PkgIterator Pkg
= Cache
.PkgBegin(); Pkg
.end() == false; Pkg
++)
977 if (Pkg
->VersionList
== 0)
980 if (Pkg
->ProvidesList
== 0)
981 ShapeMap
[Pkg
->ID
] = 0;
983 ShapeMap
[Pkg
->ID
] = 1;
988 if (Pkg
->ProvidesList
== 0)
989 ShapeMap
[Pkg
->ID
] = 2;
991 ShapeMap
[Pkg
->ID
] = 3;
995 // Load the list of packages from the command line into the show list
996 for (const char **I
= CmdL
.FileList
+ 1; *I
!= 0; I
++)
998 // Process per-package flags
1003 if (P
.end()[-1] == '^')
1009 if (P
.end()[-1] == ',')
1013 // Locate the package
1014 pkgCache::PkgIterator Pkg
= Cache
.FindPkg(P
);
1015 if (Pkg
.end() == true)
1017 _error
->Warning(_("Unable to locate package %s"),*I
);
1020 Show
[Pkg
->ID
] = ToShow
;
1023 Flags
[Pkg
->ID
] |= ForceNR
;
1027 printf("digraph packages {\n");
1028 printf("concentrate=true;\n");
1029 printf("size=\"30,40\";\n");
1035 for (pkgCache::PkgIterator Pkg
= Cache
.PkgBegin(); Pkg
.end() == false; Pkg
++)
1037 // See we need to show this package
1038 if (Show
[Pkg
->ID
] == None
|| Show
[Pkg
->ID
] >= DoneNR
)
1042 if (Show
[Pkg
->ID
] == ToShowNR
|| (Flags
[Pkg
->ID
] & ForceNR
) == ForceNR
)
1044 // Pure Provides and missing packages have no deps!
1045 if (ShapeMap
[Pkg
->ID
] == 0 || ShapeMap
[Pkg
->ID
] == 1)
1046 Show
[Pkg
->ID
] = Done
;
1048 Show
[Pkg
->ID
] = DoneNR
;
1051 Show
[Pkg
->ID
] = Done
;
1054 // No deps to map out
1055 if (Pkg
->VersionList
== 0 || Show
[Pkg
->ID
] == DoneNR
)
1058 pkgCache::VerIterator Ver
= Pkg
.VersionList();
1059 for (pkgCache::DepIterator D
= Ver
.DependsList(); D
.end() == false; D
++)
1061 // See if anything can meet this dep
1062 // Walk along the actual package providing versions
1064 pkgCache::PkgIterator DPkg
= D
.TargetPkg();
1065 for (pkgCache::VerIterator I
= DPkg
.VersionList();
1066 I
.end() == false && Hit
== false; I
++)
1068 if (Cache
.VS
->CheckDep(I
.VerStr(),D
->CompareOp
,D
.TargetVer()) == true)
1072 // Follow all provides
1073 for (pkgCache::PrvIterator I
= DPkg
.ProvidesList();
1074 I
.end() == false && Hit
== false; I
++)
1076 if (Cache
.VS
->CheckDep(I
.ProvideVersion(),D
->CompareOp
,D
.TargetVer()) == false)
1080 // Only graph critical deps
1081 if (D
.IsCritical() == true)
1083 printf("\"%s\" -> \"%s\"",Pkg
.Name(),D
.TargetPkg().Name());
1085 // Colour the node for recursion
1086 if (Show
[D
.TargetPkg()->ID
] <= DoneNR
)
1088 /* If a conflicts does not meet anything in the database
1089 then show the relation but do not recurse */
1091 (D
->Type
== pkgCache::Dep::Conflicts
||
1092 D
->Type
== pkgCache::Dep::Obsoletes
))
1094 if (Show
[D
.TargetPkg()->ID
] == None
&&
1095 Show
[D
.TargetPkg()->ID
] != ToShow
)
1096 Show
[D
.TargetPkg()->ID
] = ToShowNR
;
1100 if (GivenOnly
== true && Show
[D
.TargetPkg()->ID
] != ToShow
)
1101 Show
[D
.TargetPkg()->ID
] = ToShowNR
;
1103 Show
[D
.TargetPkg()->ID
] = ToShow
;
1110 case pkgCache::Dep::Conflicts
:
1111 case pkgCache::Dep::Obsoletes
:
1112 printf("[color=springgreen];\n");
1115 case pkgCache::Dep::PreDepends
:
1116 printf("[color=blue];\n");
1128 /* Draw the box colours after the fact since we can not tell what colour
1129 they should be until everything is finished drawing */
1130 for (pkgCache::PkgIterator Pkg
= Cache
.PkgBegin(); Pkg
.end() == false; Pkg
++)
1132 if (Show
[Pkg
->ID
] < DoneNR
)
1135 // Orange box for early recursion stoppage
1136 if (Show
[Pkg
->ID
] == DoneNR
)
1137 printf("\"%s\" [color=orange,shape=%s];\n",Pkg
.Name(),
1138 Shapes
[ShapeMap
[Pkg
->ID
]]);
1140 printf("\"%s\" [shape=%s];\n",Pkg
.Name(),
1141 Shapes
[ShapeMap
[Pkg
->ID
]]);
1148 // DoAdd - Perform an adding operation /*{{{*/
1149 // ---------------------------------------------------------------------
1151 bool DoAdd(CommandLine
&CmdL
)
1153 return _error
->Error("Unimplemented");
1155 // Make sure there is at least one argument
1156 if (CmdL
.FileSize() <= 1)
1157 return _error
->Error("You must give at least one file name");
1160 FileFd
CacheF(_config
->FindFile("Dir::Cache::pkgcache"),FileFd::WriteAny
);
1161 if (_error
->PendingError() == true)
1164 DynamicMMap
Map(CacheF
,MMap::Public
);
1165 if (_error
->PendingError() == true)
1168 OpTextProgress
Progress(*_config
);
1169 pkgCacheGenerator
Gen(Map
,Progress
);
1170 if (_error
->PendingError() == true)
1173 unsigned long Length
= CmdL
.FileSize() - 1;
1174 for (const char **I
= CmdL
.FileList
+ 1; *I
!= 0; I
++)
1176 Progress
.OverallProgress(I
- CmdL
.FileList
,Length
,1,"Generating cache");
1177 Progress
.SubProgress(Length
);
1180 FileFd
TagF(*I
,FileFd::ReadOnly
);
1181 debListParser
Parser(TagF
);
1182 if (_error
->PendingError() == true)
1183 return _error
->Error("Problem opening %s",*I
);
1185 if (Gen
.SelectFile(*I
,"") == false)
1186 return _error
->Error("Problem with SelectFile");
1188 if (Gen
.MergeList(Parser
) == false)
1189 return _error
->Error("Problem with MergeList");
1193 GCache
= &Gen
.GetCache();
1200 // DisplayRecord - Displays the complete record for the package /*{{{*/
1201 // ---------------------------------------------------------------------
1202 /* This displays the package record from the proper package index file.
1203 It is not used by DumpAvail for performance reasons. */
1204 bool DisplayRecord(pkgCache::VerIterator V
)
1206 // Find an appropriate file
1207 pkgCache::VerFileIterator Vf
= V
.FileList();
1208 for (; Vf
.end() == false; Vf
++)
1209 if ((Vf
.File()->Flags
& pkgCache::Flag::NotSource
) == 0)
1211 if (Vf
.end() == true)
1214 // Check and load the package list file
1215 pkgCache::PkgFileIterator I
= Vf
.File();
1216 if (I
.IsOk() == false)
1217 return _error
->Error(_("Package file %s is out of sync."),I
.FileName());
1219 FileFd
PkgF(I
.FileName(),FileFd::ReadOnly
);
1220 if (_error
->PendingError() == true)
1224 unsigned char *Buffer
= new unsigned char[GCache
->HeaderP
->MaxVerFileSize
+1];
1225 Buffer
[V
.FileList()->Size
] = '\n';
1226 if (PkgF
.Seek(V
.FileList()->Offset
) == false ||
1227 PkgF
.Read(Buffer
,V
.FileList()->Size
) == false)
1233 // Get a pointer to start of Description field
1234 const unsigned char *DescP
= (unsigned char*)strstr((char*)Buffer
, "Description:");
1236 // Write all but Description
1237 if (fwrite(Buffer
,1,DescP
- Buffer
,stdout
) < (size_t)(DescP
- Buffer
))
1243 // Show the right description
1244 pkgRecords
Recs(*GCache
);
1245 pkgCache::DescIterator Desc
= V
.TranslatedDescription();
1246 pkgRecords::Parser
&P
= Recs
.Lookup(Desc
.FileList());
1247 cout
<< "Description" << ( (strcmp(Desc
.LanguageCode(),"") != 0) ? "-" : "" ) << Desc
.LanguageCode() << ": " << P
.LongDesc();
1249 // Find the first field after the description (if there is any)
1250 for(DescP
++;DescP
!= &Buffer
[V
.FileList()->Size
];DescP
++)
1252 if(*DescP
== '\n' && *(DescP
+1) != ' ')
1254 // write the rest of the buffer
1255 const unsigned char *end
=&Buffer
[V
.FileList()->Size
];
1256 if (fwrite(DescP
,1,end
-DescP
,stdout
) < (size_t)(end
-DescP
))
1265 // write a final newline (after the description)
1272 // Search - Perform a search /*{{{*/
1273 // ---------------------------------------------------------------------
1274 /* This searches the package names and package descriptions for a pattern */
1277 pkgCache::DescFile
*Df
;
1281 // Search - Perform a search /*{{{*/
1282 // ---------------------------------------------------------------------
1283 /* This searches the package names and package descriptions for a pattern */
1284 bool Search(CommandLine
&CmdL
)
1286 pkgCache
&Cache
= *GCache
;
1287 bool ShowFull
= _config
->FindB("APT::Cache::ShowFull",false);
1288 bool NamesOnly
= _config
->FindB("APT::Cache::NamesOnly",false);
1289 unsigned NumPatterns
= CmdL
.FileSize() -1;
1291 pkgDepCache::Policy Plcy
;
1293 // Make sure there is at least one argument
1294 if (NumPatterns
< 1)
1295 return _error
->Error(_("You must give exactly one pattern"));
1297 // Compile the regex pattern
1298 regex_t
*Patterns
= new regex_t
[NumPatterns
];
1299 memset(Patterns
,0,sizeof(*Patterns
)*NumPatterns
);
1300 for (unsigned I
= 0; I
!= NumPatterns
; I
++)
1302 if (regcomp(&Patterns
[I
],CmdL
.FileList
[I
+1],REG_EXTENDED
| REG_ICASE
|
1306 regfree(&Patterns
[I
]);
1307 return _error
->Error("Regex compilation error");
1311 // Create the text record parser
1312 pkgRecords
Recs(Cache
);
1313 if (_error
->PendingError() == true)
1315 for (unsigned I
= 0; I
!= NumPatterns
; I
++)
1316 regfree(&Patterns
[I
]);
1320 ExDescFile
*DFList
= new ExDescFile
[Cache
.HeaderP
->PackageCount
+1];
1321 memset(DFList
,0,sizeof(*DFList
)*Cache
.HeaderP
->PackageCount
+1);
1323 // Map versions that we want to write out onto the VerList array.
1324 for (pkgCache::PkgIterator P
= Cache
.PkgBegin(); P
.end() == false; P
++)
1326 DFList
[P
->ID
].NameMatch
= NumPatterns
!= 0;
1327 for (unsigned I
= 0; I
!= NumPatterns
; I
++)
1329 if (regexec(&Patterns
[I
],P
.Name(),0,0,0) == 0)
1330 DFList
[P
->ID
].NameMatch
&= true;
1332 DFList
[P
->ID
].NameMatch
= false;
1335 // Doing names only, drop any that dont match..
1336 if (NamesOnly
== true && DFList
[P
->ID
].NameMatch
== false)
1339 // Find the proper version to use.
1340 pkgCache::VerIterator V
= Plcy
.GetCandidateVer(P
);
1341 if (V
.end() == false)
1342 DFList
[P
->ID
].Df
= V
.DescriptionList().FileList();
1345 // Include all the packages that provide matching names too
1346 for (pkgCache::PkgIterator P
= Cache
.PkgBegin(); P
.end() == false; P
++)
1348 if (DFList
[P
->ID
].NameMatch
== false)
1351 for (pkgCache::PrvIterator Prv
= P
.ProvidesList() ; Prv
.end() == false; Prv
++)
1353 pkgCache::VerIterator V
= Plcy
.GetCandidateVer(Prv
.OwnerPkg());
1354 if (V
.end() == false)
1356 DFList
[Prv
.OwnerPkg()->ID
].Df
= V
.DescriptionList().FileList();
1357 DFList
[Prv
.OwnerPkg()->ID
].NameMatch
= true;
1362 LocalitySort(&DFList
->Df
,Cache
.HeaderP
->PackageCount
,sizeof(*DFList
));
1364 // Iterate over all the version records and check them
1365 for (ExDescFile
*J
= DFList
; J
->Df
!= 0; J
++)
1367 pkgRecords::Parser
&P
= Recs
.Lookup(pkgCache::DescFileIterator(Cache
,J
->Df
));
1370 if (J
->NameMatch
== false)
1372 string LongDesc
= P
.LongDesc();
1373 Match
= NumPatterns
!= 0;
1374 for (unsigned I
= 0; I
!= NumPatterns
; I
++)
1376 if (regexec(&Patterns
[I
],LongDesc
.c_str(),0,0,0) == 0)
1385 if (ShowFull
== true)
1389 P
.GetRec(Start
,End
);
1390 fwrite(Start
,End
-Start
,1,stdout
);
1394 printf("%s - %s\n",P
.Name().c_str(),P
.ShortDesc().c_str());
1399 for (unsigned I
= 0; I
!= NumPatterns
; I
++)
1400 regfree(&Patterns
[I
]);
1402 return _error
->Error("Write to stdout failed");
1406 // ShowPackage - Dump the package record to the screen /*{{{*/
1407 // ---------------------------------------------------------------------
1409 bool ShowPackage(CommandLine
&CmdL
)
1411 pkgCache
&Cache
= *GCache
;
1412 pkgDepCache::Policy Plcy
;
1416 for (const char **I
= CmdL
.FileList
+ 1; *I
!= 0; I
++)
1418 pkgCache::PkgIterator Pkg
= Cache
.FindPkg(*I
);
1419 if (Pkg
.end() == true)
1421 _error
->Warning(_("Unable to locate package %s"),*I
);
1427 // Find the proper version to use.
1428 if (_config
->FindB("APT::Cache::AllVersions","true") == true)
1430 pkgCache::VerIterator V
;
1431 for (V
= Pkg
.VersionList(); V
.end() == false; V
++)
1433 if (DisplayRecord(V
) == false)
1439 pkgCache::VerIterator V
= Plcy
.GetCandidateVer(Pkg
);
1440 if (V
.end() == true || V
.FileList().end() == true)
1442 if (DisplayRecord(V
) == false)
1449 return _error
->Error(_("No packages found"));
1452 // ShowPkgNames - Show package names /*{{{*/
1453 // ---------------------------------------------------------------------
1454 /* This does a prefix match on the first argument */
1455 bool ShowPkgNames(CommandLine
&CmdL
)
1457 pkgCache
&Cache
= *GCache
;
1458 pkgCache::PkgIterator I
= Cache
.PkgBegin();
1459 bool All
= _config
->FindB("APT::Cache::AllNames","false");
1461 if (CmdL
.FileList
[1] != 0)
1463 for (;I
.end() != true; I
++)
1465 if (All
== false && I
->VersionList
== 0)
1468 if (strncmp(I
.Name(),CmdL
.FileList
[1],strlen(CmdL
.FileList
[1])) == 0)
1469 cout
<< I
.Name() << endl
;
1476 for (;I
.end() != true; I
++)
1478 if (All
== false && I
->VersionList
== 0)
1480 cout
<< I
.Name() << endl
;
1486 // ShowSrcPackage - Show source package records /*{{{*/
1487 // ---------------------------------------------------------------------
1489 bool ShowSrcPackage(CommandLine
&CmdL
)
1492 List
.ReadMainList();
1494 // Create the text record parsers
1495 pkgSrcRecords
SrcRecs(List
);
1496 if (_error
->PendingError() == true)
1499 for (const char **I
= CmdL
.FileList
+ 1; *I
!= 0; I
++)
1503 pkgSrcRecords::Parser
*Parse
;
1504 while ((Parse
= SrcRecs
.Find(*I
,false)) != 0)
1505 cout
<< Parse
->AsStr() << endl
;;
1510 // Policy - Show the results of the preferences file /*{{{*/
1511 // ---------------------------------------------------------------------
1513 bool Policy(CommandLine
&CmdL
)
1516 return _error
->Error("Generate must be enabled for this function");
1518 pkgCache
&Cache
= *GCache
;
1519 pkgPolicy
Plcy(&Cache
);
1520 if (ReadPinFile(Plcy
) == false || ReadPinDir(Plcy
) == false)
1523 // Print out all of the package files
1524 if (CmdL
.FileList
[1] == 0)
1526 cout
<< _("Package files:") << endl
;
1527 for (pkgCache::PkgFileIterator F
= Cache
.FileBegin(); F
.end() == false; F
++)
1529 // Locate the associated index files so we can derive a description
1531 if (SrcList
->FindIndex(F
,Indx
) == false &&
1532 _system
->FindIndex(F
,Indx
) == false)
1533 return _error
->Error(_("Cache is out of sync, can't x-ref a package file"));
1536 Plcy
.GetPriority(F
),Indx
->Describe(true).c_str());
1538 // Print the reference information for the package
1539 string Str
= F
.RelStr();
1540 if (Str
.empty() == false)
1541 printf(" release %s\n",F
.RelStr().c_str());
1542 if (F
.Site() != 0 && F
.Site()[0] != 0)
1543 printf(" origin %s\n",F
.Site());
1546 // Show any packages have explicit pins
1547 cout
<< _("Pinned packages:") << endl
;
1548 pkgCache::PkgIterator I
= Cache
.PkgBegin();
1549 for (;I
.end() != true; I
++)
1551 if (Plcy
.GetPriority(I
) == 0)
1554 // Print the package name and the version we are forcing to
1555 cout
<< " " << I
.Name() << " -> ";
1557 pkgCache::VerIterator V
= Plcy
.GetMatch(I
);
1558 if (V
.end() == true)
1559 cout
<< _("(not found)") << endl
;
1561 cout
<< V
.VerStr() << endl
;
1567 // Print out detailed information for each package
1568 for (const char **I
= CmdL
.FileList
+ 1; *I
!= 0; I
++)
1570 pkgCache::PkgIterator Pkg
= Cache
.FindPkg(*I
);
1571 if (Pkg
.end() == true)
1573 _error
->Warning(_("Unable to locate package %s"),*I
);
1577 cout
<< Pkg
.Name() << ":" << endl
;
1579 // Installed version
1580 cout
<< _(" Installed: ");
1581 if (Pkg
->CurrentVer
== 0)
1582 cout
<< _("(none)") << endl
;
1584 cout
<< Pkg
.CurrentVer().VerStr() << endl
;
1586 // Candidate Version
1587 cout
<< _(" Candidate: ");
1588 pkgCache::VerIterator V
= Plcy
.GetCandidateVer(Pkg
);
1589 if (V
.end() == true)
1590 cout
<< _("(none)") << endl
;
1592 cout
<< V
.VerStr() << endl
;
1595 if (Plcy
.GetPriority(Pkg
) != 0)
1597 cout
<< _(" Package pin: ");
1598 V
= Plcy
.GetMatch(Pkg
);
1599 if (V
.end() == true)
1600 cout
<< _("(not found)") << endl
;
1602 cout
<< V
.VerStr() << endl
;
1605 // Show the priority tables
1606 cout
<< _(" Version table:") << endl
;
1607 for (V
= Pkg
.VersionList(); V
.end() == false; V
++)
1609 if (Pkg
.CurrentVer() == V
)
1610 cout
<< " *** " << V
.VerStr();
1612 cout
<< " " << V
.VerStr();
1613 cout
<< " " << Plcy
.GetPriority(Pkg
) << endl
;
1614 for (pkgCache::VerFileIterator VF
= V
.FileList(); VF
.end() == false; VF
++)
1616 // Locate the associated index files so we can derive a description
1618 if (SrcList
->FindIndex(VF
.File(),Indx
) == false &&
1619 _system
->FindIndex(VF
.File(),Indx
) == false)
1620 return _error
->Error(_("Cache is out of sync, can't x-ref a package file"));
1621 printf(_(" %4i %s\n"),Plcy
.GetPriority(VF
.File()),
1622 Indx
->Describe(true).c_str());
1630 // Madison - Look a bit like katie's madison /*{{{*/
1631 // ---------------------------------------------------------------------
1633 bool Madison(CommandLine
&CmdL
)
1636 return _error
->Error("Generate must be enabled for this function");
1638 SrcList
->ReadMainList();
1640 pkgCache
&Cache
= *GCache
;
1642 // Create the src text record parsers and ignore errors about missing
1643 // deb-src lines that are generated from pkgSrcRecords::pkgSrcRecords
1644 pkgSrcRecords
SrcRecs(*SrcList
);
1645 if (_error
->PendingError() == true)
1648 for (const char **I
= CmdL
.FileList
+ 1; *I
!= 0; I
++)
1650 pkgCache::PkgIterator Pkg
= Cache
.FindPkg(*I
);
1652 if (Pkg
.end() == false)
1654 for (pkgCache::VerIterator V
= Pkg
.VersionList(); V
.end() == false; V
++)
1656 for (pkgCache::VerFileIterator VF
= V
.FileList(); VF
.end() == false; VF
++)
1658 // This might be nice, but wouldn't uniquely identify the source -mdz
1659 // if (VF.File().Archive() != 0)
1661 // cout << setw(10) << Pkg.Name() << " | " << setw(10) << V.VerStr() << " | "
1662 // << VF.File().Archive() << endl;
1665 // Locate the associated index files so we can derive a description
1666 for (pkgSourceList::const_iterator S
= SrcList
->begin(); S
!= SrcList
->end(); S
++)
1668 vector
<pkgIndexFile
*> *Indexes
= (*S
)->GetIndexFiles();
1669 for (vector
<pkgIndexFile
*>::const_iterator IF
= Indexes
->begin();
1670 IF
!= Indexes
->end(); IF
++)
1672 if ((*IF
)->FindInCache(*(VF
.File().Cache())) == VF
.File())
1674 cout
<< setw(10) << Pkg
.Name() << " | " << setw(10) << V
.VerStr() << " | "
1675 << (*IF
)->Describe(true) << endl
;
1685 pkgSrcRecords::Parser
*SrcParser
;
1686 while ((SrcParser
= SrcRecs
.Find(*I
,false)) != 0)
1688 // Maybe support Release info here too eventually
1689 cout
<< setw(10) << SrcParser
->Package() << " | "
1690 << setw(10) << SrcParser
->Version() << " | "
1691 << SrcParser
->Index().Describe(true) << endl
;
1698 // GenCaches - Call the main cache generator /*{{{*/
1699 // ---------------------------------------------------------------------
1701 bool GenCaches(CommandLine
&Cmd
)
1703 OpTextProgress
Progress(*_config
);
1706 if (List
.ReadMainList() == false)
1708 return pkgMakeStatusCache(List
,Progress
);
1711 // ShowHelp - Show a help screen /*{{{*/
1712 // ---------------------------------------------------------------------
1714 bool ShowHelp(CommandLine
&Cmd
)
1716 ioprintf(cout
,_("%s %s for %s compiled on %s %s\n"),PACKAGE
,VERSION
,
1717 COMMON_ARCH
,__DATE__
,__TIME__
);
1719 if (_config
->FindB("version") == true)
1723 _("Usage: apt-cache [options] command\n"
1724 " apt-cache [options] add file1 [file2 ...]\n"
1725 " apt-cache [options] showpkg pkg1 [pkg2 ...]\n"
1726 " apt-cache [options] showsrc pkg1 [pkg2 ...]\n"
1728 "apt-cache is a low-level tool used to manipulate APT's binary\n"
1729 "cache files, and query information from them\n"
1732 " add - Add a package file to the source cache\n"
1733 " gencaches - Build both the package and source cache\n"
1734 " showpkg - Show some general information for a single package\n"
1735 " showsrc - Show source records\n"
1736 " stats - Show some basic statistics\n"
1737 " dump - Show the entire file in a terse form\n"
1738 " dumpavail - Print an available file to stdout\n"
1739 " unmet - Show unmet dependencies\n"
1740 " search - Search the package list for a regex pattern\n"
1741 " show - Show a readable record for the package\n"
1742 " depends - Show raw dependency information for a package\n"
1743 " rdepends - Show reverse dependency information for a package\n"
1744 " pkgnames - List the names of all packages in the system\n"
1745 " dotty - Generate package graphs for GraphViz\n"
1746 " xvcg - Generate package graphs for xvcg\n"
1747 " policy - Show policy settings\n"
1750 " -h This help text.\n"
1751 " -p=? The package cache.\n"
1752 " -s=? The source cache.\n"
1753 " -q Disable progress indicator.\n"
1754 " -i Show only important deps for the unmet command.\n"
1755 " -c=? Read this configuration file\n"
1756 " -o=? Set an arbitrary configuration option, eg -o dir::cache=/tmp\n"
1757 "See the apt-cache(8) and apt.conf(5) manual pages for more information.\n");
1761 // CacheInitialize - Initialize things for apt-cache /*{{{*/
1762 // ---------------------------------------------------------------------
1764 void CacheInitialize()
1766 _config
->Set("quiet",0);
1767 _config
->Set("help",false);
1770 int main(int argc
,const char *argv
[]) /*{{{*/
1772 CommandLine::Args Args
[] = {
1773 {'h',"help","help",0},
1774 {'v',"version","version",0},
1775 {'p',"pkg-cache","Dir::Cache::pkgcache",CommandLine::HasArg
},
1776 {'s',"src-cache","Dir::Cache::srcpkgcache",CommandLine::HasArg
},
1777 {'q',"quiet","quiet",CommandLine::IntLevel
},
1778 {'i',"important","APT::Cache::Important",0},
1779 {'f',"full","APT::Cache::ShowFull",0},
1780 {'g',"generate","APT::Cache::Generate",0},
1781 {'a',"all-versions","APT::Cache::AllVersions",0},
1782 {'n',"names-only","APT::Cache::NamesOnly",0},
1783 {0,"all-names","APT::Cache::AllNames",0},
1784 {0,"recurse","APT::Cache::RecurseDepends",0},
1785 {'c',"config-file",0,CommandLine::ConfigFile
},
1786 {'o',"option",0,CommandLine::ArbItem
},
1787 {0,"installed","APT::Cache::Installed",0},
1789 CommandLine::Dispatch CmdsA
[] = {{"help",&ShowHelp
},
1791 {"gencaches",&GenCaches
},
1792 {"showsrc",&ShowSrcPackage
},
1794 CommandLine::Dispatch CmdsB
[] = {{"showpkg",&DumpPackage
},
1797 {"dumpavail",&DumpAvail
},
1800 {"depends",&Depends
},
1801 {"rdepends",&RDepends
},
1804 {"show",&ShowPackage
},
1805 {"pkgnames",&ShowPkgNames
},
1807 {"madison",&Madison
},
1812 // Set up gettext support
1813 setlocale(LC_ALL
,"");
1814 textdomain(PACKAGE
);
1816 // Parse the command line and initialize the package library
1817 CommandLine
CmdL(Args
,_config
);
1818 if (pkgInitConfig(*_config
) == false ||
1819 CmdL
.Parse(argc
,argv
) == false ||
1820 pkgInitSystem(*_config
,_system
) == false)
1822 _error
->DumpErrors();
1826 // See if the help should be shown
1827 if (_config
->FindB("help") == true ||
1828 CmdL
.FileSize() == 0)
1834 // Deal with stdout not being a tty
1835 if (isatty(STDOUT_FILENO
) && _config
->FindI("quiet",0) < 1)
1836 _config
->Set("quiet","1");
1838 if (CmdL
.DispatchArg(CmdsA
,false) == false && _error
->PendingError() == false)
1841 if (_config
->FindB("APT::Cache::Generate",true) == false)
1843 Map
= new MMap(*new FileFd(_config
->FindFile("Dir::Cache::pkgcache"),
1844 FileFd::ReadOnly
),MMap::Public
|MMap::ReadOnly
);
1848 // Open the cache file
1849 SrcList
= new pkgSourceList
;
1850 SrcList
->ReadMainList();
1852 // Generate it and map it
1854 pkgMakeStatusCache(*SrcList
,Prog
,&Map
,true);
1857 if (_error
->PendingError() == false)
1859 pkgCache
Cache(Map
);
1861 if (_error
->PendingError() == false)
1862 CmdL
.DispatchArg(CmdsB
);
1867 // Print any errors or warnings found during parsing
1868 if (_error
->empty() == false)
1870 bool Errors
= _error
->PendingError();
1871 _error
->DumpErrors();
1872 return Errors
== true?100:0;