1 #ifndef APT_PRIVATE_CACHESET_H
2 #define APT_PRIVATE_CACHESET_H
4 #include <apt-pkg/cachefile.h>
5 #include <apt-pkg/cacheset.h>
6 #include <apt-pkg/sptr.h>
11 #include "private-output.h"
15 struct VersionSortDescriptionLocality
17 bool operator () (const pkgCache::VerIterator
&v_lhs
,
18 const pkgCache::VerIterator
&v_rhs
)
20 pkgCache::DescFile
*A
= v_lhs
.TranslatedDescription().FileList();
21 pkgCache::DescFile
*B
= v_rhs
.TranslatedDescription().FileList();
31 if (A
->File
== B
->File
)
32 return A
->Offset
< B
->Offset
;
34 return A
->File
< B
->File
;
38 // sorted by locality which makes iterating much faster
39 typedef APT::VersionContainer
<
40 std::set
<pkgCache::VerIterator
,
41 VersionSortDescriptionLocality
> > LocalitySortedVersionSet
;
45 virtual bool operator () (const pkgCache::PkgIterator
&P
) {
49 // FIXME: add default argument for OpProgress (or overloaded function)
50 bool GetLocalitySortedVersionSet(pkgCacheFile
&CacheFile
,
51 LocalitySortedVersionSet
&output_set
,
53 OpProgress
&progress
);
54 bool GetLocalitySortedVersionSet(pkgCacheFile
&CacheFile
,
55 LocalitySortedVersionSet
&output_set
,
56 OpProgress
&progress
);
59 // CacheSetHelper saving virtual packages /*{{{*/
60 class CacheSetHelperVirtuals
: public APT::CacheSetHelper
{
62 APT::PackageSet virtualPkgs
;
64 virtual pkgCache::VerIterator
canNotFindCandidateVer(pkgCacheFile
&Cache
, pkgCache::PkgIterator
const &Pkg
) {
65 virtualPkgs
.insert(Pkg
);
66 return CacheSetHelper::canNotFindCandidateVer(Cache
, Pkg
);
69 virtual pkgCache::VerIterator
canNotFindNewestVer(pkgCacheFile
&Cache
, pkgCache::PkgIterator
const &Pkg
) {
70 virtualPkgs
.insert(Pkg
);
71 return CacheSetHelper::canNotFindNewestVer(Cache
, Pkg
);
74 virtual void canNotFindAllVer(APT::VersionContainerInterface
* vci
, pkgCacheFile
&Cache
, pkgCache::PkgIterator
const &Pkg
) {
75 virtualPkgs
.insert(Pkg
);
76 CacheSetHelper::canNotFindAllVer(vci
, Cache
, Pkg
);
79 CacheSetHelperVirtuals(bool const ShowErrors
= true, GlobalError::MsgType
const &ErrorType
= GlobalError::NOTICE
) : CacheSetHelper(ShowErrors
, ErrorType
) {}
83 // CacheSetHelperAPTGet - responsible for message telling from the CacheSets/*{{{*/
84 class CacheSetHelperAPTGet
: public APT::CacheSetHelper
{
85 /** \brief stream message should be printed to */
87 /** \brief were things like Task or RegEx used to select packages? */
90 APT::PackageSet virtualPkgs
;
93 std::list
<std::pair
<pkgCache::VerIterator
, std::string
> > selectedByRelease
;
95 CacheSetHelperAPTGet(std::ostream
&out
) : APT::CacheSetHelper(true), out(out
) {
96 explicitlyNamed
= true;
99 virtual void showTaskSelection(pkgCache::PkgIterator
const &Pkg
, std::string
const &pattern
) {
100 ioprintf(out
, _("Note, selecting '%s' for task '%s'\n"),
101 Pkg
.FullName(true).c_str(), pattern
.c_str());
102 explicitlyNamed
= false;
104 virtual void showRegExSelection(pkgCache::PkgIterator
const &Pkg
, std::string
const &pattern
) {
105 ioprintf(out
, _("Note, selecting '%s' for regex '%s'\n"),
106 Pkg
.FullName(true).c_str(), pattern
.c_str());
107 explicitlyNamed
= false;
109 virtual void showSelectedVersion(pkgCache::PkgIterator
const &Pkg
, pkgCache::VerIterator
const Ver
,
110 std::string
const &ver
, bool const verIsRel
) {
111 if (ver
== Ver
.VerStr())
113 selectedByRelease
.push_back(make_pair(Ver
, ver
));
116 bool showVirtualPackageErrors(pkgCacheFile
&Cache
) {
117 if (virtualPkgs
.empty() == true)
119 for (APT::PackageSet::const_iterator Pkg
= virtualPkgs
.begin();
120 Pkg
!= virtualPkgs
.end(); ++Pkg
) {
121 if (Pkg
->ProvidesList
!= 0) {
122 ioprintf(c1out
,_("Package %s is a virtual package provided by:\n"),
123 Pkg
.FullName(true).c_str());
125 pkgCache::PrvIterator I
= Pkg
.ProvidesList();
126 unsigned short provider
= 0;
127 for (; I
.end() == false; ++I
) {
128 pkgCache::PkgIterator Pkg
= I
.OwnerPkg();
130 if (Cache
[Pkg
].CandidateVerIter(Cache
) == I
.OwnerVer()) {
131 c1out
<< " " << Pkg
.FullName(true) << " " << I
.OwnerVer().VerStr();
132 if (Cache
[Pkg
].Install() == true && Cache
[Pkg
].NewInstall() == false)
133 c1out
<< _(" [Installed]");
138 // if we found no candidate which provide this package, show non-candidates
140 for (I
= Pkg
.ProvidesList(); I
.end() == false; ++I
)
141 c1out
<< " " << I
.OwnerPkg().FullName(true) << " " << I
.OwnerVer().VerStr()
142 << _(" [Not candidate version]") << std::endl
;
144 out
<< _("You should explicitly select one to install.") << std::endl
;
147 _("Package %s is not available, but is referred to by another package.\n"
148 "This may mean that the package is missing, has been obsoleted, or\n"
149 "is only available from another source\n"),Pkg
.FullName(true).c_str());
152 std::string VersionsList
;
153 SPtrArray
<bool> Seen
= new bool[Cache
.GetPkgCache()->Head().PackageCount
];
154 memset(Seen
,0,Cache
.GetPkgCache()->Head().PackageCount
*sizeof(*Seen
));
155 for (pkgCache::DepIterator Dep
= Pkg
.RevDependsList();
156 Dep
.end() == false; ++Dep
) {
157 if (Dep
->Type
!= pkgCache::Dep::Replaces
)
159 if (Seen
[Dep
.ParentPkg()->ID
] == true)
161 Seen
[Dep
.ParentPkg()->ID
] = true;
162 List
+= Dep
.ParentPkg().FullName(true) + " ";
163 //VersionsList += std::string(Dep.ParentPkg().CurVersion) + "\n"; ???
165 ShowList(c1out
,_("However the following packages replace it:"),List
,VersionsList
);
172 virtual pkgCache::VerIterator
canNotFindCandidateVer(pkgCacheFile
&Cache
, pkgCache::PkgIterator
const &Pkg
) {
173 APT::VersionSet
const verset
= tryVirtualPackage(Cache
, Pkg
, APT::VersionSet::CANDIDATE
);
174 if (verset
.empty() == false)
175 return *(verset
.begin());
176 else if (ShowError
== true) {
177 _error
->Error(_("Package '%s' has no installation candidate"),Pkg
.FullName(true).c_str());
178 virtualPkgs
.insert(Pkg
);
180 return pkgCache::VerIterator(Cache
, 0);
183 virtual pkgCache::VerIterator
canNotFindNewestVer(pkgCacheFile
&Cache
, pkgCache::PkgIterator
const &Pkg
) {
184 if (Pkg
->ProvidesList
!= 0)
186 APT::VersionSet
const verset
= tryVirtualPackage(Cache
, Pkg
, APT::VersionSet::NEWEST
);
187 if (verset
.empty() == false)
188 return *(verset
.begin());
189 if (ShowError
== true)
190 ioprintf(out
, _("Virtual packages like '%s' can't be removed\n"), Pkg
.FullName(true).c_str());
194 pkgCache::GrpIterator Grp
= Pkg
.Group();
195 pkgCache::PkgIterator P
= Grp
.PackageList();
196 for (; P
.end() != true; P
= Grp
.NextPkg(P
))
200 if (P
->CurrentVer
!= 0) {
201 // TRANSLATORS: Note, this is not an interactive question
202 ioprintf(c1out
,_("Package '%s' is not installed, so not removed. Did you mean '%s'?\n"),
203 Pkg
.FullName(true).c_str(), P
.FullName(true).c_str());
208 ioprintf(c1out
,_("Package '%s' is not installed, so not removed\n"),Pkg
.FullName(true).c_str());
210 return pkgCache::VerIterator(Cache
, 0);
213 APT::VersionSet
tryVirtualPackage(pkgCacheFile
&Cache
, pkgCache::PkgIterator
const &Pkg
,
214 APT::VersionSet::Version
const &select
) {
215 /* This is a pure virtual package and there is a single available
216 candidate providing it. */
217 if (unlikely(Cache
[Pkg
].CandidateVer
!= 0) || Pkg
->ProvidesList
== 0)
218 return APT::VersionSet();
220 pkgCache::PkgIterator Prov
;
221 bool found_one
= false;
222 for (pkgCache::PrvIterator P
= Pkg
.ProvidesList(); P
; ++P
) {
223 pkgCache::VerIterator
const PVer
= P
.OwnerVer();
224 pkgCache::PkgIterator
const PPkg
= PVer
.ParentPkg();
226 /* Ignore versions that are not a candidate. */
227 if (Cache
[PPkg
].CandidateVer
!= PVer
)
230 if (found_one
== false) {
233 } else if (PPkg
!= Prov
) {
234 // same group, so it's a foreign package
235 if (PPkg
->Group
== Prov
->Group
) {
236 // do we already have the requested arch?
237 if (strcmp(Pkg
.Arch(), Prov
.Arch()) == 0 ||
238 strcmp(Prov
.Arch(), "all") == 0 ||
239 unlikely(strcmp(PPkg
.Arch(), Prov
.Arch()) == 0)) // packages have only on candidate, but just to be sure
241 // see which architecture we prefer more and switch to it
242 std::vector
<std::string
> archs
= APT::Configuration::getArchitectures();
243 if (std::find(archs
.begin(), archs
.end(), PPkg
.Arch()) < std::find(archs
.begin(), archs
.end(), Prov
.Arch()))
247 found_one
= false; // we found at least two
252 if (found_one
== true) {
253 ioprintf(out
, _("Note, selecting '%s' instead of '%s'\n"),
254 Prov
.FullName(true).c_str(), Pkg
.FullName(true).c_str());
255 return APT::VersionSet::FromPackage(Cache
, Prov
, select
, *this);
257 return APT::VersionSet();
260 inline bool allPkgNamedExplicitly() const { return explicitlyNamed
; }