]>
Commit | Line | Data |
---|---|---|
1 | // Includes /*{{{*/ | |
2 | #include <config.h> | |
3 | ||
4 | #include <apt-pkg/cachefile.h> | |
5 | #include <apt-pkg/cacheset.h> | |
6 | #include <apt-pkg/cmndline.h> | |
7 | #include <apt-pkg/error.h> | |
8 | #include <apt-pkg/fileutl.h> | |
9 | #include <apt-pkg/indexfile.h> | |
10 | #include <apt-pkg/pkgrecords.h> | |
11 | #include <apt-pkg/pkgsystem.h> | |
12 | #include <apt-pkg/sourcelist.h> | |
13 | #include <apt-pkg/strutl.h> | |
14 | #include <apt-pkg/tagfile.h> | |
15 | #include <apt-pkg/cacheiterators.h> | |
16 | #include <apt-pkg/configuration.h> | |
17 | #include <apt-pkg/depcache.h> | |
18 | #include <apt-pkg/macros.h> | |
19 | #include <apt-pkg/pkgcache.h> | |
20 | ||
21 | #include <apt-private/private-cacheset.h> | |
22 | #include <apt-private/private-output.h> | |
23 | #include <apt-private/private-show.h> | |
24 | ||
25 | #include <stdio.h> | |
26 | #include <ostream> | |
27 | #include <string> | |
28 | ||
29 | #include <apti18n.h> | |
30 | /*}}}*/ | |
31 | ||
32 | namespace APT { | |
33 | namespace Cmd { | |
34 | ||
35 | // DisplayRecord - Displays the complete record for the package /*{{{*/ | |
36 | // --------------------------------------------------------------------- | |
37 | static bool DisplayRecord(pkgCacheFile &CacheFile, pkgCache::VerIterator V, | |
38 | std::ostream &out) | |
39 | { | |
40 | pkgCache *Cache = CacheFile.GetPkgCache(); | |
41 | if (unlikely(Cache == NULL)) | |
42 | return false; | |
43 | pkgDepCache *depCache = CacheFile.GetDepCache(); | |
44 | if (unlikely(depCache == NULL)) | |
45 | return false; | |
46 | ||
47 | // Find an appropriate file | |
48 | pkgCache::VerFileIterator Vf = V.FileList(); | |
49 | for (; Vf.end() == false; ++Vf) | |
50 | if ((Vf.File()->Flags & pkgCache::Flag::NotSource) == 0) | |
51 | break; | |
52 | if (Vf.end() == true) | |
53 | Vf = V.FileList(); | |
54 | ||
55 | // Check and load the package list file | |
56 | pkgCache::PkgFileIterator I = Vf.File(); | |
57 | if (I.IsOk() == false) | |
58 | return _error->Error(_("Package file %s is out of sync."),I.FileName()); | |
59 | ||
60 | // find matching sources.list metaindex | |
61 | pkgSourceList *SrcList = CacheFile.GetSourceList(); | |
62 | pkgIndexFile *Index; | |
63 | if (SrcList->FindIndex(I, Index) == false && | |
64 | _system->FindIndex(I, Index) == false) | |
65 | return _error->Error("Can not find indexfile for Package %s (%s)", | |
66 | V.ParentPkg().Name(), V.VerStr()); | |
67 | std::string source_index_file = Index->Describe(true); | |
68 | ||
69 | // Read the record | |
70 | FileFd PkgF; | |
71 | if (PkgF.Open(I.FileName(), FileFd::ReadOnly, FileFd::Extension) == false) | |
72 | return false; | |
73 | pkgTagSection Tags; | |
74 | pkgTagFile TagF(&PkgF); | |
75 | ||
76 | if (TagF.Jump(Tags, V.FileList()->Offset) == false) | |
77 | return _error->Error("Internal Error, Unable to parse a package record"); | |
78 | ||
79 | // make size nice | |
80 | std::string installed_size; | |
81 | if (Tags.FindI("Installed-Size") > 0) | |
82 | strprintf(installed_size, "%sB", SizeToStr(Tags.FindI("Installed-Size")*1024).c_str()); | |
83 | else | |
84 | installed_size = _("unknown"); | |
85 | std::string package_size; | |
86 | if (Tags.FindI("Size") > 0) | |
87 | strprintf(package_size, "%sB", SizeToStr(Tags.FindI("Size")).c_str()); | |
88 | else | |
89 | package_size = _("unknown"); | |
90 | ||
91 | pkgDepCache::StateCache &state = (*depCache)[V.ParentPkg()]; | |
92 | bool is_installed = V.ParentPkg().CurrentVer() == V; | |
93 | const char *manual_installed; | |
94 | if (is_installed) | |
95 | manual_installed = !(state.Flags & pkgCache::Flag::Auto) ? "yes" : "no"; | |
96 | else | |
97 | manual_installed = 0; | |
98 | ||
99 | // FIXME: add verbose that does not do the removal of the tags? | |
100 | TFRewriteData RW[] = { | |
101 | // delete, apt-cache show has this info and most users do not care | |
102 | {"MD5sum", NULL, NULL}, | |
103 | {"SHA1", NULL, NULL}, | |
104 | {"SHA256", NULL, NULL}, | |
105 | {"Filename", NULL, NULL}, | |
106 | {"Multi-Arch", NULL, NULL}, | |
107 | {"Architecture", NULL, NULL}, | |
108 | {"Conffiles", NULL, NULL}, | |
109 | // we use the translated description | |
110 | {"Description", NULL, NULL}, | |
111 | {"Description-md5", NULL, NULL}, | |
112 | // improve | |
113 | {"Installed-Size", installed_size.c_str(), NULL}, | |
114 | {"Size", package_size.c_str(), "Download-Size"}, | |
115 | // add | |
116 | {"APT-Manual-Installed", manual_installed, NULL}, | |
117 | {"APT-Sources", source_index_file.c_str(), NULL}, | |
118 | {NULL, NULL, NULL} | |
119 | }; | |
120 | ||
121 | if(TFRewrite(stdout, Tags, NULL, RW) == false) | |
122 | return _error->Error("Internal Error, Unable to parse a package record"); | |
123 | ||
124 | // write the description | |
125 | pkgRecords Recs(*Cache); | |
126 | // FIXME: show (optionally) all available translations(?) | |
127 | pkgCache::DescIterator Desc = V.TranslatedDescription(); | |
128 | if (Desc.end() == false) | |
129 | { | |
130 | pkgRecords::Parser &P = Recs.Lookup(Desc.FileList()); | |
131 | out << "Description: " << P.LongDesc(); | |
132 | } | |
133 | ||
134 | // write a final newline (after the description) | |
135 | out << std::endl << std::endl; | |
136 | ||
137 | return true; | |
138 | } | |
139 | /*}}}*/ | |
140 | bool ShowPackage(CommandLine &CmdL) /*{{{*/ | |
141 | { | |
142 | pkgCacheFile CacheFile; | |
143 | CacheSetHelperVirtuals helper(true, GlobalError::NOTICE); | |
144 | APT::VersionList::Version const select = _config->FindB("APT::Cache::AllVersions", false) ? | |
145 | APT::VersionList::ALL : APT::VersionList::CANDIDATE; | |
146 | APT::VersionList const verset = APT::VersionList::FromCommandLine(CacheFile, CmdL.FileList + 1, select, helper); | |
147 | for (APT::VersionList::const_iterator Ver = verset.begin(); Ver != verset.end(); ++Ver) | |
148 | if (DisplayRecord(CacheFile, Ver, c1out) == false) | |
149 | return false; | |
150 | ||
151 | if (select == APT::VersionList::CANDIDATE) | |
152 | { | |
153 | APT::VersionList const verset_all = APT::VersionList::FromCommandLine(CacheFile, CmdL.FileList + 1, APT::VersionList::ALL, helper); | |
154 | int const records = verset_all.size() - verset.size(); | |
155 | if (records > 0) | |
156 | _error->Notice(P_("There is %i additional record. Please use the '-a' switch to see it", "There are %i additional records. Please use the '-a' switch to see them.", records), records); | |
157 | } | |
158 | ||
159 | for (APT::PackageSet::const_iterator Pkg = helper.virtualPkgs.begin(); | |
160 | Pkg != helper.virtualPkgs.end(); ++Pkg) | |
161 | { | |
162 | c1out << "Package: " << Pkg.FullName(true) << std::endl; | |
163 | c1out << "State: " << _("not a real package (virtual)") << std::endl; | |
164 | // FIXME: show providers, see private-cacheset.h | |
165 | // CacheSetHelperAPTGet::showVirtualPackageErrors() | |
166 | } | |
167 | ||
168 | if (verset.empty() == true) | |
169 | { | |
170 | if (helper.virtualPkgs.empty() == true) | |
171 | return _error->Error(_("No packages found")); | |
172 | else | |
173 | _error->Notice(_("No packages found")); | |
174 | } | |
175 | ||
176 | return true; | |
177 | } | |
178 | /*}}}*/ | |
179 | } // namespace Cmd | |
180 | } // namespace APT |