]>
Commit | Line | Data |
---|---|---|
ee0167c4 | 1 | // Includes /*{{{*/ |
453b82a3 DK |
2 | #include <config.h> |
3 | ||
b9179170 | 4 | #include <apt-pkg/cachefile.h> |
b9179170 | 5 | #include <apt-pkg/cacheset.h> |
b9179170 | 6 | #include <apt-pkg/cmndline.h> |
453b82a3 | 7 | #include <apt-pkg/error.h> |
b9179170 | 8 | #include <apt-pkg/fileutl.h> |
453b82a3 | 9 | #include <apt-pkg/indexfile.h> |
b9179170 | 10 | #include <apt-pkg/pkgrecords.h> |
b9179170 | 11 | #include <apt-pkg/pkgsystem.h> |
453b82a3 DK |
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> | |
b9179170 | 20 | |
453b82a3 DK |
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> | |
b9179170 | 28 | |
453b82a3 | 29 | #include <apti18n.h> |
ee0167c4 | 30 | /*}}}*/ |
b9179170 MV |
31 | |
32 | namespace APT { | |
33 | namespace Cmd { | |
34 | ||
35 | // DisplayRecord - Displays the complete record for the package /*{{{*/ | |
36 | // --------------------------------------------------------------------- | |
c3ccac92 | 37 | static bool DisplayRecord(pkgCacheFile &CacheFile, pkgCache::VerIterator V, |
453b82a3 | 38 | std::ostream &out) |
b9179170 MV |
39 | { |
40 | pkgCache *Cache = CacheFile.GetPkgCache(); | |
41 | if (unlikely(Cache == NULL)) | |
42 | return false; | |
85d7c0eb MV |
43 | pkgDepCache *depCache = CacheFile.GetDepCache(); |
44 | if (unlikely(depCache == NULL)) | |
45 | return false; | |
b9179170 MV |
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 | ||
1179953a MV |
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 | ||
b9179170 MV |
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); | |
9e51c0b6 MV |
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) | |
17622532 | 82 | strprintf(installed_size, "%sB", SizeToStr(Tags.FindI("Installed-Size")*1024).c_str()); |
9e51c0b6 MV |
83 | else |
84 | installed_size = _("unknown"); | |
85 | std::string package_size; | |
86 | if (Tags.FindI("Size") > 0) | |
17622532 | 87 | strprintf(package_size, "%sB", SizeToStr(Tags.FindI("Size")).c_str()); |
9e51c0b6 MV |
88 | else |
89 | package_size = _("unknown"); | |
90 | ||
85d7c0eb MV |
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 | |
44d9e9f9 | 97 | manual_installed = ""; |
17622532 MV |
98 | |
99 | // FIXME: add verbose that does not do the removal of the tags? | |
88593886 DK |
100 | std::vector<pkgTagSection::Tag> RW; |
101 | // delete, apt-cache show has this info and most users do not care | |
102 | RW.push_back(pkgTagSection::Tag::Remove("MD5sum")); | |
103 | RW.push_back(pkgTagSection::Tag::Remove("SHA1")); | |
104 | RW.push_back(pkgTagSection::Tag::Remove("SHA256")); | |
105 | RW.push_back(pkgTagSection::Tag::Remove("SHA512")); | |
106 | RW.push_back(pkgTagSection::Tag::Remove("Filename")); | |
107 | RW.push_back(pkgTagSection::Tag::Remove("Multi-Arch")); | |
108 | RW.push_back(pkgTagSection::Tag::Remove("Architecture")); | |
109 | RW.push_back(pkgTagSection::Tag::Remove("Conffiles")); | |
110 | // we use the translated description | |
111 | RW.push_back(pkgTagSection::Tag::Remove("Description")); | |
112 | RW.push_back(pkgTagSection::Tag::Remove("Description-md5")); | |
113 | // improve | |
114 | RW.push_back(pkgTagSection::Tag::Rewrite("Installed-Size", installed_size)); | |
115 | RW.push_back(pkgTagSection::Tag::Remove("Size")); | |
116 | RW.push_back(pkgTagSection::Tag::Rewrite("Download-Size", package_size)); | |
117 | // add | |
118 | RW.push_back(pkgTagSection::Tag::Rewrite("APT-Manual-Installed", manual_installed)); | |
119 | RW.push_back(pkgTagSection::Tag::Rewrite("APT-Sources", source_index_file)); | |
85d7c0eb | 120 | |
88593886 DK |
121 | FileFd stdoutfd; |
122 | if (stdoutfd.OpenDescriptor(STDOUT_FILENO, FileFd::WriteOnly, false) == false || | |
123 | Tags.Write(stdoutfd, TFRewritePackageOrder, RW) == false || stdoutfd.Close() == false) | |
9e51c0b6 | 124 | return _error->Error("Internal Error, Unable to parse a package record"); |
b9179170 MV |
125 | |
126 | // write the description | |
127 | pkgRecords Recs(*Cache); | |
2a79257e | 128 | // FIXME: show (optionally) all available translations(?) |
b9179170 MV |
129 | pkgCache::DescIterator Desc = V.TranslatedDescription(); |
130 | if (Desc.end() == false) | |
131 | { | |
132 | pkgRecords::Parser &P = Recs.Lookup(Desc.FileList()); | |
2a79257e | 133 | out << "Description: " << P.LongDesc(); |
b9179170 MV |
134 | } |
135 | ||
136 | // write a final newline (after the description) | |
137 | out << std::endl << std::endl; | |
138 | ||
139 | return true; | |
140 | } | |
141 | /*}}}*/ | |
ee0167c4 | 142 | bool ShowPackage(CommandLine &CmdL) /*{{{*/ |
b9179170 MV |
143 | { |
144 | pkgCacheFile CacheFile; | |
145 | CacheSetHelperVirtuals helper(true, GlobalError::NOTICE); | |
e6f0c9bc DK |
146 | APT::CacheSetHelper::VerSelector const select = _config->FindB("APT::Cache::AllVersions", false) ? |
147 | APT::CacheSetHelper::ALL : APT::CacheSetHelper::CANDIDATE; | |
b9179170 MV |
148 | APT::VersionList const verset = APT::VersionList::FromCommandLine(CacheFile, CmdL.FileList + 1, select, helper); |
149 | for (APT::VersionList::const_iterator Ver = verset.begin(); Ver != verset.end(); ++Ver) | |
150 | if (DisplayRecord(CacheFile, Ver, c1out) == false) | |
151 | return false; | |
152 | ||
e6f0c9bc | 153 | if (select == APT::CacheSetHelper::CANDIDATE) |
06293aa7 | 154 | { |
e6f0c9bc | 155 | APT::VersionList const verset_all = APT::VersionList::FromCommandLine(CacheFile, CmdL.FileList + 1, APT::CacheSetHelper::ALL, helper); |
6298ff8b DK |
156 | int const records = verset_all.size() - verset.size(); |
157 | if (records > 0) | |
158 | _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); | |
06293aa7 MV |
159 | } |
160 | ||
b9179170 MV |
161 | for (APT::PackageSet::const_iterator Pkg = helper.virtualPkgs.begin(); |
162 | Pkg != helper.virtualPkgs.end(); ++Pkg) | |
163 | { | |
164 | c1out << "Package: " << Pkg.FullName(true) << std::endl; | |
ad1d6bfb | 165 | c1out << "State: " << _("not a real package (virtual)") << std::endl; |
b9179170 MV |
166 | // FIXME: show providers, see private-cacheset.h |
167 | // CacheSetHelperAPTGet::showVirtualPackageErrors() | |
168 | } | |
169 | ||
170 | if (verset.empty() == true) | |
171 | { | |
172 | if (helper.virtualPkgs.empty() == true) | |
173 | return _error->Error(_("No packages found")); | |
174 | else | |
175 | _error->Notice(_("No packages found")); | |
176 | } | |
177 | ||
178 | return true; | |
179 | } | |
180 | /*}}}*/ | |
181 | } // namespace Cmd | |
182 | } // namespace APT |