]>
git.saurik.com Git - apt.git/blob - cmdline/apt-cache.cc
891b108734fa9aa3330e0b0bb6692ef268c62ae1
1 // -*- mode: cpp; mode: fold -*-
3 // $Id: apt-cache.cc,v 1.72 2004/04/30 04:34:03 mdz Exp $
4 /* ######################################################################
6 apt-cache - Manages the cache files
8 apt-cache provides some functions fo manipulating the cache files.
9 It uses the command line interface common to all the APT tools.
11 Returns 100 on failure, 0 on success.
13 ##################################################################### */
15 // Include Files /*{{{*/
16 #include <apt-pkg/error.h>
18 #include <apt-pkg/pkgcachegen.h>
19 #include <apt-pkg/cachefile.h>
20 #include <apt-pkg/init.h>
21 #include <apt-pkg/progress.h>
22 #include <apt-pkg/sourcelist.h>
23 #include <apt-pkg/cmndline.h>
24 #include <apt-pkg/strutl.h>
25 #include <apt-pkg/pkgrecords.h>
26 #include <apt-pkg/srcrecords.h>
27 #include <apt-pkg/version.h>
28 #include <apt-pkg/policy.h>
29 #include <apt-pkg/tagfile.h>
30 #include <apt-pkg/algorithms.h>
31 #include <apt-pkg/sptr.h>
32 #include <apt-pkg/cacheset.h>
50 pkgSourceList
*SrcList
= 0;
52 // LocalitySort - Sort a version list by package file locality /*{{{*/
53 // ---------------------------------------------------------------------
55 int LocalityCompare(const void *a
, const void *b
)
57 pkgCache::VerFile
*A
= *(pkgCache::VerFile
**)a
;
58 pkgCache::VerFile
*B
= *(pkgCache::VerFile
**)b
;
67 if (A
->File
== B
->File
)
68 return A
->Offset
- B
->Offset
;
69 return A
->File
- B
->File
;
72 void LocalitySort(pkgCache::VerFile
**begin
,
73 unsigned long Count
,size_t Size
)
75 qsort(begin
,Count
,Size
,LocalityCompare
);
78 void LocalitySort(pkgCache::DescFile
**begin
,
79 unsigned long Count
,size_t Size
)
81 qsort(begin
,Count
,Size
,LocalityCompare
);
84 // UnMet - Show unmet dependencies /*{{{*/
85 // ---------------------------------------------------------------------
87 bool UnMet(CommandLine
&CmdL
)
89 pkgCache
&Cache
= *GCache
;
90 bool Important
= _config
->FindB("APT::Cache::Important",false);
92 for (pkgCache::PkgIterator P
= Cache
.PkgBegin(); P
.end() == false; P
++)
94 for (pkgCache::VerIterator V
= P
.VersionList(); V
.end() == false; V
++)
97 for (pkgCache::DepIterator D
= V
.DependsList(); D
.end() == false;)
100 pkgCache::DepIterator Start
;
101 pkgCache::DepIterator End
;
104 // Skip conflicts and replaces
105 if (End
->Type
!= pkgCache::Dep::PreDepends
&&
106 End
->Type
!= pkgCache::Dep::Depends
&&
107 End
->Type
!= pkgCache::Dep::Suggests
&&
108 End
->Type
!= pkgCache::Dep::Recommends
)
111 // Important deps only
112 if (Important
== true)
113 if (End
->Type
!= pkgCache::Dep::PreDepends
&&
114 End
->Type
!= pkgCache::Dep::Depends
)
117 // Verify the or group
119 pkgCache::DepIterator RealStart
= Start
;
122 // See if this dep is Ok
123 pkgCache::Version
**VList
= Start
.AllTargets();
144 ioprintf(cout
,_("Package %s version %s has an unmet dep:\n"),
145 P
.FullName(true).c_str(),V
.VerStr());
148 // Print out the dep type
149 cout
<< " " << End
.DepType() << ": ";
155 cout
<< Start
.TargetPkg().FullName(true);
156 if (Start
.TargetVer() != 0)
157 cout
<< " (" << Start
.CompType() << " " << Start
.TargetVer() <<
173 // DumpPackage - Show a dump of a package record /*{{{*/
174 // ---------------------------------------------------------------------
176 bool DumpPackage(CommandLine
&CmdL
)
178 pkgCache
&Cache
= *GCache
;
179 APT::PackageSet pkgset
= APT::PackageSet::FromCommandLine(Cache
, CmdL
.FileList
);
181 for (APT::PackageSet::const_iterator Pkg
= pkgset
.begin(); Pkg
!= pkgset
.end(); ++Pkg
)
183 cout
<< "Package: " << Pkg
.FullName(true) << endl
;
184 cout
<< "Versions: " << endl
;
185 for (pkgCache::VerIterator Cur
= Pkg
.VersionList(); Cur
.end() != true; Cur
++)
187 cout
<< Cur
.VerStr();
188 for (pkgCache::VerFileIterator Vf
= Cur
.FileList(); Vf
.end() == false; Vf
++)
189 cout
<< " (" << Vf
.File().FileName() << ")";
191 for (pkgCache::DescIterator D
= Cur
.DescriptionList(); D
.end() == false; D
++)
193 cout
<< " Description Language: " << D
.LanguageCode() << endl
194 << " File: " << D
.FileList().File().FileName() << endl
195 << " MD5: " << D
.md5() << endl
;
202 cout
<< "Reverse Depends: " << endl
;
203 for (pkgCache::DepIterator D
= Pkg
.RevDependsList(); D
.end() != true; D
++)
205 cout
<< " " << D
.ParentPkg().FullName(true) << ',' << D
.TargetPkg().FullName(true);
207 cout
<< ' ' << DeNull(D
.TargetVer()) << endl
;
212 cout
<< "Dependencies: " << endl
;
213 for (pkgCache::VerIterator Cur
= Pkg
.VersionList(); Cur
.end() != true; Cur
++)
215 cout
<< Cur
.VerStr() << " - ";
216 for (pkgCache::DepIterator Dep
= Cur
.DependsList(); Dep
.end() != true; Dep
++)
217 cout
<< Dep
.TargetPkg().FullName(true) << " (" << (int)Dep
->CompareOp
<< " " << DeNull(Dep
.TargetVer()) << ") ";
221 cout
<< "Provides: " << endl
;
222 for (pkgCache::VerIterator Cur
= Pkg
.VersionList(); Cur
.end() != true; Cur
++)
224 cout
<< Cur
.VerStr() << " - ";
225 for (pkgCache::PrvIterator Prv
= Cur
.ProvidesList(); Prv
.end() != true; Prv
++)
226 cout
<< Prv
.ParentPkg().FullName(true) << " ";
229 cout
<< "Reverse Provides: " << endl
;
230 for (pkgCache::PrvIterator Prv
= Pkg
.ProvidesList(); Prv
.end() != true; Prv
++)
231 cout
<< Prv
.OwnerPkg().FullName(true) << " " << Prv
.OwnerVer().VerStr() << endl
;
237 // Stats - Dump some nice statistics /*{{{*/
238 // ---------------------------------------------------------------------
240 bool Stats(CommandLine
&Cmd
)
242 pkgCache
&Cache
= *GCache
;
243 cout
<< _("Total package names: ") << Cache
.Head().GroupCount
<< " (" <<
244 SizeToStr(Cache
.Head().GroupCount
*Cache
.Head().GroupSz
) << ')' << endl
245 << _("Total package structures: ") << 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
.FullName(true) << 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().FullName(true) << ' ' <<
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 APT::PackageSet pkgset
= APT::PackageSet::FromCommandLine(Cache
, CmdL
.FileList
);
546 for (APT::PackageSet::const_iterator Pkg
= pkgset
.begin(); Pkg
!= pkgset
.end(); ++Pkg
)
547 Colours
[Pkg
->ID
] = 1;
549 bool Recurse
= _config
->FindB("APT::Cache::RecurseDepends",false);
550 bool Installed
= _config
->FindB("APT::Cache::Installed",false);
551 bool Important
= _config
->FindB("APT::Cache::Important",false);
555 DidSomething
= false;
556 for (pkgCache::PkgIterator Pkg
= Cache
.PkgBegin(); Pkg
.end() == false; Pkg
++)
558 if (Colours
[Pkg
->ID
] != 1)
560 Colours
[Pkg
->ID
] = 2;
563 pkgCache::VerIterator Ver
= Pkg
.VersionList();
564 if (Ver
.end() == true)
566 cout
<< '<' << Pkg
.FullName(true) << '>' << endl
;
570 cout
<< Pkg
.FullName(true) << endl
;
572 for (pkgCache::DepIterator D
= Ver
.DependsList(); D
.end() == false; D
++)
574 // Important deps only
575 if (Important
== true)
576 if (D
->Type
!= pkgCache::Dep::PreDepends
&&
577 D
->Type
!= pkgCache::Dep::Depends
)
580 pkgCache::PkgIterator Trg
= D
.TargetPkg();
582 if((Installed
&& Trg
->CurrentVer
!= 0) || !Installed
)
585 if ((D
->CompareOp
& pkgCache::Dep::Or
) == pkgCache::Dep::Or
)
591 if (Trg
->VersionList
== 0)
592 cout
<< D
.DepType() << ": <" << Trg
.FullName(true) << ">" << endl
;
594 cout
<< D
.DepType() << ": " << Trg
.FullName(true) << endl
;
597 Colours
[D
.TargetPkg()->ID
]++;
601 // Display all solutions
602 SPtrArray
<pkgCache::Version
*> List
= D
.AllTargets();
603 pkgPrioSortList(Cache
,List
);
604 for (pkgCache::Version
**I
= List
; *I
!= 0; I
++)
606 pkgCache::VerIterator
V(Cache
,*I
);
607 if (V
!= Cache
.VerP
+ V
.ParentPkg()->VersionList
||
608 V
->ParentPkg
== D
->Package
)
610 cout
<< " " << V
.ParentPkg().FullName(true) << endl
;
613 Colours
[D
.ParentPkg()->ID
]++;
618 while (DidSomething
== true);
623 // RDepends - Print out a reverse dependency tree - mbc /*{{{*/
624 // ---------------------------------------------------------------------
626 bool RDepends(CommandLine
&CmdL
)
628 pkgCache
&Cache
= *GCache
;
629 SPtrArray
<unsigned> Colours
= new unsigned[Cache
.Head().PackageCount
];
630 memset(Colours
,0,sizeof(*Colours
)*Cache
.Head().PackageCount
);
632 APT::PackageSet pkgset
= APT::PackageSet::FromCommandLine(Cache
, CmdL
.FileList
);
633 for (APT::PackageSet::const_iterator Pkg
= pkgset
.begin(); Pkg
!= pkgset
.end(); ++Pkg
)
634 Colours
[Pkg
->ID
] = 1;
636 bool Recurse
= _config
->FindB("APT::Cache::RecurseDepends",false);
637 bool Installed
= _config
->FindB("APT::Cache::Installed",false);
641 DidSomething
= false;
642 for (pkgCache::PkgIterator Pkg
= Cache
.PkgBegin(); Pkg
.end() == false; Pkg
++)
644 if (Colours
[Pkg
->ID
] != 1)
646 Colours
[Pkg
->ID
] = 2;
649 pkgCache::VerIterator Ver
= Pkg
.VersionList();
650 if (Ver
.end() == true)
652 cout
<< '<' << Pkg
.FullName(true) << '>' << endl
;
656 cout
<< Pkg
.FullName(true) << endl
;
658 cout
<< "Reverse Depends:" << endl
;
659 for (pkgCache::DepIterator D
= Pkg
.RevDependsList(); D
.end() == false; D
++)
662 pkgCache::PkgIterator Trg
= D
.ParentPkg();
664 if((Installed
&& Trg
->CurrentVer
!= 0) || !Installed
)
667 if ((D
->CompareOp
& pkgCache::Dep::Or
) == pkgCache::Dep::Or
)
672 if (Trg
->VersionList
== 0)
673 cout
<< D
.DepType() << ": <" << Trg
.FullName(true) << ">" << endl
;
675 cout
<< Trg
.FullName(true) << endl
;
678 Colours
[D
.ParentPkg()->ID
]++;
682 // Display all solutions
683 SPtrArray
<pkgCache::Version
*> List
= D
.AllTargets();
684 pkgPrioSortList(Cache
,List
);
685 for (pkgCache::Version
**I
= List
; *I
!= 0; I
++)
687 pkgCache::VerIterator
V(Cache
,*I
);
688 if (V
!= Cache
.VerP
+ V
.ParentPkg()->VersionList
||
689 V
->ParentPkg
== D
->Package
)
691 cout
<< " " << V
.ParentPkg().FullName(true) << endl
;
694 Colours
[D
.ParentPkg()->ID
]++;
699 while (DidSomething
== true);
704 // xvcg - Generate a graph for xvcg /*{{{*/
705 // ---------------------------------------------------------------------
706 // Code contributed from Junichi Uekawa <dancer@debian.org> on 20 June 2002.
708 bool XVcg(CommandLine
&CmdL
)
710 pkgCache
&Cache
= *GCache
;
711 bool GivenOnly
= _config
->FindB("APT::Cache::GivenOnly",false);
713 /* Normal packages are boxes
714 Pure Provides are triangles
716 rhomb are missing packages*/
717 const char *Shapes
[] = {"ellipse","triangle","box","rhomb"};
719 /* Initialize the list of packages to show.
721 2 = To Show no recurse
722 3 = Emitted no recurse
725 enum States
{None
=0, ToShow
, ToShowNR
, DoneNR
, Done
};
726 enum TheFlags
{ForceNR
=(1<<0)};
727 unsigned char *Show
= new unsigned char[Cache
.Head().PackageCount
];
728 unsigned char *Flags
= new unsigned char[Cache
.Head().PackageCount
];
729 unsigned char *ShapeMap
= new unsigned char[Cache
.Head().PackageCount
];
731 // Show everything if no arguments given
732 if (CmdL
.FileList
[1] == 0)
733 for (unsigned long I
= 0; I
!= Cache
.Head().PackageCount
; I
++)
736 for (unsigned long I
= 0; I
!= Cache
.Head().PackageCount
; I
++)
738 memset(Flags
,0,sizeof(*Flags
)*Cache
.Head().PackageCount
);
741 for (pkgCache::PkgIterator Pkg
= Cache
.PkgBegin(); Pkg
.end() == false; Pkg
++)
743 if (Pkg
->VersionList
== 0)
746 if (Pkg
->ProvidesList
== 0)
747 ShapeMap
[Pkg
->ID
] = 0;
749 ShapeMap
[Pkg
->ID
] = 1;
754 if (Pkg
->ProvidesList
== 0)
755 ShapeMap
[Pkg
->ID
] = 2;
757 ShapeMap
[Pkg
->ID
] = 3;
761 // Load the list of packages from the command line into the show list
762 for (const char **I
= CmdL
.FileList
+ 1; *I
!= 0; I
++)
764 // Process per-package flags
769 if (P
.end()[-1] == '^')
775 if (P
.end()[-1] == ',')
779 // Locate the package
780 pkgCache::PkgIterator Pkg
= Cache
.FindPkg(P
);
781 if (Pkg
.end() == true)
783 _error
->Warning(_("Unable to locate package %s"),*I
);
786 Show
[Pkg
->ID
] = ToShow
;
789 Flags
[Pkg
->ID
] |= ForceNR
;
793 cout
<< "graph: { title: \"packages\"" << endl
<<
794 "xmax: 700 ymax: 700 x: 30 y: 30" << endl
<<
795 "layout_downfactor: 8" << endl
;
801 for (pkgCache::PkgIterator Pkg
= Cache
.PkgBegin(); Pkg
.end() == false; Pkg
++)
803 // See we need to show this package
804 if (Show
[Pkg
->ID
] == None
|| Show
[Pkg
->ID
] >= DoneNR
)
807 //printf ("node: { title: \"%s\" label: \"%s\" }\n", Pkg.Name(), Pkg.Name());
810 if (Show
[Pkg
->ID
] == ToShowNR
|| (Flags
[Pkg
->ID
] & ForceNR
) == ForceNR
)
812 // Pure Provides and missing packages have no deps!
813 if (ShapeMap
[Pkg
->ID
] == 0 || ShapeMap
[Pkg
->ID
] == 1)
814 Show
[Pkg
->ID
] = Done
;
816 Show
[Pkg
->ID
] = DoneNR
;
819 Show
[Pkg
->ID
] = Done
;
822 // No deps to map out
823 if (Pkg
->VersionList
== 0 || Show
[Pkg
->ID
] == DoneNR
)
826 pkgCache::VerIterator Ver
= Pkg
.VersionList();
827 for (pkgCache::DepIterator D
= Ver
.DependsList(); D
.end() == false; D
++)
829 // See if anything can meet this dep
830 // Walk along the actual package providing versions
832 pkgCache::PkgIterator DPkg
= D
.TargetPkg();
833 for (pkgCache::VerIterator I
= DPkg
.VersionList();
834 I
.end() == false && Hit
== false; I
++)
836 if (Cache
.VS
->CheckDep(I
.VerStr(),D
->CompareOp
,D
.TargetVer()) == true)
840 // Follow all provides
841 for (pkgCache::PrvIterator I
= DPkg
.ProvidesList();
842 I
.end() == false && Hit
== false; I
++)
844 if (Cache
.VS
->CheckDep(I
.ProvideVersion(),D
->CompareOp
,D
.TargetVer()) == false)
849 // Only graph critical deps
850 if (D
.IsCritical() == true)
852 printf ("edge: { sourcename: \"%s\" targetname: \"%s\" class: 2 ",Pkg
.FullName(true).c_str(), D
.TargetPkg().FullName(true).c_str() );
854 // Colour the node for recursion
855 if (Show
[D
.TargetPkg()->ID
] <= DoneNR
)
857 /* If a conflicts does not meet anything in the database
858 then show the relation but do not recurse */
860 (D
->Type
== pkgCache::Dep::Conflicts
||
861 D
->Type
== pkgCache::Dep::DpkgBreaks
||
862 D
->Type
== pkgCache::Dep::Obsoletes
))
864 if (Show
[D
.TargetPkg()->ID
] == None
&&
865 Show
[D
.TargetPkg()->ID
] != ToShow
)
866 Show
[D
.TargetPkg()->ID
] = ToShowNR
;
870 if (GivenOnly
== true && Show
[D
.TargetPkg()->ID
] != ToShow
)
871 Show
[D
.TargetPkg()->ID
] = ToShowNR
;
873 Show
[D
.TargetPkg()->ID
] = ToShow
;
880 case pkgCache::Dep::Conflicts
:
881 printf("label: \"conflicts\" color: lightgreen }\n");
883 case pkgCache::Dep::DpkgBreaks
:
884 printf("label: \"breaks\" color: lightgreen }\n");
886 case pkgCache::Dep::Obsoletes
:
887 printf("label: \"obsoletes\" color: lightgreen }\n");
890 case pkgCache::Dep::PreDepends
:
891 printf("label: \"predepends\" color: blue }\n");
903 /* Draw the box colours after the fact since we can not tell what colour
904 they should be until everything is finished drawing */
905 for (pkgCache::PkgIterator Pkg
= Cache
.PkgBegin(); Pkg
.end() == false; Pkg
++)
907 if (Show
[Pkg
->ID
] < DoneNR
)
910 if (Show
[Pkg
->ID
] == DoneNR
)
911 printf("node: { title: \"%s\" label: \"%s\" color: orange shape: %s }\n", Pkg
.FullName(true).c_str(), Pkg
.FullName(true).c_str(),
912 Shapes
[ShapeMap
[Pkg
->ID
]]);
914 printf("node: { title: \"%s\" label: \"%s\" shape: %s }\n", Pkg
.FullName(true).c_str(), Pkg
.FullName(true).c_str(),
915 Shapes
[ShapeMap
[Pkg
->ID
]]);
927 // Dotty - Generate a graph for Dotty /*{{{*/
928 // ---------------------------------------------------------------------
929 /* Dotty is the graphvis program for generating graphs. It is a fairly
930 simple queuing algorithm that just writes dependencies and nodes.
931 http://www.research.att.com/sw/tools/graphviz/ */
932 bool Dotty(CommandLine
&CmdL
)
934 pkgCache
&Cache
= *GCache
;
935 bool GivenOnly
= _config
->FindB("APT::Cache::GivenOnly",false);
937 /* Normal packages are boxes
938 Pure Provides are triangles
940 Hexagons are missing packages*/
941 const char *Shapes
[] = {"hexagon","triangle","box","diamond"};
943 /* Initialize the list of packages to show.
945 2 = To Show no recurse
946 3 = Emitted no recurse
949 enum States
{None
=0, ToShow
, ToShowNR
, DoneNR
, Done
};
950 enum TheFlags
{ForceNR
=(1<<0)};
951 unsigned char *Show
= new unsigned char[Cache
.Head().PackageCount
];
952 unsigned char *Flags
= new unsigned char[Cache
.Head().PackageCount
];
953 unsigned char *ShapeMap
= new unsigned char[Cache
.Head().PackageCount
];
955 // Show everything if no arguments given
956 if (CmdL
.FileList
[1] == 0)
957 for (unsigned long I
= 0; I
!= Cache
.Head().PackageCount
; I
++)
960 for (unsigned long I
= 0; I
!= Cache
.Head().PackageCount
; I
++)
962 memset(Flags
,0,sizeof(*Flags
)*Cache
.Head().PackageCount
);
965 for (pkgCache::PkgIterator Pkg
= Cache
.PkgBegin(); Pkg
.end() == false; Pkg
++)
967 if (Pkg
->VersionList
== 0)
970 if (Pkg
->ProvidesList
== 0)
971 ShapeMap
[Pkg
->ID
] = 0;
973 ShapeMap
[Pkg
->ID
] = 1;
978 if (Pkg
->ProvidesList
== 0)
979 ShapeMap
[Pkg
->ID
] = 2;
981 ShapeMap
[Pkg
->ID
] = 3;
985 // Load the list of packages from the command line into the show list
986 for (const char **I
= CmdL
.FileList
+ 1; *I
!= 0; I
++)
988 // Process per-package flags
993 if (P
.end()[-1] == '^')
999 if (P
.end()[-1] == ',')
1003 // Locate the package
1004 pkgCache::PkgIterator Pkg
= Cache
.FindPkg(P
);
1005 if (Pkg
.end() == true)
1007 _error
->Warning(_("Unable to locate package %s"),*I
);
1010 Show
[Pkg
->ID
] = ToShow
;
1013 Flags
[Pkg
->ID
] |= ForceNR
;
1017 printf("digraph packages {\n");
1018 printf("concentrate=true;\n");
1019 printf("size=\"30,40\";\n");
1025 for (pkgCache::PkgIterator Pkg
= Cache
.PkgBegin(); Pkg
.end() == false; Pkg
++)
1027 // See we need to show this package
1028 if (Show
[Pkg
->ID
] == None
|| Show
[Pkg
->ID
] >= DoneNR
)
1032 if (Show
[Pkg
->ID
] == ToShowNR
|| (Flags
[Pkg
->ID
] & ForceNR
) == ForceNR
)
1034 // Pure Provides and missing packages have no deps!
1035 if (ShapeMap
[Pkg
->ID
] == 0 || ShapeMap
[Pkg
->ID
] == 1)
1036 Show
[Pkg
->ID
] = Done
;
1038 Show
[Pkg
->ID
] = DoneNR
;
1041 Show
[Pkg
->ID
] = Done
;
1044 // No deps to map out
1045 if (Pkg
->VersionList
== 0 || Show
[Pkg
->ID
] == DoneNR
)
1048 pkgCache::VerIterator Ver
= Pkg
.VersionList();
1049 for (pkgCache::DepIterator D
= Ver
.DependsList(); D
.end() == false; D
++)
1051 // See if anything can meet this dep
1052 // Walk along the actual package providing versions
1054 pkgCache::PkgIterator DPkg
= D
.TargetPkg();
1055 for (pkgCache::VerIterator I
= DPkg
.VersionList();
1056 I
.end() == false && Hit
== false; I
++)
1058 if (Cache
.VS
->CheckDep(I
.VerStr(),D
->CompareOp
,D
.TargetVer()) == true)
1062 // Follow all provides
1063 for (pkgCache::PrvIterator I
= DPkg
.ProvidesList();
1064 I
.end() == false && Hit
== false; I
++)
1066 if (Cache
.VS
->CheckDep(I
.ProvideVersion(),D
->CompareOp
,D
.TargetVer()) == false)
1070 // Only graph critical deps
1071 if (D
.IsCritical() == true)
1073 printf("\"%s\" -> \"%s\"",Pkg
.FullName(true).c_str(),D
.TargetPkg().FullName(true).c_str());
1075 // Colour the node for recursion
1076 if (Show
[D
.TargetPkg()->ID
] <= DoneNR
)
1078 /* If a conflicts does not meet anything in the database
1079 then show the relation but do not recurse */
1081 (D
->Type
== pkgCache::Dep::Conflicts
||
1082 D
->Type
== pkgCache::Dep::Obsoletes
))
1084 if (Show
[D
.TargetPkg()->ID
] == None
&&
1085 Show
[D
.TargetPkg()->ID
] != ToShow
)
1086 Show
[D
.TargetPkg()->ID
] = ToShowNR
;
1090 if (GivenOnly
== true && Show
[D
.TargetPkg()->ID
] != ToShow
)
1091 Show
[D
.TargetPkg()->ID
] = ToShowNR
;
1093 Show
[D
.TargetPkg()->ID
] = ToShow
;
1100 case pkgCache::Dep::Conflicts
:
1101 case pkgCache::Dep::Obsoletes
:
1102 printf("[color=springgreen];\n");
1105 case pkgCache::Dep::PreDepends
:
1106 printf("[color=blue];\n");
1118 /* Draw the box colours after the fact since we can not tell what colour
1119 they should be until everything is finished drawing */
1120 for (pkgCache::PkgIterator Pkg
= Cache
.PkgBegin(); Pkg
.end() == false; Pkg
++)
1122 if (Show
[Pkg
->ID
] < DoneNR
)
1125 // Orange box for early recursion stoppage
1126 if (Show
[Pkg
->ID
] == DoneNR
)
1127 printf("\"%s\" [color=orange,shape=%s];\n",Pkg
.FullName(true).c_str(),
1128 Shapes
[ShapeMap
[Pkg
->ID
]]);
1130 printf("\"%s\" [shape=%s];\n",Pkg
.FullName(true).c_str(),
1131 Shapes
[ShapeMap
[Pkg
->ID
]]);
1138 // DoAdd - Perform an adding operation /*{{{*/
1139 // ---------------------------------------------------------------------
1141 bool DoAdd(CommandLine
&CmdL
)
1143 return _error
->Error("Unimplemented");
1145 // Make sure there is at least one argument
1146 if (CmdL
.FileSize() <= 1)
1147 return _error
->Error("You must give at least one file name");
1150 FileFd
CacheF(_config
->FindFile("Dir::Cache::pkgcache"),FileFd::WriteAny
);
1151 if (_error
->PendingError() == true)
1154 DynamicMMap
Map(CacheF
,MMap::Public
);
1155 if (_error
->PendingError() == true)
1158 OpTextProgress
Progress(*_config
);
1159 pkgCacheGenerator
Gen(Map
,Progress
);
1160 if (_error
->PendingError() == true)
1163 unsigned long Length
= CmdL
.FileSize() - 1;
1164 for (const char **I
= CmdL
.FileList
+ 1; *I
!= 0; I
++)
1166 Progress
.OverallProgress(I
- CmdL
.FileList
,Length
,1,"Generating cache");
1167 Progress
.SubProgress(Length
);
1170 FileFd
TagF(*I
,FileFd::ReadOnly
);
1171 debListParser
Parser(TagF
);
1172 if (_error
->PendingError() == true)
1173 return _error
->Error("Problem opening %s",*I
);
1175 if (Gen
.SelectFile(*I
,"") == false)
1176 return _error
->Error("Problem with SelectFile");
1178 if (Gen
.MergeList(Parser
) == false)
1179 return _error
->Error("Problem with MergeList");
1183 GCache
= &Gen
.GetCache();
1190 // DisplayRecord - Displays the complete record for the package /*{{{*/
1191 // ---------------------------------------------------------------------
1192 /* This displays the package record from the proper package index file.
1193 It is not used by DumpAvail for performance reasons. */
1194 bool DisplayRecord(pkgCache::VerIterator V
)
1196 // Find an appropriate file
1197 pkgCache::VerFileIterator Vf
= V
.FileList();
1198 for (; Vf
.end() == false; Vf
++)
1199 if ((Vf
.File()->Flags
& pkgCache::Flag::NotSource
) == 0)
1201 if (Vf
.end() == true)
1204 // Check and load the package list file
1205 pkgCache::PkgFileIterator I
= Vf
.File();
1206 if (I
.IsOk() == false)
1207 return _error
->Error(_("Package file %s is out of sync."),I
.FileName());
1209 FileFd
PkgF(I
.FileName(),FileFd::ReadOnly
);
1210 if (_error
->PendingError() == true)
1214 unsigned char *Buffer
= new unsigned char[GCache
->HeaderP
->MaxVerFileSize
+1];
1215 Buffer
[V
.FileList()->Size
] = '\n';
1216 if (PkgF
.Seek(V
.FileList()->Offset
) == false ||
1217 PkgF
.Read(Buffer
,V
.FileList()->Size
) == false)
1223 // Get a pointer to start of Description field
1224 const unsigned char *DescP
= (unsigned char*)strstr((char*)Buffer
, "Description:");
1226 // Write all but Description
1227 if (fwrite(Buffer
,1,DescP
- Buffer
,stdout
) < (size_t)(DescP
- Buffer
))
1233 // Show the right description
1234 pkgRecords
Recs(*GCache
);
1235 pkgCache::DescIterator Desc
= V
.TranslatedDescription();
1236 pkgRecords::Parser
&P
= Recs
.Lookup(Desc
.FileList());
1237 cout
<< "Description" << ( (strcmp(Desc
.LanguageCode(),"") != 0) ? "-" : "" ) << Desc
.LanguageCode() << ": " << P
.LongDesc();
1239 // Find the first field after the description (if there is any)
1240 for(DescP
++;DescP
!= &Buffer
[V
.FileList()->Size
];DescP
++)
1242 if(*DescP
== '\n' && *(DescP
+1) != ' ')
1244 // write the rest of the buffer
1245 const unsigned char *end
=&Buffer
[V
.FileList()->Size
];
1246 if (fwrite(DescP
,1,end
-DescP
,stdout
) < (size_t)(end
-DescP
))
1255 // write a final newline (after the description)
1265 pkgCache::DescFile
*Df
;
1269 // Search - Perform a search /*{{{*/
1270 // ---------------------------------------------------------------------
1271 /* This searches the package names and package descriptions for a pattern */
1272 bool Search(CommandLine
&CmdL
)
1274 pkgCache
&Cache
= *GCache
;
1275 bool const ShowFull
= _config
->FindB("APT::Cache::ShowFull",false);
1276 bool const NamesOnly
= _config
->FindB("APT::Cache::NamesOnly",false);
1277 unsigned int const NumPatterns
= CmdL
.FileSize() -1;
1279 pkgDepCache::Policy Plcy
;
1281 // Make sure there is at least one argument
1282 if (NumPatterns
< 1)
1283 return _error
->Error(_("You must give at least one search pattern"));
1285 // Compile the regex pattern
1286 regex_t
*Patterns
= new regex_t
[NumPatterns
];
1287 memset(Patterns
,0,sizeof(*Patterns
)*NumPatterns
);
1288 for (unsigned I
= 0; I
!= NumPatterns
; I
++)
1290 if (regcomp(&Patterns
[I
],CmdL
.FileList
[I
+1],REG_EXTENDED
| REG_ICASE
|
1294 regfree(&Patterns
[I
]);
1295 return _error
->Error("Regex compilation error");
1299 if (_error
->PendingError() == true)
1301 for (unsigned I
= 0; I
!= NumPatterns
; I
++)
1302 regfree(&Patterns
[I
]);
1306 ExDescFile
*DFList
= new ExDescFile
[Cache
.HeaderP
->GroupCount
+1];
1307 memset(DFList
,0,sizeof(*DFList
)*Cache
.HeaderP
->GroupCount
+1);
1309 // Map versions that we want to write out onto the VerList array.
1310 for (pkgCache::GrpIterator G
= Cache
.GrpBegin(); G
.end() == false; ++G
)
1312 if (DFList
[G
->ID
].NameMatch
== true)
1315 DFList
[G
->ID
].NameMatch
= true;
1316 for (unsigned I
= 0; I
!= NumPatterns
; I
++)
1318 if (regexec(&Patterns
[I
],G
.Name(),0,0,0) == 0)
1320 DFList
[G
->ID
].NameMatch
= false;
1324 // Doing names only, drop any that dont match..
1325 if (NamesOnly
== true && DFList
[G
->ID
].NameMatch
== false)
1328 // Find the proper version to use
1329 pkgCache::PkgIterator P
= G
.FindPreferredPkg();
1330 if (P
.end() == true)
1332 pkgCache::VerIterator V
= Plcy
.GetCandidateVer(P
);
1333 if (V
.end() == false)
1334 DFList
[G
->ID
].Df
= V
.DescriptionList().FileList();
1336 if (DFList
[G
->ID
].NameMatch
== false)
1339 // Include all the packages that provide matching names too
1340 for (pkgCache::PrvIterator Prv
= P
.ProvidesList() ; Prv
.end() == false; Prv
++)
1342 pkgCache::VerIterator V
= Plcy
.GetCandidateVer(Prv
.OwnerPkg());
1343 if (V
.end() == true)
1346 unsigned long id
= Prv
.OwnerPkg().Group()->ID
;
1347 DFList
[id
].Df
= V
.DescriptionList().FileList();
1348 DFList
[id
].NameMatch
= true;
1352 LocalitySort(&DFList
->Df
,Cache
.HeaderP
->GroupCount
,sizeof(*DFList
));
1354 // Create the text record parser
1355 pkgRecords
Recs(Cache
);
1356 // Iterate over all the version records and check them
1357 for (ExDescFile
*J
= DFList
; J
->Df
!= 0; J
++)
1359 pkgRecords::Parser
&P
= Recs
.Lookup(pkgCache::DescFileIterator(Cache
,J
->Df
));
1361 if (J
->NameMatch
== false && NamesOnly
== false)
1363 string
const LongDesc
= P
.LongDesc();
1364 J
->NameMatch
= true;
1365 for (unsigned I
= 0; I
!= NumPatterns
; I
++)
1367 if (regexec(&Patterns
[I
],LongDesc
.c_str(),0,0,0) == 0)
1369 J
->NameMatch
= false;
1374 if (J
->NameMatch
== true)
1376 if (ShowFull
== true)
1380 P
.GetRec(Start
,End
);
1381 fwrite(Start
,End
-Start
,1,stdout
);
1385 printf("%s - %s\n",P
.Name().c_str(),P
.ShortDesc().c_str());
1390 for (unsigned I
= 0; I
!= NumPatterns
; I
++)
1391 regfree(&Patterns
[I
]);
1393 return _error
->Error("Write to stdout failed");
1398 /* show automatically installed packages (sorted) */
1399 bool ShowAuto(CommandLine
&CmdL
)
1402 pkgDepCache
DepCache(GCache
);
1405 std::vector
<string
> packages
;
1406 packages
.reserve(GCache
->HeaderP
->PackageCount
/ 3);
1408 for (pkgCache::PkgIterator P
= GCache
->PkgBegin(); P
.end() == false; P
++)
1409 if (DepCache
[P
].Flags
& pkgCache::Flag::Auto
)
1410 packages
.push_back(P
.Name());
1412 std::sort(packages
.begin(), packages
.end());
1414 for (vector
<string
>::iterator I
= packages
.begin(); I
!= packages
.end(); I
++)
1420 // ShowPackage - Dump the package record to the screen /*{{{*/
1421 // ---------------------------------------------------------------------
1423 bool ShowPackage(CommandLine
&CmdL
)
1425 pkgCache
&Cache
= *GCache
;
1426 pkgDepCache::Policy Plcy
;
1428 APT::PackageSet pkgset
= APT::PackageSet::FromCommandLine(Cache
, CmdL
.FileList
);
1429 for (APT::PackageSet::const_iterator Pkg
= pkgset
.begin(); Pkg
!= pkgset
.end(); ++Pkg
)
1431 // Find the proper version to use.
1432 if (_config
->FindB("APT::Cache::AllVersions","true") == true)
1434 pkgCache::VerIterator V
;
1435 for (V
= Pkg
.VersionList(); V
.end() == false; V
++)
1437 if (DisplayRecord(V
) == false)
1443 pkgCache::VerIterator V
= Plcy
.GetCandidateVer(Pkg
);
1444 if (V
.end() == true || V
.FileList().end() == true)
1446 if (DisplayRecord(V
) == false)
1451 if (pkgset
.empty() == false)
1453 return _error
->Error(_("No packages found"));
1456 // ShowPkgNames - Show package names /*{{{*/
1457 // ---------------------------------------------------------------------
1458 /* This does a prefix match on the first argument */
1459 bool ShowPkgNames(CommandLine
&CmdL
)
1461 pkgCache
&Cache
= *GCache
;
1462 pkgCache::GrpIterator I
= Cache
.GrpBegin();
1463 bool const All
= _config
->FindB("APT::Cache::AllNames","false");
1465 if (CmdL
.FileList
[1] != 0)
1467 for (;I
.end() != true; I
++)
1469 if (All
== false && I
->FirstPackage
== 0)
1471 if (I
.FindPkg("any")->VersionList
== 0)
1473 if (strncmp(I
.Name(),CmdL
.FileList
[1],strlen(CmdL
.FileList
[1])) == 0)
1474 cout
<< I
.Name() << endl
;
1481 for (;I
.end() != true; I
++)
1483 if (All
== false && I
->FirstPackage
== 0)
1485 if (I
.FindPkg("any")->VersionList
== 0)
1487 cout
<< I
.Name() << endl
;
1493 // ShowSrcPackage - Show source package records /*{{{*/
1494 // ---------------------------------------------------------------------
1496 bool ShowSrcPackage(CommandLine
&CmdL
)
1499 List
.ReadMainList();
1501 // Create the text record parsers
1502 pkgSrcRecords
SrcRecs(List
);
1503 if (_error
->PendingError() == true)
1507 for (const char **I
= CmdL
.FileList
+ 1; *I
!= 0; I
++)
1511 pkgSrcRecords::Parser
*Parse
;
1512 unsigned found_this
= 0;
1513 while ((Parse
= SrcRecs
.Find(*I
,false)) != 0) {
1514 cout
<< Parse
->AsStr() << endl
;;
1518 if (found_this
== 0) {
1519 _error
->Warning(_("Unable to locate package %s"),*I
);
1525 return _error
->Error(_("No packages found"));
1528 // Policy - Show the results of the preferences file /*{{{*/
1529 // ---------------------------------------------------------------------
1531 bool Policy(CommandLine
&CmdL
)
1534 return _error
->Error("Generate must be enabled for this function");
1536 pkgCache
&Cache
= *GCache
;
1537 pkgPolicy
Plcy(&Cache
);
1538 if (ReadPinFile(Plcy
) == false || ReadPinDir(Plcy
) == false)
1541 // Print out all of the package files
1542 if (CmdL
.FileList
[1] == 0)
1544 cout
<< _("Package files:") << endl
;
1545 for (pkgCache::PkgFileIterator F
= Cache
.FileBegin(); F
.end() == false; F
++)
1547 // Locate the associated index files so we can derive a description
1549 if (SrcList
->FindIndex(F
,Indx
) == false &&
1550 _system
->FindIndex(F
,Indx
) == false)
1551 return _error
->Error(_("Cache is out of sync, can't x-ref a package file"));
1554 Plcy
.GetPriority(F
),Indx
->Describe(true).c_str());
1556 // Print the reference information for the package
1557 string Str
= F
.RelStr();
1558 if (Str
.empty() == false)
1559 printf(" release %s\n",F
.RelStr().c_str());
1560 if (F
.Site() != 0 && F
.Site()[0] != 0)
1561 printf(" origin %s\n",F
.Site());
1564 // Show any packages have explicit pins
1565 cout
<< _("Pinned packages:") << endl
;
1566 pkgCache::PkgIterator I
= Cache
.PkgBegin();
1567 for (;I
.end() != true; I
++)
1569 if (Plcy
.GetPriority(I
) == 0)
1572 // Print the package name and the version we are forcing to
1573 cout
<< " " << I
.FullName(true) << " -> ";
1575 pkgCache::VerIterator V
= Plcy
.GetMatch(I
);
1576 if (V
.end() == true)
1577 cout
<< _("(not found)") << endl
;
1579 cout
<< V
.VerStr() << endl
;
1585 string
const myArch
= _config
->Find("APT::Architecture");
1586 char const * const msgInstalled
= _(" Installed: ");
1587 char const * const msgCandidate
= _(" Candidate: ");
1588 short const InstalledLessCandidate
=
1589 mbstowcs(NULL
, msgInstalled
, 0) - mbstowcs(NULL
, msgCandidate
, 0);
1590 short const deepInstalled
=
1591 (InstalledLessCandidate
< 0 ? (InstalledLessCandidate
*-1) : 0) - 1;
1592 short const deepCandidate
=
1593 (InstalledLessCandidate
> 0 ? (InstalledLessCandidate
) : 0) - 1;
1595 // Print out detailed information for each package
1596 APT::PackageSet pkgset
= APT::PackageSet::FromCommandLine(Cache
, CmdL
.FileList
);
1597 for (APT::PackageSet::const_iterator I
= pkgset
.begin(); I
!= pkgset
.end(); ++I
)
1599 pkgCache::PkgIterator Pkg
= I
.Group().FindPkg("any");
1601 for (; Pkg
.end() != true; Pkg
= I
.Group().NextPkg(Pkg
)) {
1602 if (strcmp(Pkg
.Arch(),"all") == 0)
1605 cout
<< Pkg
.FullName(true) << ":" << endl
;
1607 // Installed version
1608 cout
<< msgInstalled
<< OutputInDepth(deepInstalled
, " ");
1609 if (Pkg
->CurrentVer
== 0)
1610 cout
<< _("(none)") << endl
;
1612 cout
<< Pkg
.CurrentVer().VerStr() << endl
;
1614 // Candidate Version
1615 cout
<< msgCandidate
<< OutputInDepth(deepCandidate
, " ");
1616 pkgCache::VerIterator V
= Plcy
.GetCandidateVer(Pkg
);
1617 if (V
.end() == true)
1618 cout
<< _("(none)") << endl
;
1620 cout
<< V
.VerStr() << endl
;
1623 if (Plcy
.GetPriority(Pkg
) != 0)
1625 cout
<< _(" Package pin: ");
1626 V
= Plcy
.GetMatch(Pkg
);
1627 if (V
.end() == true)
1628 cout
<< _("(not found)") << endl
;
1630 cout
<< V
.VerStr() << endl
;
1633 // Show the priority tables
1634 cout
<< _(" Version table:") << endl
;
1635 for (V
= Pkg
.VersionList(); V
.end() == false; V
++)
1637 if (Pkg
.CurrentVer() == V
)
1638 cout
<< " *** " << V
.VerStr();
1640 cout
<< " " << V
.VerStr();
1641 cout
<< " " << Plcy
.GetPriority(Pkg
) << endl
;
1642 for (pkgCache::VerFileIterator VF
= V
.FileList(); VF
.end() == false; VF
++)
1644 // Locate the associated index files so we can derive a description
1646 if (SrcList
->FindIndex(VF
.File(),Indx
) == false &&
1647 _system
->FindIndex(VF
.File(),Indx
) == false)
1648 return _error
->Error(_("Cache is out of sync, can't x-ref a package file"));
1649 printf(" %4i %s\n",Plcy
.GetPriority(VF
.File()),
1650 Indx
->Describe(true).c_str());
1659 // Madison - Look a bit like katie's madison /*{{{*/
1660 // ---------------------------------------------------------------------
1662 bool Madison(CommandLine
&CmdL
)
1665 return _error
->Error("Generate must be enabled for this function");
1667 SrcList
->ReadMainList();
1669 pkgCache
&Cache
= *GCache
;
1671 // Create the src text record parsers and ignore errors about missing
1672 // deb-src lines that are generated from pkgSrcRecords::pkgSrcRecords
1673 pkgSrcRecords
SrcRecs(*SrcList
);
1674 if (_error
->PendingError() == true)
1677 APT::PackageSet pkgset
= APT::PackageSet::FromCommandLine(Cache
, CmdL
.FileList
);
1678 for (APT::PackageSet::const_iterator Pkg
= pkgset
.begin(); Pkg
!= pkgset
.end(); ++Pkg
)
1680 if (Pkg
.end() == false)
1682 for (pkgCache::VerIterator V
= Pkg
.VersionList(); V
.end() == false; V
++)
1684 for (pkgCache::VerFileIterator VF
= V
.FileList(); VF
.end() == false; VF
++)
1686 // This might be nice, but wouldn't uniquely identify the source -mdz
1687 // if (VF.File().Archive() != 0)
1689 // cout << setw(10) << Pkg.Name() << " | " << setw(10) << V.VerStr() << " | "
1690 // << VF.File().Archive() << endl;
1693 // Locate the associated index files so we can derive a description
1694 for (pkgSourceList::const_iterator S
= SrcList
->begin(); S
!= SrcList
->end(); S
++)
1696 vector
<pkgIndexFile
*> *Indexes
= (*S
)->GetIndexFiles();
1697 for (vector
<pkgIndexFile
*>::const_iterator IF
= Indexes
->begin();
1698 IF
!= Indexes
->end(); IF
++)
1700 if ((*IF
)->FindInCache(*(VF
.File().Cache())) == VF
.File())
1702 cout
<< setw(10) << Pkg
.FullName(true) << " | " << setw(10) << V
.VerStr() << " | "
1703 << (*IF
)->Describe(true) << endl
;
1713 pkgSrcRecords::Parser
*SrcParser
;
1714 while ((SrcParser
= SrcRecs
.Find(Pkg
.Name(),false)) != 0)
1716 // Maybe support Release info here too eventually
1717 cout
<< setw(10) << SrcParser
->Package() << " | "
1718 << setw(10) << SrcParser
->Version() << " | "
1719 << SrcParser
->Index().Describe(true) << endl
;
1726 // GenCaches - Call the main cache generator /*{{{*/
1727 // ---------------------------------------------------------------------
1729 bool GenCaches(CommandLine
&Cmd
)
1731 OpTextProgress
Progress(*_config
);
1734 if (List
.ReadMainList() == false)
1736 return pkgMakeStatusCache(List
,Progress
);
1739 // ShowHelp - Show a help screen /*{{{*/
1740 // ---------------------------------------------------------------------
1742 bool ShowHelp(CommandLine
&Cmd
)
1744 ioprintf(cout
,_("%s %s for %s compiled on %s %s\n"),PACKAGE
,VERSION
,
1745 COMMON_ARCH
,__DATE__
,__TIME__
);
1747 if (_config
->FindB("version") == true)
1751 _("Usage: apt-cache [options] command\n"
1752 " apt-cache [options] add file1 [file2 ...]\n"
1753 " apt-cache [options] showpkg pkg1 [pkg2 ...]\n"
1754 " apt-cache [options] showsrc pkg1 [pkg2 ...]\n"
1756 "apt-cache is a low-level tool used to manipulate APT's binary\n"
1757 "cache files, and query information from them\n"
1760 " add - Add a package file to the source cache\n"
1761 " gencaches - Build both the package and source cache\n"
1762 " showpkg - Show some general information for a single package\n"
1763 " showsrc - Show source records\n"
1764 " stats - Show some basic statistics\n"
1765 " dump - Show the entire file in a terse form\n"
1766 " dumpavail - Print an available file to stdout\n"
1767 " unmet - Show unmet dependencies\n"
1768 " search - Search the package list for a regex pattern\n"
1769 " show - Show a readable record for the package\n"
1770 " showauto - Display a list of automatically installed packages\n"
1771 " depends - Show raw dependency information for a package\n"
1772 " rdepends - Show reverse dependency information for a package\n"
1773 " pkgnames - List the names of all packages in the system\n"
1774 " dotty - Generate package graphs for GraphViz\n"
1775 " xvcg - Generate package graphs for xvcg\n"
1776 " policy - Show policy settings\n"
1779 " -h This help text.\n"
1780 " -p=? The package cache.\n"
1781 " -s=? The source cache.\n"
1782 " -q Disable progress indicator.\n"
1783 " -i Show only important deps for the unmet command.\n"
1784 " -c=? Read this configuration file\n"
1785 " -o=? Set an arbitrary configuration option, eg -o dir::cache=/tmp\n"
1786 "See the apt-cache(8) and apt.conf(5) manual pages for more information.\n");
1790 // CacheInitialize - Initialize things for apt-cache /*{{{*/
1791 // ---------------------------------------------------------------------
1793 void CacheInitialize()
1795 _config
->Set("quiet",0);
1796 _config
->Set("help",false);
1799 int main(int argc
,const char *argv
[]) /*{{{*/
1801 CommandLine::Args Args
[] = {
1802 {'h',"help","help",0},
1803 {'v',"version","version",0},
1804 {'p',"pkg-cache","Dir::Cache::pkgcache",CommandLine::HasArg
},
1805 {'s',"src-cache","Dir::Cache::srcpkgcache",CommandLine::HasArg
},
1806 {'q',"quiet","quiet",CommandLine::IntLevel
},
1807 {'i',"important","APT::Cache::Important",0},
1808 {'f',"full","APT::Cache::ShowFull",0},
1809 {'g',"generate","APT::Cache::Generate",0},
1810 {'a',"all-versions","APT::Cache::AllVersions",0},
1811 {'n',"names-only","APT::Cache::NamesOnly",0},
1812 {0,"all-names","APT::Cache::AllNames",0},
1813 {0,"recurse","APT::Cache::RecurseDepends",0},
1814 {'c',"config-file",0,CommandLine::ConfigFile
},
1815 {'o',"option",0,CommandLine::ArbItem
},
1816 {0,"installed","APT::Cache::Installed",0},
1818 CommandLine::Dispatch CmdsA
[] = {{"help",&ShowHelp
},
1820 {"gencaches",&GenCaches
},
1821 {"showsrc",&ShowSrcPackage
},
1823 CommandLine::Dispatch CmdsB
[] = {{"showpkg",&DumpPackage
},
1826 {"dumpavail",&DumpAvail
},
1829 {"depends",&Depends
},
1830 {"rdepends",&RDepends
},
1833 {"show",&ShowPackage
},
1834 {"pkgnames",&ShowPkgNames
},
1835 {"showauto",&ShowAuto
},
1837 {"madison",&Madison
},
1842 // Set up gettext support
1843 setlocale(LC_ALL
,"");
1844 textdomain(PACKAGE
);
1846 // Parse the command line and initialize the package library
1847 CommandLine
CmdL(Args
,_config
);
1848 if (pkgInitConfig(*_config
) == false ||
1849 CmdL
.Parse(argc
,argv
) == false ||
1850 pkgInitSystem(*_config
,_system
) == false)
1852 _error
->DumpErrors();
1856 // See if the help should be shown
1857 if (_config
->FindB("help") == true ||
1858 CmdL
.FileSize() == 0)
1864 // Deal with stdout not being a tty
1865 if (isatty(STDOUT_FILENO
) && _config
->FindI("quiet",0) < 1)
1866 _config
->Set("quiet","1");
1868 if (CmdL
.DispatchArg(CmdsA
,false) == false && _error
->PendingError() == false)
1871 if (_config
->FindB("APT::Cache::Generate",true) == false)
1873 Map
= new MMap(*new FileFd(_config
->FindFile("Dir::Cache::pkgcache"),
1874 FileFd::ReadOnly
),MMap::Public
|MMap::ReadOnly
);
1878 // Open the cache file
1879 SrcList
= new pkgSourceList
;
1880 SrcList
->ReadMainList();
1882 // Generate it and map it
1884 pkgMakeStatusCache(*SrcList
,Prog
,&Map
,true);
1887 if (_error
->PendingError() == false)
1889 pkgCache
Cache(Map
);
1891 if (_error
->PendingError() == false)
1892 CmdL
.DispatchArg(CmdsB
);
1897 // Print any errors or warnings found during parsing
1898 if (_error
->empty() == false)
1900 bool Errors
= _error
->PendingError();
1901 _error
->DumpErrors();
1902 return Errors
== true?100:0;